First attempt at GOT

This commit is contained in:
plutoo 2017-09-09 03:20:24 +02:00
parent b39773b1d4
commit a2c7efe618
3 changed files with 39 additions and 29 deletions

View File

@ -2,5 +2,5 @@ install:
cp base_rules $(DEVKITA64)/
cp base_tools $(DEVKITA64)/
cp switch_rules $(DEVKITA64)/
cp lib/switch.ld $(DEVKITA64)/lib/
cp lib/switch.specs $(DEVKITA64)/lib/
cp lib/switch.ld $(DEVKITA64)/aarch64-none-elf/lib/
cp lib/switch.specs $(DEVKITA64)/aarch64-none-elf/lib/

View File

@ -63,10 +63,13 @@ SECTIONS
*(.data.*)
*(.gnu.linkonce.d*)
CONSTRUCTORS
*(.got)
. = ALIGN(4);
__got_start__ = .;
*(.got)
__got_end__ = .;
} : data
.tdata ALIGN(4) :
{
__tdata_lma = .;

View File

@ -1,19 +1,41 @@
.section ".crt0","ax"
.global _start, _sysexit, main
_start:
b startup
bl startup
.word 0x454d4f48
.word 0x57455242
startup:
mov x4, x30
// get aslr base
sub x30, x30, #4
// clear .bss
ldr x0, =__bss_start__
ldr x1, =__bss_end__
sub x1, x1, x0
bl ClearMem
add x1, x1, #7
bic x1, x1, #7
mov x2, #0
bss_loop:
str x2, [x0], #8
subs x1, x1, #8
bne bss_loop
// relocate .got
ldr x0, =__got_start__
ldr x1, =__got_end__
sub x1, x1, x0
add x1, x1, #3
bic x1, x1, #3
got_loop:
ldr x2, [x0]
add x2, x2, x30
str x2, [x0], #8
subs x1, x1, #8
bne got_loop
mov x0, #0 // argc
mov x1, #0 // argv
@ -23,18 +45,3 @@ startup:
_sysexit:
svc 0x7
ClearMem:
mov x2, #3 // Round down to nearest word boundary
add x1, x1, x2 // Shouldn't be needed
bics x1, x1, x2 // Clear 2 LSB (and set Z)
beq ClearMem_end // Quit if copy size is 0
mov x2, #0
ClrLoop:
str x2, [x0], #4
subs x1, x1, #4
bne ClrLoop
ClearMem_end:
ret