以下是链接脚本的代码片段。
.data :
{
*(.data*)
}
> ram
. = ALIGN(4);
/* Set Stack after code & data */
_stack_start = .;
我该如何在我的 Rust 代码中(不使用标准库)访问_stack_start(堆栈的起始地址)?
#![no_std]
#![no_main]
#![allow(dead_code)]
#[no_mangle]
pub fn _start() {
// let sp: i32 = _stack_start; -> **This causes compilation error**
type FnPtr = fn() -> ();
let th: FnPtr = trap_handler;
unsafe {
asm!("csrw mtvec, {}" ,
in(reg) th);
}
loop {}
}
_start()
需要使用extern "C"
,并且最好将其标记为返回!
。 - Chayim Friedman