diff --git a/reactos/boot/freeldr/freeldr/CMakeLists.txt b/reactos/boot/freeldr/freeldr/CMakeLists.txt index 85b3d5a3671..8fe1ebdd8af 100644 --- a/reactos/boot/freeldr/freeldr/CMakeLists.txt +++ b/reactos/boot/freeldr/freeldr/CMakeLists.txt @@ -16,11 +16,8 @@ if(ARCH MATCHES i386) arch/i386/i386bug.c) if(NOT MSVC) list(APPEND FREELDR_BASE64K_SOURCE - arch/i386/boot.S arch/i386/drvmap.S - arch/i386/i386cpu.S arch/i386/i386pnp.S - arch/i386/i386pxe.S arch/i386/linux.S arch/i386/multiboot.S arch/i386/mb.S) @@ -32,8 +29,6 @@ elseif(ARCH MATCHES amd64) if(NOT MSVC) list(APPEND FREELDR_BASE64K_SOURCE arch/i386/drvmap.S - arch/i386/i386cpu.S - arch/i386/i386idt.S arch/i386/i386trap.S arch/amd64/mb.S) else() diff --git a/reactos/boot/freeldr/freeldr/arch/i386/entry.S b/reactos/boot/freeldr/freeldr/arch/i386/entry.S index 835cf7c11e0..816ae641f8e 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/entry.S +++ b/reactos/boot/freeldr/freeldr/arch/i386/entry.S @@ -259,8 +259,8 @@ _Int386: mov ecx, 9 rep movsd - /* Set the callback index */ - mov bx, 0 + /* Set the function ID */ + mov bx, FNID_Int386 /* Set continue address and switch to real mode */ mov dword ptr [ContinueAddress], offset Int386_return @@ -282,6 +282,86 @@ Int386_return: ret +/* + * U16 PxeCallApi(U16 Segment, U16 Offset, U16 Service, VOID *Parameter); + * + * RETURNS: + */ +PUBLIC _PxeCallApi +_PxeCallApi: + push ebp + mov ebp, esp + + pusha + push es + + /* copy entry point */ + mov eax, [ebp + 8] + shl eax, 16 + mov ax, [ebp + 12] + mov dword ptr ds:[BSS_PxeEntryPoint], eax + + /* copy function */ + mov ax, [ebp + 16] + mov word ptr ds:[BSS_PxeFunction], ax + + /* convert pointer to data buffer to segment/offset */ + mov eax, [ebp + 20] + shr eax, 4 + and eax, HEX(0f000) + mov word ptr ds:[BSS_PxeBufferSegment], ax + mov eax, [ebp + 20] + and eax, HEX(0ffff) + mov word ptr ds:[BSS_PxeBufferOffset], ax + + /* Set the function ID and call realmode */ + mov bx, FNID_PxeCallApi + call i386CallRealMode + + pop es + popa + + mov esp, ebp + pop ebp + + mov ax, word ptr [BSS_PxeResult] + + ret + + +PUBLIC _SoftReboot +_SoftReboot: + /* Set the function ID */ + mov bx, FNID_SoftReboot + + /*Switch to real mode (We don't return) */ + jmp SwitchToReal + + +PUBLIC _ChainLoadBiosBootSectorCode +_ChainLoadBiosBootSectorCode: + /* Set the boot drive */ + mov dl, byte ptr [_FrldrBootDrive] + + /* Set the function ID */ + mov bx, FNID_ChainLoadBiosBootSectorCode + + /*Switch to real mode (We don't return) */ + jmp SwitchToReal + + +PUBLIC i386CallRealMode +i386CallRealMode: + /* Set continue address and switch to real mode */ + mov dword ptr [ContinueAddress], offset i386CallRealMode_return + jmp SwitchToReal +i386CallRealMode_return: + ret + + +/* Entrypoint for realmode function calls + * ContinueAddress must be set to the return point from realmode + * bx must be set to the ID of the realmode function to call. */ SwitchToReal: /* Set sane segments */ mov ax, PMODE_DS diff --git a/reactos/boot/freeldr/freeldr/arch/i386/i386idt.c b/reactos/boot/freeldr/freeldr/arch/i386/i386idt.c index 3444e094151..a4dd2e8b221 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/i386idt.c +++ b/reactos/boot/freeldr/freeldr/arch/i386/i386idt.c @@ -3,7 +3,7 @@ KIDTENTRY DECLSPEC_ALIGN(4) i386Idt[32]; -KDESCRIPTOR i386IdtDescriptor = {0, 255, i386Idt}; +KDESCRIPTOR i386IdtDescriptor = {0, 255, (ULONG)i386Idt}; static void diff --git a/reactos/boot/freeldr/freeldr/arch/i386/realmode.S b/reactos/boot/freeldr/freeldr/arch/i386/realmode.S index 9ee976cf230..1cc01cab1fe 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/realmode.S +++ b/reactos/boot/freeldr/freeldr/arch/i386/realmode.S @@ -20,18 +20,12 @@ _kernel_pagetable: PUBLIC _lowmem_pagetable _lowmem_pagetable: -PUBLIC _ChainLoadBiosBootSectorCode -_ChainLoadBiosBootSectorCode: - PUBLIC _BootOldLinuxKernel _BootOldLinuxKernel: PUBLIC _BootNewLinuxKernel _BootNewLinuxKernel: -PUBLIC _SoftReboot -_SoftReboot: - PUBLIC _DriveMapOldInt13HandlerAddress _DriveMapOldInt13HandlerAddress: @@ -53,7 +47,4 @@ _PnpBiosGetDeviceNodeCount: PUBLIC _PnpBiosSupported _PnpBiosSupported: -PUBLIC _PxeCallApi -_PxeCallApi: - END diff --git a/reactos/boot/freeldr/freeldr/arch/realmode/helpers.inc b/reactos/boot/freeldr/freeldr/arch/realmode/helpers.inc index adf3abf41f0..4121850f6a0 100644 --- a/reactos/boot/freeldr/freeldr/arch/realmode/helpers.inc +++ b/reactos/boot/freeldr/freeldr/arch/realmode/helpers.inc @@ -102,3 +102,19 @@ SoftReboot: /* and jump to location FFFF:0 in ROM */ ljmp16 HEX(0FFFF), HEX(0000) + + +ChainLoadBiosBootSectorCode: + + /* Load segment registers */ + cli + xor ax, ax + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + mov ss, ax + mov esp, HEX(7C00) + + /* Jump to the bootsector code */ + ljmp16 HEX(0000), HEX(7C00) diff --git a/reactos/boot/freeldr/freeldr/arch/realmode/i386.S b/reactos/boot/freeldr/freeldr/arch/realmode/i386.S index 76856e3014b..e5522ca80e1 100644 --- a/reactos/boot/freeldr/freeldr/arch/realmode/i386.S +++ b/reactos/boot/freeldr/freeldr/arch/realmode/i386.S @@ -121,10 +121,13 @@ pm_offset: .word 0 // receives address of PE entry point .word PMODE_CS nop - +// FIXME: use ljmp16 PMODE_CS:inpmode + hexed 32bit jump callback_table: .word Int386 + .word SoftReboot + .word ChainLoadBiosBootSectorCode + .word PxeCallApi /* 16-bit stack pointer */ diff --git a/reactos/boot/freeldr/freeldr/include/arch/pc/x86common.h b/reactos/boot/freeldr/freeldr/include/arch/pc/x86common.h index 483f2ccf6a3..15e81707f46 100644 --- a/reactos/boot/freeldr/freeldr/include/arch/pc/x86common.h +++ b/reactos/boot/freeldr/freeldr/include/arch/pc/x86common.h @@ -22,13 +22,23 @@ #define DISKREADBUFFER_SIZE 512 /* These addresses specify the realmode "BSS section" layout */ -#define BSS_RealModeEntry (BSS_START + 0) -#define BSS_CallbackAddress (BSS_START + 4) -#define BSS_CallbackReturn (BSS_START + 8) +#define BSS_RealModeEntry (BSS_START + 0) +#define BSS_CallbackAddress (BSS_START + 4) +#define BSS_CallbackReturn (BSS_START + 8) +#define BSS_RegisterSet (BSS_START + 16) /* size = 36 */ +#define BSS_IntVector (BSS_START + 52) +#define BSS_PxeEntryPoint (BSS_START + 56) +#define BSS_PxeBufferSegment (BSS_START + 60) +#define BSS_PxeBufferOffset (BSS_START + 64) +#define BSS_PxeFunction (BSS_START + 68) +#define BSS_PxeResult (BSS_START + 72) -#define BSS_RegisterSet (BSS_START + 16) /* size = 36 */ -#define BSS_IntVector (BSS_START + 52) -// next 52 + +/* Realmode function IDs */ +#define FNID_Int386 0 +#define FNID_SoftReboot 1 +#define FNID_ChainLoadBiosBootSectorCode 2 +#define FNID_PxeCallApi 3 /* Layout of the REGS structure */ #define REGS_EAX 0