Debian Codegraph @

src/cpu/core_normal.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 #include "paging.h"
30
31 #if C_DEBUG
32 #include "debug.h"
33 #endif
34
35 #if (!C_CORE_INLINE)
36 #define LoadMb(off) mem_readb(off)
37 #define LoadMw(off) mem_readw(off)
38 #define LoadMd(off) mem_readd(off)
39 #define SaveMb(off,val) mem_writeb(off,val)
40 #define SaveMw(off,val) mem_writew(off,val)
41 #define SaveMd(off,val) mem_writed(off,val)
42 #else
43 #include "paging.h"
44 #define LoadMb(off) mem_readb_inline(off)
45 #define LoadMw(off) mem_readw_inline(off)
46 #define LoadMd(off) mem_readd_inline(off)
47 #define SaveMb(off,val) mem_writeb_inline(off,val)
48 #define SaveMw(off,val) mem_writew_inline(off,val)
49 #define SaveMd(off,val) mem_writed_inline(off,val)
50 #endif
51
52 extern Bitu cycle_count;
53
54 #if C_FPU
55 #define CPU_FPU 1 //Enable FPU escape instructions
56 #endif
57
58 #define CPU_PIC_CHECK 1
59 #define CPU_TRAP_CHECK 1
60
61 #define OPCODE_NONE 0x000
62 #define OPCODE_0F 0x100
63 #define OPCODE_SIZE 0x200
64
65 #define PREFIX_ADDR 0x1
66 #define PREFIX_REP 0x2
67
68 #define TEST_PREFIX_ADDR (core.prefixes & PREFIX_ADDR)
69 #define TEST_PREFIX_REP (core.prefixes & PREFIX_REP)
70
71 #define DO_PREFIX_SEG(_SEG) \
72 BaseDS=SegBase(_SEG); \
73 BaseSS=SegBase(_SEG); \
74 core.base_val_ds=_SEG; \
75 goto restart_opcode;
76
77 #define DO_PREFIX_ADDR() \
78 core.prefixes=(core.prefixes & ~PREFIX_ADDR) | \
79 (cpu.code.big ^ PREFIX_ADDR); \
80 core.ea_table=&EATable[(core.prefixes&1) * 256]; \
81 goto restart_opcode;
82
83 #define DO_PREFIX_REP(_ZERO) \
84 core.prefixes|=PREFIX_REP; \
85 core.rep_zero=_ZERO; \
86 goto restart_opcode;
87
88 typedef PhysPt (*GetEAHandler)(void);
89
90 static const Bit32u AddrMaskTable[2]={0x0000ffff,0xffffffff};
91
92 static struct {
93 Bitu opcode_index;
94 PhysPt cseip;
95 PhysPt base_ds,base_ss;
96 SegNames base_val_ds;
97 bool rep_zero;
98 Bitu prefixes;
99 GetEAHandler * ea_table;
100 } core;
101
102 #define GETIP (core.cseip-SegBase(cs))
103 #define SAVEIP reg_eip=GETIP;
104 #define LOADIP core.cseip=(SegBase(cs)+reg_eip);
105
106 #define SegBase(c) SegPhys(c)
107 #define BaseDS core.base_ds
108 #define BaseSS core.base_ss
109
110 static INLINE Bit8u Fetchb() {
111 Bit8u temp=LoadMb(core.cseip);
112 core.cseip+=1;
113 return temp;
114 }
115
116 static INLINE Bit16u Fetchw() {
117 Bit16u temp=LoadMw(core.cseip);
118 core.cseip+=2;
119 return temp;
120 }
121 static INLINE Bit32u Fetchd() {
122 Bit32u temp=LoadMd(core.cseip);
123 core.cseip+=4;
124 return temp;
125 }
126
127 #define Push_16 CPU_Push16
128 #define Push_32 CPU_Push32
129 #define Pop_16 CPU_Pop16
130 #define Pop_32 CPU_Pop32
131
132 #include "instructions.h"
133 #include "core_normal/support.h"
134 #include "core_normal/string.h"
135
136
137 #define EALookupTable (core.ea_table)
138
139 Bits CPU_Core_Normal_Run(void) {
140 while (CPU_Cycles-->0) {
141 LOADIP;
142 core.opcode_index=cpu.code.big*0x200;
143 core.prefixes=cpu.code.big;
144 core.ea_table=&EATable[cpu.code.big*256];
145 BaseDS=SegBase(ds);
146 BaseSS=SegBase(ss);
147 core.base_val_ds=ds;
148 #if C_DEBUG
149 #if C_HEAVY_DEBUG
150 if (DEBUG_HeavyIsBreakpoint()) {
151 FillFlags();
152 return debugCallback;
153 };
154 #endif
155 cycle_count++;
156 #endif
157 restart_opcode:
158 switch (core.opcode_index+Fetchb()) {
159 #include "core_normal/prefix_none.h"
160 #include "core_normal/prefix_0f.h"
161 #include "core_normal/prefix_66.h"
162 #include "core_normal/prefix_66_0f.h"
163 default:
164 illegal_opcode:
165 #if C_DEBUG
166 {
167 Bitu len=(GETIP-reg_eip);
168 LOADIP;
169 if (len>16) len=16;
170 char tempcode[16*2+1];char * writecode=tempcode;
171 for (;len>0;len--) {
172 sprintf(writecode,"%02X",mem_readb(core.cseip++));
173 writecode+=2;
174 }
175 LOG(LOG_CPU,LOG_NORMAL)("Illegal/Unhandled opcode %s",tempcode);
176 }
177 #endif
178 CPU_Exception(6,0);
179 continue;
180 }
181 SAVEIP;
182 }
183 FillFlags();
184 return CBRET_NONE;
185 decode_end:
186 SAVEIP;
187 FillFlags();
188 return CBRET_NONE;
189 }
190
191 Bits CPU_Core_Normal_Trap_Run(void) {
192 Bits oldCycles = CPU_Cycles;
193 CPU_Cycles = 1;
194 cpu.trap_skip = false;
195
196 Bits ret=CPU_Core_Normal_Run();
197 if (!cpu.trap_skip) CPU_HW_Interrupt(1);
198 CPU_Cycles = oldCycles-1;
199 cpudecoder = &CPU_Core_Normal_Run;
200
201 return ret;
202 }
203
204
205
206 void CPU_Core_Normal_Init(void) {
207
208 }
209