From 4076751ce21ec1534db675bd238bed3ee1fc0df7 Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Fri, 10 Jun 2011 12:55:14 +0000 Subject: [PATCH] [FREELDR] Fix MSVC and amd64 build svn path=/trunk/; revision=52172 --- reactos/boot/freeldr/freeldr/CMakeLists.txt | 34 +++++++++-- .../boot/freeldr/freeldr/arch/amd64/arch.S | 60 +++++++++---------- .../boot/freeldr/freeldr/arch/amd64/loader.c | 1 - .../boot/freeldr/freeldr/arch/amd64/stubs.S | 48 +++++++++++++++ .../boot/freeldr/freeldr/arch/i386/realmode.S | 8 +-- reactos/boot/freeldr/freeldr/disk/disk.c | 17 +++--- reactos/boot/freeldr/freeldr/disk/scsiport.c | 27 +++++++++ reactos/boot/freeldr/freeldr/freeldr.c | 11 ---- .../freeldr/include/arch/amd64/amd64.h | 13 ++-- .../freeldr/include/arch/amd64/machpc.h | 1 + .../freeldr/include/arch/i386/realmode.h | 13 ++++ reactos/boot/freeldr/freeldr/include/disk.h | 2 + .../boot/freeldr/freeldr/include/freeldr.h | 1 + 13 files changed, 173 insertions(+), 63 deletions(-) create mode 100644 reactos/boot/freeldr/freeldr/arch/amd64/stubs.S create mode 100644 reactos/boot/freeldr/freeldr/include/arch/i386/realmode.h diff --git a/reactos/boot/freeldr/freeldr/CMakeLists.txt b/reactos/boot/freeldr/freeldr/CMakeLists.txt index 87902b5c38d..65b54009b39 100644 --- a/reactos/boot/freeldr/freeldr/CMakeLists.txt +++ b/reactos/boot/freeldr/freeldr/CMakeLists.txt @@ -18,9 +18,14 @@ if(ARCH MATCHES i386) arch/i386/arch.S) endif() elseif(ARCH MATCHES amd64) - list(APPEND FREELDR_STARTUP_SOURCE - arch/i386/fathelp.S - arch/amd64/arch.S) + if(MSVC) + list(APPEND FREELDR_BASE64K_SOURCE + arch/amd64/stubs.S) + else() + list(APPEND FREELDR_STARTUP_SOURCE + arch/i386/fathelp.S + arch/amd64/arch.S) + endif() endif() if(ARCH MATCHES i386) @@ -39,12 +44,14 @@ if(ARCH MATCHES i386) arch/i386/i386bug.c) endif() 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) + endif() endif() set_source_files_properties(${FREELDR_BASE64K_SOURCE} PROPERTIES COMPILE_DEFINITIONS "_NTHAL_") @@ -60,7 +67,7 @@ list(APPEND FREELDR_BASE_SOURCE disk/disk.c disk/partition.c disk/ramdisk.c - disk/scsiport.c + #disk/scsiport.c fs/ext2.c fs/fat.c fs/fs.c @@ -148,6 +155,25 @@ if(ARCH MATCHES i386) arch/i386/xboxvideo.c windows/i386/ntsetup.c windows/i386/wlmemory.c) +elseif(ARCH MATCHES amd64) + list(APPEND FREELDR_ARCH_SOURCE + arch/amd64/loader.c + arch/i386/hardware.c + arch/i386/hwacpi.c + arch/i386/hwapm.c + arch/i386/hwpci.c + arch/i386/i386rtl.c + arch/i386/i386disk.c + arch/i386/i386vid.c + arch/i386/machpc.c + arch/i386/ntoskrnl.c + arch/i386/pccons.c + arch/i386/pcdisk.c + arch/i386/pcmem.c + arch/i386/pcrtc.c + arch/i386/pcvideo.c + windows/amd64/ntsetup.c + windows/amd64/wlmemory.c) else() #TBD endif() diff --git a/reactos/boot/freeldr/freeldr/arch/amd64/arch.S b/reactos/boot/freeldr/freeldr/arch/amd64/arch.S index 236a0be4b69..2bb7efba100 100644 --- a/reactos/boot/freeldr/freeldr/arch/amd64/arch.S +++ b/reactos/boot/freeldr/freeldr/arch/amd64/arch.S @@ -25,21 +25,21 @@ RealEntryPoint: /* checkPoint Charlie - where it all began... */ mov si, offset CheckPoint0 - call writestr + call writestr /* Setup a real mode stack */ mov sp, stack16 /* Zero BootDrive and BootPartition */ xor eax, eax - mov BootDrive, eax - mov BootPartition, eax + mov FrldrBootDrive, eax + mov FrldrBootPartition, eax /* Store the boot drive */ - mov BootDrive, dl + mov FrldrBootDrive, dl /* Store the boot partition */ - mov BootPartition, dh + mov FrldrBootPartition, dh /* Load the GDT */ lgdt gdtptr @@ -50,16 +50,16 @@ RealEntryPoint: /* checkPoint Charlie - where it all began... */ mov si, offset CheckPoint1 - call writestr - + call writestr + call x86_16_BuildPageTables - + /* checkPoint Charlie - where it all began... */ mov si, offset CheckPoint2 - call writestr + call writestr /* Check if CPU supports CPUID */ - + pushfd pop eax mov ebx, eax @@ -70,8 +70,8 @@ RealEntryPoint: pop eax cmp eax,ebx jz NO_CPUID_SUPPORT_DETECTED - - /* CPUID support detected - getting the PAE/PGE */ + + /* CPUID support detected - getting the PAE/PGE */ mov eax,1 // Fn0000_0001 - PAE in EDX[6] cpuid @@ -79,24 +79,24 @@ RealEntryPoint: and edx,0x00a0 test edx,edx // are PAE and PGE bits set? jz NO_X64_SUPPORT_DETECTED - + /* PAE and PGE are here */ - + xor edx, edx mov eax, 0x80000001 cpuid and edx, 0x20000000 test edx,edx jz NO_X64_SUPPORT_DETECTED - + /* X64 Processor */ - + /* checkPoint Charlie - where it all began... */ mov si, offset CheckPoint3 - call writestr + call writestr jmp switch64 - + NO_X64_SUPPORT_DETECTED: mov si, offset NotAnX64Processor // Loading message call writestr @@ -129,7 +129,7 @@ switch64: // mov ds, ax // mov word ptr ds:[0xb8002], 0x0e02 + '2' - + /* Return into real mode */ call x86_64_SwitchToReal .code16 @@ -169,7 +169,7 @@ x86_16_EnableA20: ret /* - * We define 512 2MB pages at the start of memory, so we can access the first + * We define 512 2MB pages at the start of memory, so we can access the first * 1 GB as if paging was disabled */ x86_16_BuildPageTables: @@ -238,7 +238,7 @@ writestr: popad popfd ret - + writechr: pushf @@ -252,7 +252,7 @@ writechr: //.global x86_16_SwitchToLong x86_16_SwitchToLong: - + cli xor ax,ax @@ -332,7 +332,7 @@ SwitchToReal1: /* Step 2 - disable long mode in EFER MSR */ // mov ecx, 0xC0000080 // Specify EFER MSR -// rdmsr +// rdmsr // and eax, ~0x00000100 // Disable EFER.LME // wrmsr @@ -408,12 +408,12 @@ gdtptr: .long gdt /* Base Address */ -.global BootDrive -BootDrive: +.global FrldrBootDrive +FrldrBootDrive: .long 0 - -.global BootPartition -BootPartition: + +.global FrldrBootPartition +FrldrBootPartition: .long 0 .global NotAnX64Processor @@ -431,12 +431,12 @@ NoCPUIDSupport: CheckPoint0: .ascii "Starting FreeLoader..." .byte 0x0d, 0x0a, 0 - + .global CheckPoint1 CheckPoint1: .ascii "FreeLoader[16-bit]: building page tables..." .byte 0x0d, 0x0a, 0 - + .global CheckPoint2 CheckPoint2: .ascii "FreeLoader[16-bit]: checking CPU for x64 long mode..." diff --git a/reactos/boot/freeldr/freeldr/arch/amd64/loader.c b/reactos/boot/freeldr/freeldr/arch/amd64/loader.c index 9970090cd3a..f72cbe9a4c9 100644 --- a/reactos/boot/freeldr/freeldr/arch/amd64/loader.c +++ b/reactos/boot/freeldr/freeldr/arch/amd64/loader.c @@ -27,7 +27,6 @@ extern ULONG_PTR KernelBase; ULONG_PTR GdtBase, IdtBase, TssBase; extern ROS_KERNEL_ENTRY_POINT KernelEntryPoint; -PPAGE_DIRECTORY_AMD64 pPML4; PVOID pIdt, pGdt; /* FUNCTIONS *****************************************************************/ diff --git a/reactos/boot/freeldr/freeldr/arch/amd64/stubs.S b/reactos/boot/freeldr/freeldr/arch/amd64/stubs.S new file mode 100644 index 00000000000..3f2e0e4a462 --- /dev/null +++ b/reactos/boot/freeldr/freeldr/arch/amd64/stubs.S @@ -0,0 +1,48 @@ + + +#include + +EXTERN BootMain:PROC + +.code64 + +/* 64 bit entry point */ +PUBLIC mainCRTStartup +mainCRTStartup: + jmp BootMain + +PUBLIC Int386 +Int386: + ret + +PUBLIC __lgdt +__lgdt: + +PUBLIC __ltr +__ltr: + +PUBLIC PxeCallApi +PxeCallApi: + .long 0 + +PUBLIC PageDirectoryStart +PageDirectoryStart: + .long 0 + +PUBLIC PageDirectoryEnd +PageDirectoryEnd: + .long 0 + +PUBLIC PnpBiosGetDeviceNode +PnpBiosGetDeviceNode: + .long 0 + +PUBLIC PnpBiosGetDeviceNodeCount +PnpBiosGetDeviceNodeCount: + .long 0 + +PUBLIC PnpBiosSupported +PnpBiosSupported: + .long 0 + +END diff --git a/reactos/boot/freeldr/freeldr/arch/i386/realmode.S b/reactos/boot/freeldr/freeldr/arch/i386/realmode.S index 78a1faecb2d..0a92ece8e1f 100644 --- a/reactos/boot/freeldr/freeldr/arch/i386/realmode.S +++ b/reactos/boot/freeldr/freeldr/arch/i386/realmode.S @@ -14,10 +14,10 @@ _LoaderEntry: // globals -PUBLIC _BootPartition -_BootPartition: -PUBLIC _BootDrive -_BootDrive: +PUBLIC _FrldrBootPartition +_FrldrBootPartition: +PUBLIC _FrldrBootDrive +_FrldrBootDrive: PUBLIC _PageDirectoryStart _PageDirectoryStart: diff --git a/reactos/boot/freeldr/freeldr/disk/disk.c b/reactos/boot/freeldr/freeldr/disk/disk.c index 77800d0609f..e932247bd40 100644 --- a/reactos/boot/freeldr/freeldr/disk/disk.c +++ b/reactos/boot/freeldr/freeldr/disk/disk.c @@ -132,18 +132,21 @@ DiskGetBootPath(char *BootPath, unsigned Size) /* FIXME */ else if (DiskReadBootRecord(FrldrBootDrive, 0, &MasterBootRecord)) { - /* This is a hard disk */ + ULONG BootPartition; - if (!DiskGetActivePartitionEntry(FrldrBootDrive, &PartitionEntry, &FrldrBootPartition)) + /* This is a hard disk */ + if (!DiskGetActivePartitionEntry(FrldrBootDrive, &PartitionEntry, &BootPartition)) { DbgPrint("Invalid active partition information\n"); return FALSE; } - if (Size <= sizeof(Path) + 18 + strlen(Device) + strlen(Partition)) - { - return FALSE; - } + FrldrBootPartition = BootPartition; + + if (Size <= sizeof(Path) + 18 + strlen(Device) + strlen(Partition)) + { + return FALSE; + } strcpy(BootPath, Path); @@ -158,7 +161,7 @@ DiskGetBootPath(char *BootPath, unsigned Size) strcat(BootPath, "partition("); strcat(BootPath, Partition); strcat(BootPath, ")"); - } + } else { /* This is a CD-ROM drive */ diff --git a/reactos/boot/freeldr/freeldr/disk/scsiport.c b/reactos/boot/freeldr/freeldr/disk/scsiport.c index 254760ff24a..4f82c7f18b6 100644 --- a/reactos/boot/freeldr/freeldr/disk/scsiport.c +++ b/reactos/boot/freeldr/freeldr/disk/scsiport.c @@ -11,6 +11,33 @@ #include #include +#undef ScsiPortLogError +#undef ScsiPortMoveMemory +#undef ScsiPortWritePortBufferUchar +#undef ScsiPortWritePortBufferUlong +#undef ScsiPortWritePortBufferUshort +#undef ScsiPortWritePortUchar +#undef ScsiPortWritePortUlong +#undef ScsiPortWritePortUshort +#undef ScsiPortWriteRegisterBufferUchar +#undef ScsiPortWriteRegisterBufferUlong +#undef ScsiPortWriteRegisterBufferUshort +#undef ScsiPortWriteRegisterUchar +#undef ScsiPortWriteRegisterUlong +#undef ScsiPortWriteRegisterUshort +#undef ScsiPortReadPortBufferUchar +#undef ScsiPortReadPortBufferUlong +#undef ScsiPortReadPortBufferUshort +#undef ScsiPortReadPortUchar +#undef ScsiPortReadPortUlong +#undef ScsiPortReadPortUshort +#undef ScsiPortReadRegisterBufferUchar +#undef ScsiPortReadRegisterBufferUlong +#undef ScsiPortReadRegisterBufferUshort +#undef ScsiPortReadRegisterUchar +#undef ScsiPortReadRegisterUlong +#undef ScsiPortReadRegisterUshort + #define NDEBUG #include diff --git a/reactos/boot/freeldr/freeldr/freeldr.c b/reactos/boot/freeldr/freeldr/freeldr.c index 98af295c4c7..57899168b2a 100644 --- a/reactos/boot/freeldr/freeldr/freeldr.c +++ b/reactos/boot/freeldr/freeldr/freeldr.c @@ -54,17 +54,6 @@ VOID BootMain(LPSTR CmdLine) RunLoader(); } -#ifdef _MSC_VER -long _ftol2(double f) -{ - return _ftol(f); -} -long _ftol2_sse(double f) -{ - return _ftol(f); -} -#endif - // We need to emulate these, because the original ones don't work in freeldr int __cdecl wctomb(char *mbchar, wchar_t wchar) { diff --git a/reactos/boot/freeldr/freeldr/include/arch/amd64/amd64.h b/reactos/boot/freeldr/freeldr/include/arch/amd64/amd64.h index e5c73d4b4e5..da68bcedf6b 100644 --- a/reactos/boot/freeldr/freeldr/include/arch/amd64/amd64.h +++ b/reactos/boot/freeldr/freeldr/include/arch/amd64/amd64.h @@ -18,7 +18,9 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#ifndef __ASM__ #pragma once +#endif // This is needed because headers define wrong one for ReactOS #undef KIP0PCRADDRESS @@ -49,17 +51,16 @@ #define APIC_PHYS_BASE 0xfee00000 -#define NUM_PAGES_KERNEL +#define NUM_PAGES_KERNEL #ifndef ASM -typedef struct _PAGE_DIRECTORY_AMD64 -{ - HARDWARE_PTE Pde[512]; -} PAGE_DIRECTORY_AMD64, *PPAGE_DIRECTORY_AMD64; - VOID FrLdrSetupGdtIdt(VOID); +#include +#define FrldrBootDrive *((PULONG)BSS_BootDrive) +#define FrldrBootPartition *((PULONG)BSS_BootPartition) + #endif /* EOF */ diff --git a/reactos/boot/freeldr/freeldr/include/arch/amd64/machpc.h b/reactos/boot/freeldr/freeldr/include/arch/amd64/machpc.h index efcf293dcab..2205524d590 100644 --- a/reactos/boot/freeldr/freeldr/include/arch/amd64/machpc.h +++ b/reactos/boot/freeldr/freeldr/include/arch/amd64/machpc.h @@ -49,6 +49,7 @@ VOID PcPrepareForReactOS(IN BOOLEAN Setup); ULONG PcMemGetMemoryMap(PBIOS_MEMORY_MAP BiosMemoryMap, ULONG MaxMemoryMapSize); +BOOLEAN PcDiskGetBootPath(char *BootPath, unsigned Size); BOOLEAN PcDiskReadLogicalSectors(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer); BOOLEAN PcDiskGetPartitionEntry(ULONG DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry); BOOLEAN PcDiskGetDriveGeometry(ULONG DriveNumber, PGEOMETRY DriveGeometry); diff --git a/reactos/boot/freeldr/freeldr/include/arch/i386/realmode.h b/reactos/boot/freeldr/freeldr/include/arch/i386/realmode.h new file mode 100644 index 00000000000..9126b815fcc --- /dev/null +++ b/reactos/boot/freeldr/freeldr/include/arch/i386/realmode.h @@ -0,0 +1,13 @@ + + +/* These addresses specify the realmode "BSS section" */ +#define BSS_START HEX(7000) +#define BSS_CallbackAddress BSS_START + 0 +#define BSS_CallbackReturn BSS_START + 8 +#define BSS_BootDrive BSS_START + 16 +#define BSS_BootPartition BSS_START + 20 + +#define PE_LOAD_BASE HEX(9000) +#define IMAGE_DOS_HEADER_e_lfanew 36 +#define IMAGE_FILE_HEADER_SIZE 20 +#define IMAGE_OPTIONAL_HEADER_AddressOfEntryPoint 16 diff --git a/reactos/boot/freeldr/freeldr/include/disk.h b/reactos/boot/freeldr/freeldr/include/disk.h index 2261930cf4f..0d53518ef8c 100644 --- a/reactos/boot/freeldr/freeldr/include/disk.h +++ b/reactos/boot/freeldr/freeldr/include/disk.h @@ -123,8 +123,10 @@ PCSTR DiskGetErrorCodeString(ULONG ErrorCode); BOOLEAN DiskReadLogicalSectors(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer); // Implemented in i386disk.c BOOLEAN DiskIsDriveRemovable(ULONG DriveNumber); VOID DiskStopFloppyMotor(VOID); // Implemented in i386disk.c +#ifndef _M_AMD64 extern ULONG FrldrBootDrive; extern ULONG FrldrBootPartition; +#endif BOOLEAN DiskGetBootPath(char *BootPath, unsigned Size); diff --git a/reactos/boot/freeldr/freeldr/include/freeldr.h b/reactos/boot/freeldr/freeldr/include/freeldr.h index 694c9c764a9..3545c2c8f64 100644 --- a/reactos/boot/freeldr/freeldr/include/freeldr.h +++ b/reactos/boot/freeldr/freeldr/include/freeldr.h @@ -95,6 +95,7 @@ #elif defined(_M_AMD64) #include #include +#include #include #endif /* misc files */