.intel_syntax noprefix
+//org 8000h
+
.text
.code16
+
#define BootSectorStackTop 0x7bf2
#define DataAreaStartHigh 0x2
#define DataAreaStartLow 0x4
#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
//
// This code is loaded at 0000:8000 so we have to
// encode a jmp instruction to jump to 0000:8200
-//.org 0x8000
.global _mainCRTStartup // For Mingw32 builds where the linker looks for this symbol
_mainCRTStartup:
jmp LoadFile // Load the next cluster (if any)
LoadFile_Done:
- 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
+ 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:
-msgLoading:
- .ascii "Loading FreeLoader..."
- .byte 0x0d,0x0a,0
-
-// times 510-($-$$) db 0 // Pad to 510 bytes
-.org 0x1fe
- .word 0x0aa55 // BootSector signature
-
+msgLoading: .asciz "Loading FreeLoader...\r\n"
-// pseudo adresses
-//.org 0x7dfd
-BootPartition:
+ .org 0x1fe // Pad to 510 bytes
+ .word 0x0aa55 // BootSector signature