#ifndef __cc_def__
# define __cc_def__
#include "global.h"

#    include <strings.h>
#    include <setjmp.h>

#ifdef _ns32sf641_
#    include  <asis.h>
#else
#    include <ns32000.h>
#endif

#define NULL         0
#define	MAX_INT      /*NOSTRICT*/ ((int) 0x7fffffff)
#define	MIN_INT      /*NOSTRICT*/ ((int) 0x80000000)
#define MAX_WORD     /*NOSTRICT*/ ((int) 0x00007fff)
#define MIN_WORD     /*NOSTRICT*/ ((int) 0xffff8000)
#define MAX_BYTE     /*NOSTRICT*/ ((int) 0x0000007f)
#define MIN_BYTE     /*NOSTRICT*/ ((int) 0xffffff80)
#define	MAX_UINT     /*NOSTRICT*/ ((unsigned) 0xffffffff)
#define	MAX_UWORD    /*NOSTRICT*/ ((unsigned) 0x0000ffff)
#define	MAX_UBYTE    /*NOSTRICT*/ ((unsigned) 0x000000ff)


#define CR           '\r'
#define LF           '\n'
#define TAB          '\t'
#define CTRL_L       '\014'
#define CTRL_B       '\002'
#define CTRL_Q       '\021'
#define CTRL_S       '\023'
#define CTRL_H       '\010'


#define MIN(x,y)	    ((x) < (y) ? (x) : (y))
#define MAX(x,y)	    ((x) > (y) ? (x) : (y))
#define ORD(x)             /*NOSTRICT*/ ((int) (x))
#define BIT_ON(bit, reg)   ((boolean) (((reg) & (unsigned) (1 << (bit))) != 0))
#define BIT_OFF(bit, reg)  ((boolean) (((reg) & (unsigned) (1 << (bit))) == 0))
#define SET_BIT(bit, reg)      ((reg) |= (unsigned)   (1 << (bit)))
#define CLEAR_BIT(bit, reg)    ((reg) &= (unsigned) (~(1 << (bit))))

#define IS_PATERN_SET(patern,   reg)      ((patern) == (reg & (patern)))
#define IS_PATERN_CLEAR(patern,   reg)    ( !(reg & (patern)))
#define PATERN_SET(patern,   reg)      (reg    |= (patern))
#define PATERN_CLEAR(patern,   reg)    (reg    &= ~(patern))

#define STRINGS_EQUAL(s1, s2)  ((boolean) (strcmp((s1), (s2)) == 0))
#define STRINGS_N_EQUAL(s1, s2, n)  ((boolean) (strncmp((s1), (s2), (n)) == 0))
#define CONTENTS_OF(addr)      (* ((unsigned *) (addr)))
#define EMPTY_STRING(str)      ((boolean) (((str) == (char *) NULL) OR \
                                           ((str)[0] == '\0')))
#ifndef DELAY
#define DELAY(m) {volatile int j; for (j = m; j > 0; j-- );}
#endif

#define CUR_PORT  -1
#define LAN_PORT  99

#   if ((CORE_TYPE == SF) AND NOT (defined(SIM_32K)))
#	define BPT_TYPE long
#	define BPT_INST_SIZE 'D'
#	define SVC_INST_SIZE 4
#	define BPT_CMD	0xffefa1e8	/* Opcode of BPT instruction */
#   else 
#	define BPT_TYPE byte
#	define BPT_INST_SIZE 'B'
#	define SVC_INST_SIZE 1
#	define BPT_CMD   0xf2		/* Opcode of BPT instruction */

#   endif
#   ifdef DEBUG
#	define const 
#   endif
typedef const  char   msg[];
extern msg reset_message__;
extern msg ether_reset_message__;
extern msg vr_message__;
extern msg ready_prompt__;
extern msg cont_prompt__;
extern msg nmi_message__;
extern msg cxp_return__;
extern msg program_end__;
extern msg step_ended__;
extern msg e_syntax__;
extern msg e_bpt_undefined__;
extern msg e_busy__;
extern msg e_bad_trans_mode__;
extern msg e_load_crc__;
extern msg e_multiple_cxp__;
extern msg e_search_failed__;
extern msg e_verify__;
extern msg e_wpt_undefined__;
extern msg e_abort__;
extern msg e_non_cmon_bpt__;
extern msg e_dbg__;
extern msg e_dvz__;
extern msg e_flg__;
extern msg e_fpu__;
extern msg e_ill__;
extern msg e_nbe__;
extern msg e_nmi__;
extern msg e_nvi__;
extern msg e_non_valid_page__;
extern msg e_ovf__;
extern msg e_pending__;
extern msg e_pol_timeout__;
extern msg e_pol_invalid_len__;
extern msg e_pol_short_cmd__;
extern msg e_pol_invalid_crc__;
extern msg e_pol_crc_error__;
extern msg e_pol_cr_missing__;
extern msg e_protect__;
extern msg e_rbe__;
extern msg e_rts__;
extern msg e_unknown_svc__;
extern msg e_non_cmon_trace__;
extern msg e_und__;
extern msg e_user__;
extern msg e_vio__;
extern msg e_con__;
extern msg e_dspm_err__;

