diff --git a/boot/CMakeLists.txt b/boot/CMakeLists.txt index 188179ef0ff..e0558666490 100644 --- a/boot/CMakeLists.txt +++ b/boot/CMakeLists.txt @@ -10,16 +10,22 @@ include_directories(BEFORE freeldr/freeldr/include) include_directories(${REACTOS_SOURCE_DIR}/ntoskrnl/include) if(ARCH MATCHES i386) +if(MSVC) +list(APPEND FREELDR_BASE64K_SOURCE + freeldr/freeldr/arch/i386/realmode.S) +else() list(APPEND FREELDR_STARTUP_SOURCE freeldr/freeldr/arch/i386/fathelp.S freeldr/freeldr/arch/i386/arch.S) +endif() elseif(ARCH MATCHES amd64) list(APPEND FREELDR_STARTUP_SOURCE - freeldr/freeldr/arch/amd64/fathelp.S + freeldr/freeldr/arch/i386/fathelp.S freeldr/freeldr/arch/amd64/arch.S) endif(ARCH MATCHES i386) if(ARCH MATCHES i386) +if(NOT MSVC) list(APPEND FREELDR_BASE64K_SOURCE freeldr/freeldr/arch/i386/boot.S freeldr/freeldr/arch/i386/drvmap.S @@ -31,12 +37,13 @@ list(APPEND FREELDR_BASE64K_SOURCE freeldr/freeldr/arch/i386/linux.S freeldr/freeldr/arch/i386/mb.S freeldr/freeldr/arch/i386/i386bug.c) +endif() elseif(ARCH MATCHES amd64) list(APPEND FREELDR_BASE64K_SOURCE - freeldr/freeldr/arch/amd64/drvmap.S - freeldr/freeldr/arch/amd64/i386cpu.S - freeldr/freeldr/arch/amd64/i386idt.S - freeldr/freeldr/arch/amd64/i386trap.S + freeldr/freeldr/arch/i386/drvmap.S + freeldr/freeldr/arch/i386/i386cpu.S + freeldr/freeldr/arch/i386/i386idt.S + freeldr/freeldr/arch/i386/i386trap.S freeldr/freeldr/arch/amd64/mb.S) endif(ARCH MATCHES i386) @@ -107,7 +114,6 @@ include_directories(${REACTOS_SOURCE_DIR}/include/reactos/elf) if(ARCH MATCHES i386) list(APPEND FREELDR_ARCH_SOURCE - freeldr/freeldr/arch/i386/_alloca.S freeldr/freeldr/arch/i386/archmach.c freeldr/freeldr/arch/i386/custom.c freeldr/freeldr/arch/i386/drivemap.c @@ -171,7 +177,16 @@ add_library(freeldr SHARED ${CMAKE_CURRENT_BINARY_DIR}/freeldr_freeldr.h.gch ${FREELDR_SOURCE}) -set_target_properties(freeldr PROPERTIES LINK_FLAGS "-Wl,--strip-all -Wl,-entry,_mainCRTStartup -Wl,--image-base,0x8000 -Wl,--exclude-all-symbols -Wl,--subsystem,native -Wl,--file-alignment,0x1000 -Wl,-T,${REACTOS_SOURCE_DIR}/global.lds" SUFFIX ".sys") +if(NOT MSVC) +set_target_properties(freeldr PROPERTIES LINK_FLAGS "-Wl,--strip-all -Wl,--exclude-all-symbols -Wl,--file-alignment,0x1000 -Wl,-T,${REACTOS_SOURCE_DIR}/global.lds" SUFFIX ".sys") +set_image_base(freeldr 0x8000) +else() +set_target_properties(freeldr PROPERTIES LINK_FLAGS "/DRIVER /FIXED /ALIGN:0x400 /SECTION:.text,ERW /SECTION:.data,RW /MERGE:.text16=.text /MERGE:.data=.text /MERGE:.rdata=.text /MERGE:.bss=.text /SUBSYSTEM:BOOT_APPLICATION" SUFFIX ".sys") +set_image_base(freeldr 0x10000) +endif() + +set_subsystem(freeldr native) +set_entrypoint(freeldr mainCRTStartup) if(ARCH MATCHES i386) target_link_libraries(freeldr mini_hal) @@ -184,6 +199,7 @@ target_link_libraries(freeldr rtl libcntpr) add_pch(freeldr ${CMAKE_CURRENT_SOURCE_DIR}/freeldr/freeldr/include/freeldr.h ${FREELDR_SOURCE}) +add_dependencies(freeldr ks386) list(APPEND SETUPLDR_SOURCE ${FREELDR_STARTUP_SOURCE} @@ -194,7 +210,15 @@ list(APPEND SETUPLDR_SOURCE add_library(setupldr SHARED ${SETUPLDR_SOURCE}) -set_target_properties(setupldr PROPERTIES LINK_FLAGS "-Wl,--strip-all -Wl,-entry,_mainCRTStartup -Wl,--image-base,0x8000 -Wl,--exclude-all-symbols -Wl,--subsystem,native -Wl,--file-alignment,0x1000 -Wl,-T,${REACTOS_SOURCE_DIR}/global.lds" SUFFIX ".sys" COMPILE_DEFINITIONS "FREELDR_REACTOS_SETUP") +if(NOT MSVC) +set_target_properties(setupldr PROPERTIES LINK_FLAGS "-Wl,--strip-all -Wl,--exclude-all-symbols -Wl,--file-alignment,0x1000 -Wl,-T,${REACTOS_SOURCE_DIR}/global.lds" SUFFIX ".sys" COMPILE_DEFINITIONS "FREELDR_REACTOS_SETUP") +set_image_base(setupldr 0x8000) +else() +set_target_properties(setupldr PROPERTIES LINK_FLAGS "/SECTION:.text,ERWP,ALIGN=0x1000" SUFFIX ".sys" COMPILE_DEFINITIONS "FREELDR_REACTOS_SETUP") +endif() + +set_subsystem(setupldr native) +set_entrypoint(freeldr mainCRTStartup) if(ARCH MATCHES i386) target_link_libraries(setupldr mini_hal) @@ -206,7 +230,9 @@ target_link_libraries(setupldr cmlib rtl libcntpr) - + +add_dependencies(setupldr ks386) + # Bootcd files add_minicd_target(setupldr loader setupldr.sys) add_minicd_target(freeldr loader freeldr.sys) diff --git a/boot/freeldr/freeldr/arch/amd64/arch.S b/boot/freeldr/freeldr/arch/amd64/arch.S index 9def109221c..236a0be4b69 100644 --- a/boot/freeldr/freeldr/arch/amd64/arch.S +++ b/boot/freeldr/freeldr/arch/amd64/arch.S @@ -1,10 +1,13 @@ -.intel_syntax noprefix -.text -.code16 #define ASM + +#include + #include +.text +.code16 + //.org 0x8000 .global RealEntryPoint diff --git a/boot/freeldr/freeldr/arch/amd64/boot.S b/boot/freeldr/freeldr/arch/amd64/boot.S index eb3ba3c3c64..bc2e43e9e8b 100644 --- a/boot/freeldr/freeldr/arch/amd64/boot.S +++ b/boot/freeldr/freeldr/arch/amd64/boot.S @@ -17,14 +17,17 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include + + .text .code16 #define ASM #include - -EXTERN(ChainLoadBiosBootSectorCode) +PUBLIC ChainLoadBiosBootSectorCode +ChainLoadBiosBootSectorCode: .code64 call x86_64_SwitchToReal @@ -46,7 +49,8 @@ EXTERN(ChainLoadBiosBootSectorCode) // ljmpl $0x0000,$0x7C00 jmp 0x7c00:0x0000 -EXTERN(SoftReboot) +PUBLIC SoftReboot +SoftReboot: .code64 call x86_64_SwitchToReal diff --git a/boot/freeldr/freeldr/arch/amd64/drvmap.S b/boot/freeldr/freeldr/arch/amd64/drvmap.S deleted file mode 100644 index 6871fe0f62d..00000000000 --- a/boot/freeldr/freeldr/arch/amd64/drvmap.S +++ /dev/null @@ -1,132 +0,0 @@ -/* - * FreeLoader - * Copyright (C) 1998-2002 Brian Palmer - * - * 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. - */ - - .text - .code16 - -#define ASM -#include - - -EXTERN(DriveMapInt13HandlerStart) -Int13Handler: - - pushw %bp - movw %sp,%bp - pushw %ax - pushw %cx - pushw %si - - cld - - /* Get callers flags from stack */ - movw 0x06(%bp),%ax - movw %ax,%cs:(CallersFlags - Int13Handler) - - /* Save the drive number they passed in */ - movb %dl,%cs:(PassedInDriveNumber - Int13Handler) - - /* Now we need to perform the mapping */ - xorw %cx,%cx - movw $(Int13HandlerMapCount - Int13Handler),%si - /* Get the count of drives in the map list */ - movb %cs:(%si),%cl - incw %si - - /* If the map list is empty then just call the old int 13h handler */ - cmpb $0,%cl - jz CallOldInt13Handler - -GetMappedDriveNumberLoop: - - /* Get the next drive number in the list */ - lodsw %cs:(%si),%ax - /* Check to see if it's the one they are calling int 13h for */ - cmpb %al,%dl - /* If not get the next one */ - jne GetMappedDriveNumberLoopNext - - /* If we get here then we have found a mapped drive */ - /* Send new drive number on to the old int 13h handler */ - movb %ah,%dl - /* Call BIOS Int 13 Handler */ - jmp CallOldInt13Handler - -GetMappedDriveNumberLoopNext: - loop GetMappedDriveNumberLoop - -CallOldInt13Handler: - /* Restore the registers we changed off the stack */ - popw %si - popw %cx - popw %ax - - /* Put flags onto stack */ - pushw %cs:(CallersFlags - Int13Handler) - - /* Call old int 13h handler with new drive number */ - .byte 0x9a /* lcall */ -EXTERN(DriveMapOldInt13HandlerAddress) - .word 0 - .word 0 - - /* Update the callers flags with the values the BIOS returned */ - pushw %ax - pushf - popw %ax - movw %ax,0x06(%bp) - popw %ax - /* Restore the callers drive number */ - movb %cs:(PassedInDriveNumber - Int13Handler),%dl - - popw %bp - - iret - -CallersFlags: - .word 0 - -PassedInDriveNumber: - .byte 0 - -EXTERN(DriveMapInt13HandlerMapList) -Int13HandlerMapCount: - .byte 0 - -Int13HandlerDrive1: - .byte 0 -Int13HandlerDriveNew1: - .byte 0 - -Int13HandlerDrive2: - .byte 0 -Int13HandlerDriveNew2: - .byte 0 - -Int13HandlerDrive3: - .byte 0 -Int13HandlerDriveNew3: - .byte 0 - -Int13HandlerDrive4: - .byte 0 -Int13HandlerDriveNew4: - .byte 0 - -EXTERN(DriveMapInt13HandlerEnd) diff --git a/boot/freeldr/freeldr/arch/amd64/fathelp.S b/boot/freeldr/freeldr/arch/amd64/fathelp.S deleted file mode 100644 index 8aad29bbfe7..00000000000 --- a/boot/freeldr/freeldr/arch/amd64/fathelp.S +++ /dev/null @@ -1,235 +0,0 @@ -// fathelp.S -// FAT12/16 Boot Sector Helper Code -// Copyright (c) 1998, 2001, 2002, 2003 Brian Palmer - -.intel_syntax noprefix - -//org 8000h - -.text - -.code16 - - -#define BootSectorStackTop 0x7bf2 -#define DataAreaStartHigh 0x2 -#define DataAreaStartLow 0x4 -#define BiosCHSDriveSizeHigh 0x6 -#define BiosCHSDriveSizeLow 0x8 -#define BiosCHSDriveSize 0x8 -#define ReadSectorsOffset 0xa -#define ReadClusterOffset 0xc -#define PutCharsOffset 0xe - -#define OEMName 3 -#define BytesPerSector 11 -#define SectsPerCluster 13 -#define ReservedSectors 14 -#define NumberOfFats 16 -#define MaxRootEntries 17 -#define TotalSectors 19 -#define MediaDescriptor 21 -#define SectorsPerFat 22 -#define SectorsPerTrack 24 -#define NumberOfHeads 26 -#define HiddenSectors 28 -#define TotalSectorsBig 32 -#define BootDrive 36 -#define Reserved 37 -#define ExtendSig 38 -#define SerialNumber 39 -#define VolumeLabel 43 -#define FileSystem 54 - -#define BootPartition 0x7dfd - - -// This code will be stored in the first 512 bytes -// of freeldr.sys. The first 3 bytes will be a jmp -// instruction to skip past the FAT helper code -// that is stored in the rest of the 512 bytes. -// -// This code is loaded at 0000:8000 so we have to -// encode a jmp instruction to jump to 0000:8200 - -.global _mainCRTStartup // For Mingw32 builds where the linker looks for this symbol -_mainCRTStartup: -.global start -start: - .byte 0xe9 - .byte 0xfd - .byte 0x01 - -// Now starts the extra boot code that we will store -// in the first 512 bytes of freeldr.sys. This code -// allows the FAT12/16 bootsector to navigate the -// FAT table so that we can still load freeldr.sys -// even if it is fragmented. - - -FatHelperEntryPoint: - - push ax // First save AX - the start cluster of freeldr.sys - - - // Display "Loading FreeLoader..." message - mov esi, offset msgLoading // Loading message - call [bp-PutCharsOffset] // Display it - - - call ReadFatIntoMemory - - pop ax // Restore AX (start cluster) - // AX has start cluster of freeldr.sys - - mov bx,0x800 - mov es,bx - -LoadFile: - push ax - call IsFat12 - pop ax - jnc LoadFile2 - cmp ax,0x0ff8 // Check to see if this is the last cluster in the chain - jmp LoadFile3 -LoadFile2: - cmp ax,0x0fff8 -LoadFile3: - jae LoadFile_Done // If so continue, if not then read then next one - push ax - xor bx,bx // Load ROSLDR starting at 0000:8000h - push es - call [bp-ReadClusterOffset] - pop es - - xor bx,bx - mov bl, [bp+SectsPerCluster] - shl bx,5 // BX = BX * 512 / 16 - mov ax,es // Increment the load address by - add ax,bx // The size of a cluster - mov es,ax - - call IsFat12 - pop ax - push es - jnc LoadFile4 - call GetFatEntry12 // Get the next entry - jmp LoadFile5 -LoadFile4: - call GetFatEntry16 -LoadFile5: - pop es - - jmp LoadFile // Load the next cluster (if any) - -LoadFile_Done: - mov dl,BYTE PTR [bp+BootDrive] // Load the boot drive into DL - mov dh,[BootPartition] // Load the boot partition into DH - - push 0 // push segment (0x0000) - mov bx, [0x8000 + 0xA8] // load the RVA of the EntryPoint into eax - add bx, 0x8000 // RVA -> VA and skip 3 bytes (jump to fathelper code) - push bx // push offset - retf // Transfer control to FreeLoader - -// Reads the entire FAT into memory at 7000:0000 -ReadFatIntoMemory: - mov ax, [bp+HiddenSectors] - mov dx, [bp+HiddenSectors+2] - add ax, [bp+ReservedSectors] - adc dx, 0 - mov cx, [bp+SectorsPerFat] - mov bx,0x7000 - mov es,bx - xor bx,bx - call [bp-ReadSectorsOffset] - ret - - -// Returns the FAT entry for a given cluster number for 16-bit FAT -// On entry AX has cluster number -// On return AX has FAT entry for that cluster -GetFatEntry16: - - mov cx,2 // AX = AX * 2 (since FAT16 entries are 2 bytes) - mul cx - shl dx,12 - - mov bx,0x7000 - add bx,dx - mov es,bx - mov bx,ax // Restore FAT entry offset - mov ax, es:[bx] // Get FAT entry - - ret - - -// Returns the FAT entry for a given cluster number for 12-bit FAT -// On entry AX has cluster number -// On return AX has FAT entry for that cluster -GetFatEntry12: - - push ax - mov cx,ax - shr ax,1 - add ax,cx // AX = AX * 1.5 (AX = AX + (AX / 2)) (since FAT12 entries are 12 bits) - - mov bx,0x7000 - mov es,bx - mov bx,ax // Put FAT entry offset into BX - mov ax, es:[bx] // Get FAT entry - pop cx // Get cluster number from stack - and cx,1 - jz UseLow12Bits - and ax,0x0fff0 - shr ax,4 - jmp GetFatEntry12_Done - -UseLow12Bits: - and ax,0x0fff - -GetFatEntry12_Done: - - ret - - -// Returns CF = 1 if this is a FAT12 file system -// Otherwise CF = 0 for FAT16 -IsFat12: - - mov ebx, [bp-DataAreaStartLow] - // EBX now has the number of the starting sector of the data area - // starting from the beginning of the disk, so subtrace hidden sectors - sub ebx, [bp+HiddenSectors] - - - xor eax,eax - mov ax, [bp+TotalSectors] - cmp ax, 0 - jnz IsFat12_2 - mov eax, [bp+TotalSectorsBig] - - // EAX now contains the number of sectors on the volume - -IsFat12_2: - sub eax,ebx // Subtract data area start sector - xor edx,edx // from total sectors of volume - - // EDX:EAX now contains the number of data sectors on the volume - movzx ebx, byte ptr [bp+SectsPerCluster] - div ebx - // EAX now has the number of clusters on the volume - stc - cmp eax,4085 - jb IsFat12_Done - clc - -IsFat12_Done: - ret - - - -msgLoading: .asciz "Loading FreeLoader...\r\n" - - .org 0x1fe // Pad to 510 bytes - .word 0x0aa55 // BootSector signature diff --git a/boot/freeldr/freeldr/arch/amd64/i386cpu.S b/boot/freeldr/freeldr/arch/amd64/i386cpu.S deleted file mode 100644 index ee3ee6fe256..00000000000 --- a/boot/freeldr/freeldr/arch/amd64/i386cpu.S +++ /dev/null @@ -1,131 +0,0 @@ -/* - * FreeLoader - * Copyright (C) 2003 Eric Kohl - * - * 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. - */ - - .text - .code16 - -#define ASM - -#include - -/* - * U32 CpuidSupported(VOID); - * - * RETURNS: - * 0x00000001: CPU supports the CPUID instruction - * 0x00000300: Found 80386 CPU - * 0x00000400: Found 80486 CPU without CPUID support - */ - -EXTERN(CpuidSupported) - .code32 - - pushl %ecx /* save ECX */ - - pushfl /* push original EFLAGS */ - popl %eax /* get original EFLAGS */ - movl %eax,%ecx /* save original EFLAGS */ - xorl $0x40000,%eax /* flip AC bit in EFLAGS */ - pushl %eax /* save new EFLAGS value on stack */ - popfl /* replace current EFLAGS value */ - - pushfl /* get new EFLAGS */ - popl %eax /* store new EFLAGS in EAX */ - xorl %ecx, %eax /* can't toggle AC bit, processor=80386 */ - - movl $0x300,%eax /* return processor id */ - jz NoCpuid /* jump if 80386 processor */ - - pushl %ecx - popfl /* restore AC bit in EFLAGS first */ - - movl %ecx,%eax /* get original EFLAGS */ - xorl $0x200000,%eax /* flip ID bit in EFLAGS */ - pushl %eax /* save new EFLAGS value on stack */ - popfl /* replace current EFLAGS value */ - pushfl /* get new EFLAGS */ - popl %eax /* store new EFLAGS in EAX */ - xorl %ecx,%eax /* can't toggle ID bit, */ - - movl $0x400,%eax /* return processor id */ - je NoCpuid /* processor=80486 */ - - movl $1,%eax /* CPUID supported */ - -NoCpuid: - pushl %ecx - popfl /* restore EFLAGS */ - popl %ecx /* retore ECX */ - - ret - - -/* - * VOID GetCpuid(U32 Level, U32 *eax, U32 *ebx, U32 *ecx, U32 *edx); - */ - -EXTERN(GetCpuid) - .code32 - - pushl %ebp - movl %esp,%ebp - - pushl %eax - pushl %ebx - pushl %ecx - pushl %edx - pushl %esi - - movl 0x08(%ebp),%eax - - cpuid - - movl 0x0C(%ebp),%esi - movl %eax,(%esi) - - movl 0x10(%ebp),%esi - movl %ebx,(%esi) - - movl 0x14(%ebp),%esi - movl %ecx,(%esi) - - movl 0x18(%ebp),%esi - movl %edx,(%esi) - - popl %esi - popl %edx - popl %ecx - popl %ebx - popl %eax - - movl %ebp,%esp - popl %ebp - ret - - -/* - * U64 RDTSC(VOID); - */ - -EXTERN(RDTSC) - .code32 - rdtsc - ret - -/* EOF */ diff --git a/boot/freeldr/freeldr/arch/amd64/i386idt.S b/boot/freeldr/freeldr/arch/amd64/i386idt.S deleted file mode 100644 index 10d3f16a0ae..00000000000 --- a/boot/freeldr/freeldr/arch/amd64/i386idt.S +++ /dev/null @@ -1,224 +0,0 @@ -/* - * FreeLoader - * Copyright (C) 1998-2002 Brian Palmer - * - * 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. - */ - - .text - .code16 - -#define ASM -#include - - - .p2align 2 /* force 4-byte alignment */ -EXTERN(i386idt) - /* Exception 0 - Divide By Zero */ - .word i386DivideByZero /* Offset 0 - 15 */ - .word 0x0008 /* Selector */ - .word 0x8e00 /* Flags, Zero Byte */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 1 - Debug Exception */ - .word i386DebugException /* Offset 0 - 15 */ - .word 0x0008 /* Selector */ - .word 0x8e00 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 2 - NMI */ - .word i386NMIException /* Offset 0 - 15 */ - .word 0x0008 /* Selector */ - .word 0x8e00 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 3 - Breakpoint (INT 3) */ - .word i386Breakpoint /* Offset 0 - 15 */ - .word 0x0008 /* Selector */ - .word 0x8e00 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 4 - Overflow (INTO with EFLAGS[OF] set) */ - .word i386Overflow /* Offset 0 - 15 */ - .word 0x0008 /* Selector */ - .word 0x8e00 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 5 - Bound Exception */ - .word i386BoundException /* Offset 0 - 15 */ - .word 0x0008 /* Selector */ - .word 0x8e00 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 6 - Invalid Opcode */ - .word i386InvalidOpcode /* Offset 0 - 15 */ - .word 0x0008 /* Selector */ - .word 0x8e00 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 7 - FPU Not Available */ - .word i386FPUNotAvailable /* Offset 0 - 15 */ - .word 0x0008 /* Selector */ - .word 0x8e00 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 8 - Double Fault */ - .word i386DoubleFault /* Offset 0 - 15 */ - .word 0x0008 /* Selector */ - .word 0x8e00 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 9 - Coprocessor Segment Overrun */ - .word i386CoprocessorSegment /* Offset 0 - 15 */ - .word 0x0008 /* Selector */ - .word 0x8e00 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 10 (0x0A) - Invalid TSS */ - .word i386InvalidTSS /* Offset 0 - 15 */ - .word 0x0008 /* Selector */ - .word 0x8e00 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 11 (0x0B) - Segment Not Present */ - .word i386SegmentNotPresent /* Offset 0 - 15 */ - .word 0x0008 /* Selector */ - .word 0x8e00 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 12 (0x0C) - Stack Exception */ - .word i386StackException /* Offset 0 - 15 */ - .word 0x0008 /* Selector */ - .word 0x8e00 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 13 (0x0D) - General Protection Fault */ - .word i386GeneralProtectionFault /* Offset 0 - 15 */ - .word 0x0008 /* Selector */ - .word 0x8e00 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 14 (0x0E) - Page Fault */ - .word i386PageFault /* Offset 0 - 15 */ - .word 0x0008 /* Selector */ - .word 0x8e00 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 15 (0x0F) - Reserved */ - .word 0x0000 /* Offset 0 - 15 */ - .word 0x0000 /* Selector */ - .word 0x0000 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 16 (0x10) - Coprocessor Error */ - .word i386CoprocessorError /* Offset 0 - 15 */ - .word 0x0008 /* Selector */ - .word 0x8e00 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 17 (0x11) - Alignment Check */ - .word i386AlignmentCheck /* Offset 0 - 15 */ - .word 0x0008 /* Selector */ - .word 0x8e00 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 18 (0x12) - Machine Check */ - .word i386MachineCheck /* Offset 0 - 15 */ - .word 0x0008 /* Selector */ - .word 0x8e00 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 19 (0x13) - Reserved */ - .word 0x0000 /* Offset 0 - 15 */ - .word 0x0000 /* Selector */ - .word 0x0000 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 20 (0x14) - Reserved */ - .word 0x0000 /* Offset 0 - 15 */ - .word 0x0000 /* Selector */ - .word 0x0000 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 21 (0x15) - Reserved */ - .word 0x0000 /* Offset 0 - 15 */ - .word 0x0000 /* Selector */ - .word 0x0000 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 22 (0x16) - Reserved */ - .word 0x0000 /* Offset 0 - 15 */ - .word 0x0000 /* Selector */ - .word 0x0000 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 23 (0x17) - Reserved */ - .word 0x0000 /* Offset 0 - 15 */ - .word 0x0000 /* Selector */ - .word 0x0000 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 24 (0x18) - Reserved */ - .word 0x0000 /* Offset 0 - 15 */ - .word 0x0000 /* Selector */ - .word 0x0000 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 25 (0x19) - Reserved */ - .word 0x0000 /* Offset 0 - 15 */ - .word 0x0000 /* Selector */ - .word 0x0000 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 26 (0x1A) - Reserved */ - .word 0x0000 /* Offset 0 - 15 */ - .word 0x0000 /* Selector */ - .word 0x0000 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 27 (0x1B) - Reserved */ - .word 0x0000 /* Offset 0 - 15 */ - .word 0x0000 /* Selector */ - .word 0x0000 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 28 (0x1C) - Reserved */ - .word 0x0000 /* Offset 0 - 15 */ - .word 0x0000 /* Selector */ - .word 0x0000 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 29 (0x1D) - Reserved */ - .word 0x0000 /* Offset 0 - 15 */ - .word 0x0000 /* Selector */ - .word 0x0000 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 30 (0x1E) - Reserved */ - .word 0x0000 /* Offset 0 - 15 */ - .word 0x0000 /* Selector */ - .word 0x0000 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - - /* Exception 31 (0x1F) - Reserved */ - .word 0x0000 /* Offset 0 - 15 */ - .word 0x0000 /* Selector */ - .word 0x0000 /* Zero byte, flags */ - .word 0x0000 /* Offset 16 - 31 */ - -/* IDT table pointer */ -EXTERN(i386idtptr) - .word (i386idtptr-i386idt) /* Limit */ - .long i386idt /* Base Address */ diff --git a/boot/freeldr/freeldr/arch/amd64/i386pnp.S b/boot/freeldr/freeldr/arch/amd64/i386pnp.S index 19589275bac..c74fb97d64d 100644 --- a/boot/freeldr/freeldr/arch/amd64/i386pnp.S +++ b/boot/freeldr/freeldr/arch/amd64/i386pnp.S @@ -17,6 +17,9 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include + + .text .code16 @@ -255,4 +258,5 @@ EXTERN(PnpBiosGetDeviceNode) ret +END /* EOF */ diff --git a/boot/freeldr/freeldr/arch/amd64/i386trap.S b/boot/freeldr/freeldr/arch/amd64/i386trap.S deleted file mode 100644 index 195bf097cd0..00000000000 --- a/boot/freeldr/freeldr/arch/amd64/i386trap.S +++ /dev/null @@ -1,942 +0,0 @@ -/* - * FreeLoader - * Copyright (C) 1998-2002 Brian Palmer - * - * 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. - */ - - .text - .code16 - -#define ASM -#include -#include - -#define SCREEN_ATTR 0x1f /* Bright white on blue background */ - -.macro SAVE_CPU_REGS - movl %eax,i386_EAX - movl %ebx,i386_EBX - movl %ecx,i386_ECX - movl %edx,i386_EDX - movl %esp,i386_ESP - movl %ebp,i386_EBP - movl %esi,i386_ESI - movl %edi,i386_EDI - movw %ds,%ax - movw %ax,i386_DS - movw %es,%ax - movw %ax,i386_ES - movw %fs,%ax - movw %ax,i386_FS - movw %gs,%ax - movw %ax,i386_GS - movw %ss,%ax - movw %ax,i386_SS - popl %eax - movl %eax,i386_EIP - popl %eax - movw %ax,i386_CS - popl %eax - movl %eax,i386_EFLAGS - movl %cr0,%eax - movl %eax,i386_CR0 - //movl %cr1,%eax - //movl %eax,i386_CR1 - movl %cr2,%eax - movl %eax,i386_CR2 - movl %cr3,%eax - movl %eax,i386_CR3 - movl %dr0,%eax - movl %eax,i386_DR0 - movl %dr1,%eax - movl %eax,i386_DR1 - movl %dr2,%eax - movl %eax,i386_DR2 - movl %dr3,%eax - movl %eax,i386_DR3 - movl %dr6,%eax - movl %eax,i386_DR6 - movl %dr7,%eax - movl %eax,i386_DR7 - sgdt i386_GDTR - sidt i386_IDTR - sldt i386_LDTR - str i386_TR -.endm - - - -i386ExceptionHandlerText: - .ascii "An error occured in FreeLoader\n" - .ascii VERSION - .ascii "\n" - .asciz "Report this error to the ReactOS Development mailing list \n\n" - -i386DivideByZeroText: - .asciz "Exception 00: DIVIDE BY ZERO\n\n" -i386DebugExceptionText: - .asciz "Exception 01: DEBUG EXCEPTION\n\n" -i386NMIExceptionText: - .asciz "Exception 02: NON-MASKABLE INTERRUPT EXCEPTION\n\n" -i386BreakpointText: - .asciz "Exception 03: BREAKPOINT (INT 3)\n\n" -i386OverflowText: - .asciz "Exception 04: OVERFLOW\n\n" -i386BoundExceptionText: - .asciz "Exception 05: BOUND EXCEPTION\n\n" -i386InvalidOpcodeText: - .asciz "Exception 06: INVALID OPCODE\n\n" -i386FPUNotAvailableText: - .asciz "Exception 07: FPU NOT AVAILABLE\n\n" -i386DoubleFaultText: - .asciz "Exception 08: DOUBLE FAULT\n\n" -i386CoprocessorSegmentText: - .asciz "Exception 09: COPROCESSOR SEGMENT OVERRUN\n\n" -i386InvalidTSSText: - .asciz "Exception 0A: INVALID TSS\n\n" -i386SegmentNotPresentText: - .asciz "Exception 0B: SEGMENT NOT PRESENT\n\n" -i386StackExceptionText: - .asciz "Exception 0C: STACK EXCEPTION\n\n" -i386GeneralProtectionFaultText: - .asciz "Exception 0D: GENERAL PROTECTION FAULT\n\n" -i386PageFaultText: - .asciz "Exception 0E: PAGE FAULT\n\n" -i386CoprocessorErrorText: - .asciz "Exception 10: COPROCESSOR ERROR\n\n" -i386AlignmentCheckText: - .asciz "Exception 11: ALIGNMENT CHECK\n\n" -i386MachineCheckText: - .asciz "Exception 12: MACHINE CHECK\n\n" - -i386_EAX_Text: - .asciz "EAX: " -i386_EBX_Text: - .asciz "EBX: " -i386_ECX_Text: - .asciz "ECX: " -i386_EDX_Text: - .asciz "EDX: " -i386_ESP_Text: - .asciz " ESP: " -i386_EBP_Text: - .asciz " EBP: " -i386_ESI_Text: - .asciz " ESI: " -i386_EDI_Text: - .asciz " EDI: " -i386_CS_Text: - .asciz "CS: " -i386_DS_Text: - .asciz "DS: " -i386_ES_Text: - .asciz "ES: " -i386_FS_Text: - .asciz "FS: " -i386_GS_Text: - .asciz "GS: " -i386_SS_Text: - .asciz "SS: " -i386_EFLAGS_Text: - .asciz " EFLAGS: " -i386_EIP_Text: - .asciz " EIP: " -i386_ERROR_CODE_Text: - .asciz " ERROR CODE: " -i386_CR0_Text: - .asciz " CR0: " -i386_CR1_Text: - .asciz " CR1: " -i386_CR2_Text: - .asciz " CR2: " -i386_CR3_Text: - .asciz " CR3: " -i386_DR0_Text: - .asciz " DR0: " -i386_DR1_Text: - .asciz " DR1: " -i386_DR2_Text: - .asciz " DR2: " -i386_DR3_Text: - .asciz " DR3: " -i386_DR6_Text: - .asciz " DR6: " -i386_DR7_Text: - .asciz " DR7: " -i386_GDTR_Text: - .asciz " GDTR Base: " -i386_IDTR_Text: - .asciz " IDTR Base: " -i386_Limit_Text: - .asciz " Limit: " -i386_LDTR_Text: - .asciz " LDTR: " -i386_TR_Text: - .asciz " TR: " - -i386FramesText: - .asciz "Frames:\n" - -/* Set by each exception handler to the address of the description text */ -i386ExceptionDescriptionText: - .long 0 - -/* Used to store the contents of all the registers when an exception occurs */ -i386_EAX: - .long 0 -i386_EBX: - .long 0 -i386_ECX: - .long 0 -i386_EDX: - .long 0 -i386_ESP: - .long 0 -i386_EBP: - .long 0 -i386_ESI: - .long 0 -i386_EDI: - .long 0 -i386_CS: - .word 0 -i386_DS: - .word 0 -i386_ES: - .word 0 -i386_FS: - .word 0 -i386_GS: - .word 0 -i386_SS: - .word 0 -i386_EFLAGS: - .long 0 -i386_EIP: - .long 0 -i386_ERROR_CODE: - .long 0 -i386_CR0: - .long 0 -i386_CR1: - .long 0 -i386_CR2: - .long 0 -i386_CR3: - .long 0 -i386_DR0: - .long 0 -i386_DR1: - .long 0 -i386_DR2: - .long 0 -i386_DR3: - .long 0 -i386_DR6: - .long 0 -i386_DR7: - .long 0 -i386_GDTR: - .word 0 - .long 0 -i386_IDTR: - .word 0 - .long 0 -i386_LDTR: - .word 0 -i386_TR: - .word 0 - -/* Used to store the current X and Y position on the screen */ -i386_ScreenPosX: - .long 0 -i386_ScreenPosY: - .long 0 - -/************************************************************************/ -i386CommonExceptionHandler: - .code32 - - SAVE_CPU_REGS - - pushl $SCREEN_ATTR - call MachVideoClearScreen - add $4,%esp - - movl $i386ExceptionHandlerText,%esi - call i386PrintText - - movl i386ExceptionDescriptionText,%esi - call i386PrintText - - movl $i386_EAX_Text,%esi - call i386PrintText - movl i386_EAX,%eax - call i386PrintHexDword // Display EAX - movl $i386_ESP_Text,%esi - call i386PrintText - movl i386_ESP,%eax - call i386PrintHexDword // Display ESP - movl $i386_CR0_Text,%esi - call i386PrintText - movl i386_CR0,%eax - call i386PrintHexDword // Display CR0 - movl $i386_DR0_Text,%esi - call i386PrintText - movl i386_DR0,%eax - call i386PrintHexDword // Display DR0 - movl $0,i386_ScreenPosX - incl i386_ScreenPosY - movl $i386_EBX_Text,%esi - call i386PrintText - movl i386_EBX,%eax - call i386PrintHexDword // Display EBX - movl $i386_EBP_Text,%esi - call i386PrintText - movl i386_EBP,%eax - call i386PrintHexDword // Display EBP - movl $i386_CR1_Text,%esi - call i386PrintText - movl i386_CR1,%eax - call i386PrintHexDword // Display CR1 - movl $i386_DR1_Text,%esi - call i386PrintText - movl i386_DR1,%eax - call i386PrintHexDword // Display DR1 - movl $0,i386_ScreenPosX - incl i386_ScreenPosY - movl $i386_ECX_Text,%esi - call i386PrintText - movl i386_ECX,%eax - call i386PrintHexDword // Display ECX - movl $i386_ESI_Text,%esi - call i386PrintText - movl i386_ESI,%eax - call i386PrintHexDword // Display ESI - movl $i386_CR2_Text,%esi - call i386PrintText - movl i386_CR2,%eax - call i386PrintHexDword // Display CR2 - movl $i386_DR2_Text,%esi - call i386PrintText - movl i386_DR2,%eax - call i386PrintHexDword // Display DR2 - movl $0,i386_ScreenPosX - incl i386_ScreenPosY - movl $i386_EDX_Text,%esi - call i386PrintText - movl i386_EDX,%eax - call i386PrintHexDword // Display EDX - movl $i386_EDI_Text,%esi - call i386PrintText - movl i386_EDI,%eax - call i386PrintHexDword // Display EDI - movl $i386_CR3_Text,%esi - call i386PrintText - movl i386_CR3,%eax - call i386PrintHexDword // Display CR3 - movl $i386_DR3_Text,%esi - call i386PrintText - movl i386_DR3,%eax - call i386PrintHexDword // Display DR3 - incl i386_ScreenPosY - movl $55,i386_ScreenPosX - movl $i386_DR6_Text,%esi - call i386PrintText - movl i386_DR6,%eax - call i386PrintHexDword // Display DR6 - incl i386_ScreenPosY - movl $55,i386_ScreenPosX - movl $i386_DR7_Text,%esi - call i386PrintText - movl i386_DR7,%eax - call i386PrintHexDword // Display DR7 - movl $0,i386_ScreenPosX - incl i386_ScreenPosY - incl i386_ScreenPosY - movl $i386_CS_Text,%esi - call i386PrintText - movw i386_CS,%ax - call i386PrintHexWord // Display CS - movl $i386_EIP_Text,%esi - call i386PrintText - movl i386_EIP,%eax - call i386PrintHexDword // Display EIP - movl $0,i386_ScreenPosX - incl i386_ScreenPosY - movl $i386_DS_Text,%esi - call i386PrintText - movw i386_DS,%ax - call i386PrintHexWord // Display DS - movl $i386_ERROR_CODE_Text,%esi - call i386PrintText - movl i386_ERROR_CODE,%eax - call i386PrintHexDword // Display ERROR CODE - movl $0,i386_ScreenPosX - incl i386_ScreenPosY - movl $i386_ES_Text,%esi - call i386PrintText - movw i386_ES,%ax - call i386PrintHexWord // Display ES - movl $i386_EFLAGS_Text,%esi - call i386PrintText - movl i386_EFLAGS,%eax - call i386PrintHexDword // Display EFLAGS - movl $0,i386_ScreenPosX - incl i386_ScreenPosY - movl $i386_FS_Text,%esi - call i386PrintText - movw i386_FS,%ax - call i386PrintHexWord // Display FS - movl $i386_GDTR_Text,%esi - call i386PrintText - movl i386_GDTR+2,%eax - call i386PrintHexDword // Display GDTR Base - movl $i386_Limit_Text,%esi - call i386PrintText - movw i386_GDTR,%ax - call i386PrintHexWord // Display GDTR Limit - movl $0,i386_ScreenPosX - incl i386_ScreenPosY - movl $i386_GS_Text,%esi - call i386PrintText - movw i386_GS,%ax - call i386PrintHexWord // Display GS - movl $i386_IDTR_Text,%esi - call i386PrintText - movl i386_IDTR+2,%eax - call i386PrintHexDword // Display IDTR Base - movl $i386_Limit_Text,%esi - call i386PrintText - movw i386_IDTR,%ax - call i386PrintHexWord // Display IDTR Limit - movl $0,i386_ScreenPosX - incl i386_ScreenPosY - movl $i386_SS_Text,%esi - call i386PrintText - movw i386_SS,%ax - call i386PrintHexWord // Display SS - movl $i386_LDTR_Text,%esi - call i386PrintText - movw i386_LDTR,%ax - call i386PrintHexWord // Display LDTR - movl $i386_TR_Text,%esi - call i386PrintText - movw i386_TR,%ax - call i386PrintHexWord // Display TR - movl $0,i386_ScreenPosX - incl i386_ScreenPosY - incl i386_ScreenPosY - call i386PrintFrames // Display frames - incl i386_ScreenPosY - incl i386_ScreenPosY - - cli -i386ExceptionHandlerHang: - hlt - jmp i386ExceptionHandlerHang - - iret - -i386PrintFrames: - movl $0,i386_ScreenPosX - movl $i386FramesText,%esi - call i386PrintText - - movl i386_EBP,%edi -printnextframe: - test %edi,%edi - je nomoreframes - movl $STACK32ADDR,%eax - cmpl %edi,%eax - jbe nomoreframes - movl 4(%edi),%eax - pushl %edi - call i386PrintHexDword // Display frame - popl %edi - incl i386_ScreenPosX - incl i386_ScreenPosX - movl 0(%edi),%edi - jmp printnextframe -nomoreframes: - ret - -/************************************************************************/ -/* AL = Char to display */ -/************************************************************************/ -i386PrintChar: - .code32 - - pushl i386_ScreenPosY - pushl i386_ScreenPosX - pushl $SCREEN_ATTR - andl $0xff,%eax - pushl %eax - call MachVideoPutChar - addl $16,%esp - - ret - -/************************************************************************/ -/* ESI = Address of text to display */ -/************************************************************************/ -i386PrintText: - .code32 - -i386PrintTextLoop: - lodsb - - // Check for end of string char - cmp $0,%al - je i386PrintTextDone - - // Check for newline char - cmp $0x0a,%al - jne i386PrintTextLoop2 - incl i386_ScreenPosY - movl $0,i386_ScreenPosX - jmp i386PrintTextLoop - -i386PrintTextLoop2: - call i386PrintChar - incl i386_ScreenPosX - - jmp i386PrintTextLoop - -i386PrintTextDone: - - ret - -/************************************************************************/ -/* Prints the value in EAX on the screen in hex */ -/************************************************************************/ -i386PrintHexDword: - .code32 - - call i386PrintHex1 - -i386PrintHex1: - call i386PrintHex2 -i386PrintHex2: - call i386PrintHex3 -i386PrintHex3: - movb $4,%cl - rol %cl,%eax - push %eax - andb $0x0f,%al - movl $i386PrintHexTable,%ebx - xlat /*$i386PrintHexTable*/ - call i386PrintChar - incl i386_ScreenPosX - pop %eax - - ret - -i386PrintHexTable: - .ascii "0123456789ABCDEF" - -/************************************************************************/ -/* Prints the value in AX on the screen in hex */ -/************************************************************************/ -i386PrintHexWord: - .code32 - - call i386PrintHexWord1 -i386PrintHexWord1: - call i386PrintHexWord2 -i386PrintHexWord2: - movb $4,%cl - rol %cl,%ax - push %eax - andb $0x0f,%al - movl $i386PrintHexTable,%ebx - xlat /*$i386PrintHexTable*/ - call i386PrintChar - incl i386_ScreenPosX - pop %eax - - ret - -/************************************************************************/ -/* Prints the value in AL on the screen in hex */ -/************************************************************************/ -i386PrintHexByte: - .code32 - - call i386PrintHexByte1 -i386PrintHexByte1: - movb $4,%cl - rol %cl,%al - push %eax - andb $0x0f,%al - movl $i386PrintHexTable,%ebx - xlat /*$i386PrintHexTable*/ - call i386PrintChar - incl i386_ScreenPosX - pop %eax - - ret - -/************************************************************************/ -EXTERN(i386DivideByZero) - .code32 - - movl $i386DivideByZeroText,i386ExceptionDescriptionText - jmp i386CommonExceptionHandler - -/************************************************************************/ -EXTERN(i386DebugException) - .code32 - - movl $i386DebugExceptionText,i386ExceptionDescriptionText - jmp i386CommonExceptionHandler - -/************************************************************************/ -EXTERN(i386NMIException) - .code32 - - movl $i386NMIExceptionText,i386ExceptionDescriptionText - jmp i386CommonExceptionHandler - -/************************************************************************/ -EXTERN(i386Breakpoint) - .code32 - - movl $i386BreakpointText,i386ExceptionDescriptionText - jmp i386CommonExceptionHandler - -/************************************************************************/ -EXTERN(i386Overflow) - .code32 - - movl $i386OverflowText,i386ExceptionDescriptionText - jmp i386CommonExceptionHandler - -/************************************************************************/ -EXTERN(i386BoundException) - .code32 - - movl $i386BoundExceptionText,i386ExceptionDescriptionText - jmp i386CommonExceptionHandler - -/************************************************************************/ -EXTERN(i386InvalidOpcode) - .code32 - - movl $i386InvalidOpcodeText,i386ExceptionDescriptionText - jmp i386CommonExceptionHandler - -/************************************************************************/ -EXTERN(i386FPUNotAvailable) - .code32 - - movl $i386FPUNotAvailableText,i386ExceptionDescriptionText - jmp i386CommonExceptionHandler - -/************************************************************************/ -EXTERN(i386DoubleFault) - .code32 - - popl %eax - movl %eax,i386_ERROR_CODE - - movl $i386DoubleFaultText,i386ExceptionDescriptionText - jmp i386CommonExceptionHandler - -/************************************************************************/ -EXTERN(i386CoprocessorSegment) - .code32 - - movl $i386CoprocessorSegmentText,i386ExceptionDescriptionText - jmp i386CommonExceptionHandler - -/************************************************************************/ -EXTERN(i386InvalidTSS) - .code32 - - popl %eax - movl %eax,i386_ERROR_CODE - - movl $i386InvalidTSSText,i386ExceptionDescriptionText - jmp i386CommonExceptionHandler - -/************************************************************************/ -EXTERN(i386SegmentNotPresent) - .code32 - - popl %eax - movl %eax,i386_ERROR_CODE - - movl $i386SegmentNotPresentText,i386ExceptionDescriptionText - jmp i386CommonExceptionHandler - -/************************************************************************/ -EXTERN(i386StackException) - .code32 - - popl %eax - movl %eax,i386_ERROR_CODE - - movl $i386StackExceptionText,i386ExceptionDescriptionText - jmp i386CommonExceptionHandler - -/************************************************************************/ -EXTERN(i386GeneralProtectionFault) - .code32 - - popl %eax - movl %eax,i386_ERROR_CODE - - movl $i386GeneralProtectionFaultText,i386ExceptionDescriptionText - jmp i386CommonExceptionHandler - -/************************************************************************/ -EXTERN(i386PageFault) - .code32 - - popl %eax - movl %eax,i386_ERROR_CODE - - movl $i386PageFaultText,i386ExceptionDescriptionText - jmp i386CommonExceptionHandler - -/************************************************************************/ -EXTERN(i386CoprocessorError) - .code32 - - movl $i386CoprocessorErrorText,i386ExceptionDescriptionText - jmp i386CommonExceptionHandler - -/************************************************************************/ -EXTERN(i386AlignmentCheck) - .code32 - - movl $i386AlignmentCheckText,i386ExceptionDescriptionText - jmp i386CommonExceptionHandler - -/************************************************************************/ -EXTERN(i386MachineCheck) - .code32 - - movl $i386MachineCheckText,i386ExceptionDescriptionText - jmp i386CommonExceptionHandler - -/************************************************************************ - * DEBUGGING SUPPORT FUNCTIONS - ************************************************************************/ -EXTERN(_INSTRUCTION_BREAKPOINT1) - .code32 - - pushl %eax - - movl 8(%esp),%eax - - movl %eax,%dr0 - movl %dr7,%eax - andl $0xfff0ffff,%eax - orl $0x00000303,%eax - movl %eax,%dr7 - - popl %eax - - ret - -EXTERN(_MEMORY_READWRITE_BREAKPOINT1) - .code32 - - pushl %eax - - movl 8(%esp),%eax - - movl %eax,%dr0 - movl %dr7,%eax - andl $0xfff0ffff,%eax - orl $0x00030303,%eax - movl %eax,%dr7 - - popl %eax - - ret - -EXTERN(_MEMORY_WRITE_BREAKPOINT1) - .code32 - - pushl %eax - - movl 8(%esp),%eax - - movl %eax,%dr0 - movl %dr7,%eax - andl $0xfff0ffff,%eax - orl $0x00010303,%eax - movl %eax,%dr7 - - popl %eax - - ret - -EXTERN(_INSTRUCTION_BREAKPOINT2) - .code32 - - pushl %eax - - movl 8(%esp),%eax - - movl %eax,%dr1 - movl %dr7,%eax - andl $0xff0fffff,%eax - orl $0x0000030c,%eax - movl %eax,%dr7 - - popl %eax - - ret - -EXTERN(_MEMORY_READWRITE_BREAKPOINT2) - .code32 - - pushl %eax - - movl 8(%esp),%eax - - movl %eax,%dr1 - movl %dr7,%eax - andl $0xff0fffff,%eax - orl $0x0030030c,%eax - movl %eax,%dr7 - - popl %eax - - ret - -EXTERN(_MEMORY_WRITE_BREAKPOINT2) - .code32 - - pushl %eax - - movl 8(%esp),%eax - - movl %eax,%dr1 - movl %dr7,%eax - andl $0xff0fffff,%eax - orl $0x0010030c,%eax - movl %eax,%dr7 - - popl %eax - - ret - -EXTERN(_INSTRUCTION_BREAKPOINT3) - .code32 - - pushl %eax - - movl 8(%esp),%eax - - movl %eax,%dr2 - movl %dr7,%eax - andl $0xf0ffffff,%eax - orl $0x00000330,%eax - movl %eax,%dr7 - - popl %eax - - ret - -EXTERN(_MEMORY_READWRITE_BREAKPOINT3) - .code32 - - pushl %eax - - movl 8(%esp),%eax - - movl %eax,%dr2 - movl %dr7,%eax - andl $0xf0ffffff,%eax - orl $0x03000330,%eax - movl %eax,%dr7 - - popl %eax - - ret - -EXTERN(_MEMORY_WRITE_BREAKPOINT3) - .code32 - - pushl %eax - - movl 8(%esp),%eax - - movl %eax,%dr2 - movl %dr7,%eax - andl $0xf0ffffff,%eax - orl $0x01000330,%eax - movl %eax,%dr7 - - popl %eax - - ret - -EXTERN(_INSTRUCTION_BREAKPOINT4) - .code32 - - pushl %eax - - movl 8(%esp),%eax - - movl %eax,%dr3 - movl %dr7,%eax - andl $0x0fffffff,%eax - orl $0x000003c0,%eax - movl %eax,%dr7 - - popl %eax - - ret - -EXTERN(_MEMORY_READWRITE_BREAKPOINT4) - .code32 - - pushl %eax - - movl 8(%esp),%eax - - movl %eax,%dr3 - movl %dr7,%eax - andl $0x0fffffff,%eax - orl $0x300003c0,%eax - movl %eax,%dr7 - - popl %eax - - ret - -EXTERN(_MEMORY_WRITE_BREAKPOINT4) - .code32 - - pushl %eax - - movl 8(%esp),%eax - - movl %eax,%dr3 - movl %dr7,%eax - andl $0x0fffffff,%eax - orl $0x100003c0,%eax - movl %eax,%dr7 - - popl %eax - - ret diff --git a/boot/freeldr/freeldr/arch/amd64/int386.S b/boot/freeldr/freeldr/arch/amd64/int386.S index a22e409c61c..6881173910d 100644 --- a/boot/freeldr/freeldr/arch/amd64/int386.S +++ b/boot/freeldr/freeldr/arch/amd64/int386.S @@ -17,6 +17,9 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include + + .intel_syntax noprefix .text .code16 @@ -168,3 +171,5 @@ Int386_vector_opcode: mov eax, Int386_eax ret + +END diff --git a/boot/freeldr/freeldr/arch/amd64/mb.S b/boot/freeldr/freeldr/arch/amd64/mb.S index 2d515e90053..51b06bc1e01 100644 --- a/boot/freeldr/freeldr/arch/amd64/mb.S +++ b/boot/freeldr/freeldr/arch/amd64/mb.S @@ -17,6 +17,9 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include + + .text .code16 @@ -61,3 +64,5 @@ pd_startup: .fill 4096, 1, 0 PageDirectoryEnd: + +END diff --git a/boot/freeldr/freeldr/arch/i386/_alloca.S b/boot/freeldr/freeldr/arch/i386/_alloca.S deleted file mode 100644 index 920db73b40e..00000000000 --- a/boot/freeldr/freeldr/arch/i386/_alloca.S +++ /dev/null @@ -1,33 +0,0 @@ -/* stuff needed for libgcc on win32. */ - -/*#ifdef L_chkstk*/ -#ifdef WIN32 - - .global ___chkstk - .global __alloca -___chkstk: -__alloca: - pushl %ecx /* save temp */ - movl %esp,%ecx /* get sp */ - addl $0x8,%ecx /* and point to return addr */ - -probe: cmpl $0x1000,%eax /* > 4k ?*/ - jb done - - subl $0x1000,%ecx /* yes, move pointer down 4k*/ - orl $0x0,(%ecx) /* probe there */ - subl $0x1000,%eax /* decrement count */ - jmp probe /* and do it again */ - -done: subl %eax,%ecx - orl $0x0,(%ecx) /* less that 4k, just peek here */ - - movl %esp,%eax - movl %ecx,%esp /* decrement stack */ - - movl (%eax),%ecx /* recover saved temp */ - movl 4(%eax),%eax /* get return address */ - jmp *%eax - - -#endif diff --git a/boot/freeldr/freeldr/arch/i386/arch.S b/boot/freeldr/freeldr/arch/i386/arch.S index 225dc4be3f9..c15a1c653ed 100644 --- a/boot/freeldr/freeldr/arch/i386/arch.S +++ b/boot/freeldr/freeldr/arch/i386/arch.S @@ -17,16 +17,19 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -.intel_syntax noprefix -#define HEX(y) 0x##y - -#define ASM +#include #include #include - .code16 +EXTERN _BootMain:PROC +EXTERN __bss_start__:DWORD +EXTERN __bss_end__:DWORD +EXTERN i386idtptr:FWORD -EXTERN(RealEntryPoint) +.code16 + +PUBLIC RealEntryPoint +RealEntryPoint: cli @@ -44,9 +47,10 @@ EXTERN(RealEntryPoint) sti /* Init pmode */ - call switch_to_prot + call switch_to_prot - .code32 +.endcode16 +.code32 /* Zero BootDrive and BootPartition */ xor eax, eax @@ -64,7 +68,7 @@ EXTERN(RealEntryPoint) call _BootMain call switch_to_real - .code16 +.code16 int HEX(19) @@ -78,9 +82,8 @@ stop: * Switches the processor to protected mode * it destroys eax */ -EXTERN(switch_to_prot) - -.code16 +PUBLIC switch_to_prot +switch_to_prot: cli /* None of these */ @@ -104,9 +107,9 @@ EXTERN(switch_to_prot) mov word ptr ds:[stack16], sp /* Load the GDT */ - lgdt gdtptr + lgdt gdtptr /* Load the IDT */ - lidt i386idtptr + lidt i386idtptr /* Enable Protected Mode */ mov eax, cr0 @@ -114,12 +117,12 @@ EXTERN(switch_to_prot) mov cr0, eax /* Clear prefetch queue & correct CS */ - //ljmp PMODE_CS, inpmode - jmp far ptr PMODE_CS:inpmode - -.code32 + ljmp16 PMODE_CS, inpmode inpmode: +.endcode16 +.code32 + /* Setup segment selectors */ mov ax, PMODE_DS mov ds, ax @@ -139,9 +142,8 @@ inpmode: * Switches the processor back to real mode * it destroys eax */ -EXTERN(switch_to_real) - -.code32 +PUBLIC switch_to_real +switch_to_real: /* We don't know what values are currently */ /* in the segment registers. So we are */ @@ -182,7 +184,7 @@ switch_to_real16: mov cr0, eax /* Clear prefetch queue & correct CS */ - //ljmp $0, $inrmode + //ljmp16 0, offset inrmode jmp far ptr 0:inrmode inrmode: @@ -207,7 +209,7 @@ inrmode: push word ptr ds:[code16ret] /* Load IDTR with real mode value */ - lidt rmode_idtptr + lidt rmode_idtptr sti /* These are ok now */ @@ -218,9 +220,8 @@ inrmode: /* * Needed for enabling the a20 address line */ -.code16 empty_8042: - .word 0x00eb,0x00eb // jmp $+2, jmp $+2 + .word HEX(00eb), HEX(00eb) // jmp $+2, jmp $+2 in al, HEX(64) cmp al, HEX(ff) // legacy-free machine without keyboard jz empty_8042_ret // controllers on Intel Macs read back 0xFF @@ -229,11 +230,14 @@ empty_8042: empty_8042_ret: ret +.endcode16 +.code32 + /* * Enable the A20 address line (to allow access to over 1mb) */ -EXTERN(_EnableA20) -.code32 +PUBLIC _EnableA20 +_EnableA20: pusha @@ -248,7 +252,9 @@ EXTERN(_EnableA20) out HEX(60), al call empty_8042 call switch_to_prot - .code32 + +.endcode16 +.code32 popa @@ -257,23 +263,26 @@ EXTERN(_EnableA20) /* * Disable the A20 address line */ -EXTERN(_DisableA20) -.code32 +PUBLIC _DisableA20 +_DisableA20: pusha call switch_to_real - .code16 - call empty_8042 +.code16 + + call empty_8042 mov al, HEX(D1) // command write out HEX(64), al call empty_8042 mov al, HEX(DD) // A20 off out HEX(60), al - call empty_8042 - call switch_to_prot - .code32 + call empty_8042 + call switch_to_prot + +.endcode16 +.code32 popa @@ -301,7 +310,7 @@ EXTERN(_DisableA20) #define INITIAL_BASE HEX(200000) /* Align 32 bits boundary */ -.align 4 + .align 4 /* Multiboot header */ MultibootHeader: @@ -331,10 +340,10 @@ MultibootEntry: /* 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 + 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) + ljmp PMODE_CS, (mb1 + INITIAL_BASE - FREELDR_BASE) + //jmp far ptr PMODE_CS: (offset mb1 + INITIAL_BASE - FREELDR_BASE) mb1: mov dx, PMODE_DS mov ds, dx @@ -374,13 +383,13 @@ mb3: rep movsd /* Load the GDT and IDT */ - lgdt gdtptr - lidt i386idtptr + lgdt gdtptr + lidt i386idtptr /* Clear prefetch queue & correct CS, * jump to low mem */ - //ljmp $PMODE_CS, $mb4 - jmp far ptr PMODE_CS:mb4 + ljmp PMODE_CS, mb4 + //jmp far ptr PMODE_CS:mb4 mb4: /* Reload segment selectors */ mov dx, PMODE_DS @@ -416,15 +425,17 @@ mb7: /* GO! */ push eax - call _BootMain + call _BootMain mbfail: call switch_to_real - .code16 - int 0x19 -mbstop: jmp mbstop /* We should never get here */ +.code16 + int HEX(19) +mbstop: + jmp mbstop /* We should never get here */ - .code32 +.endcode16 +.code32 /* 16-bit stack pointer */ stack16: @@ -496,8 +507,13 @@ mb_info: cmdline: .fill CMDLINE_SIZE, 1, 0 -EXTERN(_BootDrive) +PUBLIC _BootDrive +_BootDrive: .long 0 - -EXTERN(_BootPartition) + +PUBLIC _BootPartition +_BootPartition: .long 0 + +END + diff --git a/boot/freeldr/freeldr/arch/i386/realmode.S b/boot/freeldr/freeldr/arch/i386/realmode.S new file mode 100644 index 00000000000..4464a17ad70 --- /dev/null +++ b/boot/freeldr/freeldr/arch/i386/realmode.S @@ -0,0 +1,80 @@ + + +#include + +.code16 +PUBLIC _mainCRTStartup +_mainCRTStartup: +_LoaderEntry: + ret + +.endcode16 + +.code32 + + +// globals +PUBLIC _BootPartition +_BootPartition: +PUBLIC _BootDrive +_BootDrive: + +PUBLIC _PageDirectoryStart +_PageDirectoryStart: +PUBLIC _PageDirectoryEnd +_PageDirectoryEnd: + +PUBLIC _startup_pagedirectory +_startup_pagedirectory: +PUBLIC _apic_pagetable +_apic_pagetable: +PUBLIC _kernel_pagetable +_kernel_pagetable: +PUBLIC _lowmem_pagetable +_lowmem_pagetable: + + +PUBLIC RealEntryPoint +RealEntryPoint: + +PUBLIC _EnableA20 +_EnableA20: + +PUBLIC _ChainLoadBiosBootSectorCode +_ChainLoadBiosBootSectorCode: + +PUBLIC _BootOldLinuxKernel +_BootOldLinuxKernel: + +PUBLIC _BootNewLinuxKernel +_BootNewLinuxKernel: + +PUBLIC _SoftReboot +_SoftReboot: + +PUBLIC _DriveMapOldInt13HandlerAddress +_DriveMapOldInt13HandlerAddress: + +PUBLIC _DriveMapInt13HandlerStart +_DriveMapInt13HandlerStart: + +PUBLIC _DriveMapInt13HandlerEnd +_DriveMapInt13HandlerEnd: + +PUBLIC _DriveMapInt13HandlerMapList +_DriveMapInt13HandlerMapList: + +PUBLIC _PnpBiosGetDeviceNode +_PnpBiosGetDeviceNode: + +PUBLIC _PnpBiosGetDeviceNodeCount +_PnpBiosGetDeviceNodeCount: + +PUBLIC _PnpBiosSupported +_PnpBiosSupported: + +PUBLIC _Int386 +_Int386: + + +END diff --git a/boot/freeldr/freeldr/debug.c b/boot/freeldr/freeldr/debug.c index 4ab90966192..daabc6715f3 100644 --- a/boot/freeldr/freeldr/debug.c +++ b/boot/freeldr/freeldr/debug.c @@ -341,7 +341,6 @@ MsgBoxPrint(const char *Format, ...) } NTKERNELAPI -DECLSPEC_NORETURN VOID NTAPI KeBugCheckEx( diff --git a/boot/freeldr/freeldr/freeldr.c b/boot/freeldr/freeldr/freeldr.c index 04dae9b6541..077f2bb6686 100644 --- a/boot/freeldr/freeldr/freeldr.c +++ b/boot/freeldr/freeldr/freeldr.c @@ -53,3 +53,14 @@ VOID BootMain(LPSTR CmdLine) #endif RunLoader(); } + +#ifdef _MSC_VER +long _ftol2(double f) +{ + return _ftol(f); +} +long _ftol2_sse(double f) +{ + return _ftol(f); +} +#endif diff --git a/boot/freeldr/freeldr/reactos/reactos.c b/boot/freeldr/freeldr/reactos/reactos.c index 22f3771b28b..959dc22b05e 100644 --- a/boot/freeldr/freeldr/reactos/reactos.c +++ b/boot/freeldr/freeldr/reactos/reactos.c @@ -606,6 +606,8 @@ LoadAndBootReactOS(PCSTR OperatingSystemName) // if (IniReadSettingByName(SectionId, "Options", value, sizeof(value))) { + PCHAR File; + // // Append boot-time options // @@ -614,7 +616,6 @@ LoadAndBootReactOS(PCSTR OperatingSystemName) // // Check if a ramdisk file was given // - PCHAR File; File = strstr(value, "/RDIMAGEPATH="); if (File) { diff --git a/boot/freeldr/freeldr/windows/winldr.c b/boot/freeldr/freeldr/windows/winldr.c index 3d5339083c0..29c4eab03ef 100644 --- a/boot/freeldr/freeldr/windows/winldr.c +++ b/boot/freeldr/freeldr/windows/winldr.c @@ -39,6 +39,11 @@ extern BOOLEAN UseRealHeap; extern ULONG LoaderPagesSpanned; extern BOOLEAN AcpiPresent; +extern HEADLESS_LOADER_BLOCK LoaderRedirectionInformation; +extern BOOLEAN WinLdrTerminalConnected; + +extern void WinLdrSetupEms(IN PCHAR BootOptions); + BOOLEAN WinLdrCheckForLoadedDll(IN OUT PLOADER_PARAMETER_BLOCK WinLdrBlock, IN PCH DllName, @@ -205,8 +210,6 @@ WinLdrInitializePhase1(PLOADER_PARAMETER_BLOCK LoaderBlock, } /* Set headless block pointer */ - extern HEADLESS_LOADER_BLOCK LoaderRedirectionInformation; - extern BOOLEAN WinLdrTerminalConnected; if (WinLdrTerminalConnected) { Extension->HeadlessLoaderBlock = MmHeapAlloc(sizeof(HEADLESS_LOADER_BLOCK)); @@ -535,7 +538,6 @@ LoadAndBootWindows(PCSTR OperatingSystemName, AllocateAndInitLPB(&LoaderBlock); /* Setup redirection support */ - extern void WinLdrSetupEms(IN PCHAR BootOptions); WinLdrSetupEms(BootOptions); /* Detect hardware */