-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
thanks [PR](rcore-os/rCore-Tutorial-v3#105) by Godones
- Loading branch information
Showing
11 changed files
with
138 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,5 @@ | |
os/src/link_app.S | ||
os/src/linker.ld | ||
user/build | ||
|
||
os/src/trace/kernel_symbol.S |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,30 @@ | ||
use std::{fs::File, io::Write, path::Path}; | ||
|
||
const TARGET_PATH: &str = "../user/target/riscv64gc-unknown-none-elf/release/"; | ||
|
||
fn main() { | ||
println!("cargo:rerun-if-changed=../user/src"); | ||
println!("cargo:rerun-if-changed={}", TARGET_PATH); | ||
println!("cargo:rerun-if-changed={}", "src"); | ||
let path = Path::new("src/trace/kernel_symbol.S"); | ||
if !path.exists() { | ||
let mut f = File::create(path).unwrap(); | ||
writeln!( | ||
f, | ||
r#" | ||
.section .rodata | ||
.align 3 | ||
.globl symbol_num | ||
.globl symbol_address | ||
.globl symbol_index | ||
.globl symbol_name | ||
symbol_num: | ||
.quad {} | ||
symbol_address: | ||
symbol_index: | ||
symbol_name:"#, | ||
0 | ||
) | ||
.unwrap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ mod sync; | |
mod syscall; | ||
mod task; | ||
mod timer; | ||
mod trace; | ||
mod trap; | ||
|
||
use core::arch::global_asm; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use core::arch::global_asm; | ||
|
||
use tracer::TracerProvider; | ||
|
||
global_asm!(include_str!("kernel_symbol.S")); | ||
|
||
extern "C" { | ||
fn symbol_num(); | ||
fn symbol_address(); | ||
fn symbol_index(); | ||
fn symbol_name(); | ||
} | ||
|
||
pub struct Provider; | ||
|
||
impl TracerProvider for Provider { | ||
fn address2symbol(&self, addr: usize) -> Option<(usize, &'static str)> { | ||
find_symbol_with_addr(addr) | ||
} | ||
} | ||
|
||
pub fn find_symbol_with_addr(addr: usize) -> Option<(usize, &'static str)> { | ||
// println!("find_sym_w/addr {:#x}", addr); | ||
let symbol_num_addr = symbol_num as usize as *const usize; | ||
// println!("symbol_num_addr {:#x}", symbol_num_addr as usize); | ||
let symbol_num = unsafe { symbol_num_addr.read_volatile() }; | ||
// println!("num = {}", symbol_num); | ||
if symbol_num == 0 { | ||
return None; | ||
} | ||
let symbol_addr = symbol_address as usize as *const usize; // 符号地址存储区域 | ||
let addr_data = unsafe { core::slice::from_raw_parts(symbol_addr, symbol_num) }; | ||
// find the symbol with the nearest address | ||
let mut index = -1isize; | ||
for i in 0..symbol_num - 1 { | ||
if addr >= addr_data[i] && addr < addr_data[i + 1] { | ||
index = i as isize; | ||
break; | ||
} | ||
} | ||
if addr == addr_data[symbol_num - 1] { | ||
index = (symbol_num - 1) as isize; | ||
} | ||
// println!("nearest addr to index = {}", index); | ||
if index == -1 { | ||
return None; | ||
} | ||
let index = index as usize; | ||
let symbol_index = symbol_index as usize as *const usize; // 符号字符串的起始位置 | ||
let index_data = unsafe { core::slice::from_raw_parts(symbol_index, symbol_num) }; | ||
let symbol_name = symbol_name as usize as *const u8; // 符号字符串 | ||
let mut last = 0; | ||
unsafe { | ||
for i in index_data[index].. { | ||
let c = symbol_name.add(i); | ||
if *c == 0 { | ||
last = i; | ||
break; | ||
} | ||
} | ||
} | ||
let name = unsafe { | ||
core::slice::from_raw_parts(symbol_name.add(index_data[index]), last - index_data[index]) | ||
}; | ||
let name = core::str::from_utf8(name).unwrap(); | ||
// println!("symbol = {}", name); | ||
Some((addr_data[index], name)) | ||
} |