| version 1.12, 2004/03/05 14:17:35 | version 1.30, 2012/01/08 11:36:47 | 
| Line 1 | Line 1 | 
 | /*      $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 12 | Line 10 | 
 | * 2. Redistributions in binary form must reproduce the above copyright | * 2. Redistributions in binary form must reproduce the above copyright | 
 | *    notice, this list of conditions and the following disclaimer in the | *    notice, this list of conditions and the following disclaimer in the | 
 | *    documentation and/or other materials provided with the distribution. | *    documentation and/or other materials provided with the distribution. | 
 | * 3. The name of the author may not be used to endorse or promote products |  | 
 | *    derived from this software without specific prior written permission. |  | 
 | * | * | 
 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | 
 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 
| Line 35 | Line 31 | 
 | /* | /* | 
 | * memory access check | * memory access check | 
 | */ | */ | 
| void | static int MEMCALL check_limit_upstairs(descriptor_t *sdp, UINT32 offset, UINT len); | 
| cpu_memoryread_check(descriptor_t *sd, UINT32 offset, UINT length, int e) | static void MEMCALL cpu_memoryread_check(descriptor_t *sdp, UINT32 offset, UINT len, int e); | 
|  | static void MEMCALL cpu_memorywrite_check(descriptor_t *sdp, UINT32 offset, UINT len, int e); | 
|  |  | 
|  | static int MEMCALL | 
|  | check_limit_upstairs(descriptor_t *sdp, UINT32 offset, UINT len) | 
 | { | { | 
| UINT32 uplimit; | UINT32 limit; | 
|  | UINT32 end; | 
 |  |  | 
| if (CPU_STAT_PM) { | __ASSERT(sdp != NULL); | 
| /* invalid */ | __ASSERT(len > 0); | 
| if (!sd->valid) { |  | 
| VERBOSE(("cpu_memoryread_check: invalid")); |  | 
| EXCEPTION(GP_EXCEPTION, 0); |  | 
| } |  | 
 |  |  | 
| /* not present */ | len--; | 
| if (!sd->p) { | end = offset + len; | 
| VERBOSE(("cpu_memoryread_check: not present")); | limit = SEG_IS_32BIT(sdp) ? 0xffffffff : 0x0000ffff; | 
| EXCEPTION(e, 0); |  | 
|  | if (SEG_IS_DATA(sdp) && SEG_IS_EXPANDDOWN_DATA(sdp)) { | 
|  | /* expand-down data segment */ | 
|  | if (sdp->u.seg.limit == 0) { | 
|  | /* | 
|  | *   32bit       16bit | 
|  | * +-------+   +-------+ FFFFFFFFh | 
|  | * |       |   |       | | 
|  | * |       |   +  [1]  + 0000FFFFh | 
|  | * | valid |   |       | | 
|  | * |       |   +-------+ 0000FFFFh - len -1 | 
|  | * |       |   | valid | | 
|  | * +-------+   +-------+ 00000000h | 
|  | */ | 
|  | if (!SEG_IS_32BIT(sdp)) { | 
|  | if ((len > limit)               /* len check */ | 
|  | || (end > limit)) {            /* [1] */ | 
|  | goto exc; | 
|  | } | 
|  | } else { | 
|  | sdp->flag |= CPU_DESC_FLAG_WHOLEADR; | 
|  | } | 
|  | } else { | 
|  | /* | 
|  | *   32bit       16bit | 
|  | * +-------+   +-------+ FFFFFFFFh | 
|  | * |  [2]  |   |       | | 
|  | * +-------+   +.......+ FFFFFFFFh - len - 1 | 
|  | * |       |   |  [2]  | | 
|  | * |       |   +.......+ 0000FFFFh | 
|  | * | valid |   |       | | 
|  | * |       |   +-------+ 0000FFFFh - len - 1 | 
|  | * |       |   | valid | | 
|  | * +-------+   +-------+ seg.limit | 
|  | * |  [1]  |   |  [1]  | | 
|  | * +-------+   +-------+ 00000000h | 
|  | */ | 
|  | if ((len > limit - sdp->u.seg.limit)    /* len check */ | 
|  | || (end < offset)                      /* wrap check */ | 
|  | || (offset < sdp->u.seg.limit)         /* [1] */ | 
|  | || (end > limit)) {                    /* [2] */ | 
|  | goto exc; | 
|  | } | 
|  | } | 
|  | } else { | 
|  | /* expand-up data or code segment */ | 
|  | if (sdp->u.seg.limit == limit) { | 
|  | /* | 
|  | *   32bit       16bit | 
|  | * +-------+   +-------+ FFFFFFFFh | 
|  | * |       |   |       | | 
|  | * |       |   +  [1]  + 0000FFFFh | 
|  | * | valid |   |       | | 
|  | * |       |   +-------+ 0000FFFFh - len - 1 | 
|  | * |       |   | valid | | 
|  | * +-------+   +-------+ 00000000h | 
|  | */ | 
|  | if (!SEG_IS_32BIT(sdp)) { | 
|  | if ((len > limit)               /* len check */ | 
|  | || (offset + len > limit)) {   /* [1] */ | 
|  | goto exc; | 
|  | } | 
|  | } else { | 
|  | sdp->flag |= CPU_DESC_FLAG_WHOLEADR; | 
|  | } | 
|  | } else { | 
|  | /* | 
|  | *   32bit       16bit | 
|  | * +-------+   +-------+ FFFFFFFFh | 
|  | * |       |   |       | | 
|  | * |       |   +.......+ 0000FFFFh | 
|  | * |  [1]  |   |  [1]  | | 
|  | * +.......+   +.......+ seg.limit | 
|  | * |       |   |       | | 
|  | * +-------+   +-------+ seg.limit - len - 1 | 
|  | * | valid |   | valid | | 
|  | * +-------+   +-------+ 00000000h | 
|  | */ | 
|  | if ((len > sdp->u.seg.limit)            /* len check */ | 
|  | || (end < offset)                      /* wrap check */ | 
|  | || (end > sdp->u.seg.limit + 1)) {     /* [1] */ | 
|  | goto exc; | 
|  | } | 
 | } | } | 
 | } | } | 
 |  | return 1;       /* Ok! */ | 
 |  |  | 
 |  | exc: | 
 |  | VERBOSE(("check_limit_upstairs: check failure: offset = 0x%08x, len = %d", offset, len + 1)); | 
 |  | #if defined(DEBUG) | 
 |  | segdesc_dump(sdp); | 
 |  | #endif | 
 |  | return 0; | 
 |  | } | 
 |  |  | 
 |  | static void MEMCALL | 
 |  | cpu_memoryread_check(descriptor_t *sdp, UINT32 offset, UINT len, int e) | 
 |  | { | 
 |  |  | 
 |  | __ASSERT(sdp != NULL); | 
 |  | __ASSERT(len > 0); | 
 |  |  | 
 |  | if (!SEG_IS_VALID(sdp)) { | 
 |  | e = GP_EXCEPTION; | 
 |  | goto exc; | 
 |  | } | 
 |  | if (!SEG_IS_PRESENT(sdp) | 
 |  | || SEG_IS_SYSTEM(sdp) | 
 |  | || (SEG_IS_CODE(sdp) && !SEG_IS_READABLE_CODE(sdp))) { | 
 |  | goto exc; | 
 |  | } | 
 |  |  | 
| switch (sd->type) { | switch (sdp->type) { | 
 | case 0:  case 1:        /* ro */ | case 0:  case 1:        /* ro */ | 
 | case 2:  case 3:        /* rw */ | case 2:  case 3:        /* rw */ | 
 | case 10: case 11:       /* rx */ |  | 
 | case 14: case 15:       /* rxc */ |  | 
 | if (offset > sd->u.seg.limit - length + 1) { |  | 
 | VERBOSE(("cpu_memoryread_check: offset(%08x) > sd->u.seg.limit(%08x) - length(%08x) + 1", offset, sd->u.seg.limit, length)); |  | 
 | EXCEPTION(e, 0); |  | 
 | } |  | 
 | if (length - 1 > sd->u.seg.limit) { |  | 
 | VERBOSE(("cpu_memoryread_check: length(%08x) - 1 > sd->u.seg.limit(%08x)", length, sd->u.seg.limit)); |  | 
 | EXCEPTION(e, 0); |  | 
 | } |  | 
 | break; |  | 
 |  |  | 
 | case 4:  case 5:        /* ro (expand down) */ | case 4:  case 5:        /* ro (expand down) */ | 
 | case 6:  case 7:        /* rw (expand down) */ | case 6:  case 7:        /* rw (expand down) */ | 
| uplimit = sd->d ? 0xffffffff : 0x0000ffff; | case 10: case 11:       /* rx */ | 
| if (offset <= sd->u.seg.limit) { | case 14: case 15:       /* rxc */ | 
| VERBOSE(("cpu_memoryread_check: offset(%08x) <= sd->u.seg.limit(%08x)", offset, sd->u.seg.limit)); | if (!check_limit_upstairs(sdp, offset, len)) | 
| EXCEPTION(e, 0); | goto exc; | 
| } |  | 
| if (offset > uplimit) { |  | 
| VERBOSE(("cpu_memoryread_check: offset(%08x) > uplimit(%08x)", offset, uplimit)); |  | 
| EXCEPTION(e, 0); |  | 
| } |  | 
| if (uplimit - offset < length - 1) { |  | 
| VERBOSE(("cpu_memoryread_check: uplimit(%08x) - offset(%08x) < length(%08x) - 1", uplimit, offset, length)); |  | 
| EXCEPTION(e, 0); |  | 
| } |  | 
 | break; | break; | 
 |  |  | 
 | default: | default: | 
| VERBOSE(("cpu_memoryread_check: invalid type (type = %d)", sd->type)); | goto exc; | 
| EXCEPTION(e, 0); |  | 
| break; |  | 
 | } | } | 
| sd->flag |= CPU_DESC_FLAG_READABLE; | sdp->flag |= CPU_DESC_FLAG_READABLE; | 
|  | return; | 
|  |  | 
|  | exc: | 
|  | VERBOSE(("cpu_memoryread_check: check failure: offset = 0x%08x, len = %d", offset, len)); | 
|  | #if defined(DEBUG) | 
|  | segdesc_dump(sdp); | 
|  | #endif | 
|  | EXCEPTION(e, 0); | 
 | } | } | 
 |  |  | 
