mirror of
https://github.com/panpaul/tiny_os
synced 2024-09-20 09:45:19 +08:00
chore: rename symbol name from linker script
This commit is contained in:
parent
e469b99cb5
commit
70ca917778
@ -2,30 +2,46 @@ use crate::utils::extern_addr::ExternSymbol;
|
|||||||
use crate::utils::size::KIB;
|
use crate::utils::size::KIB;
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
static __kernel_start: ExternSymbol;
|
pub static KERNEL_START: ExternSymbol;
|
||||||
static __kernel_end: ExternSymbol;
|
pub static KERNEL_END: ExternSymbol;
|
||||||
|
pub static KERNEL_OFFSET: usize;
|
||||||
|
|
||||||
static __text_start: ExternSymbol;
|
static TEXT_START: ExternSymbol;
|
||||||
static __text_end: ExternSymbol;
|
static TEXT_END: ExternSymbol;
|
||||||
|
|
||||||
static __rodata_start: ExternSymbol;
|
static RODATA_START: ExternSymbol;
|
||||||
static __rodata_end: ExternSymbol;
|
static RODATA_END: ExternSymbol;
|
||||||
|
|
||||||
static __data_start: ExternSymbol;
|
static DATA_START: ExternSymbol;
|
||||||
static __data_end: ExternSymbol;
|
static DATA_END: ExternSymbol;
|
||||||
|
|
||||||
static __bss_start: ExternSymbol;
|
static BSS_START: ExternSymbol;
|
||||||
pub static __boot_stack_end: ExternSymbol;
|
pub static BOOT_STACK_END: ExternSymbol;
|
||||||
pub static __bss_end: ExternSymbol;
|
pub static BSS_END: ExternSymbol;
|
||||||
|
|
||||||
static __tss_start: ExternSymbol;
|
static TSS_START: ExternSymbol;
|
||||||
static __tss_end: ExternSymbol;
|
static TSS_END: ExternSymbol;
|
||||||
|
|
||||||
static __tdata_start: ExternSymbol;
|
static TDATA_START: ExternSymbol;
|
||||||
static __tdata_end: ExternSymbol;
|
static TDATA_END: ExternSymbol;
|
||||||
|
|
||||||
pub static __tbss_start: ExternSymbol;
|
pub static TBSS_START: ExternSymbol;
|
||||||
pub static __tbss_end: ExternSymbol;
|
pub static TBSS_END: ExternSymbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const PAGE_SIZE: usize = 4 * KIB;
|
pub const PAGE_SIZE: usize = 4 * KIB;
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn zero_bss() {
|
||||||
|
fn clear_range<T: Clone>(bgn: *mut T, end: *mut T) {
|
||||||
|
unsafe {
|
||||||
|
core::slice::from_raw_parts_mut(bgn, end.offset_from(bgn) as usize)
|
||||||
|
.fill(core::mem::zeroed())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
clear_range(BOOT_STACK_END.as_mut_ptr(), BSS_END.as_mut_ptr());
|
||||||
|
clear_range(TBSS_START.as_mut_ptr(), TBSS_END.as_mut_ptr());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -6,63 +6,64 @@ PAGE_SIZE = 0x1000;
|
|||||||
|
|
||||||
SECTIONS {
|
SECTIONS {
|
||||||
. = BASE_ADDRESS;
|
. = BASE_ADDRESS;
|
||||||
__kernel_start = .;
|
KERNEL_START = .;
|
||||||
|
__kernel_offset = . - BASE_ADDRESS;
|
||||||
|
|
||||||
.text : {
|
.text : {
|
||||||
__text_start = .;
|
TEXT_START = .;
|
||||||
*(.text.entry)
|
*(.text.entry)
|
||||||
*(.text .text.*)
|
*(.text .text.*)
|
||||||
__text_end = .;
|
TEXT_END = .;
|
||||||
}
|
}
|
||||||
|
|
||||||
.rodata : {
|
.rodata : {
|
||||||
. = ALIGN(8);
|
. = ALIGN(PAGE_SIZE);
|
||||||
__rodata_start = .;
|
RODATA_START = .;
|
||||||
*(.rodata .rodata.*)
|
*(.rodata .rodata.*)
|
||||||
*(.srodata .srodata.*)
|
*(.srodata .srodata.*)
|
||||||
__rodata_end = .;
|
RODATA_END = .;
|
||||||
}
|
}
|
||||||
|
|
||||||
.data : {
|
.data : {
|
||||||
. = ALIGN(8);
|
. = ALIGN(PAGE_SIZE);
|
||||||
__data_start = .;
|
DATA_START = .;
|
||||||
*(.data .data.*)
|
*(.data .data.*)
|
||||||
|
|
||||||
PROVIDE( __global_pointer$ = . + 0x800 );
|
PROVIDE( __global_pointer$ = . + 0x800 );
|
||||||
*(.sdata .sdata.*)
|
*(.sdata .sdata.*)
|
||||||
__data_end = .;
|
DATA_END = .;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bss : {
|
.bss : {
|
||||||
. = ALIGN(8);
|
. = ALIGN(PAGE_SIZE);
|
||||||
__bss_start = .;
|
BSS_START = .;
|
||||||
*(.bss.boot_stack)
|
*(.bss.boot_stack)
|
||||||
__boot_stack_end = .;
|
BOOT_STACK_END = .;
|
||||||
|
|
||||||
*(.bss .bss.*)
|
*(.bss .bss.*)
|
||||||
*(.sbss .sbss.*)
|
*(.sbss .sbss.*)
|
||||||
__bss_end = .;
|
BSS_END = .;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tss : {
|
.tss : {
|
||||||
. = ALIGN(8);
|
. = ALIGN(PAGE_SIZE);
|
||||||
__tss_start = .;
|
TSS_START = .;
|
||||||
|
|
||||||
. = ALIGN(8);
|
. = ALIGN(8);
|
||||||
__tdata_start = .;
|
TDATA_START = .;
|
||||||
*(.tdata .tdata.*)
|
*(.tdata .tdata.*)
|
||||||
__tdata_end = .;
|
TDATA_END = .;
|
||||||
|
|
||||||
. = ALIGN(8);
|
. = ALIGN(8);
|
||||||
__tbss_start = .;
|
TBSS_START = .;
|
||||||
*(.tbss .tbss.*)
|
*(.tbss .tbss.*)
|
||||||
__tbss_end = .;
|
TBSS_END = .;
|
||||||
|
|
||||||
__tss_end = .;
|
TSS_END = .;
|
||||||
}
|
}
|
||||||
|
|
||||||
. = ALIGN(PAGE_SIZE);
|
. = ALIGN(PAGE_SIZE);
|
||||||
__kernel_end = .;
|
KERNEL_END = .;
|
||||||
|
|
||||||
/DISCARD/ : {
|
/DISCARD/ : {
|
||||||
*(.eh_frame_hdr)
|
*(.eh_frame_hdr)
|
78
kernel/src/arch/riscv/linker64.ld
Normal file
78
kernel/src/arch/riscv/linker64.ld
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
OUTPUT_ARCH(riscv)
|
||||||
|
ENTRY(_start)
|
||||||
|
|
||||||
|
/* We use high memory (0xFFFF....) for kernel space
|
||||||
|
* For sv39 and larger layout, memory base starts from 0xFFFFFFC000000000: {1'b1, {38{1'b0}}}
|
||||||
|
* Our kernel will placed at 0xFFFFFFD000000000 (VA) and 0x80200000 (PA)
|
||||||
|
* Regions between 0x...C... and 0x...D... will be reserved for firmware starting from 0x80000000 (PA) */
|
||||||
|
|
||||||
|
PHY_BASE_ADDRESS = 0xFFFFFFD000000000;
|
||||||
|
BASE_ADDRESS = 0x80200000;
|
||||||
|
PAGE_SIZE = 0x1000;
|
||||||
|
|
||||||
|
SECTIONS {
|
||||||
|
. = PHY_BASE_ADDRESS;
|
||||||
|
KERNEL_START = .;
|
||||||
|
__kernel_offset = . - BASE_ADDRESS;
|
||||||
|
|
||||||
|
.text : AT(ADDR(.text) - __kernel_offset) {
|
||||||
|
TEXT_START = .;
|
||||||
|
*(.text.entry)
|
||||||
|
*(.text .text.*)
|
||||||
|
TEXT_END = .;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rodata : AT(ADDR(.rodata) - __kernel_offset) {
|
||||||
|
. = ALIGN(PAGE_SIZE);
|
||||||
|
RODATA_START = .;
|
||||||
|
*(.rodata .rodata.*)
|
||||||
|
*(.srodata .srodata.*)
|
||||||
|
RODATA_END = .;
|
||||||
|
}
|
||||||
|
|
||||||
|
.data : AT(ADDR(.data) - __kernel_offset) {
|
||||||
|
. = ALIGN(PAGE_SIZE);
|
||||||
|
DATA_START = .;
|
||||||
|
*(.data .data.*)
|
||||||
|
|
||||||
|
PROVIDE( __global_pointer$ = . + 0x800 );
|
||||||
|
*(.sdata .sdata.*)
|
||||||
|
DATA_END = .;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bss : AT(ADDR(.bss) - __kernel_offset) {
|
||||||
|
. = ALIGN(PAGE_SIZE);
|
||||||
|
BSS_START = .;
|
||||||
|
*(.bss.boot_stack)
|
||||||
|
BOOT_STACK_END = .;
|
||||||
|
|
||||||
|
*(.bss .bss.*)
|
||||||
|
*(.sbss .sbss.*)
|
||||||
|
BSS_END = .;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tss : AT(ADDR(.tss) - __kernel_offset) {
|
||||||
|
. = ALIGN(PAGE_SIZE);
|
||||||
|
TSS_START = .;
|
||||||
|
|
||||||
|
. = ALIGN(8);
|
||||||
|
TDATA_START = .;
|
||||||
|
*(.tdata .tdata.*)
|
||||||
|
TDATA_END = .;
|
||||||
|
|
||||||
|
. = ALIGN(8);
|
||||||
|
TBSS_START = .;
|
||||||
|
*(.tbss .tbss.*)
|
||||||
|
TBSS_END = .;
|
||||||
|
|
||||||
|
TSS_END = .;
|
||||||
|
}
|
||||||
|
|
||||||
|
. = ALIGN(PAGE_SIZE);
|
||||||
|
KERNEL_END = .;
|
||||||
|
|
||||||
|
/DISCARD/ : {
|
||||||
|
*(.eh_frame_hdr)
|
||||||
|
*(.eh_frame)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user