[FREELDR]

Fix MSVC and amd64 build

svn path=/trunk/; revision=52172
This commit is contained in:
Timo Kreuzer 2011-06-10 12:55:14 +00:00
parent 74fcd7f506
commit 4076751ce2
13 changed files with 173 additions and 63 deletions

View file

@ -18,9 +18,14 @@ if(ARCH MATCHES i386)
arch/i386/arch.S) arch/i386/arch.S)
endif() endif()
elseif(ARCH MATCHES amd64) elseif(ARCH MATCHES amd64)
list(APPEND FREELDR_STARTUP_SOURCE if(MSVC)
arch/i386/fathelp.S list(APPEND FREELDR_BASE64K_SOURCE
arch/amd64/arch.S) arch/amd64/stubs.S)
else()
list(APPEND FREELDR_STARTUP_SOURCE
arch/i386/fathelp.S
arch/amd64/arch.S)
endif()
endif() endif()
if(ARCH MATCHES i386) if(ARCH MATCHES i386)
@ -39,12 +44,14 @@ if(ARCH MATCHES i386)
arch/i386/i386bug.c) arch/i386/i386bug.c)
endif() endif()
elseif(ARCH MATCHES amd64) elseif(ARCH MATCHES amd64)
if(NOT MSVC)
list(APPEND FREELDR_BASE64K_SOURCE list(APPEND FREELDR_BASE64K_SOURCE
arch/i386/drvmap.S arch/i386/drvmap.S
arch/i386/i386cpu.S arch/i386/i386cpu.S
arch/i386/i386idt.S arch/i386/i386idt.S
arch/i386/i386trap.S arch/i386/i386trap.S
arch/amd64/mb.S) arch/amd64/mb.S)
endif()
endif() endif()
set_source_files_properties(${FREELDR_BASE64K_SOURCE} PROPERTIES COMPILE_DEFINITIONS "_NTHAL_") set_source_files_properties(${FREELDR_BASE64K_SOURCE} PROPERTIES COMPILE_DEFINITIONS "_NTHAL_")
@ -60,7 +67,7 @@ list(APPEND FREELDR_BASE_SOURCE
disk/disk.c disk/disk.c
disk/partition.c disk/partition.c
disk/ramdisk.c disk/ramdisk.c
disk/scsiport.c #disk/scsiport.c
fs/ext2.c fs/ext2.c
fs/fat.c fs/fat.c
fs/fs.c fs/fs.c
@ -148,6 +155,25 @@ if(ARCH MATCHES i386)
arch/i386/xboxvideo.c arch/i386/xboxvideo.c
windows/i386/ntsetup.c windows/i386/ntsetup.c
windows/i386/wlmemory.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() else()
#TBD #TBD
endif() endif()

View file

@ -25,21 +25,21 @@ RealEntryPoint:
/* checkPoint Charlie - where it all began... */ /* checkPoint Charlie - where it all began... */
mov si, offset CheckPoint0 mov si, offset CheckPoint0
call writestr call writestr
/* Setup a real mode stack */ /* Setup a real mode stack */
mov sp, stack16 mov sp, stack16
/* Zero BootDrive and BootPartition */ /* Zero BootDrive and BootPartition */
xor eax, eax xor eax, eax
mov BootDrive, eax mov FrldrBootDrive, eax
mov BootPartition, eax mov FrldrBootPartition, eax
/* Store the boot drive */ /* Store the boot drive */
mov BootDrive, dl mov FrldrBootDrive, dl
/* Store the boot partition */ /* Store the boot partition */
mov BootPartition, dh mov FrldrBootPartition, dh
/* Load the GDT */ /* Load the GDT */
lgdt gdtptr lgdt gdtptr
@ -50,16 +50,16 @@ RealEntryPoint:
/* checkPoint Charlie - where it all began... */ /* checkPoint Charlie - where it all began... */
mov si, offset CheckPoint1 mov si, offset CheckPoint1
call writestr call writestr
call x86_16_BuildPageTables call x86_16_BuildPageTables
/* checkPoint Charlie - where it all began... */ /* checkPoint Charlie - where it all began... */
mov si, offset CheckPoint2 mov si, offset CheckPoint2
call writestr call writestr
/* Check if CPU supports CPUID */ /* Check if CPU supports CPUID */
pushfd pushfd
pop eax pop eax
mov ebx, eax mov ebx, eax
@ -70,8 +70,8 @@ RealEntryPoint:
pop eax pop eax
cmp eax,ebx cmp eax,ebx
jz NO_CPUID_SUPPORT_DETECTED 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] mov eax,1 // Fn0000_0001 - PAE in EDX[6]
cpuid cpuid
@ -79,24 +79,24 @@ RealEntryPoint:
and edx,0x00a0 and edx,0x00a0
test edx,edx // are PAE and PGE bits set? test edx,edx // are PAE and PGE bits set?
jz NO_X64_SUPPORT_DETECTED jz NO_X64_SUPPORT_DETECTED
/* PAE and PGE are here */ /* PAE and PGE are here */
xor edx, edx xor edx, edx
mov eax, 0x80000001 mov eax, 0x80000001
cpuid cpuid
and edx, 0x20000000 and edx, 0x20000000
test edx,edx test edx,edx
jz NO_X64_SUPPORT_DETECTED jz NO_X64_SUPPORT_DETECTED
/* X64 Processor */ /* X64 Processor */
/* checkPoint Charlie - where it all began... */ /* checkPoint Charlie - where it all began... */
mov si, offset CheckPoint3 mov si, offset CheckPoint3
call writestr call writestr
jmp switch64 jmp switch64
NO_X64_SUPPORT_DETECTED: NO_X64_SUPPORT_DETECTED:
mov si, offset NotAnX64Processor // Loading message mov si, offset NotAnX64Processor // Loading message
call writestr call writestr
@ -129,7 +129,7 @@ switch64:
// mov ds, ax // mov ds, ax
// mov word ptr ds:[0xb8002], 0x0e02 + '2' // mov word ptr ds:[0xb8002], 0x0e02 + '2'
/* Return into real mode */ /* Return into real mode */
call x86_64_SwitchToReal call x86_64_SwitchToReal
.code16 .code16
@ -169,7 +169,7 @@ x86_16_EnableA20:
ret 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 * 1 GB as if paging was disabled
*/ */
x86_16_BuildPageTables: x86_16_BuildPageTables:
@ -238,7 +238,7 @@ writestr:
popad popad
popfd popfd
ret ret
writechr: writechr:
pushf pushf
@ -252,7 +252,7 @@ writechr:
//.global x86_16_SwitchToLong //.global x86_16_SwitchToLong
x86_16_SwitchToLong: x86_16_SwitchToLong:
cli cli
xor ax,ax xor ax,ax
@ -332,7 +332,7 @@ SwitchToReal1:
/* Step 2 - disable long mode in EFER MSR */ /* Step 2 - disable long mode in EFER MSR */
// mov ecx, 0xC0000080 // Specify EFER MSR // mov ecx, 0xC0000080 // Specify EFER MSR
// rdmsr // rdmsr
// and eax, ~0x00000100 // Disable EFER.LME // and eax, ~0x00000100 // Disable EFER.LME
// wrmsr // wrmsr
@ -408,12 +408,12 @@ gdtptr:
.long gdt /* Base Address */ .long gdt /* Base Address */
.global BootDrive .global FrldrBootDrive
BootDrive: FrldrBootDrive:
.long 0 .long 0
.global BootPartition .global FrldrBootPartition
BootPartition: FrldrBootPartition:
.long 0 .long 0
.global NotAnX64Processor .global NotAnX64Processor
@ -431,12 +431,12 @@ NoCPUIDSupport:
CheckPoint0: CheckPoint0:
.ascii "Starting FreeLoader..." .ascii "Starting FreeLoader..."
.byte 0x0d, 0x0a, 0 .byte 0x0d, 0x0a, 0
.global CheckPoint1 .global CheckPoint1
CheckPoint1: CheckPoint1:
.ascii "FreeLoader[16-bit]: building page tables..." .ascii "FreeLoader[16-bit]: building page tables..."
.byte 0x0d, 0x0a, 0 .byte 0x0d, 0x0a, 0
.global CheckPoint2 .global CheckPoint2
CheckPoint2: CheckPoint2:
.ascii "FreeLoader[16-bit]: checking CPU for x64 long mode..." .ascii "FreeLoader[16-bit]: checking CPU for x64 long mode..."

