Author: hbelusca Date: Fri Nov 1 00:01:07 2013 New Revision: 60812
URL: http://svn.reactos.org/svn/reactos?rev=60812&view=rev Log: [FAST486][NTVDM] BOP numbers are 1 byte and map to a function (over 255). But one can pass additional "parameters" to those functions by adding extra bytes, however such functions must advance "by hand" the instruction pointer.
[NTVDM] - Take into account our previous remark for the BIOS interrupt stubs, and comment them. - Rework EmulatorBiosOperation (move almost all of its existing code into subfunctions in bop.c) so that one can call many other BOP functions in the future (WIP). The BOP number (still called) EMULATOR_INT_BOP (of value 0xFF) is used for internal 16 --> 32 bit switching for our 32bit bios. - It appears that the IoRead/WriteCallback and IdleCallback must not be NULL for using fast486. I'm committing a temporary fix that I will definitely fix in a subsequent commit.
Added: branches/ntvdm/subsystems/ntvdm/bop.c (with props) branches/ntvdm/subsystems/ntvdm/bop.h (with props) Modified: branches/ntvdm/include/reactos/libs/fast486/fast486.h branches/ntvdm/lib/fast486/opcodes.c branches/ntvdm/subsystems/ntvdm/CMakeLists.txt branches/ntvdm/subsystems/ntvdm/bios.c branches/ntvdm/subsystems/ntvdm/bios.h branches/ntvdm/subsystems/ntvdm/emulator.c branches/ntvdm/subsystems/ntvdm/emulator.h branches/ntvdm/subsystems/ntvdm/ntvdm.c
Modified: branches/ntvdm/include/reactos/libs/fast486/fast486.h URL: http://svn.reactos.org/svn/reactos/branches/ntvdm/include/reactos/libs/fast4... ============================================================================== --- branches/ntvdm/include/reactos/libs/fast486/fast486.h [iso-8859-1] (original) +++ branches/ntvdm/include/reactos/libs/fast486/fast486.h [iso-8859-1] Fri Nov 1 00:01:07 2013 @@ -210,7 +210,7 @@ (NTAPI *FAST486_BOP_PROC) ( PFAST486_STATE State, - USHORT BopCode + UCHAR BopCode );
typedef
Modified: branches/ntvdm/lib/fast486/opcodes.c URL: http://svn.reactos.org/svn/reactos/branches/ntvdm/lib/fast486/opcodes.c?rev=... ============================================================================== --- branches/ntvdm/lib/fast486/opcodes.c [iso-8859-1] (original) +++ branches/ntvdm/lib/fast486/opcodes.c [iso-8859-1] Fri Nov 1 00:01:07 2013 @@ -4331,10 +4331,10 @@ && (ModRegRm.SecondRegister == FAST486_REG_ESP) && (State->BopCallback != NULL)) { - USHORT BopCode; + UCHAR BopCode;
/* Fetch the BOP code */ - if (!Fast486FetchWord(State, &BopCode)) + if (!Fast486FetchByte(State, &BopCode)) { /* Exception occurred */ return FALSE;
Modified: branches/ntvdm/subsystems/ntvdm/CMakeLists.txt URL: http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/CMakeList... ============================================================================== --- branches/ntvdm/subsystems/ntvdm/CMakeLists.txt [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/CMakeLists.txt [iso-8859-1] Fri Nov 1 00:01:07 2013 @@ -5,6 +5,7 @@
list(APPEND SOURCE bios.c + bop.c dos.c emulator.c pic.c
Modified: branches/ntvdm/subsystems/ntvdm/bios.c URL: http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/bios.c?re... ============================================================================== --- branches/ntvdm/subsystems/ntvdm/bios.c [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/bios.c [iso-8859-1] Fri Nov 1 00:01:07 2013 @@ -453,7 +453,7 @@
BOOLEAN BiosInitialize(VOID) { - INT i; + USHORT i; WORD Offset = 0; LPWORD IntVecTable = (LPWORD)BaseAddress; LPBYTE BiosCode = (LPBYTE)SEG_OFF_TO_PTR(BIOS_SEGMENT, 0); @@ -465,7 +465,7 @@ Bda->KeybdBufferEnd = Bda->KeybdBufferStart + BIOS_KBD_BUFFER_SIZE * sizeof(WORD);
/* Generate ISR stubs and fill the IVT */ - for (i = 0; i < 256; i++) + for (i = 0x00; i <= 0xFF; i++) { IntVecTable[i * 2] = Offset; IntVecTable[i * 2 + 1] = BIOS_SEGMENT; @@ -473,27 +473,28 @@ BiosCode[Offset++] = 0xFB; // sti
BiosCode[Offset++] = 0x6A; // push i - BiosCode[Offset++] = (BYTE)i; + BiosCode[Offset++] = (UCHAR)i;
BiosCode[Offset++] = 0x6A; // push 0 BiosCode[Offset++] = 0x00;
+// BOP_SEQ: BiosCode[Offset++] = 0xF8; // clc
BiosCode[Offset++] = LOBYTE(EMULATOR_BOP); // BOP sequence BiosCode[Offset++] = HIBYTE(EMULATOR_BOP); - BiosCode[Offset++] = LOBYTE(EMULATOR_INT_BOP); - BiosCode[Offset++] = HIBYTE(EMULATOR_INT_BOP); - - BiosCode[Offset++] = 0x73; // jnc +3 + BiosCode[Offset++] = EMULATOR_INT_BOP; + + BiosCode[Offset++] = 0x73; // jnc EXIT (offset +3) BiosCode[Offset++] = 0x03;
// HACK: The following instruction should be HLT! BiosCode[Offset++] = 0x90; // nop
- BiosCode[Offset++] = 0xEB; // jmp -10 - BiosCode[Offset++] = 0xF6; - + BiosCode[Offset++] = 0xEB; // jmp BOP_SEQ (offset -9) + BiosCode[Offset++] = 0xF7; + +// EXIT: BiosCode[Offset++] = 0x83; // add sp, 4 BiosCode[Offset++] = 0xC4; BiosCode[Offset++] = 0x04;
Modified: branches/ntvdm/subsystems/ntvdm/bios.h URL: http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/bios.h?re... ============================================================================== --- branches/ntvdm/subsystems/ntvdm/bios.h [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/bios.h [iso-8859-1] Fri Nov 1 00:01:07 2013 @@ -18,8 +18,10 @@ #define ROM_AREA_START 0xE0000 #define ROM_AREA_END 0xFFFFF #define BDA_SEGMENT 0x40 + #define BIOS_PIC_MASTER_INT 0x08 -#define BIOS_PIC_SLAVE_INT 0x70 +#define BIOS_PIC_SLAVE_INT 0x70 + #define BIOS_SEGMENT 0xF000
#define BIOS_VIDEO_INTERRUPT 0x10
Added: branches/ntvdm/subsystems/ntvdm/bop.c URL: http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/bop.c?rev... ============================================================================== --- branches/ntvdm/subsystems/ntvdm/bop.c (added) +++ branches/ntvdm/subsystems/ntvdm/bop.c [iso-8859-1] Fri Nov 1 00:01:07 2013 @@ -0,0 +1,165 @@ +/* + * COPYRIGHT: GPL - See COPYING in the top level directory + * PROJECT: ReactOS Virtual DOS Machine + * FILE: bop.c + * PURPOSE: BIOS Operation Handlers + * PROGRAMMERS: Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org> + * Hermes Belusca-Maito (hermes.belusca@sfr.fr) + */ + +/* INCLUDES *******************************************************************/ + +#define NDEBUG + +#include "emulator.h" +#include "bios.h" +#include "dos.h" +#include "vga.h" +#include "pic.h" +#include "ps2.h" +#include "timer.h" + + +LPCWSTR ExceptionName[] = +{ + L"Division By Zero", + L"Debug", + L"Unexpected Error", + L"Breakpoint", + L"Integer Overflow", + L"Bound Range Exceeded", + L"Invalid Opcode", + L"FPU Not Available" +}; + +VOID WINAPI Exception(BYTE ExceptionNumber, LPWORD Stack) +{ + WORD CodeSegment, InstructionPointer; + + ASSERT(ExceptionNumber < 8); + + /* Get the CS:IP */ + InstructionPointer = Stack[STACK_IP]; + CodeSegment = Stack[STACK_CS]; + + /* Display a message to the user */ + DisplayMessage(L"Exception: %s occured at %04X:%04X", + ExceptionName[ExceptionNumber], + CodeSegment, + InstructionPointer); + + /* Stop the VDM */ + VdmRunning = FALSE; + return; +} + +// VOID WINAPI IrqDispatch(BYTE IrqNumber, LPWORD Stack) +// { + // /* Check if this was an PIC IRQ */ + // if (IntNum >= BIOS_PIC_MASTER_INT && IntNum < BIOS_PIC_MASTER_INT + 8) + // { + // /* It was an IRQ from the master PIC */ + // BiosHandleIrq(IntNum - BIOS_PIC_MASTER_INT, Stack); + // } + // else if (IntNum >= BIOS_PIC_SLAVE_INT && IntNum < BIOS_PIC_SLAVE_INT + 8) + // { + // /* It was an IRQ from the slave PIC */ + // BiosHandleIrq(IntNum - BIOS_PIC_SLAVE_INT + 8, Stack); + // } + + // return; +// } + +// VOID WINAPI BiosInt(BYTE IntNumber, LPWORD Stack) +// { +// } + +VOID WINAPI IntDispatch(LPWORD Stack) +{ + BYTE IntNum; + + /* Get the interrupt number */ + IntNum = LOBYTE(Stack[STACK_INT_NUM]); + + /* Check if this was an exception */ + if (IntNum < 8) + { + Exception(IntNum, Stack); + return; + } + + /* Check if this was an PIC IRQ */ + if (IntNum >= BIOS_PIC_MASTER_INT && IntNum < BIOS_PIC_MASTER_INT + 8) + { + /* It was an IRQ from the master PIC */ + BiosHandleIrq(IntNum - BIOS_PIC_MASTER_INT, Stack); + return; + } + else if (IntNum >= BIOS_PIC_SLAVE_INT && IntNum < BIOS_PIC_SLAVE_INT + 8) + { + /* It was an IRQ from the slave PIC */ + BiosHandleIrq(IntNum - BIOS_PIC_SLAVE_INT + 8, Stack); + return; + } + + switch (IntNum) + { + case BIOS_VIDEO_INTERRUPT: + { + /* This is the video BIOS interrupt, call the BIOS */ + BiosVideoService(Stack); + break; + } + case BIOS_EQUIPMENT_INTERRUPT: + { + /* This is the BIOS "get equipment" command, call the BIOS */ + BiosEquipmentService(Stack); + break; + } + case BIOS_KBD_INTERRUPT: + { + /* This is the keyboard BIOS interrupt, call the BIOS */ + BiosKeyboardService(Stack); + break; + } + case BIOS_TIME_INTERRUPT: + { + /* This is the time BIOS interrupt, call the BIOS */ + BiosTimeService(Stack); + break; + } + case BIOS_SYS_TIMER_INTERRUPT: + { + /* BIOS timer update */ + BiosSystemTimerInterrupt(Stack); + break; + } + case 0x20: + { + DosInt20h(Stack); + break; + } + case 0x21: + { + DosInt21h(Stack); + break; + } + case 0x23: + { + DosBreakInterrupt(Stack); + break; + } + default: + { + DPRINT1("Unhandled interrupt: 0x%02X\n", IntNum); + break; + } + } +} + +VOID WINAPI ControlBop(LPWORD Stack) +{ + IntDispatch(Stack); +} + +/* EOF */
Propchange: branches/ntvdm/subsystems/ntvdm/bop.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: branches/ntvdm/subsystems/ntvdm/bop.h URL: http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/bop.h?rev... ============================================================================== --- branches/ntvdm/subsystems/ntvdm/bop.h (added) +++ branches/ntvdm/subsystems/ntvdm/bop.h [iso-8859-1] Fri Nov 1 00:01:07 2013 @@ -0,0 +1,10 @@ +/* + * COPYRIGHT: GPL - See COPYING in the top level directory + * PROJECT: ReactOS Virtual DOS Machine + * FILE: bop.h + * PURPOSE: BIOS Operation Handlers + * PROGRAMMERS: Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org> + * Hermes Belusca-Maito (hermes.belusca@sfr.fr) + */ + +/* EOF */
Propchange: branches/ntvdm/subsystems/ntvdm/bop.h ------------------------------------------------------------------------------ svn:eol-style = native
Modified: branches/ntvdm/subsystems/ntvdm/emulator.c URL: http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/emulator.... ============================================================================== --- branches/ntvdm/subsystems/ntvdm/emulator.c [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/emulator.c [iso-8859-1] Fri Nov 1 00:01:07 2013 @@ -225,10 +225,10 @@ } }
-static VOID WINAPI EmulatorBiosOperation(PFAST486_STATE State, USHORT BopCode) -{ - WORD StackSegment, StackPointer, CodeSegment, InstructionPointer; - BYTE IntNum; +VOID WINAPI ControlBop(LPWORD Stack); +static VOID WINAPI EmulatorBiosOperation(PFAST486_STATE State, UCHAR BopCode) +{ + WORD StackSegment, StackPointer; LPWORD Stack;
/* Get the SS:SP */ @@ -238,97 +238,20 @@ /* Get the stack */ Stack = (LPWORD)SEG_OFF_TO_PTR(StackSegment, StackPointer);
- if (BopCode == EMULATOR_INT_BOP) - { - /* Get the interrupt number */ - IntNum = LOBYTE(Stack[STACK_INT_NUM]); - - /* Get the CS:IP */ - InstructionPointer = Stack[STACK_IP]; - CodeSegment = Stack[STACK_CS]; - - /* Check if this was an exception */ - if (IntNum < 8) - { - /* Display a message to the user */ - DisplayMessage(L"Exception: %s occured at %04X:%04X", - ExceptionName[IntNum], - CodeSegment, - InstructionPointer); - - /* Stop the VDM */ - VdmRunning = FALSE; - return; - } - - /* Check if this was an PIC IRQ */ - if (IntNum >= BIOS_PIC_MASTER_INT && IntNum < BIOS_PIC_MASTER_INT + 8) - { - /* It was an IRQ from the master PIC */ - BiosHandleIrq(IntNum - BIOS_PIC_MASTER_INT, Stack); - return; - } - else if (IntNum >= BIOS_PIC_SLAVE_INT && IntNum < BIOS_PIC_SLAVE_INT + 8) - { - /* It was an IRQ from the slave PIC */ - BiosHandleIrq(IntNum - BIOS_PIC_SLAVE_INT + 8, Stack); - return; - } - - switch (IntNum) - { - case BIOS_VIDEO_INTERRUPT: - { - /* This is the video BIOS interrupt, call the BIOS */ - BiosVideoService(Stack); - break; - } - case BIOS_EQUIPMENT_INTERRUPT: - { - /* This is the BIOS "get equipment" command, call the BIOS */ - BiosEquipmentService(Stack); - break; - } - case BIOS_KBD_INTERRUPT: - { - /* This is the keyboard BIOS interrupt, call the BIOS */ - BiosKeyboardService(Stack); - break; - } - case BIOS_TIME_INTERRUPT: - { - /* This is the time BIOS interrupt, call the BIOS */ - BiosTimeService(Stack); - break; - } - case BIOS_SYS_TIMER_INTERRUPT: - { - /* BIOS timer update */ - BiosSystemTimerInterrupt(Stack); - break; - } - case 0x20: - { - DosInt20h(Stack); - break; - } - case 0x21: - { - DosInt21h(Stack); - break; - } - case 0x23: - { - DosBreakInterrupt(Stack); - break; - } - default: - { - DPRINT1("Unhandled interrupt: 0x%02X\n", IntNum); - break; - } - } - } + switch (BopCode) + { + case EMULATOR_INT_BOP: + ControlBop(Stack); + break; + + default: + DPRINT1("Invalid BOP code %u\n", BopCode); + break; + } +} + +static VOID WINAPI EmulatorIdle(PFAST486_STATE State) +{ }
static UCHAR WINAPI EmulatorIntAcknowledge(PFAST486_STATE State) @@ -350,8 +273,9 @@ /* Set the callbacks */ EmulatorContext.MemReadCallback = EmulatorReadMemory; EmulatorContext.MemWriteCallback = EmulatorWriteMemory; - EmulatorContext.IoReadCallback = EmulatorReadIo; - EmulatorContext.IoWriteCallback = EmulatorWriteIo; + EmulatorContext.IoReadCallback = EmulatorReadIo; // Must be != NULL + EmulatorContext.IoWriteCallback = EmulatorWriteIo; // Must be != NULL + EmulatorContext.IdleCallback = EmulatorIdle; // Must be != NULL EmulatorContext.BopCallback = EmulatorBiosOperation; EmulatorContext.IntAckCallback = EmulatorIntAcknowledge;
Modified: branches/ntvdm/subsystems/ntvdm/emulator.h URL: http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/emulator.... ============================================================================== --- branches/ntvdm/subsystems/ntvdm/emulator.h [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/emulator.h [iso-8859-1] Fri Nov 1 00:01:07 2013 @@ -35,13 +35,14 @@ #define EMULATOR_FLAG_ID (1 << 21)
/* Common definitions */ -#define EMULATOR_BOP 0xC4C4 -#define EMULATOR_INT_BOP 0xBEEF -#define STACK_COUNTER 0 -#define STACK_INT_NUM 1 -#define STACK_IP 2 -#define STACK_CS 3 -#define STACK_FLAGS 4 +#define EMULATOR_BOP 0xC4C4 +#define EMULATOR_INT_BOP 0xFF + +#define STACK_COUNTER 0 +#define STACK_INT_NUM 1 +#define STACK_IP 2 +#define STACK_CS 3 +#define STACK_FLAGS 4
enum {
Modified: branches/ntvdm/subsystems/ntvdm/ntvdm.c URL: http://svn.reactos.org/svn/reactos/branches/ntvdm/subsystems/ntvdm/ntvdm.c?r... ============================================================================== --- branches/ntvdm/subsystems/ntvdm/ntvdm.c [iso-8859-1] (original) +++ branches/ntvdm/subsystems/ntvdm/ntvdm.c [iso-8859-1] Fri Nov 1 00:01:07 2013 @@ -29,17 +29,6 @@
BOOLEAN VdmRunning = TRUE; LPVOID BaseAddress = NULL; -LPCWSTR ExceptionName[] = -{ - L"Division By Zero", - L"Debug", - L"Unexpected Error", - L"Breakpoint", - L"Integer Overflow", - L"Bound Range Exceeded", - L"Invalid Opcode", - L"FPU Not Available" -};
/* PUBLIC FUNCTIONS ***********************************************************/