//	bfe2 - globals
//	Copyright (c) 1999-2003 Brand Huntsman and Lee Salzman
//


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <gtk/gtk.h>


#define RC_PATH ".bferc"
#define HISTORY_PATH "__bfe.log__"

#define MAX_BREAKPOINTS 30
#define MAX_WATCHPOINTS 30

// default preferences
#define DEF_HISLEN 50
#define DEF_STACKABOVE 8
#define DEF_STACKBELOW 4
#define DEF_STEPLOCK 2
#define DEF_NEXTLOCK 2
#define DEF_RELOAD_BP 1
#define DEF_RELOAD_WP 1
#define DEF_PAGE_TAB 0

// text entry and button height
#define WIDGET_HEIGHT 20

// cpu state widgets
#define WLEN_REGISTER 85
#define WLEN_SEGMENT 110
#define WLEN_DTABLE 140
#define STACK_LIST_W 150
#define STACK_LIST_H 140
#define FLAGS_LIST_W 160
#define FLAGS_LIST_H 210

// string lengths
#define LEN_RCPATH 200
#define LEN_BUFFER 200
#define LEN_NUMBER 16
#define LEN_ADDRESS 18
#define LEN_INSTRUCTION 128
#define LEN_STRUCT_NAME 128
#define LEN_FIELD_NAME 128


#ifndef uint32
	typedef unsigned int uint32;
#endif
#ifndef int32
	typedef int int32;
#endif
#ifndef uint64
	typedef unsigned long long uint64;
#endif
#ifndef int64
	typedef long long int64;
#endif


//
// main.c
//

extern GtkWidget *bochs_button, *refreshall_button, *notebook;
extern uint show_state;


//
// misc.c
//


//
// gtk.c
//

typedef enum { HORIZONTAL, VERTICAL } e_orientation;
struct s_bgroup_button {
	GtkWidget *widget;
	guint id;
};
typedef struct s_bgroup {
	void (*callback)( struct s_bgroup *group );
	uint current;
	uint nr_buttons;
	struct s_bgroup_button button[1];
} s_bgroup;


//
// bochs.c
//

extern FILE *writepipe, *readpipe;
extern uint bochs_running, bochs_offline, p_step;
extern int bochs_pid;


//
// ctrl.c
//

extern GtkWidget *physical_text, *virtual_text, *instruction_text;
extern uint32 i_virtual_segment, i_virtual_offset, i_physical_address;
extern char i_bytes[LEN_INSTRUCTION], i_description[LEN_INSTRUCTION];


//
// state.c
//

typedef struct s_segment {
	uint32 segment;
	uint32 descriptor[2];
	uint valid;
} s_segment;
typedef struct s_table {
	uint32 base;
	uint32 limit;
} s_table;
typedef struct s_cpu {
	uint32 eax;
	uint32 ebx;
	uint32 ecx;
	uint32 edx;
	uint32 ebp;
	uint32 esi;
	uint32 edi;
	uint32 esp;
	uint32 eflags;
	uint32 eip;
	struct s_segment cs;
	struct s_segment ss;
	struct s_segment ds;
	struct s_segment es;
	struct s_segment fs;
	struct s_segment gs;
	struct s_segment ldtr;
	struct s_segment tr;
	struct s_table gdtr;
	struct s_table idtr;
	uint32 dr0;
	uint32 dr1;
	uint32 dr2;
	uint32 dr3;
	uint32 dr4;
	uint32 dr5;
	uint32 dr6;
	uint32 dr7;
	uint32 tr3;
	uint32 tr4;
	uint32 tr5;
	uint32 tr6;
	uint32 tr7;
	uint32 cr0;
	uint32 cr1;
	uint32 cr2;
	uint32 cr3;
	uint32 cr4;
	uint inhibit;
} s_cpu;

extern struct s_cpu cpu;


//
// breakpoints.c
//

enum { BP_PHYSICAL, BP_LINEAR, BP_VIRTUAL };		// toggle group
typedef enum { BP_UPDATE, BP_REDRAW } e_bp_mode;
typedef struct s_breakpoint {
	uint number;
	uint type;
	uint enabled;
	uint32 segment;
	uint32 offset;
} s_breakpoint;

extern struct s_breakpoint breakpoints[MAX_BREAKPOINTS];


//
// watchpoints.c
//

enum { WP_READ, WP_WRITE };				// toggle group
typedef enum { WP_UPDATE, WP_REDRAW } e_wp_mode;
typedef struct s_watchpoint {
	uint type;
	uint enabled;
	uint32 offset;
	uint32 value;
	uint value_size;
} s_watchpoint;

extern struct s_watchpoint watchpoints[MAX_WATCHPOINTS];


//
// memory.c
//

enum { MT_PHYSICAL, MT_LINEAR };			// toggle group
enum { MS_BYTE, MS_WORD, MS_DWORD, MS_QWORD };		// toggle group
enum { MF_HEX, MF_DEC, MF_UDEC, MF_BIN, MF_OCT };	// toggle group
typedef struct s_memwin {
	GtkWidget *window, *close_button, *refresh_button;
	GtkCList *list;
	guint id;

	uint32 base;
	uint nr_units;
	uint unit_type;
	uint unit_size;
	uint unit_format;

	struct s_memwin *prev;
	struct s_memwin *next;
} s_memwin;

extern struct s_memwin *memwin_head, *memwin_tail;


//
// structures.c
//

typedef struct s_field {
	char name[LEN_FIELD_NAME];
	uint size;

	struct s_field *prev;
	struct s_field *next;
} s_field;
typedef struct s_structwin {
	GtkWidget *window, *close_button, *refresh_button;
	GtkWidget *start_text, *total_text;
	GtkCList *list;

	char name[LEN_STRUCT_NAME];
	uint32 base;
	uint nr_elts;
	uint nr_fields;
	struct s_field *fields_head;
	struct s_field *fields_tail;

	struct s_structwin *prev;
	struct s_structwin *next;
} s_structwin;

extern struct s_structwin *structwin_head, *structwin_tail;


//
// prefs.c
//

extern uint h_maxlen, stack_above, stack_below, tracing, steplock_time, nextlock_time;
extern uint reload_breakpoints, reload_watchpoints;


//
// history.c
//
