mirror of
https://github.com/reactos/reactos.git
synced 2025-07-04 23:11:23 +00:00
[FREELDR]
- Add underscore to names of trap handlers and add C prototypes (will be needed later) - Move multiboot code to seperate file multiboot.S, not compiled atm, the code wasn't in use anyway - Remove EnableA20 dummy svn path=/trunk/; revision=52253
This commit is contained in:
parent
ef19190372
commit
c79c51d04d
8 changed files with 241 additions and 227 deletions
|
@ -17,13 +17,13 @@
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
.intel_syntax noprefix
|
|
||||||
#define HEX(y) 0x##y
|
|
||||||
|
|
||||||
#include <asm.inc>
|
#include <asm.inc>
|
||||||
#include <arch/pc/x86common.h>
|
#include <arch/pc/x86common.h>
|
||||||
#include <multiboot.h>
|
#include <multiboot.h>
|
||||||
|
|
||||||
|
EXTERN _BootMain:PROC
|
||||||
|
EXTERN _InitIdt:PROC
|
||||||
|
|
||||||
.code32
|
.code32
|
||||||
|
|
||||||
PUBLIC _RealEntryPoint
|
PUBLIC _RealEntryPoint
|
||||||
|
@ -74,6 +74,7 @@ stop:
|
||||||
nop
|
nop
|
||||||
nop
|
nop
|
||||||
|
|
||||||
|
#ifndef _USE_ML
|
||||||
/*
|
/*
|
||||||
* Switches the processor to protected mode
|
* Switches the processor to protected mode
|
||||||
* it destroys eax
|
* it destroys eax
|
||||||
|
@ -213,12 +214,9 @@ inrmode:
|
||||||
|
|
||||||
/* Now return in r-mode! */
|
/* Now return in r-mode! */
|
||||||
ret
|
ret
|
||||||
|
#endif
|
||||||
|
|
||||||
.code32
|
.code32
|
||||||
PUBLIC _EnableA20
|
|
||||||
_EnableA20:
|
|
||||||
ret
|
|
||||||
|
|
||||||
Int386_regsin:
|
Int386_regsin:
|
||||||
.long 0
|
.long 0
|
||||||
|
@ -295,153 +293,6 @@ SwitchToReal16Address:
|
||||||
nop
|
nop
|
||||||
|
|
||||||
|
|
||||||
/* Multiboot support
|
|
||||||
*
|
|
||||||
* Allows freeldr to be loaded as a "multiboot kernel" by
|
|
||||||
* other boot loaders like Grub
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define MB_INFO_SIZE 90
|
|
||||||
#define MB_INFO_FLAGS_OFFSET 0
|
|
||||||
#define MB_INFO_BOOT_DEVICE_OFFSET 12
|
|
||||||
#define MB_INFO_COMMAND_LINE_OFFSET 16
|
|
||||||
#define CMDLINE_SIZE 256
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We want to execute at 0x8000 (to be compatible with bootsector
|
|
||||||
* loading), but Grub only allows loading of multiboot kernels
|
|
||||||
* above 1MB. So we let Grub load us there and then relocate
|
|
||||||
* ourself to 0x8000
|
|
||||||
*/
|
|
||||||
#define FREELDR_BASE HEX(8000)
|
|
||||||
#define INITIAL_BASE HEX(200000)
|
|
||||||
|
|
||||||
/* Align 32 bits boundary */
|
|
||||||
.align 4
|
|
||||||
|
|
||||||
/* Multiboot header */
|
|
||||||
MultibootHeader:
|
|
||||||
/* magic */
|
|
||||||
.long MULTIBOOT_HEADER_MAGIC
|
|
||||||
/* flags */
|
|
||||||
.long MULTIBOOT_HEADER_FLAGS
|
|
||||||
/* checksum */
|
|
||||||
.long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
|
|
||||||
/* header_addr */
|
|
||||||
.long INITIAL_BASE + MultibootHeader - FREELDR_BASE
|
|
||||||
/* load_addr */
|
|
||||||
.long INITIAL_BASE
|
|
||||||
/* load_end_addr */
|
|
||||||
.long INITIAL_BASE + __bss_start__ - FREELDR_BASE
|
|
||||||
/* bss_end_addr */
|
|
||||||
.long INITIAL_BASE + __bss_end__ - FREELDR_BASE
|
|
||||||
/* entry_addr */
|
|
||||||
.long INITIAL_BASE + MultibootEntry - FREELDR_BASE
|
|
||||||
|
|
||||||
MultibootEntry:
|
|
||||||
cli /* Even after setting up the our IDT below we are
|
|
||||||
* not ready to handle hardware interrupts (no entries
|
|
||||||
* in IDT), so there's no sti here. Interrupts will be
|
|
||||||
* enabled in due time */
|
|
||||||
|
|
||||||
/* Although the multiboot spec says we should be called with the
|
|
||||||
* segment registers set to 4GB flat mode, let's be sure and set up
|
|
||||||
* our own */
|
|
||||||
lgdt gdtptrhigh + INITIAL_BASE - FREELDR_BASE
|
|
||||||
/* Reload segment selectors */
|
|
||||||
//ljmp $PMODE_CS, $(mb1 + INITIAL_BASE - FREELDR_BASE)
|
|
||||||
jmp far ptr PMODE_CS: (mb1 + INITIAL_BASE - FREELDR_BASE)
|
|
||||||
mb1:
|
|
||||||
mov dx, PMODE_DS
|
|
||||||
mov ds, dx
|
|
||||||
mov es, dx
|
|
||||||
|
|
||||||
/* Check for valid multiboot signature */
|
|
||||||
cmp eax, MULTIBOOT_BOOTLOADER_MAGIC
|
|
||||||
jne mbfail
|
|
||||||
|
|
||||||
/* Store multiboot info in a safe place */
|
|
||||||
mov esi, ebx
|
|
||||||
mov edi, offset mb_info + INITIAL_BASE - FREELDR_BASE
|
|
||||||
mov ecx, MB_INFO_SIZE
|
|
||||||
rep movsb
|
|
||||||
|
|
||||||
/* Save commandline */
|
|
||||||
mov edx, [ebx + MB_INFO_FLAGS_OFFSET]
|
|
||||||
test dword ptr [ebx + MB_INFO_FLAGS_OFFSET], MB_INFO_FLAG_COMMAND_LINE
|
|
||||||
jz mb3
|
|
||||||
mov esi, [ebx + MB_INFO_COMMAND_LINE_OFFSET]
|
|
||||||
mov edi, offset cmdline + INITIAL_BASE - FREELDR_BASE
|
|
||||||
mov ecx, CMDLINE_SIZE
|
|
||||||
mb2: lodsb
|
|
||||||
stosb
|
|
||||||
test al, al
|
|
||||||
jz mb3
|
|
||||||
dec ecx
|
|
||||||
jnz mb2
|
|
||||||
mb3:
|
|
||||||
|
|
||||||
/* Copy to low mem */
|
|
||||||
mov esi, INITIAL_BASE
|
|
||||||
mov edi, FREELDR_BASE
|
|
||||||
mov ecx, (offset __bss_end__ - FREELDR_BASE)
|
|
||||||
add ecx, 3
|
|
||||||
shr ecx, 2
|
|
||||||
rep movsd
|
|
||||||
|
|
||||||
/* Load the GDT and IDT */
|
|
||||||
lgdt gdtptr
|
|
||||||
lidt i386idtptr
|
|
||||||
|
|
||||||
/* Clear prefetch queue & correct CS,
|
|
||||||
* jump to low mem */
|
|
||||||
//ljmp $PMODE_CS, $mb4
|
|
||||||
jmp far ptr PMODE_CS:mb4
|
|
||||||
mb4:
|
|
||||||
/* Reload segment selectors */
|
|
||||||
mov dx, PMODE_DS
|
|
||||||
mov ds, dx
|
|
||||||
mov es, dx
|
|
||||||
mov fs, dx
|
|
||||||
mov gs, dx
|
|
||||||
mov ss, dx
|
|
||||||
mov esp, STACK32ADDR
|
|
||||||
|
|
||||||
mov ebx, offset mb_info
|
|
||||||
/* See if the boot device was passed in */
|
|
||||||
mov edx, [ebx + MB_INFO_FLAGS_OFFSET]
|
|
||||||
test edx, MB_INFO_FLAG_BOOT_DEVICE
|
|
||||||
jz mb5
|
|
||||||
/* Retrieve boot device info */
|
|
||||||
mov eax, [ebx + MB_INFO_BOOT_DEVICE_OFFSET]
|
|
||||||
shr eax, 16
|
|
||||||
inc al
|
|
||||||
mov byte ptr [_FrldrBootPartition], al
|
|
||||||
mov byte ptr [_FrldrBootDrive], ah
|
|
||||||
jmp mb6
|
|
||||||
mb5: /* No boot device known, assume first partition of first harddisk */
|
|
||||||
mov byte ptr [_FrldrBootDrive], HEX(80)
|
|
||||||
mov byte ptr [_FrldrBootPartition], 1
|
|
||||||
mb6:
|
|
||||||
/* Check for command line */
|
|
||||||
mov eax, offset cmdline
|
|
||||||
test dword ptr [ebx + MB_INFO_FLAGS_OFFSET], MB_INFO_FLAG_COMMAND_LINE
|
|
||||||
jnz mb7
|
|
||||||
xor eax, eax
|
|
||||||
mb7:
|
|
||||||
|
|
||||||
/* GO! */
|
|
||||||
push eax
|
|
||||||
call _BootMain
|
|
||||||
|
|
||||||
mbfail:
|
|
||||||
call switch_to_real
|
|
||||||
.code16
|
|
||||||
int 0x19
|
|
||||||
mbstop: jmp mbstop /* We should never get here */
|
|
||||||
|
|
||||||
.code32
|
|
||||||
|
|
||||||
/* 16-bit stack pointer */
|
/* 16-bit stack pointer */
|
||||||
stack16:
|
stack16:
|
||||||
.word STACK16ADDR
|
.word STACK16ADDR
|
||||||
|
@ -496,22 +347,11 @@ gdtptr:
|
||||||
.word HEX(27) /* Limit */
|
.word HEX(27) /* Limit */
|
||||||
.long gdt /* Base Address */
|
.long gdt /* Base Address */
|
||||||
|
|
||||||
/* Initial GDT table pointer for multiboot */
|
|
||||||
gdtptrhigh:
|
|
||||||
.word HEX(27) /* Limit */
|
|
||||||
.long gdt + INITIAL_BASE - FREELDR_BASE /* Base Address */
|
|
||||||
|
|
||||||
/* Real-mode IDT pointer */
|
/* Real-mode IDT pointer */
|
||||||
rmode_idtptr:
|
rmode_idtptr:
|
||||||
.word HEX(3ff) /* Limit */
|
.word HEX(3ff) /* Limit */
|
||||||
.long 0 /* Base Address */
|
.long 0 /* Base Address */
|
||||||
|
|
||||||
mb_info:
|
|
||||||
.fill MB_INFO_SIZE, 1, 0
|
|
||||||
|
|
||||||
cmdline:
|
|
||||||
.fill CMDLINE_SIZE, 1, 0
|
|
||||||
|
|
||||||
PUBLIC _FrldrBootDrive
|
PUBLIC _FrldrBootDrive
|
||||||
_FrldrBootDrive:
|
_FrldrBootDrive:
|
||||||
.long 0
|
.long 0
|
||||||
|
|
|
@ -26,91 +26,91 @@
|
||||||
.p2align 2 /* force 4-byte alignment */
|
.p2align 2 /* force 4-byte alignment */
|
||||||
EXTERN(i386idt)
|
EXTERN(i386idt)
|
||||||
/* Exception 0 - Divide By Zero */
|
/* Exception 0 - Divide By Zero */
|
||||||
.word i386DivideByZero /* Offset 0 - 15 */
|
.word _i386DivideByZero /* Offset 0 - 15 */
|
||||||
.word 0x0008 /* Selector */
|
.word 0x0008 /* Selector */
|
||||||
.word 0x8e00 /* Flags, Zero Byte */
|
.word 0x8e00 /* Flags, Zero Byte */
|
||||||
.word 0x0000 /* Offset 16 - 31 */
|
.word 0x0000 /* Offset 16 - 31 */
|
||||||
|
|
||||||
/* Exception 1 - Debug Exception */
|
/* Exception 1 - Debug Exception */
|
||||||
.word i386DebugException /* Offset 0 - 15 */
|
.word _i386DebugException /* Offset 0 - 15 */
|
||||||
.word 0x0008 /* Selector */
|
.word 0x0008 /* Selector */
|
||||||
.word 0x8e00 /* Zero byte, flags */
|
.word 0x8e00 /* Zero byte, flags */
|
||||||
.word 0x0000 /* Offset 16 - 31 */
|
.word 0x0000 /* Offset 16 - 31 */
|
||||||
|
|
||||||
/* Exception 2 - NMI */
|
/* Exception 2 - NMI */
|
||||||
.word i386NMIException /* Offset 0 - 15 */
|
.word _i386NMIException /* Offset 0 - 15 */
|
||||||
.word 0x0008 /* Selector */
|
.word 0x0008 /* Selector */
|
||||||
.word 0x8e00 /* Zero byte, flags */
|
.word 0x8e00 /* Zero byte, flags */
|
||||||
.word 0x0000 /* Offset 16 - 31 */
|
.word 0x0000 /* Offset 16 - 31 */
|
||||||
|
|
||||||
/* Exception 3 - Breakpoint (INT 3) */
|
/* Exception 3 - Breakpoint (INT 3) */
|
||||||
.word i386Breakpoint /* Offset 0 - 15 */
|
.word _i386Breakpoint /* Offset 0 - 15 */
|
||||||
.word 0x0008 /* Selector */
|
.word 0x0008 /* Selector */
|
||||||
.word 0x8e00 /* Zero byte, flags */
|
.word 0x8e00 /* Zero byte, flags */
|
||||||
.word 0x0000 /* Offset 16 - 31 */
|
.word 0x0000 /* Offset 16 - 31 */
|
||||||
|
|
||||||
/* Exception 4 - Overflow (INTO with EFLAGS[OF] set) */
|
/* Exception 4 - Overflow (INTO with EFLAGS[OF] set) */
|
||||||
.word i386Overflow /* Offset 0 - 15 */
|
.word _i386Overflow /* Offset 0 - 15 */
|
||||||
.word 0x0008 /* Selector */
|
.word 0x0008 /* Selector */
|
||||||
.word 0x8e00 /* Zero byte, flags */
|
.word 0x8e00 /* Zero byte, flags */
|
||||||
.word 0x0000 /* Offset 16 - 31 */
|
.word 0x0000 /* Offset 16 - 31 */
|
||||||
|
|
||||||
/* Exception 5 - Bound Exception */
|
/* Exception 5 - Bound Exception */
|
||||||
.word i386BoundException /* Offset 0 - 15 */
|
.word _i386BoundException /* Offset 0 - 15 */
|
||||||
.word 0x0008 /* Selector */
|
.word 0x0008 /* Selector */
|
||||||
.word 0x8e00 /* Zero byte, flags */
|
.word 0x8e00 /* Zero byte, flags */
|
||||||
.word 0x0000 /* Offset 16 - 31 */
|
.word 0x0000 /* Offset 16 - 31 */
|
||||||
|
|
||||||
/* Exception 6 - Invalid Opcode */
|
/* Exception 6 - Invalid Opcode */
|
||||||
.word i386InvalidOpcode /* Offset 0 - 15 */
|
.word _i386InvalidOpcode /* Offset 0 - 15 */
|
||||||
.word 0x0008 /* Selector */
|
.word 0x0008 /* Selector */
|
||||||
.word 0x8e00 /* Zero byte, flags */
|
.word 0x8e00 /* Zero byte, flags */
|
||||||
.word 0x0000 /* Offset 16 - 31 */
|
.word 0x0000 /* Offset 16 - 31 */
|
||||||
|
|
||||||
/* Exception 7 - FPU Not Available */
|
/* Exception 7 - FPU Not Available */
|
||||||
.word i386FPUNotAvailable /* Offset 0 - 15 */
|
.word _i386FPUNotAvailable /* Offset 0 - 15 */
|
||||||
.word 0x0008 /* Selector */
|
.word 0x0008 /* Selector */
|
||||||
.word 0x8e00 /* Zero byte, flags */
|
.word 0x8e00 /* Zero byte, flags */
|
||||||
.word 0x0000 /* Offset 16 - 31 */
|
.word 0x0000 /* Offset 16 - 31 */
|
||||||
|
|
||||||
/* Exception 8 - Double Fault */
|
/* Exception 8 - Double Fault */
|
||||||
.word i386DoubleFault /* Offset 0 - 15 */
|
.word _i386DoubleFault /* Offset 0 - 15 */
|
||||||
.word 0x0008 /* Selector */
|
.word 0x0008 /* Selector */
|
||||||
.word 0x8e00 /* Zero byte, flags */
|
.word 0x8e00 /* Zero byte, flags */
|
||||||
.word 0x0000 /* Offset 16 - 31 */
|
.word 0x0000 /* Offset 16 - 31 */
|
||||||
|
|
||||||
/* Exception 9 - Coprocessor Segment Overrun */
|
/* Exception 9 - Coprocessor Segment Overrun */
|
||||||
.word i386CoprocessorSegment /* Offset 0 - 15 */
|
.word _i386CoprocessorSegment /* Offset 0 - 15 */
|
||||||
.word 0x0008 /* Selector */
|
.word 0x0008 /* Selector */
|
||||||
.word 0x8e00 /* Zero byte, flags */
|
.word 0x8e00 /* Zero byte, flags */
|
||||||
.word 0x0000 /* Offset 16 - 31 */
|
.word 0x0000 /* Offset 16 - 31 */
|
||||||
|
|
||||||
/* Exception 10 (0x0A) - Invalid TSS */
|
/* Exception 10 (0x0A) - Invalid TSS */
|
||||||
.word i386InvalidTSS /* Offset 0 - 15 */
|
.word _i386InvalidTSS /* Offset 0 - 15 */
|
||||||
.word 0x0008 /* Selector */
|
.word 0x0008 /* Selector */
|
||||||
.word 0x8e00 /* Zero byte, flags */
|
.word 0x8e00 /* Zero byte, flags */
|
||||||
.word 0x0000 /* Offset 16 - 31 */
|
.word 0x0000 /* Offset 16 - 31 */
|
||||||
|
|
||||||
/* Exception 11 (0x0B) - Segment Not Present */
|
/* Exception 11 (0x0B) - Segment Not Present */
|
||||||
.word i386SegmentNotPresent /* Offset 0 - 15 */
|
.word _i386SegmentNotPresent /* Offset 0 - 15 */
|
||||||
.word 0x0008 /* Selector */
|
.word 0x0008 /* Selector */
|
||||||
.word 0x8e00 /* Zero byte, flags */
|
.word 0x8e00 /* Zero byte, flags */
|
||||||
.word 0x0000 /* Offset 16 - 31 */
|
.word 0x0000 /* Offset 16 - 31 */
|
||||||
|
|
||||||
/* Exception 12 (0x0C) - Stack Exception */
|
/* Exception 12 (0x0C) - Stack Exception */
|
||||||
.word i386StackException /* Offset 0 - 15 */
|
.word _i386StackException /* Offset 0 - 15 */
|
||||||
.word 0x0008 /* Selector */
|
.word 0x0008 /* Selector */
|
||||||
.word 0x8e00 /* Zero byte, flags */
|
.word 0x8e00 /* Zero byte, flags */
|
||||||
.word 0x0000 /* Offset 16 - 31 */
|
.word 0x0000 /* Offset 16 - 31 */
|
||||||
|
|
||||||
/* Exception 13 (0x0D) - General Protection Fault */
|
/* Exception 13 (0x0D) - General Protection Fault */
|
||||||
.word i386GeneralProtectionFault /* Offset 0 - 15 */
|
.word _i386GeneralProtectionFault /* Offset 0 - 15 */
|
||||||
.word 0x0008 /* Selector */
|
.word 0x0008 /* Selector */
|
||||||
.word 0x8e00 /* Zero byte, flags */
|
.word 0x8e00 /* Zero byte, flags */
|
||||||
.word 0x0000 /* Offset 16 - 31 */
|
.word 0x0000 /* Offset 16 - 31 */
|
||||||
|
|
||||||
/* Exception 14 (0x0E) - Page Fault */
|
/* Exception 14 (0x0E) - Page Fault */
|
||||||
.word i386PageFault /* Offset 0 - 15 */
|
.word _i386PageFault /* Offset 0 - 15 */
|
||||||
.word 0x0008 /* Selector */
|
.word 0x0008 /* Selector */
|
||||||
.word 0x8e00 /* Zero byte, flags */
|
.word 0x8e00 /* Zero byte, flags */
|
||||||
.word 0x0000 /* Offset 16 - 31 */
|
.word 0x0000 /* Offset 16 - 31 */
|
||||||
|
@ -122,19 +122,19 @@ EXTERN(i386idt)
|
||||||
.word 0x0000 /* Offset 16 - 31 */
|
.word 0x0000 /* Offset 16 - 31 */
|
||||||
|
|
||||||
/* Exception 16 (0x10) - Coprocessor Error */
|
/* Exception 16 (0x10) - Coprocessor Error */
|
||||||
.word i386CoprocessorError /* Offset 0 - 15 */
|
.word _i386CoprocessorError /* Offset 0 - 15 */
|
||||||
.word 0x0008 /* Selector */
|
.word 0x0008 /* Selector */
|
||||||
.word 0x8e00 /* Zero byte, flags */
|
.word 0x8e00 /* Zero byte, flags */
|
||||||
.word 0x0000 /* Offset 16 - 31 */
|
.word 0x0000 /* Offset 16 - 31 */
|
||||||
|
|
||||||
/* Exception 17 (0x11) - Alignment Check */
|
/* Exception 17 (0x11) - Alignment Check */
|
||||||
.word i386AlignmentCheck /* Offset 0 - 15 */
|
.word _i386AlignmentCheck /* Offset 0 - 15 */
|
||||||
.word 0x0008 /* Selector */
|
.word 0x0008 /* Selector */
|
||||||
.word 0x8e00 /* Zero byte, flags */
|
.word 0x8e00 /* Zero byte, flags */
|
||||||
.word 0x0000 /* Offset 16 - 31 */
|
.word 0x0000 /* Offset 16 - 31 */
|
||||||
|
|
||||||
/* Exception 18 (0x12) - Machine Check */
|
/* Exception 18 (0x12) - Machine Check */
|
||||||
.word i386MachineCheck /* Offset 0 - 15 */
|
.word _i386MachineCheck /* Offset 0 - 15 */
|
||||||
.word 0x0008 /* Selector */
|
.word 0x0008 /* Selector */
|
||||||
.word 0x8e00 /* Zero byte, flags */
|
.word 0x8e00 /* Zero byte, flags */
|
||||||
.word 0x0000 /* Offset 16 - 31 */
|
.word 0x0000 /* Offset 16 - 31 */
|
||||||
|
|
|
@ -122,26 +122,26 @@ i386ExceptionHandlerHang:
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
TRAP_STUB i386DivideByZero, 0
|
TRAP_STUB _i386DivideByZero, 0
|
||||||
TRAP_STUB i386DebugException, 1
|
TRAP_STUB _i386DebugException, 1
|
||||||
TRAP_STUB i386NMIException, 2
|
TRAP_STUB _i386NMIException, 2
|
||||||
TRAP_STUB i386Breakpoint, 3
|
TRAP_STUB _i386Breakpoint, 3
|
||||||
TRAP_STUB i386Overflow, 4
|
TRAP_STUB _i386Overflow, 4
|
||||||
TRAP_STUB i386BoundException, 5
|
TRAP_STUB _i386BoundException, 5
|
||||||
TRAP_STUB i386InvalidOpcode, 6
|
TRAP_STUB _i386InvalidOpcode, 6
|
||||||
TRAP_STUB i386FPUNotAvailable, 7
|
TRAP_STUB _i386FPUNotAvailable, 7
|
||||||
TRAP_STUB2 i386DoubleFault, 8
|
TRAP_STUB2 _i386DoubleFault, 8
|
||||||
TRAP_STUB i386CoprocessorSegment, 9
|
TRAP_STUB _i386CoprocessorSegment, 9
|
||||||
TRAP_STUB2 i386InvalidTSS, 10
|
TRAP_STUB2 _i386InvalidTSS, 10
|
||||||
TRAP_STUB2 i386SegmentNotPresent, 11
|
TRAP_STUB2 _i386SegmentNotPresent, 11
|
||||||
TRAP_STUB2 i386StackException, 12
|
TRAP_STUB2 _i386StackException, 12
|
||||||
TRAP_STUB2 i386GeneralProtectionFault, 13
|
TRAP_STUB2 _i386GeneralProtectionFault, 13
|
||||||
TRAP_STUB2 i386PageFault, 14
|
TRAP_STUB2 _i386PageFault, 14
|
||||||
// 15 is reserved
|
// 15 is reserved
|
||||||
TRAP_STUB i386CoprocessorError, 16
|
TRAP_STUB _i386CoprocessorError, 16
|
||||||
TRAP_STUB i386AlignmentCheck, 17
|
TRAP_STUB _i386AlignmentCheck, 17
|
||||||
TRAP_STUB i386MachineCheck, 18
|
TRAP_STUB _i386MachineCheck, 18
|
||||||
TRAP_STUB i386SimdFloatError, 19
|
TRAP_STUB _i386SimdFloatError, 19
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* DEBUGGING SUPPORT FUNCTIONS
|
* DEBUGGING SUPPORT FUNCTIONS
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
VOID
|
VOID
|
||||||
PcMachInit(const char *CmdLine)
|
PcMachInit(const char *CmdLine)
|
||||||
{
|
{
|
||||||
EnableA20();
|
|
||||||
|
|
||||||
/* Setup vtbl */
|
/* Setup vtbl */
|
||||||
MachVtbl.ConsPutChar = PcConsPutChar;
|
MachVtbl.ConsPutChar = PcConsPutChar;
|
||||||
MachVtbl.ConsKbHit = PcConsKbHit;
|
MachVtbl.ConsKbHit = PcConsKbHit;
|
||||||
|
|
178
reactos/boot/freeldr/freeldr/arch/i386/multiboot.S
Normal file
178
reactos/boot/freeldr/freeldr/arch/i386/multiboot.S
Normal file
|
@ -0,0 +1,178 @@
|
||||||
|
/*
|
||||||
|
* FreeLoader
|
||||||
|
* Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <asm.inc>
|
||||||
|
#include <arch/pc/x86common.h>
|
||||||
|
#include <multiboot.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* Multiboot support
|
||||||
|
*
|
||||||
|
* Allows freeldr to be loaded as a "multiboot kernel" by
|
||||||
|
* other boot loaders like Grub
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define MB_INFO_SIZE 90
|
||||||
|
#define MB_INFO_FLAGS_OFFSET 0
|
||||||
|
#define MB_INFO_BOOT_DEVICE_OFFSET 12
|
||||||
|
#define MB_INFO_COMMAND_LINE_OFFSET 16
|
||||||
|
#define CMDLINE_SIZE 256
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We want to execute at 0x8000 (to be compatible with bootsector
|
||||||
|
* loading), but Grub only allows loading of multiboot kernels
|
||||||
|
* above 1MB. So we let Grub load us there and then relocate
|
||||||
|
* ourself to 0x8000
|
||||||
|
*/
|
||||||
|
#define INITIAL_BASE HEX(200000)
|
||||||
|
|
||||||
|
/* Align 32 bits boundary */
|
||||||
|
.align 4
|
||||||
|
|
||||||
|
/* Multiboot header */
|
||||||
|
MultibootHeader:
|
||||||
|
/* magic */
|
||||||
|
.long MULTIBOOT_HEADER_MAGIC
|
||||||
|
/* flags */
|
||||||
|
.long MULTIBOOT_HEADER_FLAGS
|
||||||
|
/* checksum */
|
||||||
|
.long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
|
||||||
|
/* header_addr */
|
||||||
|
.long INITIAL_BASE + MultibootHeader - FREELDR_BASE
|
||||||
|
/* load_addr */
|
||||||
|
.long INITIAL_BASE
|
||||||
|
/* load_end_addr */
|
||||||
|
.long INITIAL_BASE + __bss_start__ - FREELDR_BASE
|
||||||
|
/* bss_end_addr */
|
||||||
|
.long INITIAL_BASE + __bss_end__ - FREELDR_BASE
|
||||||
|
/* entry_addr */
|
||||||
|
.long INITIAL_BASE + MultibootEntry - FREELDR_BASE
|
||||||
|
|
||||||
|
MultibootEntry:
|
||||||
|
cli /* Even after setting up the our IDT below we are
|
||||||
|
* not ready to handle hardware interrupts (no entries
|
||||||
|
* in IDT), so there's no sti here. Interrupts will be
|
||||||
|
* enabled in due time */
|
||||||
|
|
||||||
|
/* Although the multiboot spec says we should be called with the
|
||||||
|
* segment registers set to 4GB flat mode, let's be sure and set up
|
||||||
|
* our own */
|
||||||
|
lgdt gdtptrhigh + INITIAL_BASE - FREELDR_BASE
|
||||||
|
/* Reload segment selectors */
|
||||||
|
//ljmp $PMODE_CS, $(mb1 + INITIAL_BASE - FREELDR_BASE)
|
||||||
|
jmp far ptr PMODE_CS: (mb1 + INITIAL_BASE - FREELDR_BASE)
|
||||||
|
mb1:
|
||||||
|
mov dx, PMODE_DS
|
||||||
|
mov ds, dx
|
||||||
|
mov es, dx
|
||||||
|
|
||||||
|
/* Check for valid multiboot signature */
|
||||||
|
cmp eax, MULTIBOOT_BOOTLOADER_MAGIC
|
||||||
|
jne mbfail
|
||||||
|
|
||||||
|
/* Store multiboot info in a safe place */
|
||||||
|
mov esi, ebx
|
||||||
|
mov edi, offset mb_info + INITIAL_BASE - FREELDR_BASE
|
||||||
|
mov ecx, MB_INFO_SIZE
|
||||||
|
rep movsb
|
||||||
|
|
||||||
|
/* Save commandline */
|
||||||
|
mov edx, [ebx + MB_INFO_FLAGS_OFFSET]
|
||||||
|
test dword ptr [ebx + MB_INFO_FLAGS_OFFSET], MB_INFO_FLAG_COMMAND_LINE
|
||||||
|
jz mb3
|
||||||
|
mov esi, [ebx + MB_INFO_COMMAND_LINE_OFFSET]
|
||||||
|
mov edi, offset cmdline + INITIAL_BASE - FREELDR_BASE
|
||||||
|
mov ecx, CMDLINE_SIZE
|
||||||
|
mb2: lodsb
|
||||||
|
stosb
|
||||||
|
test al, al
|
||||||
|
jz mb3
|
||||||
|
dec ecx
|
||||||
|
jnz mb2
|
||||||
|
mb3:
|
||||||
|
|
||||||
|
/* Copy to low mem */
|
||||||
|
mov esi, INITIAL_BASE
|
||||||
|
mov edi, FREELDR_BASE
|
||||||
|
mov ecx, (offset __bss_end__ - FREELDR_BASE)
|
||||||
|
add ecx, 3
|
||||||
|
shr ecx, 2
|
||||||
|
rep movsd
|
||||||
|
|
||||||
|
/* Load the GDT and IDT */
|
||||||
|
lgdt gdtptr
|
||||||
|
lidt i386idtptr
|
||||||
|
|
||||||
|
/* Clear prefetch queue & correct CS,
|
||||||
|
* jump to low mem */
|
||||||
|
//ljmp $PMODE_CS, $mb4
|
||||||
|
jmp far ptr PMODE_CS:mb4
|
||||||
|
mb4:
|
||||||
|
/* Reload segment selectors */
|
||||||
|
mov dx, PMODE_DS
|
||||||
|
mov ds, dx
|
||||||
|
mov es, dx
|
||||||
|
mov fs, dx
|
||||||
|
mov gs, dx
|
||||||
|
mov ss, dx
|
||||||
|
mov esp, STACK32ADDR
|
||||||
|
|
||||||
|
mov ebx, offset mb_info
|
||||||
|
/* See if the boot device was passed in */
|
||||||
|
mov edx, [ebx + MB_INFO_FLAGS_OFFSET]
|
||||||
|
test edx, MB_INFO_FLAG_BOOT_DEVICE
|
||||||
|
jz mb5
|
||||||
|
/* Retrieve boot device info */
|
||||||
|
mov eax, [ebx + MB_INFO_BOOT_DEVICE_OFFSET]
|
||||||
|
shr eax, 16
|
||||||
|
inc al
|
||||||
|
mov byte ptr [_FrldrBootPartition], al
|
||||||
|
mov byte ptr [_FrldrBootDrive], ah
|
||||||
|
jmp mb6
|
||||||
|
mb5: /* No boot device known, assume first partition of first harddisk */
|
||||||
|
mov byte ptr [_FrldrBootDrive], HEX(80)
|
||||||
|
mov byte ptr [_FrldrBootPartition], 1
|
||||||
|
mb6:
|
||||||
|
/* Check for command line */
|
||||||
|
mov eax, offset cmdline
|
||||||
|
test dword ptr [ebx + MB_INFO_FLAGS_OFFSET], MB_INFO_FLAG_COMMAND_LINE
|
||||||
|
jnz mb7
|
||||||
|
xor eax, eax
|
||||||
|
mb7:
|
||||||
|
|
||||||
|
/* GO! */
|
||||||
|
push eax
|
||||||
|
call _BootMain
|
||||||
|
|
||||||
|
mbfail:
|
||||||
|
call switch_to_real
|
||||||
|
.code16
|
||||||
|
int 0x19
|
||||||
|
mbstop: jmp mbstop /* We should never get here */
|
||||||
|
|
||||||
|
mb_info:
|
||||||
|
.fill MB_INFO_SIZE, 1, 0
|
||||||
|
|
||||||
|
cmdline:
|
||||||
|
.fill CMDLINE_SIZE, 1, 0
|
||||||
|
|
||||||
|
/* Initial GDT table pointer for multiboot */
|
||||||
|
gdtptrhigh:
|
||||||
|
.word HEX(27) /* Limit */
|
||||||
|
.long gdt + INITIAL_BASE - FREELDR_BASE /* Base Address */
|
|
@ -72,6 +72,7 @@ IoWritePartitionTable(
|
||||||
return STATUS_NOT_IMPLEMENTED;
|
return STATUS_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef _MSC_VER
|
||||||
NTHALAPI
|
NTHALAPI
|
||||||
VOID
|
VOID
|
||||||
NTAPI
|
NTAPI
|
||||||
|
@ -119,3 +120,4 @@ KeStallExecutionProcessor(
|
||||||
#error unimplemented
|
#error unimplemented
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -2,23 +2,10 @@
|
||||||
|
|
||||||
#include <asm.inc>
|
#include <asm.inc>
|
||||||
|
|
||||||
.code16
|
|
||||||
PUBLIC _mainCRTStartup
|
|
||||||
_mainCRTStartup:
|
|
||||||
_LoaderEntry:
|
|
||||||
ret
|
|
||||||
|
|
||||||
.endcode16
|
|
||||||
|
|
||||||
.code32
|
.code32
|
||||||
|
|
||||||
|
|
||||||
// globals
|
// globals
|
||||||
PUBLIC _FrldrBootPartition
|
|
||||||
_FrldrBootPartition:
|
|
||||||
PUBLIC _FrldrBootDrive
|
|
||||||
_FrldrBootDrive:
|
|
||||||
|
|
||||||
PUBLIC _PageDirectoryStart
|
PUBLIC _PageDirectoryStart
|
||||||
_PageDirectoryStart:
|
_PageDirectoryStart:
|
||||||
PUBLIC _PageDirectoryEnd
|
PUBLIC _PageDirectoryEnd
|
||||||
|
@ -33,13 +20,6 @@ _kernel_pagetable:
|
||||||
PUBLIC _lowmem_pagetable
|
PUBLIC _lowmem_pagetable
|
||||||
_lowmem_pagetable:
|
_lowmem_pagetable:
|
||||||
|
|
||||||
|
|
||||||
PUBLIC RealEntryPoint
|
|
||||||
RealEntryPoint:
|
|
||||||
|
|
||||||
PUBLIC _EnableA20
|
|
||||||
_EnableA20:
|
|
||||||
|
|
||||||
PUBLIC _ChainLoadBiosBootSectorCode
|
PUBLIC _ChainLoadBiosBootSectorCode
|
||||||
_ChainLoadBiosBootSectorCode:
|
_ChainLoadBiosBootSectorCode:
|
||||||
|
|
||||||
|
@ -73,9 +53,6 @@ _PnpBiosGetDeviceNodeCount:
|
||||||
PUBLIC _PnpBiosSupported
|
PUBLIC _PnpBiosSupported
|
||||||
_PnpBiosSupported:
|
_PnpBiosSupported:
|
||||||
|
|
||||||
PUBLIC _Int386
|
|
||||||
_Int386:
|
|
||||||
|
|
||||||
PUBLIC _PxeCallApi
|
PUBLIC _PxeCallApi
|
||||||
_PxeCallApi:
|
_PxeCallApi:
|
||||||
|
|
||||||
|
|
|
@ -24,4 +24,23 @@
|
||||||
#undef KIP0PCRADDRESS
|
#undef KIP0PCRADDRESS
|
||||||
#define KIP0PCRADDRESS 0xffdff000
|
#define KIP0PCRADDRESS 0xffdff000
|
||||||
|
|
||||||
|
void i386DivideByZero(void);
|
||||||
|
void i386DebugException(void);
|
||||||
|
void i386NMIException(void);
|
||||||
|
void i386Breakpoint(void);
|
||||||
|
void i386Overflow(void);
|
||||||
|
void i386BoundException(void);
|
||||||
|
void i386InvalidOpcode(void);
|
||||||
|
void i386FPUNotAvailable(void);
|
||||||
|
void i386DoubleFault(void);
|
||||||
|
void i386CoprocessorSegment(void);
|
||||||
|
void i386InvalidTSS(void);
|
||||||
|
void i386SegmentNotPresent(void);
|
||||||
|
void i386StackException(void);
|
||||||
|
void i386GeneralProtectionFault(void);
|
||||||
|
void i386PageFault(void);
|
||||||
|
void i386CoprocessorError(void);
|
||||||
|
void i386AlignmentCheck(void);
|
||||||
|
void i386MachineCheck(void);
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue