Add linkerscript (experimental)

This commit is contained in:
Suguru Saito 2021-12-14 01:01:31 +09:00
parent 82afb1d9cc
commit 2323505be7
4 changed files with 127 additions and 0 deletions

31
x1/linkerscript/Makefile Normal file
View File

@ -0,0 +1,31 @@
CROSS_COMPILE := arm-linux-gnueabihf-
AS := $(CROSS_COMPILE)as
CC := $(CROSS_COMPILE)gcc
LD := $(CROSS_COMPILE)ld
OBJCOPY := $(CROSS_COMPILE)objcopy
TARGET := AppMain
OBJS := crt0.o main.o
ASFLAGS := -W
CFLAGS := -Wall -ffreestanding -fomit-frame-pointer -Os
LDFLAGS := -T x1.ld
.PHONY:
all: $(TARGET).bin
.PHONY:
clean:
-rm -f $(TARGET).bin $(TARGET).elf $(OBJS)
%.o: %.s
$(AS) $(ASFLAGS) $< -o $@
%.o: %.c
$(CC) -c $(CFLAGS) $<
$(TARGET).elf: $(OBJS)
$(LD) $(LDFLAGS) $^ -o $@
$(TARGET).bin: $(TARGET).elf
$(OBJCOPY) -O binary $< $@

41
x1/linkerscript/crt0.s Normal file
View File

@ -0,0 +1,41 @@
.text
.arm
.align 4
.global _start
_start:
stmdb sp!, {r4, lr}
/* store context */
movs r4, r0
/* Clear the .bss section */
bl .L_clean_bss
/* restore context */
adr r0, [.L_context]
str r4, [r0]
ldr r0, [r0]
/* call user's main */
bl main
ldmia sp!, {r4, pc}
.L_context:
.long 0
/*
r0 = start address
r1 = end address
tmp: r2
*/
.L_clean_bss:
ldr r0, =__bss_start
ldr r1, =__bss_end
sub r1, r1, #4
mov r2, #0
.L_clean_bss_loop:
cmp r0, r1
strlt r2, [r0], #4
blt .L_clean_bss_loop
bx lr

4
x1/linkerscript/main.c Normal file
View File

@ -0,0 +1,4 @@
int main(void *arg)
{
return 0;
}

51
x1/linkerscript/x1.ld Normal file
View File

@ -0,0 +1,51 @@
OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(_start)
MEMORY {
RAM (xrw): ORIGIN = 0x90000000, LENGTH = 15M
}
SECTIONS {
.text : {
*(.text)
*(.text*)
*(.rodata)
*(.rodata*)
*(.glue_7)
*(.glue_7t)
KEEP (*(.init))
KEEP (*(.fini))
. = ALIGN(4);
} > RAM
.data : {
*(.data)
*(.data*)
. = ALIGN(4);
} > RAM
.bss : {
__bss_start = .;
*(.bss)
*(COMMON)
. = ALIGN(4);
__bss_end = .;
} > RAM
/DISCARD/ : {
*(.discard)
*(.discard.*)
*(.comment)
}
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.ARM.attributes 0 : { *(.ARM.attributes) }
}