Skip to content

Commit

Permalink
Optimize sections table
Browse files Browse the repository at this point in the history
  • Loading branch information
djphoenix committed May 5, 2019
1 parent 374b0eb commit efabec8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 32 deletions.
40 changes: 27 additions & 13 deletions ld/system.ld
Expand Up @@ -8,9 +8,19 @@ ENTRY(_efi_start)
PROVIDE(__stack_end__ = 0x2000);
PROVIDE(__pagetable__ = 0x20000);

PHDRS
{
headers PT_PHDR PHDRS;
text PT_LOAD FILEHDR;
rodata PT_LOAD;
data PT_LOAD;
}

SECTIONS
{
.reloc 0x400FE0 : ALIGN(1) {}
.reloc 0x400FE0 (NOLOAD) : ALIGN(1) {
LONG(0) LONG(10) SHORT(0)
} :text
.text 0x401000 : ALIGN(1) {
__text_start__ = . ;
*boot.a:bootstrap.o(.text .text.*)
Expand All @@ -19,31 +29,35 @@ SECTIONS
PROVIDE (etext = .);
. = ALIGN(64);
__text_end__ = . ;
}
.data : ALIGN(1) {
} :text
.rodata : ALIGN(1) {
. = ALIGN(8);
__modules_start__ = . ;
*(.modules)
. = ALIGN(64);
__modules_end__ = . ;

. = ALIGN(8);
__data_start__ = . ;
*(.rodata .rodata.*)
} :rodata
.data : ALIGN(1) {
. = ALIGN(8);
__VTABLE_START__ = . ;
__INIT_LIST__ = . ; QUAD(0) *(.init_array*) QUAD(0)
__CTOR_LIST__ = . ; QUAD(0) *(.ctor*) QUAD(0)
__CTOR_LIST__ = . ; QUAD(0) *(.init_array*) *(.ctor*) QUAD(0)
__DTOR_LIST__ = . ; QUAD(0) *(.dtor*) QUAD(0)
*(.data.rel.ro.*)
*(.data.rel.*)
__VTABLE_END__ = . ;
*(.got .got.*)
*(.data .data.*)
__data_end__ = . ;

__modules_start__ = . ;
*(.modules)
. = ALIGN(64);
__modules_end__ = . ;
}
.bss : ALIGN(1) {
} :data
.bss (NOLOAD) : ALIGN(1) {
__bss_start__ = . ;
*(.bss .bss.*)
*(COMMON)
__bss_end__ = . ;
}
} :data
/DISCARD/ : { *(.comment) *(.eh_frame) *(.note*) }
}
2 changes: 1 addition & 1 deletion makefiles/rules.mk
Expand Up @@ -49,4 +49,4 @@ $(BIN): $(BIN).elf.strip
$(OOBJDIR)/modules-linked.o: $(MODOBJS)
@ mkdir -p $(dir $@)
$(Q) cat $^ > $(@:.o=.b); echo -n ' ' >> $(@:.o=.b)
$(Q) $(OBJCOPY) -Oelf64-x86-64 -Bi386 -Ibinary --rename-section .data=.modules $(@:.o=.b) $@
$(Q) $(OBJCOPY) -Oelf64-x86-64 -Bi386 -Ibinary --rename-section .data=.modules --set-section-flags .data=alloc,load,data,readonly $(@:.o=.b) $@
21 changes: 3 additions & 18 deletions src/boot/bootstrap.s
Expand Up @@ -17,7 +17,7 @@ multiboot_header:

.long multiboot_header
.long __text_start__
.long __modules_end__
.long __bss_start__
.long __bss_end__ + 0x80000
.long multiboot_entry

Expand Down Expand Up @@ -48,7 +48,6 @@ multiboot_entry:

# Clear BSS
lea __bss_start__-_start(%ebp), %edi
xor %ecx, %ecx
lea __bss_end__-_start(%ebp), %ecx
sub %edi, %ecx
xor %eax, %eax
Expand Down Expand Up @@ -150,7 +149,7 @@ multiboot_entry:
or $0x100, %eax
wrmsr

# Enable pading
# Enable paging
mov %cr0, %eax
or $0x80000000, %eax
mov %eax, %cr0
Expand Down Expand Up @@ -237,7 +236,7 @@ reloc_vtables:
static_init:
push %rbp
push %rax
lea __INIT_LIST__(%rip), %rbp
lea __CTOR_LIST__(%rip), %rbp
1:
add $8, %rbp
mov (%rbp), %rax
Expand All @@ -246,15 +245,6 @@ static_init:
callq *%rax
jmp 1b
2:
lea __CTOR_LIST__(%rip), %rbp
3:
add $8, %rbp
mov (%rbp), %rax
test %rax, %rax
je 4f
callq *%rax
jmp 3b
4:
pop %rax
pop %rbp
ret
Expand Down Expand Up @@ -282,8 +272,3 @@ GDT64.Code:
GDT64.Data:
.quad 0x00CF92000000FFFF
GDT64.End:

.section .reloc, "a"
.long 0
.long 10
.word 0

0 comments on commit efabec8

Please sign in to comment.