--- np2/i386c/ia32/ia32.c 2008/01/25 17:49:46 1.20 +++ np2/i386c/ia32/ia32.c 2011/12/21 18:02:15 1.23 @@ -1,5 +1,3 @@ -/* $Id: ia32.c,v 1.20 2008/01/25 17:49:46 monaka Exp $ */ - /* * Copyright (c) 2002-2003 NONAKA Kimihiro * All rights reserved. @@ -134,16 +132,20 @@ ia32_setemm(UINT frame, UINT32 addr) { /* * ¥â¡¼¥ÉÁ«°Ü */ -void FASTCALL +void CPUCALL change_pm(BOOL onoff) { +#if 0 int i; +#endif if (onoff) { +#if 0 for (i = 0; i < CPU_SEGREG_NUM; i++) { CPU_STAT_SREG(i).valid = 1; CPU_STAT_SREG(i).dpl = 0; } +#endif VERBOSE(("Entering to Protected-Mode...")); } else { VERBOSE(("Leaveing from Protected-Mode...")); @@ -153,11 +155,11 @@ change_pm(BOOL onoff) CPU_STATSAVE.cpu_inst_default.op_32 = CPU_STATSAVE.cpu_inst_default.as_32 = 0; CPU_STAT_SS32 = 0; - CPU_SET_CPL(0); + set_cpl(0); CPU_STAT_PM = onoff; } -void FASTCALL +void CPUCALL change_pg(BOOL onoff) { @@ -166,26 +168,27 @@ change_pg(BOOL onoff) } else { VERBOSE(("Leaveing from Paging-Mode...")); } + CPU_STAT_PAGING = onoff; } -void FASTCALL +void CPUCALL change_vm(BOOL onoff) { int i; CPU_STAT_VM86 = onoff; if (onoff) { + VERBOSE(("Entering to Virtual-8086-Mode...")); for (i = 0; i < CPU_SEGREG_NUM; i++) { CPU_STAT_SREGLIMIT(i) = 0xffff; - CPU_SET_SEGREG(i, CPU_REGS_SREG(i)); + LOAD_SEGREG(i, CPU_REGS_SREG(i)); } CPU_INST_OP32 = CPU_INST_AS32 = CPU_STATSAVE.cpu_inst_default.op_32 = CPU_STATSAVE.cpu_inst_default.as_32 = 0; CPU_STAT_SS32 = 0; - CPU_SET_CPL(3); - VERBOSE(("Entering to Virtual-8086-Mode...")); + set_cpl(3); } else { VERBOSE(("Leaveing from Virtual-8086-Mode...")); } @@ -194,7 +197,7 @@ change_vm(BOOL onoff) /* * flags */ -static void +static void CPUCALL modify_eflags(UINT32 new_flags, UINT32 mask) { UINT32 orig = CPU_EFLAG; @@ -216,7 +219,7 @@ modify_eflags(UINT32 new_flags, UINT32 m } } -void +void CPUCALL set_flags(UINT16 new_flags, UINT16 mask) { @@ -225,7 +228,7 @@ set_flags(UINT16 new_flags, UINT16 mask) modify_eflags(new_flags, mask); } -void +void CPUCALL set_eflags(UINT32 new_flags, UINT32 mask) { @@ -234,3 +237,29 @@ set_eflags(UINT32 new_flags, UINT32 mask mask |= AC_FLAG|ID_FLAG; modify_eflags(new_flags, mask); } + +/* + * CR3 (Page Directory Entry base physical address) + */ +void CPUCALL +set_cr3(UINT32 new_cr3) +{ + + VERBOSE(("set_CR3: old = %08x, new = 0x%08x", CPU_CR3, new_cr3)); + + CPU_CR3 = new_cr3 & CPU_CR3_MASK; + CPU_STAT_PDE_BASE = CPU_CR3 & CPU_CR3_PD_MASK; + tlb_flush(0); +} + +/* + * CPL (Current Privilege Level) + */ +void CPUCALL +set_cpl(int new_cpl) +{ + int cpl = new_cpl & 3; + + CPU_STAT_CPL = (UINT8)cpl; + CPU_STAT_USER_MODE = (cpl == 3) ? CPU_MODE_USER : CPU_MODE_SUPERVISER; +}