From 0dae8b8d48c586f52cbc23b65acb4d744b01482e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Fr=C3=B6schle?= Date: Wed, 18 Feb 2015 15:54:14 +0000 Subject: [PATCH] fixed emulator "struct emu"-dependent calls --- BaS_gcc.files | 1 + Makefile | 2 +- bas.lk.in | 1 + include/setjmp.h | 11 +++++++++++ include/x86emu.h | 4 +--- x86emu/x86biosemu.c | 24 ++++++++++++------------ x86emu/x86emu.c | 33 ++++++++++++++------------------- 7 files changed, 41 insertions(+), 35 deletions(-) create mode 100644 include/setjmp.h diff --git a/BaS_gcc.files b/BaS_gcc.files index 9377182..a04be06 100644 --- a/BaS_gcc.files +++ b/BaS_gcc.files @@ -206,3 +206,4 @@ util/setjmp.c util/setjmp.S include/x86emu_regs.h x86emu/x86emu_util.c +include/setjmp.h diff --git a/Makefile b/Makefile index d9054c1..68b06a4 100644 --- a/Makefile +++ b/Makefile @@ -217,7 +217,7 @@ define CC_TEMPLATE #$(1)/objs/x86ops.o: CFLAGS=$(CFLAGS_OPTIMIZED) #$(1)/objs/x86ops2.o: CFLAGS=$(CFLAGS_OPTIMIZED) #$(1)/objs/x86fpu.o: CFLAGS=$(CFLAGS_OPTIMIZED) -#$(1)/objs/x86biosemu.o: CFLAGS=$(CFLAGS_OPTIMIZED) +$(1)/objs/x86biosemu.o: CFLAGS=$(CFLAGS_OPTIMIZED) #$(1)/objs/x86pcibios.o: CFLAGS=$(CFLAGS_OPTIMIZED) $(1)/objs/%.o:%.c diff --git a/bas.lk.in b/bas.lk.in index 47ac066..c7675a4 100644 --- a/bas.lk.in +++ b/bas.lk.in @@ -99,6 +99,7 @@ SECTIONS OBJDIR/x86emu.o(.text) OBJDIR/x86emu_util.o(.text) + OBJDIR/x86biosemu.o(.text) OBJDIR/radeon_base.o(.text) OBJDIR/radeon_accel.o(.text) diff --git a/include/setjmp.h b/include/setjmp.h new file mode 100644 index 0000000..010591b --- /dev/null +++ b/include/setjmp.h @@ -0,0 +1,11 @@ +#ifndef _SETJMP_H_ +#define _SETJMP_H_ + +#include "bas_types.h" + +typedef uint32_t jmp_buf[18]; + +extern int setjmp(jmp_buf env); +extern void longjmp(jmp_buf env, int val); + +#endif /* _SETJMP_H_ */ diff --git a/include/x86emu.h b/include/x86emu.h index 306eea1..1374acf 100644 --- a/include/x86emu.h +++ b/include/x86emu.h @@ -35,7 +35,7 @@ #define __X86EMU_X86EMU_H #include "bas_types.h" - +#include "setjmp.h" /* * General EAX, EBX, ECX, EDX type registers. Note that for @@ -111,8 +111,6 @@ struct X86EMU_regs { uint8_t __pad[3]; }; -typedef uint32_t jmp_buf[18]; - struct X86EMU { char *mem_base; diff --git a/x86emu/x86biosemu.c b/x86emu/x86biosemu.c index 42a1c93..cfbb22b 100644 --- a/x86emu/x86biosemu.c +++ b/x86emu/x86biosemu.c @@ -12,13 +12,13 @@ #define USE_SDRAM #define DIRECT_ACCESS -#define MEM_WB(where, what) wrb(where, what) -#define MEM_WW(where, what) wrw(where, what) -#define MEM_WL(where, what) wrl(where, what) +#define MEM_WB(where, what) emu->emu_wrb(emu, where, what) +#define MEM_WW(where, what) emu->emu_wrw(emu, where, what) +#define MEM_WL(where, what) emu->emu_wrl(emu, where, what) -#define MEM_RB(where) rdb(where) -#define MEM_RW(where) rdw(where) -#define MEM_RL(where) rdl(where) +#define MEM_RB(where) emu->emu_rdb(emu, where) +#define MEM_RW(where) emu->emu_rdw(emu, where) +#define MEM_RL(where) emu->emu_rdl(emu, where) #define PCI_VGA_RAM_IMAGE_START 0xC0000 #define PCI_RAM_IMAGE_START 0xD0000 @@ -81,7 +81,7 @@ extern int x86_pcibios_emulator(); //X86EMU_sysEnv _X86EMU_env; /* general software interrupt handler */ -uint32_t getIntVect(int num) +uint32_t getIntVect(struct X86EMU *emu, int num) { return MEM_RW(num << 2) + (MEM_RW((num << 2) + 2) << 4); } @@ -219,9 +219,9 @@ void do_int(struct X86EMU *emu, int num) case 0x10: case 0x42: case 0x6D: - if (getIntVect(num) == 0x0000) + if (getIntVect(emu, num) == 0x0000) dbg("uninitialised int vector\r\n"); - if (getIntVect(num) == 0xFF065) + if (getIntVect(emu, num) == 0xFF065) { //ret = int42_handler(); ret = 1; @@ -360,9 +360,9 @@ void run_bios(struct radeonfb_info *rinfo) { char *date = "01/01/99"; for (i = 0; date[i]; i++) - wrb(0xffff5 + i, date[i]); - wrb(0xffff7, '/'); - wrb(0xffffa, '/'); + emu.emu_wrb(&emu, 0xffff5 + i, date[i]); + emu.emu_wrb(&emu, 0xffff7, '/'); + emu.emu_wrb(&emu, 0xffffa, '/'); } { /* FixME: move PIT init to its own file */ diff --git a/x86emu/x86emu.c b/x86emu/x86emu.c index 740fc90..07b5a57 100644 --- a/x86emu/x86emu.c +++ b/x86emu/x86emu.c @@ -34,6 +34,7 @@ #include #include #include +#include "setjmp.h" static void x86emu_intr_raise (struct X86EMU *, uint8_t type); @@ -174,12 +175,14 @@ static uint32_t pop_long (struct X86EMU *); REMARKS: Handles any pending asychronous interrupts. ****************************************************************************/ -static void -x86emu_intr_dispatch(struct X86EMU *emu, uint8_t intno) +static void x86emu_intr_dispatch(struct X86EMU *emu, uint8_t intno) { - if (emu->_X86EMU_intrTab[intno]) { + if (emu->_X86EMU_intrTab[intno]) + { (*emu->_X86EMU_intrTab[intno]) (emu, intno); - } else { + } + else + { push_word(emu, (uint16_t) emu->x86.R_FLG); CLEAR_FLAG(F_IF); CLEAR_FLAG(F_TF); @@ -190,17 +193,18 @@ x86emu_intr_dispatch(struct X86EMU *emu, uint8_t intno) } } -static void -x86emu_intr_handle(struct X86EMU *emu) +static void x86emu_intr_handle(struct X86EMU *emu) { uint8_t intno; - if (emu->x86.intr & INTR_SYNCH) { + if (emu->x86.intr & INTR_SYNCH) + { intno = emu->x86.intno; emu->x86.intr = 0; x86emu_intr_dispatch(emu, intno); } } + /**************************************************************************** PARAMETERS: intrnum - Interrupt number to raise @@ -209,8 +213,7 @@ REMARKS: Raise the specified interrupt to be handled before the execution of the next instruction. ****************************************************************************/ -void -x86emu_intr_raise(struct X86EMU *emu, uint8_t intrnum) +void x86emu_intr_raise(struct X86EMU *emu, uint8_t intrnum) { emu->x86.intno = intrnum; emu->x86.intr |= INTR_SYNCH; @@ -221,20 +224,12 @@ Main execution loop for the emulator. We return from here when the system halts, which is normally caused by a stack fault when we return from the original real mode call. ****************************************************************************/ -void -X86EMU_exec(struct X86EMU *emu) +void X86EMU_exec(struct X86EMU *emu) { emu->x86.intr = 0; -#ifdef _NOT_USED_ -#ifdef _KERNEL - if (setjmp(&emu->exec_state)) + if (setjmp(emu->exec_state)) return; -#else - if (setjmp(emu->exec_state)) - return; -#endif -#endif /* _NOT_USED_ */ for (;;) { if (emu->x86.intr) {