mirror of
https://github.com/panpaul/tiny_os
synced 2024-09-20 09:45:19 +08:00
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:
parent
c451aa4c76
commit
8824345b17
@ -34,7 +34,7 @@ unsafe extern "C" fn _start(hart_id: usize, fdt_addr: usize) -> ! {
|
|||||||
ld t0, 0(t0)
|
ld t0, 0(t0)
|
||||||
|
|
||||||
# load and relocate registers
|
# load and relocate registers
|
||||||
lla tp, TSS_START
|
lla tp, TLS_START
|
||||||
lla sp, {stack} + {stack_size}
|
lla sp, {stack} + {stack_size}
|
||||||
add gp, gp, t0
|
add gp, gp, t0
|
||||||
add tp, tp, t0
|
add tp, tp, t0
|
||||||
@ -72,7 +72,7 @@ unsafe fn pre_main(hart_id: usize, fdt_addr: usize) {
|
|||||||
|
|
||||||
setup_memory(fdt_addr);
|
setup_memory(fdt_addr);
|
||||||
setup_kernel_paging();
|
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();
|
install_kernel_pagetable();
|
||||||
|
|
||||||
// after kernel paging, board level early console is broken (no address mapping)
|
// after kernel paging, board level early console is broken (no address mapping)
|
||||||
|
@ -22,8 +22,8 @@ extern "C" {
|
|||||||
pub static BOOT_STACK_END: ExternSymbol;
|
pub static BOOT_STACK_END: ExternSymbol;
|
||||||
pub static BSS_END: ExternSymbol;
|
pub static BSS_END: ExternSymbol;
|
||||||
|
|
||||||
pub static TSS_START: ExternSymbol;
|
pub static TLS_START: ExternSymbol;
|
||||||
pub static TSS_END: ExternSymbol;
|
pub static TLS_END: ExternSymbol;
|
||||||
|
|
||||||
pub static TDATA_START: ExternSymbol;
|
pub static TDATA_START: ExternSymbol;
|
||||||
pub static TDATA_END: 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 {
|
pub unsafe fn kernel_phys_to_virt(phys: PhysAddr) -> VirtAddr {
|
||||||
VirtAddr(phys.as_usize() + KERNEL_OFFSET)
|
VirtAddr(phys.as_usize() + KERNEL_OFFSET)
|
||||||
}
|
}
|
||||||
|
@ -50,8 +50,8 @@ SECTIONS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
. = ALIGN(PAGE_SIZE);
|
. = ALIGN(PAGE_SIZE);
|
||||||
.tss : AT(ADDR(.tss) - __kernel_offset) {
|
.tls : AT(ADDR(.tls) - __kernel_offset) {
|
||||||
TSS_START = .;
|
TLS_START = .;
|
||||||
|
|
||||||
. = ALIGN(8);
|
. = ALIGN(8);
|
||||||
TDATA_START = .;
|
TDATA_START = .;
|
||||||
@ -63,9 +63,10 @@ SECTIONS {
|
|||||||
*(.tbss .tbss.*)
|
*(.tbss .tbss.*)
|
||||||
TBSS_END = .;
|
TBSS_END = .;
|
||||||
|
|
||||||
TSS_END = .;
|
TLS_END = .;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
. = TLS_END;
|
||||||
. = ALIGN(PAGE_SIZE);
|
. = ALIGN(PAGE_SIZE);
|
||||||
KERNEL_END = .;
|
KERNEL_END = .;
|
||||||
|
|
||||||
|
@ -55,8 +55,8 @@ SECTIONS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
. = ALIGN(PAGE_SIZE);
|
. = ALIGN(PAGE_SIZE);
|
||||||
.tss : AT(ADDR(.tss) - __kernel_offset) {
|
.tls : AT(ADDR(.tls) - __kernel_offset) {
|
||||||
TSS_START = .;
|
TLS_START = .;
|
||||||
|
|
||||||
. = ALIGN(8);
|
. = ALIGN(8);
|
||||||
TDATA_START = .;
|
TDATA_START = .;
|
||||||
@ -68,9 +68,10 @@ SECTIONS {
|
|||||||
*(.tbss .tbss.*)
|
*(.tbss .tbss.*)
|
||||||
TBSS_END = .;
|
TBSS_END = .;
|
||||||
|
|
||||||
TSS_END = .;
|
TLS_END = .;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
. = TLS_END;
|
||||||
. = ALIGN(PAGE_SIZE);
|
. = ALIGN(PAGE_SIZE);
|
||||||
KERNEL_END = .;
|
KERNEL_END = .;
|
||||||
|
|
||||||
|
@ -126,8 +126,8 @@ pub unsafe fn setup_kernel_paging() {
|
|||||||
map_section!((RODATA), MapAttr::READABLE);
|
map_section!((RODATA), MapAttr::READABLE);
|
||||||
map_section!((DATA, BSS), MapAttr::READABLE | MapAttr::WRITABLE);
|
map_section!((DATA, BSS), MapAttr::READABLE | MapAttr::WRITABLE);
|
||||||
|
|
||||||
// TODO: every core must have a separate TSS section
|
// TODO: every core must have a separate TLS section
|
||||||
map_section!((TSS), MapAttr::READABLE | MapAttr::WRITABLE);
|
map_section!((TLS), MapAttr::READABLE | MapAttr::WRITABLE);
|
||||||
|
|
||||||
// map 4 GiB physical memory
|
// map 4 GiB physical memory
|
||||||
// TODO: walk fdt to get all memory region? put it in driver init
|
// TODO: walk fdt to get all memory region? put it in driver init
|
||||||
|
Loading…
Reference in New Issue
Block a user