From 75bb755327186fd630119b87594c3cf0828a3ee2 Mon Sep 17 00:00:00 2001 From: Astro Date: Mon, 27 May 2019 01:44:24 +0200 Subject: [PATCH] extend linker script --- .cargo/config | 2 +- link.x | 60 +++++++++++++++++++------------------------ src/cortex_a9/regs.rs | 6 +++++ src/main.rs | 5 ++-- 4 files changed, 35 insertions(+), 38 deletions(-) diff --git a/.cargo/config b/.cargo/config index 70a37e8..b7af52c 100644 --- a/.cargo/config +++ b/.cargo/config @@ -2,7 +2,7 @@ runner = "./runner.sh" linker = "arm-none-eabihf-gcc" rustflags = [ - "-C", "link-arg=-Wl,-Tlink.x", + "-C", "link-arg=-Wl,-Tlink.x,-N", "-C", "target-feature=a9,armv7-a,neon", "-C", "target-cpu=cortex-a9", ] diff --git a/link.x b/link.x index 9dcbe80..4f13df0 100644 --- a/link.x +++ b/link.x @@ -1,57 +1,49 @@ ENTRY(_boot_cores); -/* SECTIONS */ -/* { */ -/* . = 0x8000; */ - -/* .text : */ -/* { */ -/* KEEP(*(.text.boot)) *(.text .text.*) */ -/* } */ - -/* /DISCARD/ : { *(.comment) *(.gnu*) *(.note*) *(.eh_frame*) } */ -/* } */ +STACK_SIZE = 0x2000 - 0x10; +MEMORY +{ + /* 256 kB On-Chip Memory */ + OCM : ORIGIN = 0, LENGTH = 0x40000 +} SECTIONS { - /* Starts at LOADER_ADDR. */ - . = 0x8000; - __start = .; - __text_start = .; .text : { + /* Starts at LOADER_ADDR. */ + . = 0x8000; KEEP(*(.text.boot)) - *(.text) - } - . = ALIGN(4096); /* align to page size */ - __text_end = .; + *(.text .text.*) + . = ALIGN(4096); /* align to page size */ + } > OCM - __rodata_start = .; .rodata : { *(.rodata) - } - . = ALIGN(4096); /* align to page size */ - __rodata_end = .; + . = ALIGN(4096); /* align to page size */ + } > OCM - __data_start = .; .data : { *(.data) - } - . = ALIGN(4096); /* align to page size */ - __data_end = .; + . = ALIGN(4096); /* align to page size */ + } > OCM - __bss_start = .; - .bss : + .bss (NOLOAD) : { - bss = .; *(.bss) - } - . = ALIGN(4096); /* align to page size */ - __bss_end = .; - __end = .; + . = ALIGN(4096); /* align to page size */ + } > OCM + __bss_start = ADDR(.bss); + __bss_end = ADDR(.bss) + SIZEOF(.bss); + + .stack (NOLOAD) : { + . += STACK_SIZE; + } > OCM + __stack_end = ADDR(.stack); + __stack_start = ADDR(.stack) + SIZEOF(.stack); /DISCARD/ : { diff --git a/src/cortex_a9/regs.rs b/src/cortex_a9/regs.rs index 203d328..fd8eda4 100644 --- a/src/cortex_a9/regs.rs +++ b/src/cortex_a9/regs.rs @@ -30,10 +30,16 @@ macro_rules! def_reg_set { } } +/// Stack Pointer pub struct SP; def_reg_get!(SP, u32, "mov $0, sp"); def_reg_set!(SP, u32, "mov sp, $0"); +/// Link register (function call return address) +pub struct LR; +def_reg_get!(LR, u32, "mov $0, lr"); +def_reg_set!(LR, u32, "mov lr, $0"); + pub struct MPIDR; def_reg_get!(MPIDR, u32, "mrc p15, 0, $0, c0, c0, 5"); diff --git a/src/main.rs b/src/main.rs index 7aca785..8b9abd4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,7 @@ use crate::cortex_a9::{asm, regs::*}; extern "C" { static mut __bss_start: u32; static mut __bss_end: u32; - static mut __end: u32; + static mut __stack_start: u32; } #[link_section = ".text.boot"] @@ -28,11 +28,10 @@ extern "C" { #[naked] pub unsafe extern "C" fn _boot_cores() -> ! { const CORE_MASK: u32 = 0x3; - let stack_start = __end + 4096; match MPIDR.get() & CORE_MASK { 0 => { - SP.set(stack_start); + SP.set(&mut __stack_start as *mut _ as u32); boot_core0(); } _ => loop {