| void | static void MEMCALL | 
| cpu_memorywrite_check(descriptor_t *sd, UINT32 offset, UINT length, int e) | cpu_memorywrite_check(descriptor_t *sdp, UINT32 offset, UINT len, int e) | 
 | { | { | 
 | UINT32 uplimit; |  | 
 |  |  | 
| if (CPU_STAT_PM) { | __ASSERT(sdp != NULL); | 
| /* invalid */ | __ASSERT(len > 0); | 
| if (!sd->valid) { |  | 
| VERBOSE(("cpu_memorywrite_check: invalid")); |  | 
| EXCEPTION(GP_EXCEPTION, 0); |  | 
| } |  | 
 |  |  | 
| /* not present */ | if (!SEG_IS_VALID(sdp)) { | 
| if (!sd->p) { | e = GP_EXCEPTION; | 
| VERBOSE(("cpu_memorywrite_check: not present")); | goto exc; | 
| EXCEPTION(e, 0); | } | 
| } | if (!SEG_IS_PRESENT(sdp) | 
|  | || SEG_IS_SYSTEM(sdp) | 
| if (!sd->s) { | || SEG_IS_CODE(sdp) | 
| VERBOSE(("cpu_memorywrite_check: system segment")); | || (SEG_IS_DATA(sdp) && !SEG_IS_WRITABLE_DATA(sdp))) { | 
| EXCEPTION(e, 0); | goto exc; | 
| } |  | 
 | } | } | 
 |  |  | 
| switch (sd->type) { | switch (sdp->type) { | 
 | case 2: case 3: /* rw */ | case 2: case 3: /* rw */ | 
 | if (offset > sd->u.seg.limit - length + 1) { |  | 
 | VERBOSE(("cpu_memorywrite_check: offset(%08x) > sd->u.seg.limit(%08x) - length(%08x) + 1", offset, sd->u.seg.limit, length)); |  | 
 | EXCEPTION(e, 0); |  | 
 | } |  | 
 | if (length - 1 > sd->u.seg.limit) { |  | 
 | VERBOSE(("cpu_memorywrite_check: length(%08x) - 1 > sd->u.seg.limit(%08x)", length, sd->u.seg.limit)); |  | 
 | EXCEPTION(e, 0); |  | 
 | } |  | 
 | break; |  | 
 |  |  | 
 | case 6: case 7: /* rw (expand down) */ | case 6: case 7: /* rw (expand down) */ | 
| uplimit = sd->d ? 0xffffffff : 0x0000ffff; | if (!check_limit_upstairs(sdp, offset, len)) | 
| if (offset <= sd->u.seg.limit) { | goto exc; | 
| VERBOSE(("cpu_memorywrite_check: offset(%08x) <= sd->u.seg.limit(%08x)", offset, sd->u.seg.limit)); |  | 
| EXCEPTION(e, 0); |  | 
| } |  | 
| if (offset > uplimit) { |  | 
| VERBOSE(("cpu_memorywrite_check: offset(%08x) > uplimit(%08x)", offset, uplimit)); |  | 
| EXCEPTION(e, 0); |  | 
| } |  | 
| if (uplimit - offset < length - 1) { |  | 
| VERBOSE(("cpu_memorywrite_check: uplimit(%08x) - offset(%08x) < length(%08x) - 1", uplimit, offset, length)); |  | 
| EXCEPTION(e, 0); |  | 
| } |  | 
 | break; | break; | 
 |  |  | 
 | default: | default: | 
| VERBOSE(("cpu_memorywrite_check: invalid type (type = %d)", sd->type)); | goto exc; | 
| EXCEPTION(e, 0); |  | 
| break; |  | 
 | } | } | 
| sd->flag |= CPU_DESC_FLAG_WRITABLE; | sdp->flag |= CPU_DESC_FLAG_WRITABLE | CPU_DESC_FLAG_READABLE; | 
|  | return; | 
|  |  | 
|  | exc: | 
|  | VERBOSE(("cpu_memorywrite_check: check failure: offset = 0x%08x, len = %d", offset, len)); | 
|  | #if defined(DEBUG) | 
|  | segdesc_dump(sdp); | 
|  | #endif | 
|  | EXCEPTION(e, 0); | 
 | } | } | 
 |  |  | 
