Navigation Menu

Skip to content

Commit

Permalink
vTables (including static inits) relocation at bootup
Browse files Browse the repository at this point in the history
  • Loading branch information
djphoenix committed Nov 14, 2016
1 parent 926b75e commit eb86c03
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
11 changes: 7 additions & 4 deletions ld/system.ld
Expand Up @@ -45,14 +45,17 @@ SECTIONS
*(.rodata .rodata.*)
. = ALIGN(8);

__VTABLE_START__ = . ;
___INIT_LIST__ = .; __INIT_LIST__ = . ;
LONG (-1); LONG (-1); *(.init_array*) LONG (0); LONG (0);
LONG (0); LONG (0); *(.init_array*) LONG (0); LONG (0);
___CTOR_LIST__ = .; __CTOR_LIST__ = . ;
LONG (-1); LONG (-1); *(.ctors); *(.ctor); *(SORT(.ctors.*)); LONG (0); LONG (0);
LONG (0); LONG (0); *(.ctors); *(.ctor); *(SORT(.ctors.*)); LONG (0); LONG (0);
___DTOR_LIST__ = .; __DTOR_LIST__ = . ;
LONG (-1); LONG (-1); *(.dtors); *(.dtor); *(SORT(.dtors.*)); LONG (0); LONG (0);
*(.data .data.*)
LONG (0); LONG (0); *(.dtors); *(.dtor); *(SORT(.dtors.*)); LONG (0); LONG (0);
*(.data.rel.*)
__VTABLE_END__ = . ;
*(.got .got.*)
*(.data .data.*)
__data_end__ = . ;

__modules_start__ = . ;
Expand Down
18 changes: 18 additions & 0 deletions src/boot/x32to64.s
Expand Up @@ -209,9 +209,27 @@ _efi_start: # EFI
jmp efi_main

x64_entry:
call reloc_vtables
call static_init
mov %rsp, %rbp
jmp main

reloc_vtables:
lea _start(%rip), %rcx
sub $_start, %rcx
lea __VTABLE_START__(%rip), %rbp
lea __VTABLE_END__(%rip), %rdx
1:
cmp %rbp, %rdx
je 3f
cmp $0, (%rbp)
je 2f
add %rcx, (%rbp)
2:
add $8, %rbp
jmp 1b
3:
ret

static_init:
push %rbp
Expand Down

0 comments on commit eb86c03

Please sign in to comment.