aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-09-13 17:43:35 +0200
committerBad Diode <bd@badd10de.dev>2021-09-13 17:43:35 +0200
commitf7826ed2b13f5c7290ce6c73f554bae588d1ace1 (patch)
tree9713019f4414814d772fcedefd6ec668fc8318df
parentea02a49f9aa46a77aaef74f0d1c743332593b217 (diff)
downloaduxnrpi-f7826ed2b13f5c7290ce6c73f554bae588d1ace1.tar.gz
uxnrpi-f7826ed2b13f5c7290ce6c73f554bae588d1ace1.zip
Cleanup linker script and make .stack section
-rw-r--r--Makefile2
-rw-r--r--src/common.h4
-rw-r--r--src/linker.ld51
-rw-r--r--src/start.s38
4 files changed, 57 insertions, 38 deletions
diff --git a/Makefile b/Makefile
index 348d974..becfccc 100644
--- a/Makefile
+++ b/Makefile
@@ -23,7 +23,7 @@ OBJ_START = $(BUILD_DIR)/start.o
23OBJ_MAIN = $(BUILD_DIR)/main.o 23OBJ_MAIN = $(BUILD_DIR)/main.o
24SRC_LINK = $(SRC_DIR)/linker.ld 24SRC_LINK = $(SRC_DIR)/linker.ld
25 25
26CFLAGS := -Wall -ffreestanding -O2 -nostdlib -lgcc -mgeneral-regs-only -fstack-protector 26CFLAGS := -Wall -ffreestanding -nostartfiles -O2 -nostdlib -lgcc -mgeneral-regs-only -fno-stack-protector
27CFLAGS += -DRPI_VERSION=$(RPI_VERSION) 27CFLAGS += -DRPI_VERSION=$(RPI_VERSION)
28AFLAGS := 28AFLAGS :=
29LDFLAGS := 29LDFLAGS :=
diff --git a/src/common.h b/src/common.h
index 4c2c6b2..ad3aad8 100644
--- a/src/common.h
+++ b/src/common.h
@@ -22,8 +22,8 @@
22// Wait for N processor cycles before returning. Implemented in start.s. 22// Wait for N processor cycles before returning. Implemented in start.s.
23void delay(u64 ticks); 23void delay(u64 ticks);
24 24
25// Clear N bytes at the given address. Implemented in start.s. 25// Clear N bytes at the given address 8 bytes at a time. Implemented in start.s.
26void memzero(u64 src, u32 n); 26void memzero64(void * src, u32 n);
27 27
28// 28//
29// GPIO Registers. 29// GPIO Registers.
diff --git a/src/linker.ld b/src/linker.ld
index cb8033f..994a50e 100644
--- a/src/linker.ld
+++ b/src/linker.ld
@@ -1,33 +1,52 @@
1ENTRY(_start) 1ENTRY(_start)
2 2
3STACK_SIZE = 1024 * 1024 * 4;
4
3SECTIONS 5SECTIONS
4{ 6{
5 . = 0x8000; 7 . = 0x8000;
6 __start = .; 8 __start = .;
7 .text : 9
8 { 10 .text : {
11 __text_start = .;
9 KEEP(*(.text.boot)) 12 KEEP(*(.text.boot))
10 *(.text) 13 *(.text)
14 *(.text.*)
15 __text_end = .;
11 } 16 }
12 . = ALIGN(4096); 17
13 .rodata : 18 .rodata : {
14 { 19 . = ALIGN(8);
20 __rodata_start = .;
15 *(.rodata) 21 *(.rodata)
22 *(.rodata.*)
23 __rodata_end = .;
16 } 24 }
17 . = ALIGN(4096); 25
18 .data : 26 .data : {
19 { 27 . = ALIGN(8);
28 __data_start = .;
20 *(.data) 29 *(.data)
30 *(.data.*)
31 __data_end = .;
21 } 32 }
22 . = ALIGN(4096); 33
23 __bss_start = .; 34 .bss (NOLOAD) : {
24 .bss : 35 . = ALIGN(8);
25 { 36 __bss_start = .;
26 bss = .;
27 *(.bss) 37 *(.bss)
38 *(.bss.*)
39 *(COMMON)
40 __bss_end = .;
41 }
42
43 .stack (NOLOAD) : {
44 . = ALIGN(8);
45 __stack_start = .;
46 . = . + STACK_SIZE;
47 __stack_end = .;
28 } 48 }
29 . = ALIGN(4096); 49
30 __bss_end = .; 50 . = ALIGN(8);
31 __bss_size = __bss_end - __bss_start;
32 __end = .; 51 __end = .;
33} 52}
diff --git a/src/start.s b/src/start.s
index f6598ce..ecedeb4 100644
--- a/src/start.s
+++ b/src/start.s
@@ -1,44 +1,44 @@
1.section ".text.boot" 1.section ".text.boot"
2 2
3.global _start 3.global _start
4
5_start: 4_start:
6 // Stop all cores except one. 5 // Stop all cores except one.
7 mrs x0, mpidr_el1 6 mrs x0, mpidr_el1
8 and x0, x0, #0xFF 7 and x0, x0, #0xFF
9 cbz x0, master 8 cbz x0, master
10 b halt 9 b halt
11 10
12// Helper function to clear x1 bytes starting at the x0 memory address. 11// Helper function to clear x1 bytes starting at the x0 memory address.
13.globl memzero 12.globl memzero64
14memzero: 13memzero64:
15 str xzr, [x0], #8 14 str xzr, [x0], #8
16 subs x1, x1, #8 15 subs x1, x1, #8
17 b.gt memzero 16 b.gt memzero64
18 ret 17 ret
19 18
20// Helper function wait for N cycles before returning. 19// Helper function wait for N cycles before returning.
21.globl delay 20.globl delay
22delay: 21delay:
23 subs x0, x0, #1 22 subs x0, x0, #1
24 bne delay 23 bne delay
25 ret 24 ret
26 25
27master: 26master:
28 // Clear bss. 27 // Set the stack memory location. Since the stack grows towards zero we set
29 ldr x0, =__bss_start 28 // the stack pointer to the end of the .stack memory section.
30 ldr x1, =__bss_size 29 ldr x0, =__stack_end
31 sub x1, x1, x0
32 bl memzero
33
34 // Set stack before our code.
35 ldr x0, =_start
36 mov sp, x0 30 mov sp, x0
37 31
32 // Clear .bss memory.
33 ldr x0, =__bss_start
34 ldr x1, =__bss_end
35 sub x1, x1, x0
36 bl memzero64
37
38 // Start C code, should not return. 38 // Start C code, should not return.
39 bl main 39 bl main
40 b halt 40 b halt
41 41
42halt: 42halt:
43 wfe 43 wfe
44 b halt 44 b halt