View file

@ -27,7 +27,6 @@ extern ULONG_PTR KernelBase;
ULONG_PTR GdtBase, IdtBase, TssBase; ULONG_PTR GdtBase, IdtBase, TssBase;
extern ROS_KERNEL_ENTRY_POINT KernelEntryPoint; extern ROS_KERNEL_ENTRY_POINT KernelEntryPoint;
PPAGE_DIRECTORY_AMD64 pPML4;
PVOID pIdt, pGdt; PVOID pIdt, pGdt;
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/

View file

@ -0,0 +1,48 @@
#include <asm.inc>
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

View file

@ -14,10 +14,10 @@ _LoaderEntry:
// globals // globals
PUBLIC _BootPartition PUBLIC _FrldrBootPartition
_BootPartition: _FrldrBootPartition:
PUBLIC _BootDrive PUBLIC _FrldrBootDrive
_BootDrive: _FrldrBootDrive:
PUBLIC _PageDirectoryStart PUBLIC _PageDirectoryStart
_PageDirectoryStart: _PageDirectoryStart:

View file

@ -132,18 +132,21 @@ DiskGetBootPath(char *BootPath, unsigned Size)
/* FIXME */ /* FIXME */
else if (DiskReadBootRecord(FrldrBootDrive, 0, &MasterBootRecord)) 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"); DbgPrint("Invalid active partition information\n");
return FALSE; return FALSE;
} }
if (Size <= sizeof(Path) + 18 + strlen(Device) + strlen(Partition)) FrldrBootPartition = BootPartition;
{
return FALSE; if (Size <= sizeof(Path) + 18 + strlen(Device) + strlen(Partition))
} {
return FALSE;
}
strcpy(BootPath, Path); strcpy(BootPath, Path);
@ -158,7 +161,7 @@ DiskGetBootPath(char *BootPath, unsigned Size)
strcat(BootPath, "partition("); strcat(BootPath, "partition(");
strcat(BootPath, Partition); strcat(BootPath, Partition);
strcat(BootPath, ")"); strcat(BootPath, ")");
} }
else else
{ {
/* This is a CD-ROM drive */ /* This is a CD-ROM drive */

View file

@ -11,6 +11,33 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#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 #define NDEBUG
#include <debug.h> #include <debug.h>

View file

@ -54,17 +54,6 @@ VOID BootMain(LPSTR CmdLine)
RunLoader(); 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 // We need to emulate these, because the original ones don't work in freeldr
int __cdecl wctomb(char *mbchar, wchar_t wchar) int __cdecl wctomb(char *mbchar, wchar_t wchar)
{ {

View file

@ -18,7 +18,9 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#ifndef __ASM__
#pragma once #pragma once
#endif
// This is needed because headers define wrong one for ReactOS // This is needed because headers define wrong one for ReactOS
#undef KIP0PCRADDRESS #undef KIP0PCRADDRESS
@ -49,17 +51,16 @@
#define APIC_PHYS_BASE 0xfee00000 #define APIC_PHYS_BASE 0xfee00000
#define NUM_PAGES_KERNEL #define NUM_PAGES_KERNEL
#ifndef ASM #ifndef ASM
typedef struct _PAGE_DIRECTORY_AMD64
{
HARDWARE_PTE Pde[512];
} PAGE_DIRECTORY_AMD64, *PPAGE_DIRECTORY_AMD64;
VOID FrLdrSetupGdtIdt(VOID); VOID FrLdrSetupGdtIdt(VOID);
#include <arch/i386/realmode.h>
#define FrldrBootDrive *((PULONG)BSS_BootDrive)
#define FrldrBootPartition *((PULONG)BSS_BootPartition)
#endif #endif
/* EOF */ /* EOF */

View file

@ -49,6 +49,7 @@ VOID PcPrepareForReactOS(IN BOOLEAN Setup);
ULONG PcMemGetMemoryMap(PBIOS_MEMORY_MAP BiosMemoryMap, ULONG MaxMemoryMapSize); 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 PcDiskReadLogicalSectors(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer);
BOOLEAN PcDiskGetPartitionEntry(ULONG DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry); BOOLEAN PcDiskGetPartitionEntry(ULONG DriveNumber, ULONG PartitionNumber, PPARTITION_TABLE_ENTRY PartitionTableEntry);
BOOLEAN PcDiskGetDriveGeometry(ULONG DriveNumber, PGEOMETRY DriveGeometry); BOOLEAN PcDiskGetDriveGeometry(ULONG DriveNumber, PGEOMETRY DriveGeometry);

View file

@ -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

View file

@ -123,8 +123,10 @@ PCSTR DiskGetErrorCodeString(ULONG ErrorCode);
BOOLEAN DiskReadLogicalSectors(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer); // Implemented in i386disk.c BOOLEAN DiskReadLogicalSectors(ULONG DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer); // Implemented in i386disk.c
BOOLEAN DiskIsDriveRemovable(ULONG DriveNumber); BOOLEAN DiskIsDriveRemovable(ULONG DriveNumber);
VOID DiskStopFloppyMotor(VOID); // Implemented in i386disk.c VOID DiskStopFloppyMotor(VOID); // Implemented in i386disk.c
#ifndef _M_AMD64
extern ULONG FrldrBootDrive; extern ULONG FrldrBootDrive;
extern ULONG FrldrBootPartition; extern ULONG FrldrBootPartition;
#endif
BOOLEAN DiskGetBootPath(char *BootPath, unsigned Size); BOOLEAN DiskGetBootPath(char *BootPath, unsigned Size);

View file

@ -95,6 +95,7 @@
#elif defined(_M_AMD64) #elif defined(_M_AMD64)
#include <arch/amd64/hardware.h> #include <arch/amd64/hardware.h>
#include <arch/amd64/machpc.h> #include <arch/amd64/machpc.h>
#include <arch/i386/pxe.h>
#include <internal/amd64/intrin_i.h> #include <internal/amd64/intrin_i.h>
#endif #endif
/* misc files */ /* misc files */