/* * Copyright (C) 2002-2004 The DOSBox Team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* $Id: cpu.cpp,v 1.58 2004-06-10 07:13:02 harekiet Exp $ */ #include #include "dosbox.h" #include "cpu.h" #include "memory.h" #include "debug.h" #include "mapper.h" #include "setup.h" #include "paging.h" #include "support.h" Bitu DEBUG_EnableDebugger(void); #if 1 #undef LOG #define LOG(X,Y) #endif CPU_Regs cpu_regs; CPUBlock cpu; Segments Segs; Bits CPU_Cycles = 0; Bits CPU_CycleLeft = 0; Bits CPU_CycleMax = 2500; Bits CPU_CycleUp = 0; Bits CPU_CycleDown = 0; CPU_Decoder * cpudecoder; void CPU_Core_Full_Init(void); void CPU_Core_Normal_Init(void); void CPU_Core_Dyn_X86_Init(void); void CPU_Push16(Bitu value) { reg_esp=(reg_esp&~cpu.stack.mask)|((reg_esp-2)&cpu.stack.mask); mem_writew(SegPhys(ss) + (reg_esp & cpu.stack.mask) ,value); } void CPU_Push32(Bitu value) { reg_esp=(reg_esp&~cpu.stack.mask)|((reg_esp-4)&cpu.stack.mask); mem_writed(SegPhys(ss) + (reg_esp & cpu.stack.mask) ,value); } Bitu CPU_Pop16(void) { Bitu val=mem_readw(SegPhys(ss) + (reg_esp & cpu.stack.mask)); reg_esp=(reg_esp&~cpu.stack.mask)|((reg_esp+2)&cpu.stack.mask); return val; } Bitu CPU_Pop32(void) { Bitu val=mem_readd(SegPhys(ss) + (reg_esp & cpu.stack.mask)); reg_esp=(reg_esp&~cpu.stack.mask)|((reg_esp+4)&cpu.stack.mask); return val; } PhysPt SelBase(Bitu sel) { if (cpu.cr0 & CR0_PROTECTION) { Descriptor desc; cpu.gdt.GetDescriptor(sel,desc); return desc.GetBase(); } else { return sel<<4; } } void CPU_SetFlags(Bitu word,Bitu mask) { reg_flags=(reg_flags & ~mask)|(word & mask)|2|FLAG_ID; cpu.direction=1-((reg_flags & FLAG_DF) >> 9); } bool CPU_PrepareException(Bitu which,Bitu error) { cpu.exception.which=which; cpu.exception.error=error; return true; } bool CPU_CLI(void) { if (cpu.pmode && ((!GETFLAG(VM) && (GETFLAG_IOPL0; Segs.val[cs]=new_cs; break; default: E_Exit("Task switch CS Type %d",cs_desc.Type()); } } CPU_SetSegGeneral(es,new_es); CPU_SetSegGeneral(ss,new_ss); CPU_SetSegGeneral(ds,new_ds); CPU_SetSegGeneral(fs,new_fs); CPU_SetSegGeneral(gs,new_gs); CPU_LTR(new_tss_selector); // LOG_MSG("Task CPL %X CS:%X IP:%X SS:%X SP:%X eflags %x",cpu.cpl,SegValue(cs),reg_eip,SegValue(ss),reg_esp,reg_flags); return true; } bool CPU_IO_Exception(Bitu port,Bitu size) { if (cpu.pmode && ((GETFLAG_IOPLcpu_tss.limit) goto doexception; where=cpu_tss.base+ofs+(port/8); Bitu map=mem_readw(where); Bitu mask=(0xffff>>(16-size)) << (port&7); if (map & mask) goto doexception; } return false; doexception: LOG_MSG("Exception"); return CPU_PrepareException(13,0); } void CPU_Exception(Bitu which,Bitu error ) { // LOG_MSG("Exception %d error %x",which,error); cpu.exception.error=error; CPU_Interrupt(which,CPU_INT_EXCEPTION | ((which>=8) ? CPU_INT_HAS_ERROR : 0),reg_eip); } Bit8u lastint; void CPU_Interrupt(Bitu num,Bitu type,Bitu oldeip) { lastint=num; #if C_DEBUG switch (num) { case 0xcd: #if C_HEAVY_DEBUG LOG(LOG_CPU,LOG_ERROR)("Call to interrupt 0xCD this is BAD"); DEBUG_HeavyWriteLogInstruction(); #endif E_Exit("Call to interrupt 0xCD this is BAD"); case 0x03: if (DEBUG_Breakpoint()) { CPU_Cycles=0; return; } }; #endif if (!cpu.pmode) { /* Save everything on a 16-bit stack */ CPU_Push16(reg_flags & 0xffff); CPU_Push16(SegValue(cs)); CPU_Push16(oldeip); SETFLAGBIT(IF,false); SETFLAGBIT(TF,false); /* Get the new CS:IP from vector table */ PhysPt base=cpu.idt.GetBase(); reg_eip=mem_readw(base+(num << 2)); Segs.val[cs]=mem_readw(base+(num << 2)+2); Segs.phys[cs]=Segs.val[cs]<<4; cpu.code.big=false; return; } else { /* Protected Mode Interrupt */ // if (type&CPU_INT_SOFTWARE && cpu.v86) goto realmode_interrupt; // DEBUG_EnableDebugger(); // LOG_MSG("interrupt start CPL %d v86 %d",cpu.cpl,cpu.v86); if ((reg_flags & FLAG_VM) && (type&CPU_INT_SOFTWARE)) { // LOG_MSG("Software int in v86, AH %X IOPL %x",reg_ah,(reg_flags & FLAG_IOPL) >>12); if ((reg_flags & FLAG_IOPL)!=FLAG_IOPL) { CPU_Exception(13,0); return; } } Descriptor gate; //TODO Check for software interrupt and check gate's dplcpu.cpl) E_Exit("Interrupt to higher privilege"); switch (cs_desc.Type()) { case DESC_CODE_N_NC_A: case DESC_CODE_N_NC_NA: case DESC_CODE_R_NC_A: case DESC_CODE_R_NC_NA: if (cs_dpl0; LOG(LOG_CPU,LOG_NORMAL)("INT:Gate to %X:%X big %d %s",gate_sel,gate_off,cs_desc.Big(),gate.Type() & 0x8 ? "386" : "286"); reg_eip=gate_off; return; } case DESC_TASK_GATE: CPU_SwitchTask(gate.GetSelector(),TSwitch_CALL_INT,oldeip); if (type & CPU_INT_HAS_ERROR) { //TODO Be sure about this, seems somewhat unclear if (cpu_tss.is386) CPU_Push32(cpu.exception.error); else CPU_Push16(cpu.exception.error); } return; default: E_Exit("Illegal descriptor type %X for int %X",gate.Type(),num); } } assert(1); return ; // make compiler happy } void CPU_IRET(bool use32,Bitu oldeip) { if (!cpu.pmode) { /* RealMode IRET */ realmode_iret: if (use32) { reg_eip=CPU_Pop32(); SegSet16(cs,CPU_Pop32()); CPU_SetFlagsd(CPU_Pop32()); } else { reg_eip=CPU_Pop16(); SegSet16(cs,CPU_Pop16()); CPU_SetFlagsw(CPU_Pop16()); } cpu.code.big=false; return; } else { /* Protected mode IRET */ if (reg_flags & FLAG_VM) { if ((reg_flags & FLAG_IOPL)!=FLAG_IOPL) { CPU_Exception(13,0); return; } else goto realmode_iret; } // DEBUG_EnableDebugger(); // LOG_MSG("IRET start CPL %d v86 %d",cpu.cpl,cpu.v86); /* Check if this is task IRET */ if (GETFLAG(NT)) { if (GETFLAG(VM)) E_Exit("Pmode IRET with VM bit set"); if (!cpu_tss.IsValid()) E_Exit("TASK Iret without valid TSS"); Bitu back_link=cpu_tss.Get_back(); CPU_SwitchTask(back_link,TSwitch_IRET,oldeip); return; } Bitu n_cs_sel,n_eip,n_flags; if (use32) { n_eip=CPU_Pop32(); n_cs_sel=CPU_Pop32() & 0xffff; n_flags=CPU_Pop32(); if (n_flags & FLAG_VM) { cpu.cpl=3; CPU_SetFlags(n_flags,FMASK_ALL | FLAG_VM); Bitu n_ss,n_esp,n_es,n_ds,n_fs,n_gs; n_esp=CPU_Pop32(); n_ss=CPU_Pop32() & 0xffff; n_es=CPU_Pop32() & 0xffff; n_ds=CPU_Pop32() & 0xffff; n_fs=CPU_Pop32() & 0xffff; n_gs=CPU_Pop32() & 0xffff; CPU_SetSegGeneral(ss,n_ss); CPU_SetSegGeneral(es,n_es); CPU_SetSegGeneral(ds,n_ds); CPU_SetSegGeneral(fs,n_fs); CPU_SetSegGeneral(gs,n_gs); reg_eip=n_eip & 0xffff; reg_esp=n_esp; cpu.code.big=false; SegSet16(cs,n_cs_sel); LOG(LOG_CPU,LOG_NORMAL)("IRET:Back to V86: CS:%X IP %X SS:%X SP %X FLAGS:%X",SegValue(cs),reg_eip,SegValue(ss),reg_esp,reg_flags); return; } } else { n_eip=CPU_Pop16(); n_cs_sel=CPU_Pop16(); n_flags=(reg_flags & 0xffff0000) | CPU_Pop16(); if (n_flags & FLAG_VM) E_Exit("VM Flag in 16-bit iret"); } Bitu n_cs_rpl=n_cs_sel & 3; Descriptor n_cs_desc; cpu.gdt.GetDescriptor(n_cs_sel,n_cs_desc); if (n_cs_rpl=cpu.cpl)) E_Exit("IRET:Same level:C:DPL0; Segs.val[cs]=n_cs_sel; reg_eip=n_eip; CPU_SetFlagsd(n_flags); LOG(LOG_CPU,LOG_NORMAL)("IRET:Same level:%X:%X big %d",n_cs_sel,n_eip,cpu.code.big); } else { /* Return to outer level */ switch (n_cs_desc.Type()) { case DESC_CODE_N_NC_A: case DESC_CODE_N_NC_NA: case DESC_CODE_R_NC_A: case DESC_CODE_R_NC_NA: if (n_cs_desc.DPL()!=n_cs_rpl) E_Exit("IRET:Outer level:NC:CS RPL != CS DPL"); break; case DESC_CODE_N_C_A: case DESC_CODE_N_C_NA: case DESC_CODE_R_C_A: case DESC_CODE_R_C_NA: if (n_cs_desc.DPL()<=cpu.cpl) E_Exit("IRET:Outer level:C:DPL <= CPL"); break; default: E_Exit("IRET:Outer level:Illegal descriptor type %X",n_cs_desc.Type()); } Segs.phys[cs]=n_cs_desc.GetBase(); cpu.code.big=n_cs_desc.Big()>0; Segs.val[cs]=n_cs_sel; CPU_SetFlagsd(n_flags); cpu.cpl=n_cs_rpl; reg_eip=n_eip; Bitu n_ss,n_esp; if (use32) { n_esp=CPU_Pop32(); n_ss=CPU_Pop32() & 0xffff; } else { n_esp=CPU_Pop16(); n_ss=CPU_Pop16(); } CPU_SetSegGeneral(ss,n_ss); if (cpu.stack.big) { reg_esp=n_esp; } else { reg_sp=n_esp; } //TODO Maybe validate other segments, but why would anyone use them? LOG(LOG_CPU,LOG_NORMAL)("IRET:Outer level:%X:%X big %d",n_cs_sel,n_eip,cpu.code.big); } return; } } void CPU_JMP(bool use32,Bitu selector,Bitu offset,Bitu oldeip) { if (!cpu.pmode || (reg_flags & FLAG_VM)) { if (!use32) { reg_eip=offset&0xffff; } else { reg_eip=offset; } SegSet16(cs,selector); cpu.code.big=false; return; } else { Bitu rpl=selector & 3; Descriptor desc; cpu.gdt.GetDescriptor(selector,desc); if (!desc.saved.seg.p) { CPU_Exception(0x0B,selector & 0xfffc); return; } switch (desc.Type()) { case DESC_CODE_N_NC_A: case DESC_CODE_N_NC_NA: case DESC_CODE_R_NC_A: case DESC_CODE_R_NC_NA: if (rpl>cpu.cpl) E_Exit("JMP:NC:RPL>CPL"); if (cpu.cpl!=desc.DPL()) E_Exit("JMP:NC:RPL != DPL"); LOG(LOG_CPU,LOG_NORMAL)("JMP:Code:NC to %X:%X big %d",selector,offset,desc.Big()); goto CODE_jmp; case DESC_CODE_N_C_A: case DESC_CODE_N_C_NA: case DESC_CODE_R_C_A: case DESC_CODE_R_C_NA: LOG(LOG_CPU,LOG_NORMAL)("JMP:Code:C to %X:%X big %d",selector,offset,desc.Big()); CODE_jmp: /* Normal jump to another selector:offset */ Segs.phys[cs]=desc.GetBase(); cpu.code.big=desc.Big()>0; Segs.val[cs]=(selector & 0xfffc) | cpu.cpl; reg_eip=offset; return; case DESC_386_TSS_A: if (desc.DPL()cpu.cpl) E_Exit("CALL:CODE:NC:RPL>CPL"); if (call.DPL()!=cpu.cpl) E_Exit("CALL:CODE:NC:DPL!=CPL"); LOG(LOG_CPU,LOG_NORMAL)("CALL:CODE:NC to %X:%X",selector,offset); goto call_code; case DESC_CODE_N_C_A:case DESC_CODE_N_C_NA: case DESC_CODE_R_C_A:case DESC_CODE_R_C_NA: if (call.DPL()>cpu.cpl) E_Exit("CALL:CODE:C:DPL>CPL"); LOG(LOG_CPU,LOG_NORMAL)("CALL:CODE:C to %X:%X",selector,offset); call_code: if (!use32) { CPU_Push16(SegValue(cs)); CPU_Push16(oldeip); reg_eip=offset & 0xffff; } else { CPU_Push32(SegValue(cs)); CPU_Push32(oldeip); reg_eip=offset; } Segs.phys[cs]=call.GetBase(); cpu.code.big=call.Big()>0; Segs.val[cs]=(selector & 0xfffc) | cpu.cpl; return; case DESC_386_CALL_GATE: case DESC_286_CALL_GATE: { if (call.DPL()=0;i--) CPU_Push32(mem_readd(o_stack+i*4)); CPU_Push32(SegValue(cs)); CPU_Push32(oldeip); } else { CPU_Push16(o_ss); //save old stack CPU_Push16(o_esp); if (call.saved.gate.paramcount&31) for (Bits i=(call.saved.gate.paramcount&31)-1;i>=0;i--) CPU_Push16(mem_readw(o_stack+i*2)); CPU_Push16(SegValue(cs)); CPU_Push16(oldeip); } cpu.cpl = n_cs_desc.DPL(); /* Switch to new CS:EIP */ Segs.phys[cs] = n_cs_desc.GetBase(); Segs.val[cs] = (n_cs_sel & 0xfffc) | cpu.cpl; cpu.code.big = n_cs_desc.Big()>0; reg_eip = n_eip; if (!use32) reg_eip&=0xffff; break; } case DESC_CODE_N_C_A:case DESC_CODE_N_C_NA: case DESC_CODE_R_C_A:case DESC_CODE_R_C_NA: call_gate_same_privilege: E_Exit("Call gate to same priviledge"); break; } } /* Call Gates */ break; case DESC_386_TSS_A: if (call.DPL()=cpu.cpl)) E_Exit("RET to C segment of higher privilege"); break; default: E_Exit("RET from illegal descriptor type %X",desc.Type()); } RET_same_level: Segs.phys[cs]=desc.GetBase(); cpu.code.big=desc.Big()>0; Segs.val[cs]=selector; reg_eip=offset; if (cpu.stack.big) { reg_esp+=bytes; } else { reg_sp+=bytes; } LOG(LOG_CPU,LOG_NORMAL)("RET - Same level to %X:%X RPL %X DPL %X",selector,offset,rpl,desc.DPL()); return; } else { /* Return to outer level */ if (bytes) E_Exit("RETF outer level with immediate value"); Bitu n_esp,n_ss; if (use32) { n_esp = CPU_Pop32(); n_ss = CPU_Pop32() & 0xffff; } else { n_esp = CPU_Pop16(); n_ss = CPU_Pop16(); } cpu.cpl = rpl; CPU_SetSegGeneral(ss,n_ss); if (cpu.stack.big) { reg_esp = n_esp; } else { reg_sp = n_esp; } Segs.phys[cs]=desc.GetBase(); cpu.code.big=desc.Big()>0; Segs.val[cs]=(selector&0xfffc) | cpu.cpl; reg_eip=offset; // LOG(LOG_MISC,LOG_ERROR)("RET - Higher level to %X:%X RPL %X DPL %X",selector,offset,rpl,desc.DPL()); return; } LOG(LOG_CPU,LOG_NORMAL)("Prot ret %X:%X",selector,offset); return; } assert(1); } void CPU_SLDT(Bitu & selector) { selector=cpu.gdt.SLDT(); } void CPU_LLDT(Bitu selector) { cpu.gdt.LLDT(selector); LOG(LOG_CPU,LOG_NORMAL)("LDT Set to %X",selector); } void CPU_STR(Bitu & selector) { selector=cpu_tss.selector; } void CPU_LTR(Bitu selector) { cpu_tss.SetSelector(selector); } Bitu gdt_count=0; void CPU_LGDT(Bitu limit,Bitu base) { LOG(LOG_CPU,LOG_NORMAL)("GDT Set to base:%X limit:%X count %d",base,limit,gdt_count++); cpu.gdt.SetLimit(limit); cpu.gdt.SetBase(base); // if (gdt_count>20) DEBUG_EnableDebugger(); // DEBUG_EnableDebugger(); } void CPU_LIDT(Bitu limit,Bitu base) { LOG(LOG_CPU,LOG_NORMAL)("IDT Set to base:%X limit:%X",base,limit); cpu.idt.SetLimit(limit); cpu.idt.SetBase(base); } void CPU_SGDT(Bitu & limit,Bitu & base) { limit=cpu.gdt.GetLimit(); base=cpu.gdt.GetBase(); } void CPU_SIDT(Bitu & limit,Bitu & base) { limit=cpu.idt.GetLimit(); base=cpu.idt.GetBase(); } bool CPU_SET_CRX(Bitu cr,Bitu value) { switch (cr) { case 0: { Bitu changed=cpu.cr0 ^ value; if (!changed) return false; cpu.cr0=value; if (value & CR0_PROTECTION) { cpu.pmode=true; LOG(LOG_CPU,LOG_NORMAL)("Protected mode"); PAGING_Enable((value & CR0_PAGING)>0); } else { cpu.pmode=false; PAGING_Enable(false); LOG(LOG_CPU,LOG_NORMAL)("Real mode"); } break; } case 2: paging.cr2=value; break; case 3: PAGING_SetDirBase(value); break; default: LOG(LOG_CPU,LOG_ERROR)("Unhandled MOV CR%d,%X",cr,value); break; } return false; } Bitu CPU_GET_CRX(Bitu cr) { switch (cr) { case 0: return cpu.cr0; case 2: return paging.cr2; case 3: return PAGING_GetDirBase(); default: LOG(LOG_CPU,LOG_ERROR)("Unhandled MOV XXX, CR%d",cr); break; } return 0; } void CPU_SMSW(Bitu & word) { word=cpu.cr0; } Bitu CPU_LMSW(Bitu word) { word&=0xf; if (cpu.cr0 & 1) word|=1; word|=(cpu.cr0&0xfffffff0); CPU_SET_CRX(0,word); return false; } void CPU_ARPL(Bitu & dest_sel,Bitu src_sel) { if ((dest_sel & 3) < (src_sel & 3)) { dest_sel=(dest_sel & 0xfffc) + (src_sel & 3); // dest_sel|=0xff3f0000; SETFLAGBIT(ZF,true); } else { SETFLAGBIT(ZF,false); } } void CPU_LAR(Bitu selector,Bitu & ar) { if (selector == 0) { SETFLAGBIT(ZF,false); return; } Descriptor desc;Bitu rpl=selector & 3; if (!cpu.gdt.GetDescriptor(selector,desc)){ SETFLAGBIT(ZF,false); return; } switch (desc.Type()){ case DESC_CODE_N_C_A: case DESC_CODE_N_C_NA: case DESC_CODE_R_C_A: case DESC_CODE_R_C_NA: break; case DESC_286_INT_GATE: case DESC_286_TRAP_GATE: { case DESC_386_INT_GATE: case DESC_386_TRAP_GATE: SETFLAGBIT(ZF,false); return; } case DESC_LDT: case DESC_TASK_GATE: case DESC_286_TSS_A: case DESC_286_TSS_B: case DESC_286_CALL_GATE: case DESC_386_TSS_A: case DESC_386_TSS_B: case DESC_386_CALL_GATE: case DESC_DATA_EU_RO_NA: case DESC_DATA_EU_RO_A: case DESC_DATA_EU_RW_NA: case DESC_DATA_EU_RW_A: case DESC_DATA_ED_RO_NA: case DESC_DATA_ED_RO_A: case DESC_DATA_ED_RW_NA: case DESC_DATA_ED_RW_A: case DESC_CODE_N_NC_A: case DESC_CODE_N_NC_NA: case DESC_CODE_R_NC_A: case DESC_CODE_R_NC_NA: if (desc.DPL()DESC_DATA_ED_RW_A)) { return CPU_PrepareException(0x0D,value & 0xfffc); } } } Segs.val[seg]=value; Segs.phys[seg]=desc.GetBase(); if (seg==ss) { if (desc.Big()) { cpu.stack.big=true; cpu.stack.mask=0xffffffff; } else { cpu.stack.big=false; cpu.stack.mask=0xffff; } } return false; } } bool CPU_PopSeg(SegNames seg,bool use32) { Bitu val=mem_readw(SegPhys(ss) + (reg_esp & cpu.stack.mask)); if (CPU_SetSegGeneral(seg,val)) return true; Bitu addsp=2 << use32; reg_esp=(reg_esp&~cpu.stack.mask)|((reg_esp+addsp)&cpu.stack.mask); return false; } void CPU_CPUID(void) { switch (reg_eax) { case 0: /* Vendor ID String and maximum level? */ reg_eax=0; reg_ebx=('G'<< 24) || ('e' << 16) || ('n' << 8) || 'u'; reg_edx=('i'<< 24) || ('n' << 16) || ('e' << 8) || 'T'; reg_ecx=('n'<< 24) || ('t' << 16) || ('e' << 8) || 'l'; break; case 1: /* get processor type/family/model/stepping and feature flags */ reg_eax=0x402; /* intel 486 sx? */ reg_ebx=0; /* Not Supported */ reg_ecx=0; /* No features */ reg_edx=0; /* Nothing either */ break; default: LOG(LOG_CPU,LOG_ERROR)("Unhandled CPUID Function %x",reg_eax); break; } } static Bits HLT_Decode(void) { /* Once an interrupt occurs, it should change cpu core */ if (reg_eip!=cpu.hlt.eip || SegValue(cs) != cpu.hlt.cs) { cpudecoder=cpu.hlt.old_decoder; } else { CPU_Cycles=0; } return 0; } void CPU_HLT(Bitu oldeip) { if (cpu.cpl) { CPU_Exception(13,0); return; } reg_eip=oldeip; CPU_Cycles=0; cpu.hlt.cs=SegValue(cs); cpu.hlt.eip=reg_eip; cpu.hlt.old_decoder=cpudecoder; cpudecoder=&HLT_Decode; return; } void CPU_ENTER(bool use32,Bitu bytes,Bitu level) { level&=0x1f; Bitu sp_index=reg_esp&cpu.stack.mask; Bitu bp_index=reg_ebp&cpu.stack.mask; if (!use32) { sp_index-=2; mem_writew(SegPhys(ss)+sp_index,reg_bp); reg_bp=(Bit16u)(reg_esp-2); if (level) { for (Bitu i=1;i(sec); reg_eax=0; reg_ebx=0; reg_ecx=0; reg_edx=0; reg_edi=0; reg_esi=0; reg_ebp=0; reg_esp=0; SegSet16(cs,0); SegSet16(ds,0); SegSet16(es,0); SegSet16(fs,0); SegSet16(gs,0); SegSet16(ss,0); CPU_SetFlags(FLAG_IF,FMASK_ALL); //Enable interrupts cpu.cr0=0xffffffff; CPU_SET_CRX(0,0); //Initialize cpu.code.big=false; cpu.stack.mask=0xffff; cpu.stack.big=false; cpu.idt.SetBase(0); cpu.idt.SetLimit(1023); /* Init the cpu cores */ CPU_Core_Normal_Init(); CPU_Core_Full_Init(); #if (C_DYNAMIC_X86) CPU_Core_Dyn_X86_Init(); #endif MAPPER_AddHandler(CPU_CycleDecrease,MK_f11,MMOD1,"cycledown","Dec Cycles"); MAPPER_AddHandler(CPU_CycleIncrease,MK_f12,MMOD1,"cycleup" ,"Inc Cycles"); CPU_Cycles=0; CPU_CycleMax=section->Get_int("cycles");; CPU_CycleUp=section->Get_int("cycleup"); CPU_CycleDown=section->Get_int("cycledown"); const char * core=section->Get_string("core"); cpudecoder=&CPU_Core_Normal_Run; if (!strcasecmp(core,"normal")) { cpudecoder=&CPU_Core_Normal_Run; } else if (!strcasecmp(core,"full")) { cpudecoder=&CPU_Core_Full_Run; } #if (C_DYNAMIC_X86) else if (!strcasecmp(core,"dynamic")) { cpudecoder=&CPU_Core_Dyn_X86_Run; } #endif else { LOG_MSG("CPU:Unknown core type %s, switcing back to normal.",core); } CPU_JMP(false,0,0,0); //Setup the first cpu core if (!CPU_CycleMax) CPU_CycleMax = 2500; if(!CPU_CycleUp) CPU_CycleUp = 500; if(!CPU_CycleDown) CPU_CycleDown = 20; CPU_CycleLeft=0; GFX_SetTitle(CPU_CycleMax,-1); }