| BOOL | void MEMCALL | 
| cpu_stack_push_check(descriptor_t *sd, UINT32 esp, UINT length) | cpu_stack_push_check(UINT16 s, descriptor_t *sdp, UINT32 sp, UINT len) | 
 | { | { | 
 | UINT32 limit; | UINT32 limit; | 
 |  | UINT32 start; | 
 |  |  | 
| if (CPU_STAT_PM) { | __ASSERT(sdp != NULL); | 
| if (!sd->valid || !sd->p) | __ASSERT(len > 0); | 
| return FALSE; |  | 
| if (!sd->s || sd->u.seg.c || !sd->u.seg.wr) |  | 
| return FALSE; |  | 
|  |  | 
| if (!sd->d) { |  | 
| esp &= 0xffff; |  | 
| limit = 0xffff; |  | 
| } else { |  | 
| limit = 0xffffffff; |  | 
| } |  | 
| if (sd->u.seg.ec) { |  | 
| /* expand-down stack */ |  | 
| if ((esp == 0) |  | 
| || (esp < length) |  | 
| || (esp - length <= sd->u.seg.limit) |  | 
| || (esp > limit)) |  | 
| return FALSE; |  | 
| } else { |  | 
| /* expand-up stack */ |  | 
| if (esp == 0) { |  | 
| if ((sd->d && (sd->u.seg.segend != 0xffffffff)) |  | 
| || (!sd->d && (sd->u.seg.segend != 0xffff))) |  | 
| return FALSE; |  | 
| } else { |  | 
| if ((esp < length) |  | 
| || (esp - 1 > sd->u.seg.limit)) |  | 
| return FALSE; |  | 
| } |  | 
| } |  | 
| } |  | 
| return TRUE; |  | 
| } |  | 
 |  |  | 
| BOOL | len--; | 
| cpu_stack_pop_check(descriptor_t *sd, UINT32 esp, UINT length) |  | 
| { |  | 
| UINT32 limit; |  | 
 |  |  | 
| if (CPU_STAT_PM) { | if (!SEG_IS_VALID(sdp) | 
| if (!sd->valid || !sd->p) | || !SEG_IS_PRESENT(sdp) | 
| return FALSE; | || SEG_IS_SYSTEM(sdp) | 
| if (!sd->s || sd->u.seg.c || !sd->u.seg.wr) | || SEG_IS_CODE(sdp) | 
| return FALSE; | || !SEG_IS_WRITABLE_DATA(sdp)) { | 
|  | goto exc; | 
| if (!sd->d) { | } | 
| esp &= 0xffff; |  | 
| limit = 0xffff; | start = sp - len; | 
|  | limit = SEG_IS_32BIT(sdp) ? 0xffffffff : 0x0000ffff; | 
|  |  | 
|  | if (SEG_IS_EXPANDDOWN_DATA(sdp)) { | 
|  | /* expand-down stack */ | 
|  | if (!SEG_IS_32BIT(sdp)) { | 
|  | if (sp > limit) {                       /* [*] */ | 
|  | goto exc; | 
|  | } | 
|  | } | 
|  | if (sdp->u.seg.limit == 0) { | 
|  | /* | 
|  | *   32bit       16bit | 
|  | * +-------+   +-------+ FFFFFFFFh | 
|  | * |       |   |  [*]  | | 
|  | * |       |   +-------+ 0000FFFFh | 
|  | * | valid |   |       | | 
|  | * |       |   | valid | | 
|  | * |       |   |       | | 
|  | * +-------+   +-------+ 00000000h | 
|  | */ | 
|  | if (!SEG_IS_32BIT(sdp)) { | 
|  | if (sp > limit) {               /* [1] */ | 
|  | goto exc; | 
|  | } | 
|  | } else { | 
|  | sdp->flag |= CPU_DESC_FLAG_WHOLEADR; | 
|  | } | 
 | } else { | } else { | 
| limit = 0xffffffff; | /* | 
|  | *   32bit       16bit | 
|  | * +-------+   +-------+ FFFFFFFFh | 
|  | * |       |   |  [*]  | | 
|  | * | valid |   +-------+ 0000FFFFh | 
|  | * |       |   | valid | | 
|  | * +-------+   +-------+ seg.limit + len - 1 | 
|  | * |       |   |       | | 
|  | * +..[1]..+   +..[1]..+ seg.limit | 
|  | * |       |   |       | | 
|  | * +-------+   +-------+ 00000000h | 
|  | */ | 
|  | if ((len > limit - sdp->u.seg.limit)    /* len check */ | 
|  | || (start > sp)                        /* wrap check */ | 
|  | || (start < sdp->u.seg.limit)) {       /* [1] */ | 
|  | goto exc; | 
|  | } | 
 | } | } | 
| if (sd->u.seg.ec) { | } else { | 
| /* expand-down stack */ | /* expand-up stack */ | 
| if ((esp == limit) | if (sdp->u.seg.limit == limit) { | 
| || ((limit - esp) + 1 < length)) | /* | 
| return FALSE; | *   32bit       16bit | 
|  | * +-------+   +-------+ FFFFFFFFh | 
|  | * |       |   |  [1]  | | 
|  | * |       |   +-------+ 0000FFFFh | 
|  | * | valid |   |       | | 
|  | * |       |   | valid | | 
|  | * |       |   |       | | 
|  | * +-------+   +-------+ 00000000h | 
|  | */ | 
|  | if (!SEG_IS_32BIT(sdp)) { | 
|  | if (sp > limit) {               /* [1] */ | 
|  | goto exc; | 
|  | } | 
|  | } else { | 
|  | sdp->flag |= CPU_DESC_FLAG_WHOLEADR; | 
|  | } | 
 | } else { | } else { | 
| /* expand-up stack */ | /* | 
| if ((esp == limit) | *   32bit       16bit | 
| || (sd->u.seg.segend == 0) | * +-------+   +-------+ FFFFFFFFh | 
| || (esp > sd->u.seg.limit) | * |       |   |       | | 
| || ((sd->u.seg.limit - esp) + 1 < length)) | * |  [1]  |   +  [1]  + 0000FFFFh | 
| return FALSE; | * |       |   |       | | 
|  | * +-------+   +-------+ seg.limit | 
|  | * | valid |   | valid | | 
|  | * +.......+   +.......+ len - 1 | 
|  | * |  [+]  |   |  [+]  | | 
|  | * +-------+   +-------+ 00000000h | 
|  | * | 
|  | * [+]: wrap check | 
|  | */ | 
|  | if ((len > sdp->u.seg.limit)            /* len check */ | 
|  | || (start > sp)                        /* wrap check */ | 
|  | || (sp > sdp->u.seg.limit + 1)) {      /* [1] */ | 
|  | goto exc; | 
|  | } | 
 | } | } | 
 | } | } | 
| return TRUE; | return; | 
| } |  | 
|  |  | 
|  |  | 
| #if defined(IA32_SUPPORT_PREFETCH_QUEUE) |  | 
| /* |  | 
| * code prefetch |  | 
| */ |  | 
| #define CPU_PREFETCHQ_MASK      (CPU_PREFETCH_QUEUE_LENGTH - 1) |  | 
|  |  | 
| INLINE static MEMCALL void |  | 
| cpu_prefetch(UINT32 address) |  | 
| { |  | 
| UINT offset = address & CPU_PREFETCHQ_MASK; |  | 
| UINT length = CPU_PREFETCH_QUEUE_LENGTH - offset; |  | 
 |  |  | 
| cpu_memory_access_la_region(address, length, CPU_PAGE_READ_CODE, CPU_STAT_USER_MODE, CPU_PREFETCHQ + offset); | exc: | 
| CPU_PREFETCHQ_REMAIN = length; | VERBOSE(("cpu_stack_push_check: check failure: selector = %04x, sp = 0x%08x, len = %d", s, sp, len)); | 
|  | #if defined(DEBUG) | 
|  | segdesc_dump(sdp); | 
|  | #endif | 
|  | EXCEPTION(SS_EXCEPTION, s & 0xfffc); | 
 | } | } | 
 |  |  | 
