|
|
| version 1.11, 2004/02/20 16:09:04 | version 1.16, 2004/03/24 14:34:23 |
|---|---|
| Line 1 | Line 1 |
| /* $Id$ */ | /* $Id$ */ |
| /* | /* |
| * Copyright (c) 2002-2003 NONAKA Kimihiro | * Copyright (c) 2002-2004 NONAKA Kimihiro |
| * All rights reserved. | * All rights reserved. |
| * | * |
| * Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without |
| Line 154 cpu_memorywrite_check(descriptor_t *sd, | Line 154 cpu_memorywrite_check(descriptor_t *sd, |
| sd->flag |= CPU_DESC_FLAG_WRITABLE; | sd->flag |= CPU_DESC_FLAG_WRITABLE; |
| } | } |
| BOOL | void |
| cpu_stack_push_check(descriptor_t *sd, UINT32 esp, UINT length) | cpu_stack_push_check(UINT16 s, descriptor_t *sd, UINT32 esp, UINT length) |
| { | { |
| UINT32 limit; | UINT32 limit; |
| if (CPU_STAT_PM) { | if (CPU_STAT_PM) { |
| if (!sd->valid || !sd->p) | if (!sd->valid || !sd->p) { |
| return FALSE; | VERBOSE(("cpu_stack_push_check: valid = %d, present = %d", sd->valid, sd->p)); |
| if (!sd->s || sd->u.seg.c || !sd->u.seg.wr) | EXCEPTION(SS_EXCEPTION, s & 0xfffc); |
| return FALSE; | } |
| if (!sd->s || sd->u.seg.c || !sd->u.seg.wr) { | |
| VERBOSE(("cpu_stack_push_check: s = %d, c = %d, wr", sd->s, sd->u.seg.c, sd->u.seg.wr)); | |
| EXCEPTION(SS_EXCEPTION, s & 0xfffc); | |
| } | |
| if (!sd->d) { | if (!sd->d) { |
| esp &= 0xffff; | |
| limit = 0xffff; | limit = 0xffff; |
| } else { | } else { |
| limit = 0xffffffff; | limit = 0xffffffff; |
| Line 176 cpu_stack_push_check(descriptor_t *sd, U | Line 179 cpu_stack_push_check(descriptor_t *sd, U |
| if ((esp == 0) | if ((esp == 0) |
| || (esp < length) | || (esp < length) |
| || (esp - length <= sd->u.seg.limit) | || (esp - length <= sd->u.seg.limit) |
| || (esp > limit)) | || (esp > limit)) { |
| return FALSE; | VERBOSE(("cpu_stack_push_check: expand-down, esp = %08x, length = %08x", esp, length)); |
| VERBOSE(("cpu_stack_push_check: limit = %08x, seglimit = %08x", limit, sd->u.seg.limit)); | |
| VERBOSE(("cpu_stack_push_check: segbase = %08x, segend = %08x", sd->u.seg.segbase, sd->u.seg.segend)); | |
| EXCEPTION(SS_EXCEPTION, s & 0xfffc); | |
| } | |
| } else { | } else { |
| /* expand-up stack */ | /* expand-up stack */ |
| if (esp == 0) { | if (esp == 0) { |
| if ((sd->d && (sd->u.seg.segend != 0xffffffff)) | if ((sd->d && (sd->u.seg.segend != 0xffffffff)) |
| || (!sd->d && (sd->u.seg.segend != 0xffff))) | || (!sd->d && (sd->u.seg.segend != 0xffff))) { |
| return FALSE; | VERBOSE(("cpu_stack_push_check: expand-up, esp = %08x, length = %08x", esp, length)); |
| VERBOSE(("cpu_stack_push_check: limit = %08x, seglimit = %08x", limit, sd->u.seg.limit)); | |
| VERBOSE(("cpu_stack_push_check: segbase = %08x, segend = %08x", sd->u.seg.segbase, sd->u.seg.segend)); | |
| EXCEPTION(SS_EXCEPTION, s & 0xfffc); | |
| } | |
| } else { | } else { |
| if ((esp < length) | if ((esp < length) |
| || (esp - 1 > sd->u.seg.limit)) | || (esp - 1 > sd->u.seg.limit)) { |
| return FALSE; | VERBOSE(("cpu_stack_push_check: expand-up, esp = %08x, length = %08x", esp, length)); |
| VERBOSE(("cpu_stack_push_check: limit = %08x, seglimit = %08x", limit, sd->u.seg.limit)); | |
| VERBOSE(("cpu_stack_push_check: segbase = %08x, segend = %08x", sd->u.seg.segbase, sd->u.seg.segend)); | |
| EXCEPTION(SS_EXCEPTION, s & 0xfffc); | |
| } | |
| } | } |
| } | } |
| } | } |
| return TRUE; | |
| } | } |
| BOOL | void |
| cpu_stack_pop_check(descriptor_t *sd, UINT32 esp, UINT length) | cpu_stack_pop_check(UINT16 s, descriptor_t *sd, UINT32 esp, UINT length) |
| { | { |
| UINT32 limit; | UINT32 limit; |
| if (CPU_STAT_PM) { | if (CPU_STAT_PM) { |
| if (!sd->valid || !sd->p) | if (!sd->valid || !sd->p) { |
| return FALSE; | VERBOSE(("cpu_stack_pop_check: valid = %d, present = %d", sd->valid, sd->p)); |
| if (!sd->s || sd->u.seg.c || !sd->u.seg.wr) | EXCEPTION(SS_EXCEPTION, s & 0xfffc); |
| return FALSE; | } |
| if (!sd->s || sd->u.seg.c || !sd->u.seg.wr) { | |
| VERBOSE(("cpu_stack_pop_check: s = %d, c = %d, wr", sd->s, sd->u.seg.c, sd->u.seg.wr)); | |
| EXCEPTION(SS_EXCEPTION, s & 0xfffc); | |
| } | |
| if (!sd->d) { | if (!sd->d) { |
| esp &= 0xffff; | |
| limit = 0xffff; | limit = 0xffff; |
| } else { | } else { |
| limit = 0xffffffff; | limit = 0xffffffff; |
| Line 214 cpu_stack_pop_check(descriptor_t *sd, UI | Line 231 cpu_stack_pop_check(descriptor_t *sd, UI |
| if (sd->u.seg.ec) { | if (sd->u.seg.ec) { |
| /* expand-down stack */ | /* expand-down stack */ |
| if ((esp == limit) | if ((esp == limit) |
| || ((limit - esp) + 1 < length)) | || ((limit - esp) + 1 < length)) { |
| return FALSE; | VERBOSE(("cpu_stack_pop_check: expand-up, esp = %08x, length = %08x", esp, length)); |
| VERBOSE(("cpu_stack_pop_check: limit = %08x, seglimit = %08x", limit, sd->u.seg.limit)); | |
| VERBOSE(("cpu_stack_pop_check: segbase = %08x, segend = %08x", sd->u.seg.segbase, sd->u.seg.segend)); | |
| EXCEPTION(SS_EXCEPTION, s & 0xfffc); | |
| } | |
| } else { | } else { |
| /* expand-up stack */ | /* expand-up stack */ |
| if ((esp == limit) | if ((esp == limit) |
| || (sd->u.seg.segend == 0) | || (sd->u.seg.segend == 0) |
| || (esp > sd->u.seg.limit) | || (esp > sd->u.seg.limit) |
| || ((sd->u.seg.limit - esp) + 1 < length)) | || ((sd->u.seg.limit - esp) + 1 < length)) { |
| return FALSE; | VERBOSE(("cpu_stack_pop_check: expand-up, esp = %08x, length = %08x", esp, length)); |
| VERBOSE(("cpu_stack_pop_check: limit = %08x, seglimit = %08x", limit, sd->u.seg.limit)); | |
| VERBOSE(("cpu_stack_pop_check: segbase = %08x, segend = %08x", sd->u.seg.segbase, sd->u.seg.segend)); | |
| EXCEPTION(SS_EXCEPTION, s & 0xfffc); | |
| } | |
| } | } |
| } | } |
| return TRUE; | |
| } | } |
| #if defined(IA32_SUPPORT_PREFETCH_QUEUE) | |
| /* | /* |
| * code fetch | * code prefetch |
| */ | */ |
| UINT8 MEMCALL | #define CPU_PREFETCHQ_MASK (CPU_PREFETCH_QUEUE_LENGTH - 1) |
| cpu_codefetch(UINT32 offset) | |
| INLINE static MEMCALL void | |
| cpu_prefetch(UINT32 address) | |
| { | { |
| descriptor_t *sd; | UINT offset = address & CPU_PREFETCHQ_MASK; |
| UINT32 addr; | UINT length = CPU_PREFETCH_QUEUE_LENGTH - offset; |
| sd = &CPU_STAT_SREG(CPU_CS_INDEX); | cpu_memory_access_la_region(address, length, CPU_PAGE_READ_CODE|CPU_STAT_USER_MODE, CPU_PREFETCHQ + offset); |
| if (offset <= sd->u.seg.limit) { | CPU_PREFETCHQ_REMAIN = (SINT8)length; |
| addr = CPU_STAT_SREGBASE(CPU_CS_INDEX) + offset; | |
| if (!CPU_STAT_PM) | |
| return cpu_memoryread(addr); | |
| return cpu_lcmemoryread(addr); | |
| } | |
| EXCEPTION(GP_EXCEPTION, 0); | |
| return 0; /* compiler happy */ | |
| } | } |
| UINT16 MEMCALL | INLINE static MEMCALL UINT8 |
| cpu_codefetch_w(UINT32 offset) | cpu_prefetchq(UINT32 address) |
| { | { |
| descriptor_t *sd; | UINT8 v; |
| UINT32 addr; | |
| sd = &CPU_STAT_SREG(CPU_CS_INDEX); | CPU_PREFETCHQ_REMAIN--; |
| if (offset <= sd->u.seg.limit - 1) { | v = CPU_PREFETCHQ[address & CPU_PREFETCHQ_MASK]; |
| addr = CPU_STAT_SREGBASE(CPU_CS_INDEX) + offset; | return v; |
| if (!CPU_STAT_PM) | |
| return cpu_memoryread_w(addr); | |
| return cpu_lcmemoryread_w(addr); | |
| } | |
| EXCEPTION(GP_EXCEPTION, 0); | |
| return 0; /* compiler happy */ | |
| } | } |
| UINT32 MEMCALL | INLINE static MEMCALL UINT16 |
| cpu_codefetch_d(UINT32 offset) | cpu_prefetchq_w(UINT32 address) |
| { | { |
| descriptor_t *sd; | BYTE *p; |
| UINT32 addr; | UINT16 v; |
| sd = &CPU_STAT_SREG(CPU_CS_INDEX); | CPU_PREFETCHQ_REMAIN -= 2; |
| if (offset <= sd->u.seg.limit - 3) { | p = CPU_PREFETCHQ + (address & CPU_PREFETCHQ_MASK); |
| addr = CPU_STAT_SREGBASE(CPU_CS_INDEX) + offset; | v = LOADINTELWORD(p); |
| if (!CPU_STAT_PM) | return v; |
| return cpu_memoryread_d(addr); | |
| return cpu_lcmemoryread_d(addr); | |
| } | |
| EXCEPTION(GP_EXCEPTION, 0); | |
| return 0; /* compiler happy */ | |
| } | } |
| INLINE static MEMCALL UINT32 | |
| /* | cpu_prefetchq_3(UINT32 address) |
| * virtual address -> linear address | |
| */ | |
| UINT8 MEMCALL | |
| cpu_vmemoryread(int idx, UINT32 offset) | |
| { | { |
| descriptor_t *sd; | BYTE *p; |
| UINT32 addr; | UINT32 v; |
| int exc; | |
| __ASSERT((unsigned int)idx < CPU_SEGREG_NUM); | |
| sd = &CPU_STAT_SREG(idx); | |
| if (!sd->valid) { | |
| exc = GP_EXCEPTION; | |
| goto err; | |
| } | |
| if (!(sd->flag & CPU_DESC_FLAG_READABLE)) { | CPU_PREFETCHQ_REMAIN -= 3; |
| cpu_memoryread_check(sd, offset, 1, | p = CPU_PREFETCHQ + (address & CPU_PREFETCHQ_MASK); |
| (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION); | v = LOADINTELWORD(p); |
| } else { | v += ((UINT32)p[2]) << 16; |
| switch (sd->type) { | return v; |
| case 4: case 5: case 6: case 7: | |
| if (offset <= sd->u.seg.limit) { | |
| if (idx == CPU_SS_INDEX) | |
| exc = SS_EXCEPTION; | |
| else | |
| exc = GP_EXCEPTION; | |
| goto err; | |
| } | |
| break; | |
| default: | |
| if (offset > sd->u.seg.limit) { | |
| if (idx == CPU_SS_INDEX) | |
| exc = SS_EXCEPTION; | |
| else | |
| exc = GP_EXCEPTION; | |
| goto err; | |
| } | |
| break; | |
| } | |
| } | |
| addr = CPU_STAT_SREGBASE(idx) + offset; | |
| if (!CPU_STAT_PM) | |
| return cpu_memoryread(addr); | |
| return cpu_lmemoryread(addr, CPU_STAT_USER_MODE); | |
| err: | |
| EXCEPTION(exc, 0); | |
| return 0; /* compiler happy */ | |
| } | } |
| UINT16 MEMCALL | INLINE static MEMCALL UINT32 |
| cpu_vmemoryread_w(int idx, UINT32 offset) | cpu_prefetchq_d(UINT32 address) |
| { | { |
| descriptor_t *sd; | BYTE *p; |
| UINT32 addr; | UINT32 v; |
| int exc; | |
| __ASSERT((unsigned int)idx < CPU_SEGREG_NUM); | CPU_PREFETCHQ_REMAIN -= 4; |
| p = CPU_PREFETCHQ + (address & CPU_PREFETCHQ_MASK); | |
| v = LOADINTELDWORD(p); | |
| return v; | |
| } | |
| #endif /* IA32_SUPPORT_PREFETCH_QUEUE */ | |
| sd = &CPU_STAT_SREG(idx); | #if defined(IA32_SUPPORT_DEBUG_REGISTER) |
| if (!sd->valid) { | INLINE static void |
| exc = GP_EXCEPTION; | check_memory_break_point(UINT32 address, UINT length, UINT rw) |
| goto err; | { |
| } | int i; |
| if (!(sd->flag & CPU_DESC_FLAG_READABLE)) { | if (CPU_STAT_BP && !(CPU_EFLAG & RF_FLAG)) { |
| cpu_memoryread_check(sd, offset, 2, | for (i = 0; i < CPU_DEBUG_REG_INDEX_NUM; i++) { |
| (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION); | if ((CPU_STAT_BP & (1 << i)) |
| } else { | && (CPU_DR7_GET_RW(i) & rw) |
| switch (sd->type) { | |
| case 4: case 5: case 6: case 7: | |
| if (offset - 1 <= sd->u.seg.limit) { | |
| if (idx == CPU_SS_INDEX) | |
| exc = SS_EXCEPTION; | |
| else | |
| exc = GP_EXCEPTION; | |
| goto err; | |
| } | |
| break; | |
| default: | && ((address <= CPU_DR(i) && address + length > CPU_DR(i)) |
| if (offset > sd->u.seg.limit - 1) { | || (address > CPU_DR(i) && address < CPU_DR(i) + CPU_DR7_GET_LEN(i)))) { |
| if (idx == CPU_SS_INDEX) | CPU_STAT_BP_EVENT |= CPU_STAT_BP_EVENT_B(i); |
| exc = SS_EXCEPTION; | |
| else | |
| exc = GP_EXCEPTION; | |
| goto err; | |
| } | } |
| break; | |
| } | } |
| } | } |
| addr = CPU_STAT_SREGBASE(idx) + offset; | |
| if (!CPU_STAT_PM) | |
| return cpu_memoryread_w(addr); | |
| return cpu_lmemoryread_w(addr, CPU_STAT_USER_MODE); | |
| err: | |
| EXCEPTION(exc, 0); | |
| return 0; /* compiler happy */ | |
| } | } |
| #else | |
| #define check_memory_break_point(address, length, rw) | |
| #endif | |
| UINT32 MEMCALL | /* |
| cpu_vmemoryread_d(int idx, UINT32 offset) | * code fetch |
| */ | |
| UINT8 MEMCALL | |
| cpu_codefetch(UINT32 offset) | |
| { | { |
| descriptor_t *sd; | descriptor_t *sd; |
| UINT32 addr; | UINT32 addr; |
| int exc; | |
| __ASSERT((unsigned int)idx < CPU_SEGREG_NUM); | |
| sd = &CPU_STAT_SREG(idx); | |
| if (!sd->valid) { | |
| exc = GP_EXCEPTION; | |
| goto err; | |
| } | |
| if (!(sd->flag & CPU_DESC_FLAG_READABLE)) { | sd = &CPU_STAT_SREG(CPU_CS_INDEX); |
| cpu_memoryread_check(sd, offset, 4, | if (offset <= sd->u.seg.limit) { |
| (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION); | addr = sd->u.seg.segbase + offset; |
| } else { | #if defined(IA32_SUPPORT_PREFETCH_QUEUE) |
| switch (sd->type) { | if (CPU_PREFETCHQ_REMAIN <= 0) { |
| case 4: case 5: case 6: case 7: | cpu_prefetch(addr); |
| if (offset - 3 <= sd->u.seg.limit) { | } |
| if (idx == CPU_SS_INDEX) | return cpu_prefetchq(addr); |
| exc = SS_EXCEPTION; | #else /* !IA32_SUPPORT_PREFETCH_QUEUE */ |
| else | if (!CPU_STAT_PAGING) |
| exc = GP_EXCEPTION; | return cpu_memoryread(addr); |
| goto err; | return cpu_lcmemoryread(addr); |
| } | #endif /* IA32_SUPPORT_PREFETCH_QUEUE */ |
| break; | |
| default: | |
| if (offset > sd->u.seg.limit - 3) { | |
| if (idx == CPU_SS_INDEX) | |
| exc = SS_EXCEPTION; | |
| else | |
| exc = GP_EXCEPTION; | |
| goto err; | |
| } | |
| break; | |
| } | |
| } | } |
| addr = CPU_STAT_SREGBASE(idx) + offset; | EXCEPTION(GP_EXCEPTION, 0); |
| if (!CPU_STAT_PM) | |
| return cpu_memoryread_d(addr); | |
| return cpu_lmemoryread_d(addr, CPU_STAT_USER_MODE); | |
| err: | |
| EXCEPTION(exc, 0); | |
| return 0; /* compiler happy */ | return 0; /* compiler happy */ |
| } | } |
| /* vaddr memory write */ | UINT16 MEMCALL |
| void MEMCALL | cpu_codefetch_w(UINT32 offset) |
| cpu_vmemorywrite(int idx, UINT32 offset, UINT8 val) | |
| { | { |
| descriptor_t *sd; | descriptor_t *sd; |
| UINT32 addr; | UINT32 addr; |
| int exc; | #if defined(IA32_SUPPORT_PREFETCH_QUEUE) |
| UINT16 v; | |
| __ASSERT((unsigned int)idx < CPU_SEGREG_NUM); | #endif |
| sd = &CPU_STAT_SREG(idx); | |
| if (!sd->valid) { | |
| exc = GP_EXCEPTION; | |
| goto err; | |
| } | |
| if (!(sd->flag & CPU_DESC_FLAG_WRITABLE)) { | |
| cpu_memorywrite_check(sd, offset, 1, | |
| (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION); | |
| } else { | |
| switch (sd->type) { | |
| case 6: case 7: | |
| if (offset <= sd->u.seg.limit) { | |
| if (idx == CPU_SS_INDEX) | |
| exc = SS_EXCEPTION; | |
| else | |
| exc = GP_EXCEPTION; | |
| goto err; | |
| } | |
| break; | |
| default: | sd = &CPU_STAT_SREG(CPU_CS_INDEX); |
| if (offset > sd->u.seg.limit) { | if (offset <= sd->u.seg.limit - 1) { |
| if (idx == CPU_SS_INDEX) | addr = sd->u.seg.segbase + offset; |
| exc = SS_EXCEPTION; | #if defined(IA32_SUPPORT_PREFETCH_QUEUE) |
| else | if (CPU_PREFETCHQ_REMAIN <= 0) { |
| exc = GP_EXCEPTION; | cpu_prefetch(addr); |
| goto err; | } |
| } | if (CPU_PREFETCHQ_REMAIN >= 2) { |
| break; | return cpu_prefetchq_w(addr); |
| } | } |
| } | |
| addr = CPU_STAT_SREGBASE(idx) + offset; | v = cpu_prefetchq(addr); |
| if (!CPU_STAT_PM) { | addr++; |
| /* real mode */ | cpu_prefetch(addr); |
| cpu_memorywrite(addr, val); | v += (UINT16)cpu_prefetchq(addr) << 8; |
| } else { | return v; |
| /* protected mode */ | #else /* !IA32_SUPPORT_PREFETCH_QUEUE */ |
| cpu_lmemorywrite(addr, val, CPU_STAT_USER_MODE); | if (!CPU_STAT_PAGING) |
| return cpu_memoryread_w(addr); | |
| return cpu_lcmemoryread_w(addr); | |
| #endif /* IA32_SUPPORT_PREFETCH_QUEUE */ | |
| } | } |
| return; | EXCEPTION(GP_EXCEPTION, 0); |
| return 0; /* compiler happy */ | |
| err: | |
| EXCEPTION(exc, 0); | |
| } | } |
| void MEMCALL | UINT32 MEMCALL |
| cpu_vmemorywrite_w(int idx, UINT32 offset, UINT16 val) | cpu_codefetch_d(UINT32 offset) |
| { | { |
| descriptor_t *sd; | descriptor_t *sd; |
| UINT32 addr; | UINT32 addr; |
| int exc; | #if defined(IA32_SUPPORT_PREFETCH_QUEUE) |
| UINT32 v; | |
| __ASSERT((unsigned int)idx < CPU_SEGREG_NUM); | #endif |
| sd = &CPU_STAT_SREG(idx); | |
| if (!sd->valid) { | |
| exc = GP_EXCEPTION; | |
| goto err; | |
| } | |
| if (!(sd->flag & CPU_DESC_FLAG_WRITABLE)) { | |
| cpu_memorywrite_check(sd, offset, 2, | |
| (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION); | |
| } else { | |
| switch (sd->type) { | |
| case 6: case 7: | |
| if (offset - 1 <= sd->u.seg.limit) { | |
| if (idx == CPU_SS_INDEX) | |
| exc = SS_EXCEPTION; | |
| else | |
| exc = GP_EXCEPTION; | |
| goto err; | |
| } | |
| break; | |
| default: | sd = &CPU_STAT_SREG(CPU_CS_INDEX); |
| if (offset > sd->u.seg.limit - 1) { | if (offset <= sd->u.seg.limit - 3) { |
| if (idx == CPU_SS_INDEX) | addr = sd->u.seg.segbase + offset; |
| exc = SS_EXCEPTION; | #if defined(IA32_SUPPORT_PREFETCH_QUEUE) |
| else | if (CPU_PREFETCHQ_REMAIN <= 0) { |
| exc = GP_EXCEPTION; | cpu_prefetch(addr); |
| goto err; | } |
| if (CPU_PREFETCHQ_REMAIN >= 4) { | |
| return cpu_prefetchq_d(addr); | |
| } else { | |
| switch (CPU_PREFETCHQ_REMAIN) { | |
| case 1: | |
| v = cpu_prefetchq(addr); | |
| addr++; | |
| cpu_prefetch(addr); | |
| v += (UINT32)cpu_prefetchq_3(addr) << 8; | |
| break; | |
| case 2: | |
| v = cpu_prefetchq_w(addr); | |
| addr += 2; | |
| cpu_prefetch(addr); | |
| v += (UINT32)cpu_prefetchq_w(addr) << 16; | |
| break; | |
| case 3: | |
| v = cpu_prefetchq_3(addr); | |
| addr += 3; | |
| cpu_prefetch(addr); | |
| v += (UINT32)cpu_prefetchq(addr) << 24; | |
| break; | |
| } | } |
| break; | return v; |
| } | } |
| #else /* !IA32_SUPPORT_PREFETCH_QUEUE */ | |
| if (!CPU_STAT_PAGING) | |
| return cpu_memoryread_d(addr); | |
| return cpu_lcmemoryread_d(addr); | |
| #endif /* IA32_SUPPORT_PREFETCH_QUEUE */ | |
| } | } |
| addr = CPU_STAT_SREGBASE(idx) + offset; | EXCEPTION(GP_EXCEPTION, 0); |
| if (!CPU_STAT_PM) { | return 0; /* compiler happy */ |
| /* real mode */ | |
| cpu_memorywrite_w(addr, val); | |
| } else { | |
| /* protected mode */ | |
| cpu_lmemorywrite_w(addr, val, CPU_STAT_USER_MODE); | |
| } | |
| return; | |
| err: | |
| EXCEPTION(exc, 0); | |
| } | } |
| void MEMCALL | |
| cpu_vmemorywrite_d(int idx, UINT32 offset, UINT32 val) | |
| { | |
| descriptor_t *sd; | |
| UINT32 addr; | |
| int exc; | |
| __ASSERT((unsigned int)idx < CPU_SEGREG_NUM); | /* |
| * virtual address memory access functions | |
| sd = &CPU_STAT_SREG(idx); | */ |
| if (!sd->valid) { | #include "cpu_mem.mcr" |
| exc = GP_EXCEPTION; | |
| goto err; | |
| } | |
| if (!(sd->flag & CPU_DESC_FLAG_WRITABLE)) { | |
| cpu_memorywrite_check(sd, offset, 4, | |
| (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION); | |
| } else { | |
| switch (sd->type) { | |
| case 6: case 7: | |
| if (offset - 3 <= sd->u.seg.limit) { | |
| if (idx == CPU_SS_INDEX) | |
| exc = SS_EXCEPTION; | |
| else | |
| exc = GP_EXCEPTION; | |
| goto err; | |
| } | |
| break; | |
| default: | |
| if (offset > sd->u.seg.limit - 3) { | |
| if (idx == CPU_SS_INDEX) | |
| exc = SS_EXCEPTION; | |
| else | |
| exc = GP_EXCEPTION; | |
| goto err; | |
| } | |
| break; | |
| } | |
| } | |
| addr = CPU_STAT_SREGBASE(idx) + offset; | |
| if (!CPU_STAT_PM) { | |
| /* real mode */ | |
| cpu_memorywrite_d(addr, val); | |
| } else { | |
| /* protected mode */ | |
| cpu_lmemorywrite_d(addr, val, CPU_STAT_USER_MODE); | |
| } | |
| return; | |
| err: | VIRTUAL_ADDRESS_MEMORY_ACCESS_FUNCTION(b, UINT8, 1) |
| EXCEPTION(exc, 0); | VIRTUAL_ADDRESS_MEMORY_ACCESS_FUNCTION(w, UINT16, 2) |
| } | VIRTUAL_ADDRESS_MEMORY_ACCESS_FUNCTION(d, UINT32, 4) |