21 #include "x86emu/debug.h" 22 #include "x86emu/prim_ops.h" 23 #include "x86emu/regs.h" 24 #include "x86emu/x86emui.h" 25 #ifndef NO_SYS_HEADERS 31 X86EMU_intrFuncs _X86EMU_intrTab[256];
34 #if defined(__alpha__) || defined(__alpha) 48 #if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91)) 63 static __inline__
unsigned long ldq_u(
unsigned long *r11)
65 #if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91)) 66 const struct __una_u64 *ptr = (
const struct __una_u64 *) r11;
70 __asm__(
"ldq_u %0,%3\n\t" 74 :
"=&r"(r1),
"=&r"(r2)
75 :
"r"(r11),
"m"(*r11),
76 "m"(*(
const unsigned long *) (7 + (
char *) r11)));
81 static __inline__
unsigned long ldl_u(
unsigned int *r11)
83 #if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91)) 84 const struct __una_u32 *ptr = (
const struct __una_u32 *) r11;
88 __asm__(
"ldq_u %0,%3\n\t" 92 :
"=&r"(r1),
"=&r"(r2)
93 :
"r"(r11),
"m"(*r11),
94 "m"(*(
const unsigned long *) (3 + (
char *) r11)));
99 static __inline__
unsigned long ldw_u(
unsigned short *r11)
101 #if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91)) 102 const struct __una_u16 *ptr = (
const struct __una_u16 *) r11;
105 unsigned long r1, r2;
106 __asm__(
"ldq_u %0,%3\n\t" 110 :
"=&r"(r1),
"=&r"(r2)
111 :
"r"(r11),
"m"(*r11),
112 "m"(*(
const unsigned long *) (1 + (
char *) r11)));
121 static __inline__
void stq_u(
unsigned long r5,
unsigned long *r11)
123 #if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91)) 124 struct __una_u64 *ptr = (
struct __una_u64 *) r11;
127 unsigned long r1, r2, r3, r4;
129 __asm__(
"ldq_u %3,%1\n\t" 139 :
"=m"(*r11),
"=m"(*(
unsigned long *) (7 + (
char *) r11)),
140 "=&r"(r1),
"=&r"(r2),
"=&r"(r3),
"=&r"(r4)
141 :
"r"(r5),
"r"(r11));
145 static __inline__
void stl_u(
unsigned long r5,
unsigned int *r11)
147 #if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91)) 148 struct __una_u32 *ptr = (
struct __una_u32 *) r11;
151 unsigned long r1, r2, r3, r4;
153 __asm__(
"ldq_u %3,%1\n\t" 163 :
"=m"(*r11),
"=m"(*(
unsigned long *) (3 + (
char *) r11)),
164 "=&r"(r1),
"=&r"(r2),
"=&r"(r3),
"=&r"(r4)
165 :
"r"(r5),
"r"(r11));
169 static __inline__
void stw_u(
unsigned long r5,
unsigned short *r11)
171 #if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91)) 172 struct __una_u16 *ptr = (
struct __una_u16 *) r11;
175 unsigned long r1, r2, r3, r4;
177 __asm__(
"ldq_u %3,%1\n\t" 187 :
"=m"(*r11),
"=m"(*(
unsigned long *) (1 + (
char *) r11)),
188 "=&r"(r1),
"=&r"(r2),
"=&r"(r3),
"=&r"(r4)
189 :
"r"(r5),
"r"(r11));
193 #elif defined(__GNUC__) && ((__GNUC__ < 3)) && \ 194 (defined(__ia64__) || defined(ia64__)) 213 static __inline__
unsigned long __uldq(
const unsigned long *r11)
215 const struct __una_u64 *ptr = (
const struct __una_u64 *) r11;
219 static __inline__
unsigned long uldl(
const unsigned int *r11)
221 const struct __una_u32 *ptr = (
const struct __una_u32 *) r11;
225 static __inline__
unsigned long uldw(
const unsigned short *r11)
227 const struct __una_u16 *ptr = (
const struct __una_u16 *) r11;
231 static __inline__
void ustq(
unsigned long r5,
unsigned long *r11)
233 struct __una_u64 *ptr = (
struct __una_u64 *) r11;
237 static __inline__
void ustl(
unsigned long r5,
unsigned int *r11)
239 struct __una_u32 *ptr = (
struct __una_u32 *) r11;
243 static __inline__
void ustw(
unsigned long r5,
unsigned short *r11)
245 struct __una_u16 *ptr = (
struct __una_u16 *) r11;
261 u8 X86API rdb(u32 addr)
265 if (addr > M.mem_size - 1)
267 DB(printk(
"mem_read: address %#lx out of range!\n", addr);)
270 val = *(u8 *) (M.mem_base + addr);
271 DB(
if (DEBUG_MEM_TRACE()) printk(
"%#08x 1 -> %#x\n", addr, val);)
285 u16 X86API rdw(u32 addr)
289 if (addr > M.mem_size - 2)
291 DB(printk(
"mem_read: address %#lx out of range!\n", addr);)
294 #ifdef __BIG_ENDIAN__ 298 (*(u8 *) (M.mem_base + addr) |
299 (*(u8 *) (M.mem_base + addr + 1) << 8));
303 #if defined(ALPHA_UALOADS) 304 val = ldw_u((u16 *) (M.mem_base + addr));
305 #elif defined(IA64_UALOADS) 306 val = uldw((u16 *) (M.mem_base + addr));
308 val = *(u16 *) (M.mem_base + addr);
310 DB(
if (DEBUG_MEM_TRACE()) printk(
"%#08x 2 -> %#x\n", addr, val);)
323 u32 X86API rdl(u32 addr)
327 if (addr > M.mem_size - 4)
329 DB(printk(
"mem_read: address %#lx out of range!\n", addr);)
332 #ifdef __BIG_ENDIAN__ 336 (*(u8 *) (M.mem_base + addr + 0) |
337 (*(u8 *) (M.mem_base + addr + 1) << 8) |
338 (*(u8 *) (M.mem_base + addr + 2) << 16) |
339 (*(u8 *) (M.mem_base + addr + 3) << 24));
343 #if defined(ALPHA_UALOADS) 344 val = ldl_u((u32 *) (M.mem_base + addr));
345 #elif defined(IA64_UALOADS) 346 val = uldl((u32 *) (M.mem_base + addr));
348 val = *(u32 *) (M.mem_base + addr);
350 DB(
if (DEBUG_MEM_TRACE()) printk(
"%#08x 4 -> %#x\n", addr, val);)
362 void X86API wrb(u32 addr, u8 val)
364 DB(
if (DEBUG_MEM_TRACE()) printk(
"%#08x 1 <- %#x\n", addr, val);)
365 if (addr > M.mem_size - 1)
367 DB(printk(
"mem_write: address %#lx out of range!\n", addr);)
370 *(u8 *) (M.mem_base + addr) = val;
381 void X86API wrw(u32 addr, u16 val)
383 DB(
if (DEBUG_MEM_TRACE()) printk(
"%#08x 2 <- %#x\n", addr, val);)
384 if (addr > M.mem_size - 2)
386 DB(printk(
"mem_write: address %#lx out of range!\n", addr);)
389 #ifdef __BIG_ENDIAN__ 392 *(u8 *) (M.mem_base + addr + 0) = (val >> 0) & 0xff;
393 *(u8 *) (M.mem_base + addr + 1) = (val >> 8) & 0xff;
397 #if defined(ALPHA_UALOADS) 398 stw_u(val, (u16 *) (M.mem_base + addr));
399 #elif defined(IA64_UALOADS) 400 ustw(val, (u16 *) (M.mem_base + addr));
402 *(u16 *) (M.mem_base + addr) = val;
414 void X86API wrl(u32 addr, u32 val)
416 DB(
if (DEBUG_MEM_TRACE()) printk(
"%#08x 4 <- %#x\n", addr, val);)
417 if (addr > M.mem_size - 4)
419 DB(printk(
"mem_write: address %#lx out of range!\n", addr);)
422 #ifdef __BIG_ENDIAN__ 425 *(u8 *) (M.mem_base + addr + 0) = (val >> 0) & 0xff;
426 *(u8 *) (M.mem_base + addr + 1) = (val >> 8) & 0xff;
427 *(u8 *) (M.mem_base + addr + 2) = (val >> 16) & 0xff;
428 *(u8 *) (M.mem_base + addr + 3) = (val >> 24) & 0xff;
432 #if defined(ALPHA_UALOADS) 433 stl_u(val, (u32 *) (M.mem_base + addr));
434 #elif defined(IA64_UALOADS) 435 ustl(val, (u32 *) (M.mem_base + addr));
437 *(u32 *) (M.mem_base + addr) = val;
449 static u8 X86API p_inb(X86EMU_pioAddr addr)
451 DB(
if (DEBUG_IO_TRACE()) printk(
"inb %#04x \n", addr);)
463 static u16 X86API p_inw(X86EMU_pioAddr addr)
465 DB(
if (DEBUG_IO_TRACE()) printk(
"inw %#04x \n", addr);)
477 static u32 X86API p_inl(X86EMU_pioAddr addr)
479 DB(
if (DEBUG_IO_TRACE()) printk(
"inl %#04x \n", addr);)
490 static void X86API p_outb(X86EMU_pioAddr addr, u8 val)
492 DB(
if (DEBUG_IO_TRACE()) printk(
"outb %#02x -> %#04x \n", val, addr);)
503 static void X86API p_outw(X86EMU_pioAddr addr, u16 val)
505 DB(
if (DEBUG_IO_TRACE()) printk(
"outw %#04x -> %#04x \n", val, addr);)
516 static void X86API p_outl(X86EMU_pioAddr addr, u32 val)
518 DB(
if (DEBUG_IO_TRACE()) printk(
"outl %#08x -> %#04x \n", val, addr);)
524 u8(X86APIP sys_rdb)(u32 addr) = rdb;
525 u16(X86APIP sys_rdw)(u32 addr) = rdw;
526 u32(X86APIP sys_rdl)(u32 addr) = rdl;
527 void(X86APIP sys_wrb)(u32 addr, u8 val) = wrb;
528 void(X86APIP sys_wrw)(u32 addr, u16 val) = wrw;
529 void(X86APIP sys_wrl)(u32 addr, u32 val) = wrl;
530 u8(X86APIP sys_inb)(X86EMU_pioAddr addr) = p_inb;
531 u16(X86APIP sys_inw)(X86EMU_pioAddr addr) = p_inw;
532 u32(X86APIP sys_inl)(X86EMU_pioAddr addr) = p_inl;
533 void(X86APIP sys_outb)(X86EMU_pioAddr addr, u8 val) = p_outb;
534 void(X86APIP sys_outw)(X86EMU_pioAddr addr, u16 val) = p_outw;
535 void(X86APIP sys_outl)(X86EMU_pioAddr addr, u32 val) = p_outl;
550 sys_rdb = funcs->rdb;
551 sys_rdw = funcs->rdw;
552 sys_rdl = funcs->rdl;
553 sys_wrb = funcs->wrb;
554 sys_wrw = funcs->wrw;
555 sys_wrl = funcs->wrl;
569 sys_inb = funcs->inb;
570 sys_inw = funcs->inw;
571 sys_inl = funcs->inl;
572 sys_outb = funcs->outb;
573 sys_outw = funcs->outw;
574 sys_outl = funcs->outl;
590 void X86EMU_setupIntrFuncs(X86EMU_intrFuncs funcs[])
594 for (i = 0; i < 256; i++)
595 _X86EMU_intrTab[i] = NULL;
598 for (i = 0; i < 256; i++)
599 _X86EMU_intrTab[i] = funcs[i];
615 void X86EMU_prepareForInt(
int num)
617 push_word((u16) M.x86.R_FLG);
620 push_word(M.x86.R_CS);
621 M.x86.R_CS = mem_access_word(num * 4 + 2);
622 push_word(M.x86.R_IP);
623 M.x86.R_IP = mem_access_word(num * 4);