diff --git a/loader/link.x b/loader/link.x index ecb989b85..39021f109 100644 --- a/loader/link.x +++ b/loader/link.x @@ -1,190 +1,190 @@ -MEMORY -{ - FLASH : ORIGIN = 0x20501000, LENGTH = 188k - FONTS : ORIGIN = 0x20530000, LENGTH = 4352k - RAM : ORIGIN = 0x40000000, LENGTH = 16M - MEMLCD : ORIGIN = 0xB0000000, LENGTH = 32k -} -/* -Fonts go from 0x2053_0000 to 0x2097_0000 -*/ - -REGION_ALIAS("REGION_TEXT", FLASH); -REGION_ALIAS("REGION_RODATA", FLASH); -REGION_ALIAS("REGION_DATA", RAM); -REGION_ALIAS("REGION_BSS", RAM); -REGION_ALIAS("REGION_STACK", RAM); -REGION_ALIAS("REGION_HEAP", RAM); - -_lcdfb = ORIGIN(MEMLCD); -/* Size of the main kernel stack */ -_stack_size = 16K; -_eheap = ORIGIN(RAM) + LENGTH(RAM); - - -PROVIDE(_stext = ORIGIN(REGION_TEXT)); -PROVIDE(_stack_start = ORIGIN(REGION_STACK) + LENGTH(REGION_STACK)); -PROVIDE(_max_hart_id = 0); -PROVIDE(_hart_stack_size = 2K); -PROVIDE(_heap_size = 0); - -PROVIDE(trap_handler = default_trap_handler); - -/* # Pre-initialization function */ -/* If the user overrides this using the `#[pre_init]` attribute or by creating a `__pre_init` function, - then the function this points to will be called before the RAM is initialized. */ -PROVIDE(__pre_init = default_pre_init); - -/* # Multi-processing hook function - fn _mp_hook() -> bool; - - This function is called from all the harts and must return true only for one hart, - which will perform memory initialization. For other harts it must return false - and implement wake-up in platform-dependent way (e.g. after waiting for a user interrupt). -*/ -PROVIDE(_mp_hook = default_mp_hook); - -ENTRY(_start) - -SECTIONS -{ - .text.dummy (NOLOAD) : - { - /* This section is intended to make _stext address work */ - . = ABSOLUTE(_stext); - } > REGION_TEXT - - .text _stext : - { - /* Put reset handler first in .text section so it ends up as the entry */ - /* point of the program. */ - KEEP(*(.text.init)); - KEEP(*(.init)); - KEEP(*(.init.rust)); - . = ALIGN(4); - KEEP(*(.trap)); - KEEP(*(.trap.rust)); - - *(.text .text.*); - } > REGION_TEXT - - .rodata : ALIGN(4) - { - *(.rodata .rodata.*); - - /* 4-byte align the end (VMA) of this section. - This is required by LLD to ensure the LMA of the following .data - section will have the correct alignment. */ - . = ALIGN(4); - _etext = .; - } > REGION_RODATA - - .data : ALIGN(4) - { - _sidata = LOADADDR(.data); - _sdata = .; - /* Must be called __global_pointer$ for linker relaxations to work. */ - PROVIDE(__global_pointer$ = . + 0x800); - *(.sdata .sdata.* .sdata2 .sdata2.*); - *(.data .data.*); - . = ALIGN(4); - _edata = .; - } > REGION_DATA AT > REGION_RODATA - - .fonts : ALIGN(65536) - { - KEEP(*(.fontdata)); - } > FONTS - - .bss (NOLOAD) : - { - _sbss = .; - *(.sbss .sbss.* .bss .bss.*); - . = ALIGN(4); - _ebss = .; - } > REGION_BSS - - /* fictitious region that represents the memory available for the stack */ - .stack (NOLOAD) : - { - _sstack = .; - . += _stack_size; - . = ALIGN(4096); - _estack = .; - } > REGION_STACK - - /* fictitious region that represents the memory available for the heap */ - .heap (NOLOAD) : - { - . = ALIGN(4); - _sheap = .; - /* _eheap is defined elsewhere and is the remainder of RAM */ - } > REGION_HEAP - - /* fake output .got section */ - /* Dynamic relocations are unsupported. This section is only used to detect - relocatable code in the input files and raise an error if relocatable code - is found */ - .got (INFO) : - { - KEEP(*(.got .got.*)); - } - - /* Discard .eh_frame, we are not doing unwind on panic so it is not needed */ - /DISCARD/ : - { - *(.eh_frame); - *(.eh_frame_hdr); - } -} - -/* Do not exceed this mark in the error messages above | */ -ASSERT(ORIGIN(REGION_TEXT) % 4 == 0, " -ERROR(riscv-rt): the start of the REGION_TEXT must be 4-byte aligned"); - -ASSERT(ORIGIN(REGION_RODATA) % 4 == 0, " -ERROR(riscv-rt): the start of the REGION_RODATA must be 4-byte aligned"); - -ASSERT(ORIGIN(REGION_DATA) % 4 == 0, " -ERROR(riscv-rt): the start of the REGION_DATA must be 4-byte aligned"); - -ASSERT(ORIGIN(REGION_HEAP) % 4 == 0, " -ERROR(riscv-rt): the start of the REGION_HEAP must be 4-byte aligned"); - -ASSERT(ORIGIN(REGION_TEXT) % 4 == 0, " -ERROR(riscv-rt): the start of the REGION_TEXT must be 4-byte aligned"); - -ASSERT(ORIGIN(REGION_STACK) % 4 == 0, " -ERROR(riscv-rt): the start of the REGION_STACK must be 4-byte aligned"); - -ASSERT(_stext % 4 == 0, " -ERROR(riscv-rt): `_stext` must be 4-byte aligned"); - -ASSERT(_sdata % 4 == 0 && _edata % 4 == 0, " -BUG(riscv-rt): .data is not 4-byte aligned"); - -ASSERT(_sidata % 4 == 0, " -BUG(riscv-rt): the LMA of .data is not 4-byte aligned"); - -ASSERT(_sbss % 4 == 0 && _ebss % 4 == 0, " -BUG(riscv-rt): .bss is not 4-byte aligned"); - -ASSERT(_sheap % 4 == 0, " -BUG(riscv-rt): start of .heap is not 4-byte aligned"); - -ASSERT(_stext + SIZEOF(.text) < ORIGIN(REGION_TEXT) + LENGTH(REGION_TEXT), " -ERROR(riscv-rt): The .text section must be placed inside the REGION_TEXT region. -Set _stext to an address smaller than 'ORIGIN(REGION_TEXT) + LENGTH(REGION_TEXT)'"); - -ASSERT(SIZEOF(.stack) > (_max_hart_id + 1) * _hart_stack_size, " -ERROR(riscv-rt): .stack section is too small for allocating stacks for all the harts. -Consider changing `_max_hart_id` or `_hart_stack_size`."); - -ASSERT(SIZEOF(.got) == 0, " -.got section detected in the input files. Dynamic relocations are not -supported. If you are linking to C code compiled using the `gcc` crate -then modify your build script to compile the C code _without_ the --fPIC flag. See the documentation of the `gcc::Config.fpic` method for -details."); - -/* Do not exceed this mark in the error messages above | */ +MEMORY +{ + FLASH : ORIGIN = 0x20501000, LENGTH = 188k + FONTS : ORIGIN = 0x20530000, LENGTH = 4352k + RAM : ORIGIN = 0x40000000, LENGTH = 16M + MEMLCD : ORIGIN = 0xB0000000, LENGTH = 32k +} +/* +Fonts go from 0x2053_0000 to 0x2097_0000 +*/ + +REGION_ALIAS("REGION_TEXT", FLASH); +REGION_ALIAS("REGION_RODATA", FLASH); +REGION_ALIAS("REGION_DATA", RAM); +REGION_ALIAS("REGION_BSS", RAM); +REGION_ALIAS("REGION_STACK", RAM); +REGION_ALIAS("REGION_HEAP", RAM); + +_lcdfb = ORIGIN(MEMLCD); +/* Size of the main kernel stack */ +_stack_size = 16K; +_eheap = ORIGIN(RAM) + LENGTH(RAM); + + +PROVIDE(_stext = ORIGIN(REGION_TEXT)); +PROVIDE(_stack_start = ORIGIN(REGION_STACK) + LENGTH(REGION_STACK)); +PROVIDE(_max_hart_id = 0); +PROVIDE(_hart_stack_size = 2K); +PROVIDE(_heap_size = 0); + +PROVIDE(trap_handler = default_trap_handler); + +/* # Pre-initialization function */ +/* If the user overrides this using the `#[pre_init]` attribute or by creating a `__pre_init` function, + then the function this points to will be called before the RAM is initialized. */ +PROVIDE(__pre_init = default_pre_init); + +/* # Multi-processing hook function + fn _mp_hook() -> bool; + + This function is called from all the harts and must return true only for one hart, + which will perform memory initialization. For other harts it must return false + and implement wake-up in platform-dependent way (e.g. after waiting for a user interrupt). +*/ +PROVIDE(_mp_hook = default_mp_hook); + +ENTRY(_start) + +SECTIONS +{ + .text.dummy (NOLOAD) : + { + /* This section is intended to make _stext address work */ + . = ABSOLUTE(_stext); + } > REGION_TEXT + + .text _stext : + { + /* Put reset handler first in .text section so it ends up as the entry */ + /* point of the program. */ + KEEP(*(.text.init)); + KEEP(*(.init)); + KEEP(*(.init.rust)); + . = ALIGN(4); + KEEP(*(.trap)); + KEEP(*(.trap.rust)); + + *(.text .text.*); + } > REGION_TEXT + + .rodata : ALIGN(4) + { + *(.rodata .rodata.*); + + /* 4-byte align the end (VMA) of this section. + This is required by LLD to ensure the LMA of the following .data + section will have the correct alignment. */ + . = ALIGN(4); + _etext = .; + } > REGION_RODATA + + .data : ALIGN(4) + { + _sidata = LOADADDR(.data); + _sdata = .; + /* Must be called __global_pointer$ for linker relaxations to work. */ + PROVIDE(__global_pointer$ = . + 0x800); + *(.sdata .sdata.* .sdata2 .sdata2.*); + *(.data .data.*); + . = ALIGN(4); + _edata = .; + } > REGION_DATA AT > REGION_RODATA + + .fonts : ALIGN(65536) + { + KEEP(*(.fontdata)); + } > FONTS + + .bss (NOLOAD) : + { + _sbss = .; + *(.sbss .sbss.* .bss .bss.*); + . = ALIGN(4); + _ebss = .; + } > REGION_BSS + + /* fictitious region that represents the memory available for the stack */ + .stack (NOLOAD) : + { + _sstack = .; + . += _stack_size; + . = ALIGN(4096); + _estack = .; + } > REGION_STACK + + /* fictitious region that represents the memory available for the heap */ + .heap (NOLOAD) : + { + . = ALIGN(4); + _sheap = .; + /* _eheap is defined elsewhere and is the remainder of RAM */ + } > REGION_HEAP + + /* fake output .got section */ + /* Dynamic relocations are unsupported. This section is only used to detect + relocatable code in the input files and raise an error if relocatable code + is found */ + .got (INFO) : + { + KEEP(*(.got .got.*)); + } + + /* Discard .eh_frame, we are not doing unwind on panic so it is not needed */ + /DISCARD/ : + { + *(.eh_frame); + *(.eh_frame_hdr); + } +} + +/* Do not exceed this mark in the error messages above | */ +ASSERT(ORIGIN(REGION_TEXT) % 4 == 0, " +ERROR(riscv-rt): the start of the REGION_TEXT must be 4-byte aligned"); + +ASSERT(ORIGIN(REGION_RODATA) % 4 == 0, " +ERROR(riscv-rt): the start of the REGION_RODATA must be 4-byte aligned"); + +ASSERT(ORIGIN(REGION_DATA) % 4 == 0, " +ERROR(riscv-rt): the start of the REGION_DATA must be 4-byte aligned"); + +ASSERT(ORIGIN(REGION_HEAP) % 4 == 0, " +ERROR(riscv-rt): the start of the REGION_HEAP must be 4-byte aligned"); + +ASSERT(ORIGIN(REGION_TEXT) % 4 == 0, " +ERROR(riscv-rt): the start of the REGION_TEXT must be 4-byte aligned"); + +ASSERT(ORIGIN(REGION_STACK) % 4 == 0, " +ERROR(riscv-rt): the start of the REGION_STACK must be 4-byte aligned"); + +ASSERT(_stext % 4 == 0, " +ERROR(riscv-rt): `_stext` must be 4-byte aligned"); + +ASSERT(_sdata % 4 == 0 && _edata % 4 == 0, " +BUG(riscv-rt): .data is not 4-byte aligned"); + +ASSERT(_sidata % 4 == 0, " +BUG(riscv-rt): the LMA of .data is not 4-byte aligned"); + +ASSERT(_sbss % 4 == 0 && _ebss % 4 == 0, " +BUG(riscv-rt): .bss is not 4-byte aligned"); + +ASSERT(_sheap % 4 == 0, " +BUG(riscv-rt): start of .heap is not 4-byte aligned"); + +ASSERT(_stext + SIZEOF(.text) < ORIGIN(REGION_TEXT) + LENGTH(REGION_TEXT), " +ERROR(riscv-rt): The .text section must be placed inside the REGION_TEXT region. +Set _stext to an address smaller than 'ORIGIN(REGION_TEXT) + LENGTH(REGION_TEXT)'"); + +ASSERT(SIZEOF(.stack) > (_max_hart_id + 1) * _hart_stack_size, " +ERROR(riscv-rt): .stack section is too small for allocating stacks for all the harts. +Consider changing `_max_hart_id` or `_hart_stack_size`."); + +ASSERT(SIZEOF(.got) == 0, " +.got section detected in the input files. Dynamic relocations are not +supported. If you are linking to C code compiled using the `gcc` crate +then modify your build script to compile the C code _without_ the +-fPIC flag. See the documentation of the `gcc::Config.fpic` method for +details."); + +/* Do not exceed this mark in the error messages above | */ diff --git a/loader/src/minielf.rs b/loader/src/minielf.rs index 38eb095fe..132da078f 100644 --- a/loader/src/minielf.rs +++ b/loader/src/minielf.rs @@ -1,12 +1,12 @@ use core::{mem, slice}; #[cfg(feature = "atsama5d27")] -pub use armv7::{ - PhysicalAddress, VirtualAddress, +use armv7::{ + VirtualAddress, structures::paging::{ - InMemoryRegister, PageTable as L2PageTable, PageTableDescriptor, PageTableMemory, - PageTableType, Readable, TranslationTable, TranslationTableDescriptor, TranslationTableMemory, - TranslationTableType, Writeable, PAGE_TABLE_FLAGS, PAGE_TABLE_SIZE, SMALL_PAGE_FLAGS, + InMemoryRegister, PageTableDescriptor, + Readable, TranslationTableDescriptor, TranslationTableMemory, + TranslationTableType, SMALL_PAGE_FLAGS, } }; use crate::*; diff --git a/loader/src/platform/atsama5d27/boot.rs b/loader/src/platform/atsama5d27/boot.rs index 3f99d73eb..ec65e60de 100644 --- a/loader/src/platform/atsama5d27/boot.rs +++ b/loader/src/platform/atsama5d27/boot.rs @@ -5,13 +5,13 @@ use core::mem; use core::num::NonZeroUsize; -pub use armv7::structures::paging::{ +use armv7::structures::paging::{ PageTable as L2PageTable, TranslationTable, TranslationTableDescriptor, - TranslationTableType, PageTableDescriptor, PAGE_TABLE_SIZE, PageTableType, + TranslationTableType, PageTableDescriptor, PageTableType, TranslationTableMemory, PageTableMemory, PAGE_TABLE_FLAGS, SMALL_PAGE_FLAGS, }; -pub use armv7::{PhysicalAddress, VirtualAddress}; +use armv7::{PhysicalAddress, VirtualAddress}; use crate::consts::{ FLG_R, FLG_U, FLG_VALID, FLG_W, FLG_X, GUARD_MEMORY_BYTES, KERNEL_ARGUMENT_OFFSET, LOADER_CODE_ADDRESS, PAGE_TABLE_OFFSET, KERNEL_STACK_PAGE_COUNT, diff --git a/loader/src/platform/atsama5d27/debug.rs b/loader/src/platform/atsama5d27/debug.rs index 38b9b9008..f3702011a 100644 --- a/loader/src/platform/atsama5d27/debug.rs +++ b/loader/src/platform/atsama5d27/debug.rs @@ -3,13 +3,12 @@ // SPDX-License-Identifier: Apache-2.0 use atsama5d27::uart::{Uart as UartHw, Uart1}; -pub use armv7::structures::paging::{ - PageTable as L2PageTable, TranslationTable, TranslationTableDescriptor, - TranslationTableType, PageTableDescriptor, PAGE_TABLE_SIZE, PageTableType, +use armv7::structures::paging::{ + PageTable as L2PageTable, TranslationTable, + TranslationTableType, PageTableType, TranslationTableMemory, PageTableMemory, - PAGE_TABLE_FLAGS, SMALL_PAGE_FLAGS, }; -pub use armv7::{PhysicalAddress, VirtualAddress}; +use armv7::PhysicalAddress; type UartType = UartHw; diff --git a/loader/src/platform/atsama5d27/load.rs b/loader/src/platform/atsama5d27/load.rs index 054408430..4ce36d8d0 100644 --- a/loader/src/platform/atsama5d27/load.rs +++ b/loader/src/platform/atsama5d27/load.rs @@ -7,13 +7,7 @@ use crate::{ println, BootConfig, ProgramDescription, XousPid, PAGE_SIZE, STACK_PAGE_COUNT, VDBG, }; -pub use armv7::structures::paging::{ - PageTable as L2PageTable, TranslationTable, TranslationTableDescriptor, - TranslationTableType, PageTableDescriptor, PAGE_TABLE_SIZE, PageTableType, - TranslationTableMemory, PageTableMemory, - PAGE_TABLE_FLAGS, SMALL_PAGE_FLAGS, -}; -pub use armv7::{PhysicalAddress, VirtualAddress}; +use armv7::structures::paging::TranslationTableMemory; #[repr(C)] #[derive(Debug, Copy, Clone)]