[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) list(APPEND SETUPLDR_MAIN_SOURCE freeldr/freeldr/windows/setupldr2.c)
endif(ARCH MATCHES i386) 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>") 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 ${CMAKE_CURRENT_BINARY_DIR}/freeldr_freeldr.h.gch
${FREELDR_SOURCE}) ${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) if(ARCH MATCHES i386)
target_link_libraries(freeldr mini_hal) target_link_libraries(freeldr mini_hal)
@ -189,11 +189,9 @@ list(APPEND SETUPLDR_SOURCE
${FREELDR_ARCH_SOURCE} ${FREELDR_ARCH_SOURCE}
${SETUPLDR_MAIN_SOURCE}) ${SETUPLDR_MAIN_SOURCE})
add_library(setupldr SHARED add_library(setupldr SHARED ${SETUPLDR_SOURCE})
${CMAKE_CURRENT_BINARY_DIR}/freeldr_freeldr.h.gch
${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) if(ARCH MATCHES i386)
target_link_libraries(setupldr mini_hal) target_link_libraries(setupldr mini_hal)
@ -204,4 +202,3 @@ target_link_libraries(setupldr
cmlib cmlib
rtl rtl
libcntpr) 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 // FAT12/16 Boot Sector Helper Code
// Copyright (c) 1998, 2001, 2002, 2003 Brian Palmer // Copyright (c) 1998, 2001, 2002, 2003 Brian Palmer
.text .intel_syntax noprefix
.code16
.intel_syntax .text
.code16
#define BootSectorStackTop 0x7bf2 #define BootSectorStackTop 0x7bf2
#define DataAreaStartHigh 0x2 #define DataAreaStartHigh 0x2
@ -36,8 +38,6 @@
#define VolumeLabel 43 #define VolumeLabel 43
#define FileSystem 54 #define FileSystem 54
#define BootPartition 0x7dfd
// This code will be stored in the first 512 bytes // This code will be stored in the first 512 bytes
// of freeldr.sys. The first 3 bytes will be a jmp // of freeldr.sys. The first 3 bytes will be a jmp
@ -46,10 +46,11 @@
// //
// This code is loaded at 0000:8000 so we have to // This code is loaded at 0000:8000 so we have to
// encode a jmp instruction to jump to 0000:8200 // 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: _mainCRTStartup:
.globl start .global start
start: start:
.byte 0xe9 .byte 0xe9
.byte 0xfd .byte 0xfd
@ -64,80 +65,80 @@ start:
FatHelperEntryPoint: 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 // Display "Loading FreeLoader..." message
mov %esi,msgLoading /* Loading message */ mov esi, offset msgLoading // Loading message
call [%bp-PutCharsOffset] /* Display it */ call [bp-PutCharsOffset] // Display it
call ReadFatIntoMemory call ReadFatIntoMemory
pop %ax /* Restore AX (start cluster) */ pop ax // Restore AX (start cluster)
// AX has start cluster of freeldr.sys // AX has start cluster of freeldr.sys
mov %bx,0x800 mov bx,0x800
mov %es,%bx mov es,bx
LoadFile: LoadFile:
push %ax push ax
call IsFat12 call IsFat12
pop %ax pop ax
jnc LoadFile2 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 jmp LoadFile3
LoadFile2: LoadFile2:
cmp %ax,0xfff8 cmp ax,0x0fff8
LoadFile3: LoadFile3:
jae LoadFile_Done /* If so continue, if not then read then next one */ jae LoadFile_Done // If so continue, if not then read then next one
push %ax push ax
xor %bx,%bx /* Load ROSLDR starting at 0000:8000h */ xor bx,bx // Load ROSLDR starting at 0000:8000h
push %es push es
call [%bp-ReadClusterOffset] call [bp-ReadClusterOffset]
pop %es pop es
xor %bx,%bx xor bx,bx
mov %bl,BYTE [%bp+SectsPerCluster] mov bl, [bp+SectsPerCluster]
shl %bx,5 /* BX = BX * 512 / 16 */ shl bx,5 // BX = BX * 512 / 16
mov %ax,%es /* Increment the load address by */ mov ax,es // Increment the load address by
add %ax,%bx /* The size of a cluster */ add ax,bx // The size of a cluster
mov %es,%ax mov es,ax
call IsFat12 call IsFat12
pop %ax pop ax
push %es push es
jnc LoadFile4 jnc LoadFile4
call GetFatEntry12 /* Get the next entry */ call GetFatEntry12 // Get the next entry
jmp LoadFile5 jmp LoadFile5
LoadFile4: LoadFile4:
call GetFatEntry16 call GetFatEntry16
LoadFile5: LoadFile5:
pop %es pop es
jmp LoadFile /* Load the next cluster (if any) */ jmp LoadFile // Load the next cluster (if any)
LoadFile_Done: LoadFile_Done:
mov %dl,BYTE [%bp+BootDrive] /* Load the boot drive into DL */ mov dl, [bp+BootDrive] // Load the boot drive into DL
mov %dh,[BootPartition] /* Load the boot partition into DH */ 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 // Reads the entire FAT into memory at 7000:0000
ReadFatIntoMemory: ReadFatIntoMemory:
mov %ax,WORD [%bp+HiddenSectors] mov ax, [bp+HiddenSectors]
mov %dx,WORD [%bp+HiddenSectors+2] mov dx, [bp+HiddenSectors+2]
add %ax,WORD [%bp+ReservedSectors] add ax, [bp+ReservedSectors]
adc %dx,0 adc dx, 0
mov %cx,WORD [%bp+SectorsPerFat] mov cx, [bp+SectorsPerFat]
mov %bx,0x7000 mov bx,0x7000
mov %es,%bx mov es,bx
xor %bx,%bx xor bx,bx
call [%bp-ReadSectorsOffset] call [bp-ReadSectorsOffset]
ret ret
@ -146,15 +147,15 @@ ReadFatIntoMemory:
// On return AX has FAT entry for that cluster // On return AX has FAT entry for that cluster
GetFatEntry16: GetFatEntry16:
mov %cx,2 /* AX = AX * 2 (since FAT16 entries are 2 bytes) */ mov cx,2 // AX = AX * 2 (since FAT16 entries are 2 bytes)
mul %cx mul cx
shl %dx,12 shl dx,12
mov %bx,0x7000 mov bx,0x7000
add %bx,%dx add bx,dx
mov %es,%bx mov es,bx
mov %bx,%ax /* Restore FAT entry offset */ mov bx,ax // Restore FAT entry offset
es mov %ax,WORD [%bx] /* Get FAT entry */ mov ax, es:[bx] // Get FAT entry
ret ret
@ -164,24 +165,24 @@ GetFatEntry16:
// On return AX has FAT entry for that cluster // On return AX has FAT entry for that cluster
GetFatEntry12: GetFatEntry12:
push %ax push ax
mov %cx,%ax mov cx,ax
shr %ax,1 shr ax,1
add %ax,%cx /* AX = AX * 1.5 (AX = AX + (AX / 2)) (since FAT12 entries are 12 bits) */ add ax,cx // AX = AX * 1.5 (AX = AX + (AX / 2)) (since FAT12 entries are 12 bits)
mov %bx,0x7000 mov bx,0x7000
mov %es,%bx mov es,bx
mov %bx,%ax /* Put FAT entry offset into BX */ mov bx,ax // Put FAT entry offset into BX
es mov %ax,WORD [%bx] /* Get FAT entry */ mov ax, es:[bx] // Get FAT entry
pop %cx /* Get cluster number from stack */ pop cx // Get cluster number from stack
and %cx,1 and cx,1
jz UseLow12Bits jz UseLow12Bits
and %ax,0xfff0 and ax,0x0fff0
shr %ax,4 shr ax,4
jmp GetFatEntry12_Done jmp GetFatEntry12_Done
UseLow12Bits: UseLow12Bits:
and %ax,0x0fff and ax,0x0fff
GetFatEntry12_Done: GetFatEntry12_Done:
@ -192,31 +193,30 @@ GetFatEntry12_Done:
// Otherwise CF = 0 for FAT16 // Otherwise CF = 0 for FAT16
IsFat12: IsFat12:
mov %ebx,DWORD [%bp-DataAreaStartLow] mov ebx, [bp-DataAreaStartLow]
// EBX now has the number of the starting sector of the data area // EBX now has the number of the starting sector of the data area
// starting from the beginning of the disk, so subtrace hidden sectors // starting from the beginning of the disk, so subtrace hidden sectors
sub %ebx,DWORD [%bp+HiddenSectors] sub ebx, [bp+HiddenSectors]
xor %eax,%eax xor eax,eax
mov %ax,WORD [%bp+TotalSectors] mov ax, [bp+TotalSectors]
cmp %ax,0 cmp ax, 0
jnz IsFat12_2 jnz IsFat12_2
mov %eax,DWORD [%bp+TotalSectorsBig] mov eax, [bp+TotalSectorsBig]
// EAX now contains the number of sectors on the volume // EAX now contains the number of sectors on the volume
IsFat12_2: IsFat12_2:
sub %eax,%ebx /* Subtract data area start sector */ sub eax,ebx // Subtract data area start sector
xor %edx,%edx /* from total sectors of volume */ xor edx,edx // from total sectors of volume
// EDX:EAX now contains the number of data sectors on the volume // EDX:EAX now contains the number of data sectors on the volume
xor %ebx,%ebx movzx ebx, byte ptr [bp+SectsPerCluster]
mov %bl,BYTE [%bp+SectsPerCluster] div ebx
div %ebx
// EAX now has the number of clusters on the volume // EAX now has the number of clusters on the volume
stc stc
cmp %eax,4085 cmp eax,4085
jb IsFat12_Done jb IsFat12_Done
clc clc
@ -226,8 +226,14 @@ IsFat12_Done:
msgLoading: msgLoading:
.asciz "Loading FreeLoader...\r\n" .ascii "Loading FreeLoader..."
.byte 0x0d,0x0a,0
.org 0x1fe // times 510-($-$$) db 0 // Pad to 510 bytes
blockend: .org 0x1fe
.word 0x0aa55 /* BootSector signature */ .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/systimer.S
halx86/generic/i386/trap.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 list(APPEND HAL_GENERIC_PCAT_SOURCE
halx86/generic/legacy/bus/bushndlr.c halx86/generic/legacy/bus/bushndlr.c
halx86/generic/legacy/bus/cmosbus.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/bussupp.c
halx86/generic/legacy/halpcat.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 list(APPEND HAL_GENERIC_UP_SOURCE
halx86/generic/spinlock.c halx86/generic/spinlock.c
halx86/up/pic.c halx86/up/pic.c
halx86/up/processor.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>") 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 target_link_libraries(hal
${CMAKE_CURRENT_SOURCE_DIR}/halx86/hal_i386.def ${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 ${REACTOS_SOURCE_DIR}/ntoskrnl/libntoskrnl.a
libcntpr) libcntpr)
@ -99,7 +96,7 @@ list(APPEND MINI_HAL_SOURCE
endif(ARCH MATCHES i386) endif(ARCH MATCHES i386)
add_library(mini_hal ${MINI_HAL_SOURCE}) 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) add_dependencies(mini_hal psdk bugcodes)
else() 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_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_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") 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__)
add_definitions(-D_NTOSKRNL_) add_definitions(-D_NTOSKRNL_)