Commit | Line | Data |
---|---|---|
2934d1c9 MH |
1 | #include <stdio.h> |
2 | #include <ctype.h> | |
3 | #include "ansidecl.h" | |
4 | #include "opcode/d10v.h" | |
5 | ||
6 | /* FIXME: host defines */ | |
7 | typedef unsigned char uint8; | |
8 | typedef unsigned short uint16; | |
9 | typedef unsigned int uint32; | |
10 | typedef signed char int8; | |
11 | typedef signed short int16; | |
12 | typedef signed int int32; | |
13 | typedef signed long long int64; | |
14 | ||
15 | /* FIXME: D10V defines */ | |
16 | typedef uint16 reg_t; | |
17 | ||
18 | struct simops | |
19 | { | |
20 | long opcode; | |
21 | long mask; | |
22 | int format; | |
23 | int cycles; | |
24 | int unit; | |
25 | int exec_type; | |
26 | void (*func)(); | |
27 | int numops; | |
28 | int operands[9]; | |
29 | }; | |
30 | ||
31 | struct _state | |
32 | { | |
33 | reg_t regs[16]; /* general-purpose registers */ | |
34 | reg_t cregs[15]; /* control registers */ | |
35 | int64 a[2]; /* accumulators */ | |
36 | uint8 SM; | |
37 | uint8 EA; | |
38 | uint8 DB; | |
39 | uint8 IE; | |
40 | uint8 RP; | |
41 | uint8 MD; | |
42 | uint8 FX; | |
43 | uint8 ST; | |
44 | uint8 F0; | |
45 | uint8 F1; | |
46 | uint8 C; | |
47 | uint8 exe; | |
48 | uint8 *imem; | |
49 | uint8 *dmem; | |
50 | } State; | |
51 | ||
52 | extern uint16 OP[4]; | |
53 | extern struct simops Simops[]; | |
54 | ||
55 | #define PC (State.cregs[2]) | |
56 | #define PSW (State.cregs[0]) | |
57 | #define BPSW (State.cregs[1]) | |
58 | #define BPC (State.cregs[3]) | |
59 | #define RPT_C (State.cregs[7]) | |
60 | #define RPT_S (State.cregs[8]) | |
61 | #define RPT_E (State.cregs[9]) | |
62 | #define MOD_S (State.cregs[10]) | |
63 | #define MOD_E (State.cregs[11]) | |
64 | #define IBA (State.cregs[14]) | |
65 | ||
66 | #define SEXT3(x) ((((x)&0x7)^(~3))+4) | |
67 | ||
68 | /* sign-extend a 4-bit number */ | |
69 | #define SEXT4(x) ((((x)&0xf)^(~7))+8) | |
70 | ||
71 | /* sign-extend an 8-bit number */ | |
72 | #define SEXT8(x) ((((x)&0xff)^(~0x7f))+0x80) | |
73 | ||
74 | /* sign-extend a 16-bit number */ | |
75 | #define SEXT16(x) ((((x)&0xffff)^(~0x7fff))+0x8000) | |
76 | ||
77 | #define BIT40 0x8000000000LL | |
78 | #define BIT44 0x80000000000LL | |
79 | #define MAX32 0x7fffffffLL | |
80 | #define MIN32 0xff80000000LL | |
81 | #define MASK32 0xffffffffLL | |
82 | #define MASK40 0xffffffffffLL | |
83 | #define MASK44 0xfffffffffffLL | |
84 | ||
85 | ||
86 | #define RB(x) (*((uint8 *)((x)+State.imem))) | |
87 | ||
88 | #ifdef WORDS_BIGENDIAN | |
89 | ||
90 | #define RW(x) (*((uint16 *)((x)+State.imem))) | |
91 | #define RLW(x) (*((uint32 *)((x)+State.imem))) | |
92 | #define SW(addr,data) RW(addr)=data | |
93 | ||
94 | #else | |
95 | ||
96 | uint32 get_longword_swap PARAMS ((uint16 x)); | |
97 | uint16 get_word_swap PARAMS ((uint16 x)); | |
98 | void write_word_swap PARAMS ((uint16 addr, uint16 data)); | |
99 | ||
100 | #define SW(addr,data) write_word_swap(addr,data) | |
101 | #define RW(x) get_word_swap(x) | |
102 | #define RLW(x) get_longword_swap(x) | |
103 | ||
104 | #endif /* not WORDS_BIGENDIAN */ |