fix: riscv: ld: linker will not increment dot when handling .tbss, manually set dot to TLS_END for getting the correct KERNEL_END

This commit is contained in:
Paul Pan 2024-06-14 21:11:02 +08:00
parent c451aa4c76
commit 8824345b17
5 changed files with 19 additions and 12 deletions

View File

@ -34,7 +34,7 @@ unsafe extern "C" fn _start(hart_id: usize, fdt_addr: usize) -> ! {
ld t0, 0(t0)
# load and relocate registers
lla tp, TSS_START
lla tp, TLS_START
lla sp, {stack} + {stack_size}
add gp, gp, t0
add tp, tp, t0
@ -72,7 +72,7 @@ unsafe fn pre_main(hart_id: usize, fdt_addr: usize) {
setup_memory(fdt_addr);
setup_kernel_paging();
// TODO: on secondary cpu, we should copy existing kernel page table and TSS, then remap TSS
// TODO: on secondary cpu, we should copy existing kernel page table and TLS, then remap TLS
install_kernel_pagetable();
// after kernel paging, board level early console is broken (no address mapping)

View File

@ -22,8 +22,8 @@ extern "C" {
pub static BOOT_STACK_END: ExternSymbol;
pub static BSS_END: ExternSymbol;
pub static TSS_START: ExternSymbol;
pub static TSS_END: ExternSymbol;
pub static TLS_START: ExternSymbol;
pub static TLS_END: ExternSymbol;
pub static TDATA_START: ExternSymbol;
pub static TDATA_END: ExternSymbol;
@ -53,6 +53,11 @@ pub fn zero_bss() {
}
}
/* NOTE:
* `kernel_phys_to_virt` and `kernel_virt_to_phys` should only be used when interacting with `ExternSymbol`,
* for other cases, use `mmap_phys_to_virt` and `mmap_virt_to_phys` instead.
*/
pub unsafe fn kernel_phys_to_virt(phys: PhysAddr) -> VirtAddr {
VirtAddr(phys.as_usize() + KERNEL_OFFSET)
}

View File

@ -50,8 +50,8 @@ SECTIONS {
}
. = ALIGN(PAGE_SIZE);
.tss : AT(ADDR(.tss) - __kernel_offset) {
TSS_START = .;
.tls : AT(ADDR(.tls) - __kernel_offset) {
TLS_START = .;
. = ALIGN(8);
TDATA_START = .;
@ -63,9 +63,10 @@ SECTIONS {
*(.tbss .tbss.*)
TBSS_END = .;
TSS_END = .;
TLS_END = .;
}
. = TLS_END;
. = ALIGN(PAGE_SIZE);
KERNEL_END = .;

View File

@ -55,8 +55,8 @@ SECTIONS {
}
. = ALIGN(PAGE_SIZE);
.tss : AT(ADDR(.tss) - __kernel_offset) {
TSS_START = .;
.tls : AT(ADDR(.tls) - __kernel_offset) {
TLS_START = .;
. = ALIGN(8);
TDATA_START = .;
@ -68,9 +68,10 @@ SECTIONS {
*(.tbss .tbss.*)
TBSS_END = .;
TSS_END = .;
TLS_END = .;
}
. = TLS_END;
. = ALIGN(PAGE_SIZE);
KERNEL_END = .;

View File

@ -126,8 +126,8 @@ pub unsafe fn setup_kernel_paging() {
map_section!((RODATA), MapAttr::READABLE);
map_section!((DATA, BSS), MapAttr::READABLE | MapAttr::WRITABLE);
// TODO: every core must have a separate TSS section
map_section!((TSS), MapAttr::READABLE | MapAttr::WRITABLE);
// TODO: every core must have a separate TLS section
map_section!((TLS), MapAttr::READABLE | MapAttr::WRITABLE);
// map 4 GiB physical memory
// TODO: walk fdt to get all memory region? put it in driver init