diff options
author | ths <ths@c046a42c-6fe2-441c-8c8c-71466251a162> | 2007-09-29 19:21:36 +0000 |
---|---|---|
committer | ths <ths@c046a42c-6fe2-441c-8c8c-71466251a162> | 2007-09-29 19:21:36 +0000 |
commit | 671880e651e611ec32dbb978e61c0bd4bc3e180e (patch) | |
tree | a6401fdd2ea52dc7ab54b8721eea7bc820f6c1ad /target-mips/helper.c | |
parent | 544540979cb8ebb4b4ca71bd8df89e5d8e7f8600 (diff) |
Supervisor mode implementation, by Aurelien Jarno.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3267 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'target-mips/helper.c')
-rw-r--r-- | target-mips/helper.c | 61 |
1 files changed, 34 insertions, 27 deletions
diff --git a/target-mips/helper.c b/target-mips/helper.c index 8e4233ed7b..7424cda560 100644 --- a/target-mips/helper.c +++ b/target-mips/helper.c @@ -106,6 +106,8 @@ static int get_physical_address (CPUState *env, target_ulong *physical, { /* User mode can only access useg/xuseg */ int user_mode = (env->hflags & MIPS_HFLAG_MODE) == MIPS_HFLAG_UM; + int supervisor_mode = (env->hflags & MIPS_HFLAG_MODE) == MIPS_HFLAG_SM; + int kernel_mode = !user_mode && !supervisor_mode; #ifdef TARGET_MIPS64 int UX = (env->CP0_Status & (1 << CP0St_UX)) != 0; int SX = (env->CP0_Status & (1 << CP0St_SX)) != 0; @@ -120,14 +122,6 @@ static int get_physical_address (CPUState *env, target_ulong *physical, } #endif -#ifdef TARGET_MIPS64 - if (user_mode && address > 0x3FFFFFFFFFFFFFFFULL) - return TLBRET_BADADDR; -#else - if (user_mode && address > 0x7FFFFFFFUL) - return TLBRET_BADADDR; -#endif - if (address <= (int32_t)0x7FFFFFFFUL) { /* useg */ if (env->CP0_Status & (1 << CP0St_ERL)) { @@ -150,16 +144,16 @@ static int get_physical_address (CPUState *env, target_ulong *physical, } } else if (address < 0x7FFFFFFFFFFFFFFFULL) { /* xsseg */ - if (SX && address < (0x7FFFFFFFFFFFFFFFULL & env->SEGMask)) { + if ((supervisor_mode || kernel_mode) && + SX && address < (0x7FFFFFFFFFFFFFFFULL & env->SEGMask)) { ret = env->tlb->map_address(env, physical, prot, address, rw, access_type); } else { ret = TLBRET_BADADDR; } } else if (address < 0xBFFFFFFFFFFFFFFFULL) { /* xkphys */ - /* XXX: check supervisor mode */ - if (KX && (address & 0x07FFFFFFFFFFFFFFULL) < 0X0000000FFFFFFFFFULL) - { + if (kernel_mode && KX && + (address & 0x07FFFFFFFFFFFFFFULL) < 0X0000000FFFFFFFFFULL) { *physical = address & 0X0000000FFFFFFFFFULL; *prot = PAGE_READ | PAGE_WRITE; } else { @@ -167,8 +161,8 @@ static int get_physical_address (CPUState *env, target_ulong *physical, } } else if (address < 0xFFFFFFFF7FFFFFFFULL) { /* xkseg */ - /* XXX: check supervisor mode */ - if (KX && address < (0xFFFFFFFF7FFFFFFFULL & env->SEGMask)) { + if (kernel_mode && KX && + address < (0xFFFFFFFF7FFFFFFFULL & env->SEGMask)) { ret = env->tlb->map_address(env, physical, prot, address, rw, access_type); } else { ret = TLBRET_BADADDR; @@ -176,22 +170,35 @@ static int get_physical_address (CPUState *env, target_ulong *physical, #endif } else if (address < (int32_t)0xA0000000UL) { /* kseg0 */ - /* XXX: check supervisor mode */ - *physical = address - (int32_t)0x80000000UL; - *prot = PAGE_READ | PAGE_WRITE; + if (kernel_mode) { + *physical = address - (int32_t)0x80000000UL; + *prot = PAGE_READ | PAGE_WRITE; + } else { + ret = TLBRET_BADADDR; + } } else if (address < (int32_t)0xC0000000UL) { /* kseg1 */ - /* XXX: check supervisor mode */ - *physical = address - (int32_t)0xA0000000UL; - *prot = PAGE_READ | PAGE_WRITE; + if (kernel_mode) { + *physical = address - (int32_t)0xA0000000UL; + *prot = PAGE_READ | PAGE_WRITE; + } else { + ret = TLBRET_BADADDR; + } } else if (address < (int32_t)0xE0000000UL) { - /* kseg2 */ - ret = env->tlb->map_address(env, physical, prot, address, rw, access_type); + /* sseg */ + if (supervisor_mode || kernel_mode) { + ret = env->tlb->map_address(env, physical, prot, address, rw, access_type); + } else { + ret = TLBRET_BADADDR; + } } else { /* kseg3 */ - /* XXX: check supervisor mode */ /* XXX: debug segment is not emulated */ - ret = env->tlb->map_address(env, physical, prot, address, rw, access_type); + if (kernel_mode) { + ret = env->tlb->map_address(env, physical, prot, address, rw, access_type); + } else { + ret = TLBRET_BADADDR; + } } #if 0 if (logfile) { @@ -369,7 +376,7 @@ void do_interrupt (CPUState *env) } enter_debug_mode: env->hflags |= MIPS_HFLAG_DM | MIPS_HFLAG_64 | MIPS_HFLAG_CP0; - env->hflags &= ~MIPS_HFLAG_UM; + env->hflags &= ~(MIPS_HFLAG_SM | MIPS_HFLAG_UM); /* EJTAG probe trap enable is not implemented... */ if (!(env->CP0_Status & (1 << CP0St_EXL))) env->CP0_Cause &= ~(1 << CP0Ca_BD); @@ -395,7 +402,7 @@ void do_interrupt (CPUState *env) } env->CP0_Status |= (1 << CP0St_ERL) | (1 << CP0St_BEV); env->hflags |= MIPS_HFLAG_64 | MIPS_HFLAG_CP0; - env->hflags &= ~MIPS_HFLAG_UM; + env->hflags &= ~(MIPS_HFLAG_SM | MIPS_HFLAG_UM); if (!(env->CP0_Status & (1 << CP0St_EXL))) env->CP0_Cause &= ~(1 << CP0Ca_BD); env->PC[env->current_tc] = (int32_t)0xBFC00000; @@ -497,7 +504,7 @@ void do_interrupt (CPUState *env) } env->CP0_Status |= (1 << CP0St_EXL); env->hflags |= MIPS_HFLAG_64 | MIPS_HFLAG_CP0; - env->hflags &= ~MIPS_HFLAG_UM; + env->hflags &= ~(MIPS_HFLAG_SM | MIPS_HFLAG_UM); } env->hflags &= ~MIPS_HFLAG_BMASK; if (env->CP0_Status & (1 << CP0St_BEV)) { |