Debian Codegraph @

src/cpu/core_simple.cpp

raw
1 /*
2 * Copyright (C) 2002-2010 The DOSBox Team
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 #include <stdio.h>
20
21 #include "dosbox.h"
22 #include "mem.h"
23 #include "cpu.h"
24 #include "lazyflags.h"
25 #include "inout.h"
26 #include "callback.h"
27 #include "pic.h"
28 #include "fpu.h"
29
30 #if C_DEBUG
31 #include "debug.h"
32 #endif
33
34 #include "paging.h"
35 #define SegBase(c) SegPhys(c)
36 #define LoadMb(off) mem_readb(off)
37 #define LoadMw(off) mem_readw(off)
38 #define LoadMd(off) mem_readd(off)
39
40 #define SaveMb(off,val) mem_writeb(off,val)
41 #define SaveMw(off,val) mem_writew(off,val)
42 #define SaveMd(off,val) mem_writed(off,val)
43
44 extern Bitu cycle_count;
45
46 #if C_FPU
47 #define CPU_FPU 1 //Enable FPU escape instructions
48 #endif
49
50 #define CPU_PIC_CHECK 1
51 #define CPU_TRAP_CHECK 1
52
53 #define OPCODE_NONE 0x000
54 #define OPCODE_0F 0x100
55 #define OPCODE_SIZE 0x200
56
57 #define PREFIX_ADDR 0x1
58 #define PREFIX_REP 0x2
59
60 #define TEST_PREFIX_ADDR (core.prefixes & PREFIX_ADDR)
61 #define TEST_PREFIX_REP (core.prefixes & PREFIX_REP)
62
63 #define DO_PREFIX_SEG(_SEG) \
64 BaseDS=SegBase(_SEG); \
65 BaseSS=SegBase(_SEG); \
66 core.base_val_ds=_SEG; \
67 goto restart_opcode;
68
69 #define DO_PREFIX_ADDR() \
70 core.prefixes=(core.prefixes & ~PREFIX_ADDR) | \
71 (cpu.code.big ^ PREFIX_ADDR); \
72 core.ea_table=&EATable[(core.prefixes&1) * 256]; \
73 goto restart_opcode;
74
75 #define DO_PREFIX_REP(_ZERO) \
76 core.prefixes|=PREFIX_REP; \
77 core.rep_zero=_ZERO; \
78 goto restart_opcode;
79
80 typedef PhysPt (*GetEAHandler)(void);
81
82 static const Bit32u AddrMaskTable[2]={0x0000ffff,0xffffffff};
83
84 static struct {
85 Bitu opcode_index;
86 #if defined (_MSC_VER)
87 volatile HostPt cseip;
88 #else
89 HostPt cseip;
90 #endif
91 PhysPt base_ds,base_ss;
92 SegNames base_val_ds;
93 bool rep_zero;
94 Bitu prefixes;
95 GetEAHandler * ea_table;
96 } core;
97
98 #define GETIP (core.cseip-SegBase(cs)-MemBase)
99 #define SAVEIP reg_eip=GETIP;
100 #define LOADIP core.cseip=(MemBase+SegBase(cs)+reg_eip);
101
102 #define SegBase(c) SegPhys(c)
103 #define BaseDS core.base_ds
104 #define BaseSS core.base_ss
105
106 static INLINE Bit8u Fetchb() {
107 Bit8u temp=host_readb(core.cseip);
108 core.cseip+=1;
109 return temp;
110 }
111
112 static INLINE Bit16u Fetchw() {
113 Bit16u temp=host_readw(core.cseip);
114 core.cseip+=2;
115 return temp;
116 }
117 static INLINE Bit32u Fetchd() {
118 Bit32u temp=host_readd(core.cseip);
119 core.cseip+=4;
120 return temp;
121 }
122
123 #define Push_16 CPU_Push16
124 #define Push_32 CPU_Push32
125 #define Pop_16 CPU_Pop16
126 #define Pop_32 CPU_Pop32
127
128 #include "instructions.h"
129 #include "core_normal/support.h"
130 #include "core_normal/string.h"
131
132
133 #define EALookupTable (core.ea_table)
134
135 Bits CPU_Core_Simple_Run(void) {
136 while (CPU_Cycles-->0) {
137 LOADIP;
138 core.opcode_index=cpu.code.big*0x200;
139 core.prefixes=cpu.code.big;
140 core.ea_table=&EATable[cpu.code.big*256];
141 BaseDS=SegBase(ds);
142 BaseSS=SegBase(ss);
143 core.base_val_ds=ds;
144 #if C_DEBUG
145 #if C_HEAVY_DEBUG
146 if (DEBUG_HeavyIsBreakpoint()) {
147 FillFlags();
148 return debugCallback;
149 };
150 #endif
151 cycle_count++;
152 #endif
153 restart_opcode:
154 switch (core.opcode_index+Fetchb()) {
155
156 #include "core_normal/prefix_none.h"
157 #include "core_normal/prefix_0f.h"
158 #include "core_normal/prefix_66.h"
159 #include "core_normal/prefix_66_0f.h"
160 default:
161 illegal_opcode:
162 #if C_DEBUG
163 {
164 Bitu len=(GETIP-reg_eip);
165 LOADIP;
166 if (len>16) len=16;
167 char tempcode[16*2+1];char * writecode=tempcode;
168 for (;len>0;len--) {
169 // sprintf(writecode,"%X",mem_readb(core.cseip++));
170 writecode+=2;
171 }
172 LOG(LOG_CPU,LOG_NORMAL)("Illegal/Unhandled opcode %s",tempcode);
173 }
174 #endif
175 CPU_Exception(6,0);
176 continue;
177 }
178 SAVEIP;
179 }
180 FillFlags();
181 return CBRET_NONE;
182 decode_end:
183 SAVEIP;
184 FillFlags();
185 return CBRET_NONE;
186 }
187
188 // not really used
189 Bits CPU_Core_Simple_Trap_Run(void) {
190 Bits oldCycles = CPU_Cycles;
191 CPU_Cycles = 1;
192 cpu.trap_skip = false;
193
194 Bits ret=CPU_Core_Normal_Run();
195 if (!cpu.trap_skip) CPU_HW_Interrupt(1);
196 CPU_Cycles = oldCycles-1;
197 cpudecoder = &CPU_Core_Simple_Run;
198
199 return ret;
200 }
201
202
203
204 void CPU_Core_Simple_Init(void) {
205
206 }