|
|
| version 1.4, 2004/01/27 15:55:26 | version 1.10, 2005/03/12 12:32:54 |
|---|---|
| Line 12 | Line 12 |
| * 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 extern "C" { | Line 33 extern "C" { |
| #endif | #endif |
| /* | /* |
| * segment selector | |
| */ | |
| #define CPU_SEGMENT_SELECTOR_INDEX_MASK ~7 | |
| #define CPU_SEGMENT_SELECTOR_RPL_MASK 3 | |
| #define CPU_SEGMENT_TABLE_IND (1 << 2) /* 0 = GDT, 1 = LDT */ | |
| /* | |
| * segment descriptor | * segment descriptor |
| */ | */ |
| typedef struct { | typedef struct { |
| union { | union { |
| struct { | struct { |
| DWORD segbase; | UINT32 segbase; |
| DWORD segend; | UINT32 segend; |
| DWORD limit; | UINT32 limit; |
| BYTE c; /* 0 = data, 1 = code */ | UINT8 c; /* 0 = data, 1 = code */ |
| BYTE g; /* 4k base */ | UINT8 g; /* 4k base */ |
| BYTE wr; /* readable/writable */ | UINT8 wr; /* readable/writable */ |
| BYTE ec; /* expand down/conforming */ | UINT8 ec; /* expand down/conforming */ |
| } seg; | } seg; |
| struct { | struct { |
| WORD selector; | UINT16 selector; |
| WORD w_pad; | UINT16 w_pad; |
| DWORD offset; | UINT32 offset; |
| BYTE count; /* parameter count:call gate */ | UINT8 count; /* parameter count:call gate */ |
| BYTE b_pad[7]; | UINT8 b_pad[7]; |
| } gate; | } gate; |
| } u; | } u; |
| DWORD addr; /* descriptor addr */ | UINT8 valid; /* descriptor valid flag */ |
| DWORD l; /* low dword cache */ | UINT8 p; /* avail flag */ |
| DWORD h; /* high dword cache */ | |
| BYTE valid; /* descriptor valid flag */ | |
| BYTE p; /* avail flag */ | |
| BYTE type; /* descriptor type */ | |
| BYTE dpl; /* DPL */ | |
| BYTE s; /* 0 = system, 1 = code/data */ | |
| BYTE d; /* 0 = 16bit, 1 = 32bit */ | |
| BYTE flag; | UINT8 type; /* descriptor type */ |
| UINT8 dpl; /* DPL */ | |
| UINT8 rpl; /* RPL */ | |
| UINT8 s; /* 0 = system, 1 = code/data */ | |
| UINT8 d; /* 0 = 16bit, 1 = 32bit */ | |
| UINT8 flag; | |
| #define CPU_DESC_FLAG_READABLE (1 << 0) | #define CPU_DESC_FLAG_READABLE (1 << 0) |
| #define CPU_DESC_FLAG_WRITABLE (1 << 1) | #define CPU_DESC_FLAG_WRITABLE (1 << 1) |
| BYTE b_pad; | |
| } descriptor_t; | } descriptor_t; |
| Line 118 typedef struct { | Line 103 typedef struct { |
| #define CPU_GATEDESC_H_D ( 1 << 11) | #define CPU_GATEDESC_H_D ( 1 << 11) |
| /* for tss descriptor */ | /* for tss descriptor */ |
| #define CPU_TSS_H_BUSY ( 1 << 10) | #define CPU_TSS_H_BUSY ( 1 << 9) |
| /* | /* |
| * descriptor type | * descriptor type |
| Line 153 typedef struct { | Line 138 typedef struct { |
| #define CPU_SET_SEGDESC_DEFAULT(dscp, idx, selector) \ | #define CPU_SET_SEGDESC_DEFAULT(dscp, idx, selector) \ |
| do { \ | do { \ |
| (dscp)->u.seg.segbase = (DWORD)(selector) << 4; \ | (dscp)->u.seg.segbase = (UINT32)(selector) << 4; \ |
| (dscp)->u.seg.segend = (dscp)->u.seg.segbase + (dscp)->u.seg.limit; \ | (dscp)->u.seg.segend = (dscp)->u.seg.segbase + (dscp)->u.seg.limit; \ |
| (dscp)->u.seg.c = ((idx) == CPU_CS_INDEX) ? 1 : 0; \ | (dscp)->u.seg.c = ((idx) == CPU_CS_INDEX) ? 1 : 0; \ |
| (dscp)->u.seg.g = 0; \ | (dscp)->u.seg.g = 0; \ |
| (dscp)->u.seg.wr = 1; \ | |
| (dscp)->valid = 1; \ | (dscp)->valid = 1; \ |
| (dscp)->p = 1; \ | (dscp)->p = 1; \ |
| (dscp)->type = 0x02 /* writable */; \ | (dscp)->type = 0x02; /* writable */ \ |
| (dscp)->dpl = 0; \ | (dscp)->dpl = 0; \ |
| (dscp)->s = 1; /* code/data */ \ | (dscp)->s = 1; /* code/data */ \ |
| (dscp)->d = 0; \ | (dscp)->d = 0; /* 16bit */ \ |
| (dscp)->flag = 0; \ | (dscp)->flag = CPU_DESC_FLAG_READABLE|CPU_DESC_FLAG_WRITABLE; \ |
| } while (/*CONSTCOND*/ 0) | } while (/*CONSTCOND*/ 0) |
| #define CPU_SET_SEGDESC_POSTPART(dscp) \ | #define CPU_SET_TASK_BUSY(selector, dscp) \ |
| do { \ | do { \ |
| if ((dscp)->valid) { \ | UINT32 addr; \ |
| if ((dscp)->s) { \ | UINT32 h; \ |
| if (!((dscp)->h & CPU_SEGDESC_H_A)) { \ | addr = CPU_GDTR_BASE + ((selector) & CPU_SEGMENT_SELECTOR_INDEX_MASK); \ |
| (dscp)->h |= CPU_SEGDESC_H_A; \ | h = cpu_kmemoryread_d(addr + 4); \ |
| cpu_lmemorywrite_d((dscp)->addr+4, (dscp)->h); \ | if (!(h & CPU_TSS_H_BUSY)) { \ |
| } \ | (dscp)->type |= CPU_SYSDESC_TYPE_TSS_BUSY_IND; \ |
| } \ | h |= CPU_TSS_H_BUSY; \ |
| cpu_kmemorywrite_d(addr + 4, h); \ | |
| } else { \ | } else { \ |
| ia32_panic("CPU_SET_SEGDESC_POSTPART: descriptor is invalid"); \ | ia32_panic("CPU_SET_TASK_BUSY: already busy (%04x:%08x)", selector, h); \ |
| } \ | } \ |
| } while (/*CONSTCOND*/ 0) | } while (/*CONSTCOND*/ 0) |
| #define CPU_SET_TASK_BUSY(dscp) \ | #define CPU_SET_TASK_FREE(selector, dscp) \ |
| do { \ | do { \ |
| if ((dscp)->valid) { \ | UINT32 addr; \ |
| DWORD h; \ | UINT32 h; \ |
| h = cpu_lmemoryread_d((dscp)->addr + 4); \ | addr = CPU_GDTR_BASE + ((selector) & CPU_SEGMENT_SELECTOR_INDEX_MASK); \ |
| if (!(h & CPU_TSS_H_BUSY)) { \ | h = cpu_kmemoryread_d(addr + 4); \ |
| (dscp)->type |= CPU_SYSDESC_TYPE_TSS_BUSY_IND; \ | if (h & CPU_TSS_H_BUSY) { \ |
| h |= CPU_TSS_H_BUSY; \ | (dscp)->type &= ~CPU_SYSDESC_TYPE_TSS_BUSY_IND; \ |
| cpu_lmemorywrite_d((dscp)->addr + 4, h); \ | h &= ~CPU_TSS_H_BUSY; \ |
| } else { \ | cpu_kmemorywrite_d(addr + 4, h); \ |
| ia32_panic("CPU_SET_TASK_BUSY: already busy (%x)", h); \ | |
| } \ | |
| } else { \ | } else { \ |
| ia32_panic("CPU_SET_TASK_BUSY: descriptor is invalid"); \ | ia32_panic("CPU_SET_TASK_FREE: already free (%04x:%08x)", selector, h); \ |
| } \ | } \ |
| } while (/*CONSTCOND*/ 0) | } while (/*CONSTCOND*/ 0) |
| #define CPU_SET_TASK_FREE(dscp) \ | void load_descriptor(descriptor_t *descp, UINT32 addr); |
| do { \ | |
| if ((dscp)->valid) { \ | #define CPU_SET_SEGREG(idx, selector) load_segreg(idx, selector, GP_EXCEPTION) |
| DWORD h; \ | void load_segreg(int idx, UINT16 selector, int exc); |
| h = cpu_lmemoryread_d((dscp)->addr + 4); \ | void load_ss(UINT16 selector, const descriptor_t *sd, UINT cpl); |
| if (h & CPU_TSS_H_BUSY) { \ | void load_cs(UINT16 selector, const descriptor_t *sd, UINT cpl); |
| (dscp)->type &= ~CPU_SYSDESC_TYPE_TSS_BUSY_IND; \ | void load_ldtr(UINT16 selector, int exc); |
| h &= ~CPU_TSS_H_BUSY; \ | |
| cpu_lmemorywrite_d((dscp)->addr + 4, h); \ | |
| } else { \ | /* |
| ia32_panic("CPU_SET_TASK_FREE: already free (%x)", h); \ | * segment selector |
| } \ | */ |
| } else { \ | #define CPU_SEGMENT_SELECTOR_INDEX_MASK (~7) |
| ia32_panic("CPU_SET_TASK_FREE: descriptor is invalid"); \ | #define CPU_SEGMENT_SELECTOR_RPL_MASK (3) |
| } \ | #define CPU_SEGMENT_TABLE_IND (1 << 2) /* 0 = GDT, 1 = LDT */ |
| } while (/*CONSTCOND*/ 0) | |
| typedef struct { | typedef struct { |
| WORD selector; | UINT16 selector; |
| WORD idx; | UINT16 idx; |
| WORD rpl; | UINT16 rpl; |
| BYTE ldt; | UINT8 ldt; |
| BYTE pad; | UINT8 pad; |
| UINT32 addr; /* descriptor linear address */ | |
| descriptor_t desc; | descriptor_t desc; |
| } selector_t; | } selector_t; |
| int parse_selector(selector_t* ssp, WORD selector); | int parse_selector(selector_t *ssp, UINT16 selector); |
| int selector_is_not_present(selector_t* ssp); | int selector_is_not_present(const selector_t *ssp); |
| #define CPU_SET_SEGDESC(descp, addr) load_descriptor(descp, addr) | |
| #define CPU_SET_GATEDESC(descp, addr) load_descriptor(descp, addr) | |
| void load_descriptor(descriptor_t* descp, DWORD addr); | |
| #define CPU_SET_SEGREG(idx, selector) load_segreg(idx, selector, GP_EXCEPTION) | |
| void load_segreg(int idx, WORD selector, int exc); | |
| void load_ss(WORD selector, descriptor_t* sdp, BYTE cpl); | |
| void load_cs(WORD selector, descriptor_t* sdp, BYTE cpl); | |
| void load_ldtr(WORD selector, int exc); | |
| #ifdef __cplusplus | #ifdef __cplusplus |
| } | } |