#define boolean unsigned char

# ifndef FALSE
#  define FALSE 0
#  define TRUE 1
# endif


typedef enum {
        AUTOMATIC,
        T_PTB0,
        T_PTB1,
        PHYSICAL
} trans_mode_type;


typedef enum {
        TRANSP,
        STAND_ASIDE,
        STAND_ALONE
} op_mode_type;


typedef enum {
        UNKNOWN_ABT,
        INVALID_PTE_ABT,
        PROT_VIOLATION_ABT,
	HW_BPT_ABT
} abort_type;


typedef struct {
        char     flag_str[3];
        unsigned flag;
        boolean  simple;
        unsigned value;
} flag_info_type;

typedef flag_info_type   flag_struct_type[];

typedef struct {
        boolean   specified;
        int       value;
} flag_entry_type;

typedef flag_entry_type    flag_array_type[];

/*
 * Uart divisor table entry
 */
typedef struct {
    unsigned short baud, divisor;
} uart_table_entry;


typedef char s_str[S_SIZE];
typedef char l_str[L_SIZE];
typedef char vl_str[VL_SIZE];
typedef char *str;
typedef unsigned char  byte;
typedef unsigned short word;
typedef unsigned  double_word;
typedef unsigned  quad_word[2];
typedef byte	       *address;
typedef union { char b; short w; int d; int q[2]; } binval;

extern	byte end_cmon_stack__[C_IS_SIZE];
extern	byte end_interrupt_stack__[IS_SIZE];
extern unsigned    cmon_sp__, cmon_fp__, cmon_sb__, cmon_mod__;
extern unsigned    cmon_normal_intbase__, cmon_de_intbase__;
extern trans_mode_type  trans_mode__;
extern const uart_table_entry uart_table[];
extern pu_pattern__;
extern l_str  response__;
extern jmp_buf  return_env__;

#   define ERROR(str)   strcpy(response__, str); \
                        longjmp(return_env__, 1);

typedef struct {
        char        name[6];
	char	    size;
	unsigned    *save_addr;
        void        (*read_func)();
        void        (*write_func)();
} reg_desc;