| INLINE static MEMCALL UINT8 | void MEMCALL | 
| cpu_prefetchq(UINT32 address) | cpu_stack_pop_check(UINT16 s, descriptor_t *sdp, UINT32 sp, UINT len) | 
 | { | { | 
 | UINT8 v; |  | 
 |  |  | 
 | CPU_PREFETCHQ_REMAIN--; |  | 
 | v = CPU_PREFETCHQ[address & CPU_PREFETCHQ_MASK]; |  | 
 | return v; |  | 
 | } |  | 
 |  |  | 
| INLINE static MEMCALL UINT16 | __ASSERT(sdp != NULL); | 
| cpu_prefetchq_w(UINT32 address) | __ASSERT(len > 0); | 
| { |  | 
| BYTE *p; |  | 
| UINT16 v; |  | 
 |  |  | 
| CPU_PREFETCHQ_REMAIN -= 2; | if (!SEG_IS_VALID(sdp) | 
| p = CPU_PREFETCHQ + (address & CPU_PREFETCHQ_MASK); | || !SEG_IS_PRESENT(sdp) | 
| v = LOADINTELWORD(p); | || SEG_IS_SYSTEM(sdp) | 
| return v; | || SEG_IS_CODE(sdp) | 
| } | || !SEG_IS_WRITABLE_DATA(sdp)) { | 
|  | goto exc; | 
|  | } | 
 |  |  | 
| INLINE static MEMCALL UINT32 | if (!check_limit_upstairs(sdp, sp, len)) | 
| cpu_prefetchq_3(UINT32 address) | goto exc; | 
| { | return; | 
| BYTE *p; |  | 
| UINT32 v; |  | 
 |  |  | 
| CPU_PREFETCHQ_REMAIN -= 3; | exc: | 
| p = CPU_PREFETCHQ + (address & CPU_PREFETCHQ_MASK); | VERBOSE(("cpu_stack_pop_check: check failure: selector = %04x, sp = 0x%08x, len = %d", s, sp, len)); | 
| v = LOADINTELWORD(p); | #if defined(DEBUG) | 
| v += (UINT32)*p << 16; | segdesc_dump(sdp); | 
| return v; | #endif | 
|  | EXCEPTION(SS_EXCEPTION, s & 0xfffc); | 
 | } | } | 
 |  |  | 
 | INLINE static MEMCALL UINT32 |  | 
 | cpu_prefetchq_d(UINT32 address) |  | 
 | { |  | 
 | BYTE *p; |  | 
 | UINT32 v; |  | 
 |  |  | 
 | CPU_PREFETCHQ_REMAIN -= 4; |  | 
 | p = CPU_PREFETCHQ + (address & CPU_PREFETCHQ_MASK); |  | 
 | v = LOADINTELDWORD(p); |  | 
 | return v; |  | 
 | } |  | 
 | #endif  /* IA32_SUPPORT_PREFETCH_QUEUE */ |  | 
 |  |  | 
 | /* | /* | 
 | * code fetch | * code fetch | 
 | */ | */ | 
 |  | #define ucrw    (CPU_PAGE_READ_CODE | CPU_STAT_USER_MODE) | 
 |  |  | 
 | UINT8 MEMCALL | UINT8 MEMCALL | 
 | cpu_codefetch(UINT32 offset) | cpu_codefetch(UINT32 offset) | 
 | { | { | 
| descriptor_t *sd; | descriptor_t *sdp; | 
 | UINT32 addr; | UINT32 addr; | 
 |  | TLB_ENTRY_T *ep; | 
 |  |  | 
| sd = &CPU_STAT_SREG(CPU_CS_INDEX); | sdp = &CPU_CS_DESC; | 
| if (offset <= sd->u.seg.limit) { | if (offset <= sdp->u.seg.limit) { | 
| addr = sd->u.seg.segbase + offset; | addr = sdp->u.seg.segbase + offset; | 
| #if defined(IA32_SUPPORT_PREFETCH_QUEUE) | if (!CPU_STAT_PAGING) | 
| if (CPU_PREFETCHQ_REMAIN == 0) { |  | 
| cpu_prefetch(addr); |  | 
| } |  | 
| return cpu_prefetchq(addr); |  | 
| #else   /* IA32_SUPPORT_PREFETCH_QUEUE */ |  | 
| if (!CPU_STAT_PM) |  | 
 | return cpu_memoryread(addr); | return cpu_memoryread(addr); | 
| return cpu_lcmemoryread(addr); | ep = tlb_lookup(addr, ucrw); | 
| #endif  /* IA32_SUPPORT_PREFETCH_QUEUE */ | if (ep != NULL && ep->memp != NULL) { | 
|  | return ep->memp[addr & 0xfff]; | 
|  | } | 
|  | return cpu_linear_memory_read_b(addr, ucrw); | 
 | } | } | 
 | EXCEPTION(GP_EXCEPTION, 0); | EXCEPTION(GP_EXCEPTION, 0); | 
 | return 0;       /* compiler happy */ | return 0;       /* compiler happy */ | 
| Line 323  cpu_codefetch(UINT32 offset) | Line 399  cpu_codefetch(UINT32 offset) | 
 | UINT16 MEMCALL | UINT16 MEMCALL | 
 | cpu_codefetch_w(UINT32 offset) | cpu_codefetch_w(UINT32 offset) | 
 | { | { | 
| descriptor_t *sd; | descriptor_t *sdp; | 
 | UINT32 addr; | UINT32 addr; | 
| #if defined(IA32_SUPPORT_PREFETCH_QUEUE) | TLB_ENTRY_T *ep; | 
| UINT16 v; | UINT16 value; | 
| #endif |  | 
|  |  | 
| sd = &CPU_STAT_SREG(CPU_CS_INDEX); |  | 
| if (offset <= sd->u.seg.limit - 1) { |  | 
| addr = sd->u.seg.segbase + offset; |  | 
| #if defined(IA32_SUPPORT_PREFETCH_QUEUE) |  | 
| if (CPU_PREFETCHQ_REMAIN == 0) { |  | 
| cpu_prefetch(addr); |  | 
| } |  | 
| if (CPU_PREFETCHQ_REMAIN >= 2) { |  | 
| return cpu_prefetchq_w(addr); |  | 
| } |  | 
 |  |  | 
| v = cpu_prefetchq(addr); | sdp = &CPU_CS_DESC; | 
| addr++; | if (offset <= sdp->u.seg.limit - 1) { | 
| cpu_prefetch(addr); | addr = sdp->u.seg.segbase + offset; | 
| v |= cpu_prefetchq(addr) << 8; | if (!CPU_STAT_PAGING) | 
| return v; |  | 
| #else   /* IA32_SUPPORT_PREFETCH_QUEUE */ |  | 
| if (!CPU_STAT_PM) |  | 
 | return cpu_memoryread_w(addr); | return cpu_memoryread_w(addr); | 
| return cpu_lcmemoryread_w(addr); | ep = tlb_lookup(addr, ucrw); | 
| #endif  /* IA32_SUPPORT_PREFETCH_QUEUE */ | if (ep != NULL && ep->memp != NULL) { | 
|  | if ((addr + 1) & 0x00000fff) { | 
|  | return LOADINTELWORD(ep->memp + (addr & 0xfff)); | 
|  | } | 
|  | value = ep->memp[0xfff]; | 
|  | ep = tlb_lookup(addr + 1, ucrw); | 
|  | if (ep != NULL && ep->memp != NULL) { | 
|  | value += (UINT16)ep->memp[0] << 8; | 
|  | return value; | 
|  | } | 
|  | } | 
|  | return cpu_linear_memory_read_w(addr, ucrw); | 
 | } | } | 
 | EXCEPTION(GP_EXCEPTION, 0); | EXCEPTION(GP_EXCEPTION, 0); | 
 | return 0;       /* compiler happy */ | return 0;       /* compiler happy */ | 
| Line 358  cpu_codefetch_w(UINT32 offset) | Line 430  cpu_codefetch_w(UINT32 offset) | 
 | UINT32 MEMCALL | UINT32 MEMCALL | 
 | cpu_codefetch_d(UINT32 offset) | cpu_codefetch_d(UINT32 offset) | 
 | { | { | 
| descriptor_t *sd; | descriptor_t *sdp; | 
 | UINT32 addr; | UINT32 addr; | 
| #if defined(IA32_SUPPORT_PREFETCH_QUEUE) | TLB_ENTRY_T *ep[2]; | 
| UINT32 v; | UINT32 value; | 
| #endif | UINT remain; | 
|  |  | 
| sd = &CPU_STAT_SREG(CPU_CS_INDEX); | sdp = &CPU_CS_DESC; | 
| if (offset <= sd->u.seg.limit - 3) { | if (offset <= sdp->u.seg.limit - 3) { | 
| addr = sd->u.seg.segbase + offset; | addr = sdp->u.seg.segbase + offset; | 
| #if defined(IA32_SUPPORT_PREFETCH_QUEUE) | if (!CPU_STAT_PAGING) | 
| if (CPU_PREFETCHQ_REMAIN == 0) { | return cpu_memoryread_d(addr); | 
| cpu_prefetch(addr); | ep[0] = tlb_lookup(addr, ucrw); | 
| } | if (ep[0] != NULL && ep[0]->memp != NULL) { | 
| if (CPU_PREFETCHQ_REMAIN >= 4) { | remain = 0x1000 - (addr & 0xfff); | 
| return cpu_prefetchq_d(addr); | if (remain >= 4) { | 
| } else { | return LOADINTELDWORD(ep[0]->memp + (addr & 0xfff)); | 
| switch (CPU_PREFETCHQ_REMAIN) { | } | 
| case 1: | ep[1] = tlb_lookup(addr + remain, ucrw); | 
| v = cpu_prefetchq(addr); | if (ep[1] != NULL && ep[1]->memp != NULL) { | 
| cpu_prefetch(addr + 1); | switch (remain) { | 
| v += (UINT32)cpu_prefetchq_3(addr + 1) << 8; | case 3: | 
| break; | value = ep[0]->memp[0xffd]; | 
|  | value += (UINT32)LOADINTELWORD(ep[0]->memp + 0xffe) << 8; | 
| case 2: | value += (UINT32)ep[1]->memp[0] << 24; | 
| v = cpu_prefetchq_w(addr); | break; | 
| cpu_prefetch(addr + 2); |  | 
| v += (UINT32)cpu_prefetchq_w(addr + 2) << 16; | case 2: | 
| break; | value = LOADINTELWORD(ep[0]->memp + 0xffe); | 
|  | value += (UINT32)LOADINTELWORD(ep[1]->memp + 0) << 16; | 
| case 3: | break; | 
| v = cpu_prefetchq_3(addr); |  | 
| cpu_prefetch(addr + 3); | case 1: | 
| v += (UINT32)cpu_prefetchq(addr + 3) << 24; | value = ep[0]->memp[0xfff]; | 
| break; | value += (UINT32)LOADINTELWORD(ep[1]->memp + 0) << 8; | 
|  | value += (UINT32)ep[1]->memp[2] << 24; | 
|  | break; | 
|  |  | 
|  | default: | 
|  | ia32_panic("cpu_codefetch_d(): out of range. (remain = %d)\n", remain); | 
|  | return (UINT32)-1; | 
|  | } | 
|  | return value; | 
 | } | } | 
 | return v; |  | 
 | } | } | 
| #else   /* IA32_SUPPORT_PREFETCH_QUEUE */ | return cpu_linear_memory_read_d(addr, ucrw); | 
| if (!CPU_STAT_PM) |  | 
| return cpu_memoryread_d(addr); |  | 
| return cpu_lcmemoryread_d(addr); |  | 
| #endif  /* IA32_SUPPORT_PREFETCH_QUEUE */ |  | 
 | } | } | 
 | EXCEPTION(GP_EXCEPTION, 0); | EXCEPTION(GP_EXCEPTION, 0); | 
 | return 0;       /* compiler happy */ | return 0;       /* compiler happy */ | 
 | } | } | 
 |  |  | 
 |  | #undef  ucrw | 
 |  |  | 
 | /* | /* | 
| * virtual address -> linear address | * additional physical address memory access functions | 
 | */ | */ | 
| UINT8 MEMCALL | UINT64 MEMCALL | 
| cpu_vmemoryread(int idx, UINT32 offset) | cpu_memoryread_q(UINT32 paddr) | 
 | { | { | 
| descriptor_t *sd; | UINT64 value; | 
| UINT32 addr; |  | 
| int exc; |  | 
 |  |  | 
| __ASSERT((unsigned int)idx < CPU_SEGREG_NUM); | value = cpu_memoryread_d(paddr); | 
|  | value += (UINT64)cpu_memoryread_d(paddr + 4) << 32; | 
 |  |  | 
| sd = &CPU_STAT_SREG(idx); | return value; | 
| if (!sd->valid) { | } | 
| exc = GP_EXCEPTION; |  | 
| goto err; |  | 
| } |  | 
 |  |  | 
| if (!(sd->flag & CPU_DESC_FLAG_READABLE)) { | void MEMCALL | 
| cpu_memoryread_check(sd, offset, 1, | cpu_memorywrite_q(UINT32 paddr, UINT64 value) | 
| (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION); | { | 
| } else { |  | 
| switch (sd->type) { |  | 
| 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 = sd->u.seg.segbase + offset; |  | 
| if (!CPU_STAT_PM) |  | 
| return cpu_memoryread(addr); |  | 
| return cpu_lmemoryread(addr, CPU_STAT_USER_MODE); |  | 
 |  |  | 
| err: | cpu_memorywrite_d(paddr, (UINT32)value); | 
| EXCEPTION(exc, 0); | cpu_memorywrite_d(paddr + 4, (UINT32)(value >> 32)); | 
| return 0;       /* compiler happy */ |  | 
 | } | } | 
 |  |  | 
| UINT16 MEMCALL | REG80 MEMCALL | 
| cpu_vmemoryread_w(int idx, UINT32 offset) | cpu_memoryread_f(UINT32 paddr) | 
 | { | { | 
| descriptor_t *sd; | REG80 value; | 
| UINT32 addr; | int i; | 
| int exc; |  | 
 |  |  | 
| __ASSERT((unsigned int)idx < CPU_SEGREG_NUM); | for (i = 0; i < (int)sizeof(REG80); ++i) { | 
|  | value.b[i] = cpu_memoryread(paddr + i); | 
| sd = &CPU_STAT_SREG(idx); |  | 
| if (!sd->valid) { |  | 
| exc = GP_EXCEPTION; |  | 
| goto err; |  | 
 | } | } | 
 |  | return value; | 
 |  | } | 
 |  |  | 
| if (!(sd->flag & CPU_DESC_FLAG_READABLE)) { | void MEMCALL | 
| cpu_memoryread_check(sd, offset, 2, | cpu_memorywrite_f(UINT32 paddr, const REG80 *value) | 
| (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION); | { | 
| } else { | int i; | 
| 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: |  | 
| if (offset > sd->u.seg.limit - 1) { |  | 
| if (idx == CPU_SS_INDEX) |  | 
| exc = SS_EXCEPTION; |  | 
| else |  | 
| exc = GP_EXCEPTION; |  | 
| goto err; |  | 
| } |  | 
| break; |  | 
| } |  | 
| } |  | 
| addr = sd->u.seg.segbase + offset; |  | 
| if (!CPU_STAT_PM) |  | 
| return cpu_memoryread_w(addr); |  | 
| return cpu_lmemoryread_w(addr, CPU_STAT_USER_MODE); |  | 
 |  |  | 
| err: | for (i = 0; i < (int)sizeof(REG80); ++i) { | 
| EXCEPTION(exc, 0); | cpu_memorywrite(paddr + i, value->b[i]); | 
| return 0;       /* compiler happy */ | } | 
 | } | } | 
 |  |  | 
| UINT32 MEMCALL | /* | 
| cpu_vmemoryread_d(int idx, UINT32 offset) | * virtual address memory access functions | 
|  | */ | 
|  | #include "cpu_mem.mcr" | 
|  |  | 
|  | VIRTUAL_ADDRESS_MEMORY_ACCESS_FUNCTION(b, UINT8, 1) | 
|  | VIRTUAL_ADDRESS_MEMORY_ACCESS_FUNCTION(w, UINT16, 2) | 
|  | VIRTUAL_ADDRESS_MEMORY_ACCESS_FUNCTION(d, UINT32, 4) | 
|  |  | 
|  | UINT64 MEMCALL | 
|  | cpu_vmemoryread_q(int idx, UINT32 offset) | 
 | { | { | 
| descriptor_t *sd; | descriptor_t *sdp; | 
 | UINT32 addr; | UINT32 addr; | 
 | int exc; | int exc; | 
 |  |  | 
 | __ASSERT((unsigned int)idx < CPU_SEGREG_NUM); | __ASSERT((unsigned int)idx < CPU_SEGREG_NUM); | 
 |  |  | 
| sd = &CPU_STAT_SREG(idx); | sdp = &CPU_STAT_SREG(idx); | 
| if (!sd->valid) { | if (!SEG_IS_VALID(sdp)) { | 
 | exc = GP_EXCEPTION; | exc = GP_EXCEPTION; | 
 | goto err; | goto err; | 
 | } | } | 
 |  |  | 
| if (!(sd->flag & CPU_DESC_FLAG_READABLE)) { | if (!(sdp->flag & CPU_DESC_FLAG_READABLE)) { | 
| cpu_memoryread_check(sd, offset, 4, | cpu_memoryread_check(sdp, offset, 8, | 
 | (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION); | (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION); | 
| } else { | } else if (!(sdp->flag & CPU_DESC_FLAG_WHOLEADR)) { | 
| switch (sd->type) { | if (!check_limit_upstairs(sdp, offset, 8)) | 
| case 4: case 5: case 6: case 7: | goto range_failure; | 
| if (offset - 3 <= sd->u.seg.limit) { | } | 
| if (idx == CPU_SS_INDEX) | addr = sdp->u.seg.segbase + offset; | 
| exc = SS_EXCEPTION; | if (!CPU_STAT_PAGING) | 
| else | return cpu_memoryread_q(addr); | 
| exc = GP_EXCEPTION; | return cpu_linear_memory_read_q(addr, CPU_PAGE_READ_DATA | CPU_STAT_USER_MODE); | 
| goto err; |  | 
| } | range_failure: | 
| break; | VERBOSE(("cpu_vmemoryread_q: type = %d, offset = %08x, limit = %08x", sdp->type, offset, sdp->u.seg.limit)); | 
|  | exc = (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION; | 
| default: |  | 
| if (offset > sd->u.seg.limit - 3) { |  | 
| if (idx == CPU_SS_INDEX) |  | 
| exc = SS_EXCEPTION; |  | 
| else |  | 
| exc = GP_EXCEPTION; |  | 
| goto err; |  | 
| } |  | 
| break; |  | 
| } |  | 
| } |  | 
| addr = sd->u.seg.segbase + offset; |  | 
| if (!CPU_STAT_PM) |  | 
| return cpu_memoryread_d(addr); |  | 
| return cpu_lmemoryread_d(addr, CPU_STAT_USER_MODE); |  | 
|  |  | 
 | err: | err: | 
 | EXCEPTION(exc, 0); | EXCEPTION(exc, 0); | 
 | return 0;       /* compiler happy */ | return 0;       /* compiler happy */ | 
 | } | } | 
 |  |  | 
 | /* vaddr memory write */ |  | 
 | void MEMCALL | void MEMCALL | 
| cpu_vmemorywrite(int idx, UINT32 offset, UINT8 val) | cpu_vmemorywrite_q(int idx, UINT32 offset, UINT64 value) | 
 | { | { | 
| descriptor_t *sd; | descriptor_t *sdp; | 
 | UINT32 addr; | UINT32 addr; | 
 | int exc; | int exc; | 
 |  |  | 
 | __ASSERT((unsigned int)idx < CPU_SEGREG_NUM); | __ASSERT((unsigned int)idx < CPU_SEGREG_NUM); | 
 |  |  | 
| sd = &CPU_STAT_SREG(idx); | sdp = &CPU_STAT_SREG(idx); | 
| if (!sd->valid) { | if (!SEG_IS_VALID(sdp)) { | 
 | exc = GP_EXCEPTION; | exc = GP_EXCEPTION; | 
 | goto err; | goto err; | 
 | } | } | 
 |  |  | 
| if (!(sd->flag & CPU_DESC_FLAG_WRITABLE)) { | if (!(sdp->flag & CPU_DESC_FLAG_WRITABLE)) { | 
| cpu_memorywrite_check(sd, offset, 1, | cpu_memorywrite_check(sdp, offset, 8, | 
 | (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION); | (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION); | 
 |  | } else if (!(sdp->flag & CPU_DESC_FLAG_WHOLEADR)) { | 
 |  | if (!check_limit_upstairs(sdp, offset, 8)) | 
 |  | goto range_failure; | 
 |  | } | 
 |  | addr = sdp->u.seg.segbase + offset; | 
 |  | if (!CPU_STAT_PAGING) { | 
 |  | cpu_memorywrite_q(addr, value); | 
 | } else { | } else { | 
| switch (sd->type) { | cpu_linear_memory_write_q(addr, value, CPU_PAGE_READ_DATA | CPU_STAT_USER_MODE); | 
| 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 = sd->u.seg.segbase + offset; |  | 
| if (!CPU_STAT_PM) { |  | 
| /* real mode */ |  | 
| cpu_memorywrite(addr, val); |  | 
| } else { |  | 
| /* protected mode */ |  | 
| cpu_lmemorywrite(addr, val, CPU_STAT_USER_MODE); |  | 
 | } | } | 
 | return; | return; | 
 |  |  | 
 |  | range_failure: | 
 |  | VERBOSE(("cpu_vmemorywrite_q: type = %d, offset = %08x, limit = %08x", sdp->type, offset, sdp->u.seg.limit)); | 
 |  | exc = (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION; | 
 | err: | err: | 
 | EXCEPTION(exc, 0); | EXCEPTION(exc, 0); | 
 | } | } | 
 |  |  | 
| void MEMCALL | REG80 MEMCALL | 
| cpu_vmemorywrite_w(int idx, UINT32 offset, UINT16 val) | cpu_vmemoryread_f(int idx, UINT32 offset) | 
 | { | { | 
| descriptor_t *sd; | descriptor_t *sdp; | 
 | UINT32 addr; | UINT32 addr; | 
 | int exc; | int exc; | 
 |  |  | 
 | __ASSERT((unsigned int)idx < CPU_SEGREG_NUM); | __ASSERT((unsigned int)idx < CPU_SEGREG_NUM); | 
 |  |  | 
| sd = &CPU_STAT_SREG(idx); | sdp = &CPU_STAT_SREG(idx); | 
| if (!sd->valid) { | if (!SEG_IS_VALID(sdp)) { | 
 | exc = GP_EXCEPTION; | exc = GP_EXCEPTION; | 
 | goto err; | goto err; | 
 | } | } | 
 |  |  | 
| if (!(sd->flag & CPU_DESC_FLAG_WRITABLE)) { | if (!(sdp->flag & CPU_DESC_FLAG_READABLE)) { | 
| cpu_memorywrite_check(sd, offset, 2, | cpu_memoryread_check(sdp, offset, 10, | 
 | (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION); | (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION); | 
| } else { | } else if (!(sdp->flag & CPU_DESC_FLAG_WHOLEADR)) { | 
| switch (sd->type) { | if (!check_limit_upstairs(sdp, offset, 10)) | 
| case 6: case 7: | goto range_failure; | 
| if (offset - 1 <= sd->u.seg.limit) { | } | 
| if (idx == CPU_SS_INDEX) | addr = sdp->u.seg.segbase + offset; | 
| exc = SS_EXCEPTION; | if (!CPU_STAT_PAGING) | 
| else | return cpu_memoryread_f(addr); | 
| exc = GP_EXCEPTION; | return cpu_linear_memory_read_f(addr, CPU_PAGE_READ_DATA | CPU_PAGE_READ_DATA | CPU_STAT_USER_MODE); | 
| goto err; |  | 
| } | range_failure: | 
| break; | VERBOSE(("cpu_vmemoryread_f: type = %d, offset = %08x, limit = %08x", sdp->type, offset, sdp->u.seg.limit)); | 
|  | exc = (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION; | 
| default: |  | 
| if (offset > sd->u.seg.limit - 1) { |  | 
| if (idx == CPU_SS_INDEX) |  | 
| exc = SS_EXCEPTION; |  | 
| else |  | 
| exc = GP_EXCEPTION; |  | 
| goto err; |  | 
| } |  | 
| break; |  | 
| } |  | 
| } |  | 
| addr = sd->u.seg.segbase + offset; |  | 
| if (!CPU_STAT_PM) { |  | 
| /* real mode */ |  | 
| cpu_memorywrite_w(addr, val); |  | 
| } else { |  | 
| /* protected mode */ |  | 
| cpu_lmemorywrite_w(addr, val, CPU_STAT_USER_MODE); |  | 
| } |  | 
| return; |  | 
|  |  | 
 | err: | err: | 
 | EXCEPTION(exc, 0); | EXCEPTION(exc, 0); | 
 |  | { | 
 |  | REG80 dummy; | 
 |  | memset(&dummy, 0, sizeof(dummy)); | 
 |  | return dummy;   /* compiler happy */ | 
 |  | } | 
 | } | } | 
 |  |  | 
 | void MEMCALL | void MEMCALL | 
| cpu_vmemorywrite_d(int idx, UINT32 offset, UINT32 val) | cpu_vmemorywrite_f(int idx, UINT32 offset, const REG80 *value) | 
 | { | { | 
| descriptor_t *sd; | descriptor_t *sdp; | 
 | UINT32 addr; | UINT32 addr; | 
 | int exc; | int exc; | 
 |  |  | 
 | __ASSERT((unsigned int)idx < CPU_SEGREG_NUM); | __ASSERT((unsigned int)idx < CPU_SEGREG_NUM); | 
 |  |  | 
| sd = &CPU_STAT_SREG(idx); | sdp = &CPU_STAT_SREG(idx); | 
| if (!sd->valid) { | if (!SEG_IS_VALID(sdp)) { | 
 | exc = GP_EXCEPTION; | exc = GP_EXCEPTION; | 
 | goto err; | goto err; | 
 | } | } | 
 |  |  | 
| if (!(sd->flag & CPU_DESC_FLAG_WRITABLE)) { | if (!(sdp->flag & CPU_DESC_FLAG_WRITABLE)) { | 
| cpu_memorywrite_check(sd, offset, 4, | cpu_memorywrite_check(sdp, offset, 10, | 
 | (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION); | (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION); | 
 |  | } else if (!(sdp->flag & CPU_DESC_FLAG_WHOLEADR)) { | 
 |  | if (!check_limit_upstairs(sdp, offset, 10)) | 
 |  | goto range_failure; | 
 |  | } | 
 |  | addr = sdp->u.seg.segbase + offset; | 
 |  | if (!CPU_STAT_PAGING) { | 
 |  | cpu_memorywrite_f(addr, value); | 
 | } else { | } else { | 
| switch (sd->type) { | cpu_linear_memory_write_f(addr, value, CPU_PAGE_WRITE_DATA | CPU_STAT_USER_MODE); | 
| 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 = sd->u.seg.segbase + 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; | return; | 
 |  |  | 
 |  | range_failure: | 
 |  | VERBOSE(("cpu_vmemorywrite_f: type = %d, offset = %08x, limit = %08x", sdp->type, offset, sdp->u.seg.limit)); | 
 |  | exc = (idx == CPU_SS_INDEX) ? SS_EXCEPTION : GP_EXCEPTION; | 
 | err: | err: | 
 | EXCEPTION(exc, 0); | EXCEPTION(exc, 0); | 
 | } | } |