Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions boot/freeldr/freeldr/arch/i386/multiboot.S
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@
* multiboot kernels above 1MB. So we let GRUB load us
* there and then relocate ourself to FREELDR_BASE.
*/
#define INITIAL_BASE HEX(200000)
#define INITIAL_BASE TEMPCODE_BASE

/* The address that we want to execute FreeLoader */
#define DESTINATION_BASE FREELDR_BASE


#ifdef _M_IX86
Expand Down Expand Up @@ -156,16 +159,19 @@ mb2:
inc dh

mb3:
/* Adjust the gdt table address */
add dword ptr [(gdtptr + 2) + INITIAL_BASE - FREELDR_BASE], DESTINATION_BASE

/* Relocate itself to lower address */
mov esi, INITIAL_BASE
mov edi, FREELDR_BASE
mov edi, DESTINATION_BASE
mov ecx, offset __bss_start__ - FREELDR_BASE
rep movsb

/* Load segment registers for real-address mode */
mov edi, offset gdtptr
mov edi, offset gdtptr + DESTINATION_BASE - FREELDR_BASE
lgdt lXdtPrefix [rdi]
mov edi, offset idtptr
mov edi, offset idtptr + DESTINATION_BASE - FREELDR_BASE
lidt lXdtPrefix [rdi]

mov ax, HEX(10)
Expand All @@ -176,7 +182,9 @@ mb3:
mov ss, ax

/* Jump to relocated code */
ljmp HEX(08), mb4
push HEX(08)
push offset mb4 + DESTINATION_BASE - FREELDR_BASE
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will need to pass that indirectly just to compile with msvc.

retf

mbfail:
int 3
Expand All @@ -190,7 +198,7 @@ mb4:
mov cr0, rax

/* Jump to real entry point */
ljmp16 FREELDR_BASE / 16, 0
ljmp16 DESTINATION_BASE / 16, 0


/* Force 8-byte alignment */
Expand All @@ -202,8 +210,8 @@ gdt:

/* GDT table pointer */
gdtptr:
.word HEX(17) /* Limit */
.long gdt /* Base Address */
.word HEX(17) /* Limit */
.long OFF(gdt) - FREELDR_BASE /* Base Address */

/* Force 8-byte alignment */
.align 8
Expand Down
Loading