os-workshop

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit dc3894952fe274f58ddb0751d171a5dc234104d2
parent 130e7ea6690bcc7fa837bda1adc8ab7385304925
Author: Brian Swetland <swetland@frotz.net>
Date:   Mon,  9 May 2022 11:10:38 -0700

build: improve linker scripts

- more complete coverage of common sections
- __bss_start, __bss_end, etc needed by init code

Diffstat:
MMakefile | 2+-
Ahw/app.ram.ld | 6++++++
Dhw/boot.ld | 14--------------
Ahw/boot.ram.ld | 6++++++
Ahw/common.ram.ld | 42++++++++++++++++++++++++++++++++++++++++++
Dhw/simple.ld | 14--------------
Mproject/boot.app.mk | 2+-
7 files changed, 56 insertions(+), 30 deletions(-)

diff --git a/Makefile b/Makefile @@ -37,7 +37,7 @@ ARCHFLAGS += -static -nostdlib -nostartfiles -ffreestanding ARCHFLAGS += -ffunction-sections -fdata-sections ARCHFLAGS += -fno-builtin -fno-strict-aliasing -LDSCRIPT := hw/simple.ld +LDSCRIPT := hw/app.ram.ld BUILD := out diff --git a/hw/app.ram.ld b/hw/app.ram.ld @@ -0,0 +1,6 @@ + +MEMORY { + RAM (rwx) : ORIGIN = 0x40008000, LENGTH = 0x7F8000 +} + +INCLUDE "hw/common.ram.ld" diff --git a/hw/boot.ld b/hw/boot.ld @@ -1,14 +0,0 @@ -OUTPUT_ARCH( "riscv" ) -ENTRY(_start) - -SECTIONS -{ - . = 0x40000000; - .start : { *(.start) } - .text : { *(.text*) } - .rodata : { *(.rodata*) } - .data : { *(.data*) } - .bss : { *(.bss*) } - _end = .; -} - diff --git a/hw/boot.ram.ld b/hw/boot.ram.ld @@ -0,0 +1,6 @@ + +MEMORY { + RAM (rwx) : ORIGIN = 0x40000000, LENGTH = 0x8000 +} + +INCLUDE "hw/common.ram.ld" diff --git a/hw/common.ram.ld b/hw/common.ram.ld @@ -0,0 +1,42 @@ + +ENTRY(_start) + +SECTIONS { + /* RX code */ + .text : { + KEEP(*(.start)) + *(.text .text*) + *(.gnu.linkonce.t.*) + } > RAM + + /* RO data */ + .rodata : { + . = ALIGN(4096); + __rodata_start = .; + *(.rodata .rodata.* .gnu.linkonce.r.*) + . = ALIGN(4); + __rodata_end = .; + } > RAM + + /* collect any extra sections here */ + . = .; + + /* RW data */ + .data : { + . = ALIGN(4096); + __data_start = .; + *(.data .data.* .gnu.linkonce.d.*) + *(.got*) + *(.dynamic) + . = ALIGN(4); + __data_end = .; + } > RAM + + .bss : { + __bss_start = .; + *(.bss .bss.*) + *(.gnu.linkonce.b.*) + . = ALIGN(4); + __bss_end = .; + } > RAM +} diff --git a/hw/simple.ld b/hw/simple.ld @@ -1,14 +0,0 @@ -OUTPUT_ARCH( "riscv" ) -ENTRY(_start) - -SECTIONS -{ - . = 0x40008000; - .start : { *(.start) } - .text : { *(.text*) } - .rodata : { *(.rodata*) } - .data : { *(.data*) } - .bss : { *(.bss*) } - _end = .; -} - diff --git a/project/boot.app.mk b/project/boot.app.mk @@ -3,5 +3,5 @@ MOD_NAME := boot MOD_SRC := hw/src/start.S boot/entry.S boot/boot.c MOD_SRC += hw/src/debug.c MOD_LIB := c -MOD_LDSCRIPT := hw/boot.ld +MOD_LDSCRIPT := hw/boot.ram.ld include make/app.mk