extern reg_desc R0__;
extern unsigned int save_R0__;
extern reg_desc R1__;
extern unsigned int save_R1__;
extern reg_desc R2__;
extern unsigned int save_R2__;
extern reg_desc R3__;
extern unsigned int save_R3__;
extern reg_desc R4__;
extern unsigned int save_R4__;
extern reg_desc R5__;
extern unsigned int save_R5__;
extern reg_desc R6__;
extern unsigned int save_R6__;
extern reg_desc R7__;
extern unsigned int save_R7__;
extern reg_desc R8__;
extern unsigned int save_R8__;
extern reg_desc R9__;
extern unsigned int save_R9__;
extern reg_desc R10__;
extern unsigned int save_R10__;
extern reg_desc R11__;
extern unsigned int save_R11__;
extern reg_desc R12__;
extern unsigned int save_R12__;
extern reg_desc R13__;
extern unsigned int save_R13__;
extern reg_desc R14__;
extern unsigned int save_R14__;
extern reg_desc R15__;
extern unsigned int save_R15__;
extern reg_desc R16__;
extern unsigned int save_R16__;
extern reg_desc R17__;
extern unsigned int save_R17__;
extern reg_desc R18__;
extern unsigned int save_R18__;
extern reg_desc R19__;
extern unsigned int save_R19__;
extern reg_desc R20__;
extern unsigned int save_R20__;
extern reg_desc R21__;
extern unsigned int save_R21__;
extern reg_desc R22__;
extern unsigned int save_R22__;
extern reg_desc R23__;
extern unsigned int save_R23__;
extern reg_desc R24__;
extern unsigned int save_R24__;
extern reg_desc R25__;
extern unsigned int save_R25__;
extern reg_desc R26__;
extern unsigned int save_R26__;
extern reg_desc R27__;
extern unsigned int save_R27__;
extern reg_desc R28__;
extern unsigned int save_R28__;
extern reg_desc R29__;
extern unsigned int save_R29__;
extern reg_desc R30__;
extern unsigned int save_R30__;
extern reg_desc PC__;
extern unsigned int save_PC__;
extern reg_desc IN__;
extern reg_desc SP__;
extern unsigned int save_SP__;
extern reg_desc PSR__;
extern unsigned int save_PSR__;
extern reg_desc IS__;
extern unsigned int save_IS__;
extern reg_desc SP__;
extern reg_desc PSR__;
extern unsigned int save_PSR__;
extern reg_desc US__;
extern unsigned int save_US__;
extern reg_desc SB__;
extern unsigned int save_SB__;
extern reg_desc FP__;
extern unsigned int save_FP__;
extern reg_desc IS__;
extern unsigned int save_IS__;
extern reg_desc MO__;
extern unsigned int save_MO__;
extern reg_desc CFG__;
extern unsigned int save_CFG__;
extern reg_desc CFG__;
extern unsigned int save_CFG__;
extern reg_desc CFG__;
extern unsigned int save_CFG__;
extern reg_desc DC__;
extern reg_desc DS__;
extern reg_desc CA__;
extern reg_desc BR__;
extern reg_desc DC__;
extern reg_desc DS__;
extern reg_desc CA__;
extern reg_desc AM__;
extern reg_desc BPC0__;
extern reg_desc BPC1__;
extern reg_desc DES__;
extern reg_desc DD__;
extern reg_desc DC__;
extern reg_desc DS__;
extern reg_desc CA__;
extern reg_desc AM__;
extern reg_desc BPC0__;
extern reg_desc BPC1__;
extern reg_desc DES__;
extern reg_desc DD__;
extern reg_desc F0__;
extern unsigned int save_F0__;
extern reg_desc F1__;
extern unsigned int save_F1__;
extern reg_desc F2__;
extern unsigned int save_F2__;
extern reg_desc F3__;
extern unsigned int save_F3__;
extern reg_desc F4__;
extern unsigned int save_F4__;
extern reg_desc F5__;
extern unsigned int save_F5__;
extern reg_desc F6__;
extern unsigned int save_F6__;
extern reg_desc F7__;
extern unsigned int save_F7__;
extern reg_desc F8__;
extern unsigned int save_F8__;
extern reg_desc F9__;
extern unsigned int save_F9__;
extern reg_desc F10__;
extern unsigned int save_F10__;
extern reg_desc F11__;
extern unsigned int save_F11__;
extern reg_desc F12__;
extern unsigned int save_F12__;
extern reg_desc F13__;
extern unsigned int save_F13__;
extern reg_desc F14__;
extern unsigned int save_F14__;
extern reg_desc F15__;
extern unsigned int save_F15__;
extern reg_desc F16__;
extern unsigned int save_F16__;
extern reg_desc F17__;
extern unsigned int save_F17__;
extern reg_desc F18__;
extern unsigned int save_F18__;
extern reg_desc F19__;
extern unsigned int save_F19__;
extern reg_desc F20__;
extern unsigned int save_F20__;
extern reg_desc F21__;
extern unsigned int save_F21__;
extern reg_desc F22__;
extern unsigned int save_F22__;
extern reg_desc F23__;
extern unsigned int save_F23__;
extern reg_desc F24__;
extern unsigned int save_F24__;
extern reg_desc F25__;
extern unsigned int save_F25__;
extern reg_desc F26__;
extern unsigned int save_F26__;
extern reg_desc F27__;
extern unsigned int save_F27__;
extern reg_desc F28__;
extern unsigned int save_F28__;
extern reg_desc F29__;
extern unsigned int save_F29__;
extern reg_desc F30__;
extern unsigned int save_F30__;
extern reg_desc F31__;
extern unsigned int save_F31__;
extern reg_desc L0__;
extern reg_desc L2__;
extern reg_desc L4__;
extern reg_desc L6__;
extern reg_desc L8__;
extern reg_desc L10__;
extern reg_desc L12__;
extern reg_desc L14__;
extern reg_desc L16__;
extern reg_desc L18__;
extern reg_desc L20__;
extern reg_desc L22__;
extern reg_desc L24__;
extern reg_desc L26__;
extern reg_desc L28__;
extern reg_desc L30__;
extern reg_desc FS__;
extern unsigned int save_FS__;
extern reg_desc FTRL__;
extern unsigned int save_FTRL__;
extern reg_desc FTRH__;
extern unsigned int save_FTRH__;
extern reg_desc F0__;
extern reg_desc F1__;
extern reg_desc F2__;
extern reg_desc F3__;
extern reg_desc F4__;
extern reg_desc F5__;
extern reg_desc F6__;
extern reg_desc F7__;
extern reg_desc L0__;
extern reg_desc L1__;
extern reg_desc L2__;
extern reg_desc L3__;
extern reg_desc L4__;
extern reg_desc L5__;
extern reg_desc L6__;
extern reg_desc L7__;
extern reg_desc FS__;
extern const reg_desc *reg_tab__[];
#endif
