[FREELDR]

- Use fathelp.S from r43775 (amd64 branch by timo)
[CMAKE]
- Improve hal, ntoskrnl and freeldr/setupldr build.

svn path=/branches/cmake-bringup/; revision=48688
This commit is contained in:
Amine Khaldi 2010-09-02 21:00:02 +00:00
parent c988b66126
commit 1c24a9bbdd
4 changed files with 133 additions and 133 deletions

View file

@ -154,7 +154,7 @@ elseif(ARCH MATCHES amd64)
list(APPEND SETUPLDR_MAIN_SOURCE freeldr/freeldr/windows/setupldr2.c)
endif(ARCH MATCHES i386)
set_source_files_properties(${SETUPLDR_MAIN_SOURCE} PROPERTIES COMPILE_DEFINITIONS "_NTHAL_;FREELDR_REACTOS_SETUP" COMPILE_FLAGS "-ffreestanding -fno-builtin -fno-inline -fno-zero-initialized-in-bss")
set_source_files_properties(${SETUPLDR_MAIN_SOURCE} PROPERTIES COMPILE_FLAGS "-ffreestanding -fno-builtin -fno-inline -fno-zero-initialized-in-bss")
set(CMAKE_C_CREATE_SHARED_LIBRARY "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
@ -169,7 +169,7 @@ 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" SUFFIX ".sys")
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" SUFFIX ".sys")
if(ARCH MATCHES i386)
target_link_libraries(freeldr mini_hal)
@ -189,11 +189,9 @@ list(APPEND SETUPLDR_SOURCE
${FREELDR_ARCH_SOURCE}
${SETUPLDR_MAIN_SOURCE})
add_library(setupldr SHARED
${CMAKE_CURRENT_BINARY_DIR}/freeldr_freeldr.h.gch
${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" SUFFIX ".sys")
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" SUFFIX ".sys" COMPILE_DEFINITIONS "FREELDR_REACTOS_SETUP")
if(ARCH MATCHES i386)
target_link_libraries(setupldr mini_hal)
@ -204,4 +202,3 @@ target_link_libraries(setupldr
cmlib
rtl
libcntpr)
add_pch(setupldr ${CMAKE_CURRENT_SOURCE_DIR}/freeldr/freeldr/include/freeldr.h ${SETUPLDR_SOURCE})

View file

@ -1,10 +1,12 @@
// FATHELP.ASM
// fathelp.S
// FAT12/16 Boot Sector Helper Code
// Copyright (c) 1998, 2001, 2002, 2003 Brian Palmer
.text
.code16
.intel_syntax
.intel_syntax noprefix
.text
.code16
#define BootSectorStackTop 0x7bf2
#define DataAreaStartHigh 0x2
@ -16,28 +18,26 @@
#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 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
@ -46,12 +46,13 @@
//
// This code is loaded at 0000:8000 so we have to
// encode a jmp instruction to jump to 0000:8200
//.org 0x8000
.globl _mainCRTStartup /* For Mingw32 builds where the linker looks for this symbol */
.global _mainCRTStartup // For Mingw32 builds where the linker looks for this symbol
_mainCRTStartup:
.globl start
.global start
start:
.byte 0xe9
.byte 0xe9
.byte 0xfd
.byte 0x01
@ -64,80 +65,80 @@ start:
FatHelperEntryPoint:
push %ax /* First save AX - the start cluster of freeldr.sys */
push ax // First save AX - the start cluster of freeldr.sys
// Display "Loading FreeLoader..." message
mov %esi,msgLoading /* Loading message */
call [%bp-PutCharsOffset] /* Display it */
mov esi, offset msgLoading // Loading message
call [bp-PutCharsOffset] // Display it
call ReadFatIntoMemory
pop %ax /* Restore AX (start cluster) */
pop ax // Restore AX (start cluster)
// AX has start cluster of freeldr.sys
mov %bx,0x800
mov %es,%bx
mov bx,0x800
mov es,bx
LoadFile:
push %ax
push ax
call IsFat12
pop %ax
pop ax
jnc LoadFile2
cmp %ax,0xff8 /* Check to see if this is the last cluster in the chain */
cmp ax,0x0ff8 // Check to see if this is the last cluster in the chain
jmp LoadFile3
LoadFile2:
cmp %ax,0xfff8
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
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,BYTE [%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
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
pop ax
push es
jnc LoadFile4
call GetFatEntry12 /* Get the next entry */
call GetFatEntry12 // Get the next entry
jmp LoadFile5
LoadFile4:
call GetFatEntry16
LoadFile5:
pop %es
pop es
jmp LoadFile /* Load the next cluster (if any) */
jmp LoadFile // Load the next cluster (if any)
LoadFile_Done:
mov %dl,BYTE [%bp+BootDrive] /* Load the boot drive into DL */
mov %dh,[BootPartition] /* Load the boot partition into DH */
mov dl, [bp+BootDrive] // Load the boot drive into DL
mov dh, BootPartition // Load the boot partition into DH
push word ptr 0x0000
push word ptr 0x8000 // We will do a far return to 0000:8000h
// retf // Transfer control to ROSLDR
.byte 0xcb // == retf
push 0 /* push segment (0x0000) */
mov %bx, [0x80A8] /* 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,WORD [%bp+HiddenSectors]
mov %dx,WORD [%bp+HiddenSectors+2]
add %ax,WORD [%bp+ReservedSectors]
adc %dx,0
mov %cx,WORD [%bp+SectorsPerFat]
mov %bx,0x7000
mov %es,%bx
xor %bx,%bx
call [%bp-ReadSectorsOffset]
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
@ -146,15 +147,15 @@ ReadFatIntoMemory:
// 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 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 */
es mov %ax,WORD [%bx] /* Get FAT entry */
mov bx,0x7000
add bx,dx
mov es,bx
mov bx,ax // Restore FAT entry offset
mov ax, es:[bx] // Get FAT entry
ret
@ -164,24 +165,24 @@ GetFatEntry16:
// 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) */
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 */
es mov %ax,WORD [%bx] /* Get FAT entry */
pop %cx /* Get cluster number from stack */
and %cx,1
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,0xfff0
shr %ax,4
and ax,0x0fff0
shr ax,4
jmp GetFatEntry12_Done
UseLow12Bits:
and %ax,0x0fff
and ax,0x0fff
GetFatEntry12_Done:
@ -192,31 +193,30 @@ GetFatEntry12_Done:
// Otherwise CF = 0 for FAT16
IsFat12:
mov %ebx,DWORD [%bp-DataAreaStartLow]
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,DWORD [%bp+HiddenSectors]
sub ebx, [bp+HiddenSectors]
xor %eax,%eax
mov %ax,WORD [%bp+TotalSectors]
cmp %ax,0
xor eax,eax
mov ax, [bp+TotalSectors]
cmp ax, 0
jnz IsFat12_2
mov %eax,DWORD [%bp+TotalSectorsBig]
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 */
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
xor %ebx,%ebx
mov %bl,BYTE [%bp+SectsPerCluster]
div %ebx
movzx ebx, byte ptr [bp+SectsPerCluster]
div ebx
// EAX now has the number of clusters on the volume
stc
cmp %eax,4085
cmp eax,4085
jb IsFat12_Done
clc
@ -226,8 +226,14 @@ IsFat12_Done:
msgLoading:
.asciz "Loading FreeLoader...\r\n"
.ascii "Loading FreeLoader..."
.byte 0x0d,0x0a,0
.org 0x1fe
blockend:
.word 0x0aa55 /* BootSector signature */
// times 510-($-$$) db 0 // Pad to 510 bytes
.org 0x1fe
.word 0x0aa55 // BootSector signature
// pseudo adresses
//.org 0x7dfd
BootPartition:

View file

@ -28,10 +28,6 @@ list(APPEND HAL_GENERIC_SOURCE
halx86/generic/i386/systimer.S
halx86/generic/i386/trap.S)
add_library(hal_generic ${HAL_GENERIC_SOURCE} ${CMAKE_CURRENT_BINARY_DIR}/hal_generic_hal.h.gch)
add_pch(hal_generic ${CMAKE_CURRENT_SOURCE_DIR}/halx86/include/hal.h ${HAL_GENERIC_SOURCE})
add_dependencies(hal_generic psdk bugcodes)
list(APPEND HAL_GENERIC_PCAT_SOURCE
halx86/generic/legacy/bus/bushndlr.c
halx86/generic/legacy/bus/cmosbus.c
@ -42,28 +38,29 @@ list(APPEND HAL_GENERIC_PCAT_SOURCE
halx86/generic/legacy/bussupp.c
halx86/generic/legacy/halpcat.c)
add_library(hal_generic_pcat ${HAL_GENERIC_PCAT_SOURCE})
add_dependencies(hal_generic_pcat psdk)
list(APPEND HAL_GENERIC_UP_SOURCE
halx86/generic/spinlock.c
halx86/up/pic.c
halx86/up/processor.c)
add_library(hal_generic_up ${HAL_GENERIC_UP_SOURCE})
add_dependencies(hal_generic_up psdk)
set(CMAKE_C_CREATE_SHARED_LIBRARY "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
add_library(hal SHARED halx86/up/halinit_up.c halx86/up/halup.rc)
list(APPEND HAL_SOURCE
${CMAKE_CURRENT_BINARY_DIR}/hal_hal.h.gch
${HAL_GENERIC_SOURCE}
${HAL_GENERIC_PCAT_SOURCE}
${HAL_GENERIC_UP_SOURCE}
halx86/up/halinit_up.c
halx86/up/halup.rc)
set_target_properties(hal PROPERTIES LINK_FLAGS "-Wl,-entry,_HalInitSystem@8")
add_library(hal SHARED ${HAL_SOURCE})
add_pch(hal ${CMAKE_CURRENT_SOURCE_DIR}/halx86/include/hal.h ${HAL_SOURCE})
add_dependencies(hal psdk bugcodes)
set_target_properties(hal PROPERTIES LINK_FLAGS "-Wl,-entry,_HalInitSystem@8 -Wl,--image-base,0x00010000 -Wl,--subsystem,native")
target_link_libraries(hal
${CMAKE_CURRENT_SOURCE_DIR}/halx86/hal_i386.def
-Wl,--whole-archive hal_generic -Wl,--no-whole-archive
hal_generic_pcat
hal_generic_up
${REACTOS_SOURCE_DIR}/ntoskrnl/libntoskrnl.a
libcntpr)
@ -99,7 +96,7 @@ list(APPEND MINI_HAL_SOURCE
endif(ARCH MATCHES i386)
add_library(mini_hal ${MINI_HAL_SOURCE})
set_property(TARGET mini_hal PROPERTY COMPILE_DEFINITIONS _BLDR_ _MINIHAL_)
set_property(TARGET mini_hal PROPERTY COMPILE_DEFINITIONS "_BLDR_;_MINIHAL_")
add_dependencies(mini_hal psdk bugcodes)
else()

View file

@ -1,8 +1,8 @@
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> -i <SOURCE> <CMAKE_C_LINK_FLAGS> <DEFINES> -I${REACTOS_SOURCE_DIR}/include/psdk -I${REACTOS_BINARY_DIR}/include/psdk -I${REACTOS_SOURCE_DIR}/include/ -I${REACTOS_SOURCE_DIR}/include/reactos -I${REACTOS_BINARY_DIR}/include/reactos -I${REACTOS_SOURCE_DIR}/include/reactos/wine -I${REACTOS_SOURCE_DIR}/include/crt -I${REACTOS_SOURCE_DIR}/include/crt/mingw32 -I${REACTOS_SOURCE_DIR} -I${CMAKE_CURRENT_SOURCE_DIR}/include -O coff -o <OBJECT> ")
set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -Wl,-L${REACTOS_BINARY_DIR}/lib/3rdparty/mingw")
set(CMAKE_EXE_LINKER_FLAGS "-nodefaultlibs -nostdlib -Wl,-entry,_KiSystemStartup@4 -Wl,--image-base,0x80800000 -Wl,--kill-at -Wl,-T,${REACTOS_SOURCE_DIR}/global.lds")
set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
set(CMAKE_EXE_LINKER_FLAGS "-nodefaultlibs -nostdlib -Wl,-entry,_KiSystemStartup@4 -Wl,--image-base,0x80800000 -Wl,--kill-at -Wl,-T,${REACTOS_SOURCE_DIR}/global.lds -Wl,--subsystem,native")
add_definitions(-D__NTOSKRNL__)
add_definitions(-D_NTOSKRNL_)