Skip to content

refacotr: remove all c files #1131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 0 additions & 139 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,158 +1,19 @@
{
"files.associations": {
"stdbool.h": "c",
"printk.h": "c",
"stdarg.h": "c",
"process.h": "c",
"cpu.h": "c",
"mm.h": "c",
"glib.h": "c",
"asm.h": "c",
"memory.h": "c",
"kprint.h": "c",
"ptrace.h": "c",
"mouse.h": "c",
"algorithm": "c",
"array": "c",
"atomic": "c",
"*.tcc": "c",
"bitset": "c",
"cassert": "c",
"cctype": "c",
"cerrno": "c",
"chrono": "c",
"climits": "c",
"clocale": "c",
"cmath": "c",
"codecvt": "c",
"condition_variable": "c",
"cstdarg": "c",
"cstddef": "c",
"cstdint": "c",
"cstdio": "c",
"cstdlib": "c",
"cstring": "c",
"ctime": "c",
"cwchar": "c",
"cwctype": "c",
"deque": "c",
"exception": "c",
"forward_list": "c",
"functional": "c",
"iterator": "c",
"list": "c",
"map": "c",
"memory": "c",
"memory_resource": "c",
"numeric": "c",
"optional": "c",
"random": "c",
"ratio": "c",
"set": "c",
"string": "c",
"string_view": "c",
"system_error": "c",
"tuple": "c",
"type_traits": "c",
"unordered_map": "c",
"utility": "c",
"vector": "c",
"fstream": "c",
"initializer_list": "c",
"ios": "c",
"iosfwd": "c",
"istream": "c",
"limits": "c",
"locale": "c",
"mutex": "c",
"new": "c",
"ostream": "c",
"queue": "c",
"sstream": "c",
"stdexcept": "c",
"streambuf": "c",
"thread": "c",
"cinttypes": "c",
"cstdbool": "c",
"typeinfo": "c",
"unistd.h": "c",
"stdint.h": "c",
"syscall.h": "c",
"fcntl.h": "c",
"types.h": "c",
"string.h": "c",
"math.h": "c",
"arch.h": "c",
"stdio.h": "c",
"wait_queue.h": "c",
"stddef.h": "c",
"spinlock.h": "c",
"stat.h": "c",
"video.h": "c",
"ahci.h": "c",
"slab.h": "c",
"boot_info.h": "c",
"pci.h": "c",
"time.h": "c",
"errno.h": "c",
"bug.h": "c",
"sched.h": "c",
"preempt.h": "c",
"textui.h": "c",
"atomic.h": "c",
"semaphore.h": "c",
"mm-types.h": "c",
"current.h": "c",
"traceback.h": "c",
"bitcount.h": "c",
"limits.h": "c",
"mutex.h": "c",
"mount.h": "c",
"internal.h": "c",
"compiler_attributes.h": "c",
"timer.h": "c",
"hid.h": "c",
"compiler.h": "c",
"err.h": "c",
"list.h": "c",
"irqflags.h": "c",
"dirent.h": "c",
"cmd_help.h": "c",
"wait.h": "c",
"ctype.h": "c",
"stdint-gcc.h": "c",
"acpi.h": "c",
"assert.h": "c",
"sys_version.h": "c",
"cmd.h": "c",
"net.h": "c",
"cmd_test.h": "c",
"cmpxchg.h": "c",
"mman.h": "c",
"clocksource.h": "c",
"ata.h": "c",
"barrier": "c",
"charconv": "c",
"printf.h": "c",
"klog.h": "c",
"malloc.h": "c",
"*.o": "c",
"k_log.h": "c"
},
"C_Cpp.errorSquiggles": "enabled",
"esbonio.sphinx.confDir": "",
"rust-analyzer.checkOnSave.allTargets": false,
"rust-analyzer.linkedProjects": [
"./kernel/Cargo.toml",
//"./tools/Cargo.toml",

],
// "rust-analyzer.cargo.target": "riscv64gc-unknown-none-elf",
"rust-analyzer.cargo.target": "x86_64-unknown-none",
"rust-analyzer.check.overrideCommand": [
"make",
"check",

],
"makefile.configureOnOpen": false,
}
19 changes: 5 additions & 14 deletions build-scripts/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions build-scripts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
[workspace]
members = [
"kernel_build",
]
members = ["gen_kallsyms", "kernel_build"]
resolver = "2"
5 changes: 3 additions & 2 deletions build-scripts/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
.PHONY: fmt
all:
@cargo +nightly-2024-11-05 build --release -p gen_kallsyms
fmt:
cargo fmt --all $(FMT_CHECK)

clean:
@cargo clean
check:
@cargo +nightly-2024-11-05 check --workspace $(CARGO_ZBUILD) --message-format=json
.PHONY: fmt
6 changes: 6 additions & 0 deletions build-scripts/gen_kallsyms/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "gen_kallsyms"
version = "0.1.0"
edition = "2021"

[dependencies]
122 changes: 122 additions & 0 deletions build-scripts/gen_kallsyms/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
use std::str;

#[derive(Debug, Clone)]
struct KernelSymbolEntry {
vaddr: u64,
#[allow(dead_code)]
symbol_type: char,
symbol: String,
symbol_length: usize,
}

fn symbol_to_write(vaddr: u64, text_vaddr: u64, etext_vaddr: u64) -> bool {
vaddr >= text_vaddr && vaddr <= etext_vaddr
}
fn read_symbol(line: &str) -> Option<KernelSymbolEntry> {
if line.len() > 512 {
return None;
} // skip line with length >= 512
let mut parts = line.split_whitespace();
let vaddr = u64::from_str_radix(parts.next()?, 16).ok()?;
let symbol_type = parts.next()?.chars().next()?;
let symbol = parts.collect::<Vec<_>>().join(" ");
if symbol_type != 'T' && symbol_type != 't' {
return None;
} // local symbol or global symbol in text section
if symbol == "$x" {
return None;
} // skip $x symbol
let symbol_length = symbol.len() + 1; // +1 for null terminator
Some(KernelSymbolEntry {
vaddr,
symbol_type,
symbol,
symbol_length,
})
}

fn read_map() -> (Vec<KernelSymbolEntry>, u64, u64) {
let mut symbol_table = Vec::new();
let mut text_vaddr = 0;
let mut etext_vaddr = 0;
let mut line = String::new();
loop {
let size = std::io::stdin().read_line(&mut line).unwrap();
if size == 0 {
break;
}
line = line.trim().to_string();
if let Some(entry) = read_symbol(&line) {
if entry.symbol.starts_with("_text") {
text_vaddr = entry.vaddr;
} else if entry.symbol.starts_with("_etext") {
etext_vaddr = entry.vaddr;
}
symbol_table.push(entry);
}
line.clear();
}
(symbol_table, text_vaddr, etext_vaddr)
}

fn generate_result(symbol_table: &[KernelSymbolEntry], text_vaddr: u64, etext_vaddr: u64) {
println!(".section .rodata\n");
println!(".global kallsyms_address");
println!(".align 8\n");
println!("kallsyms_address:");

let mut last_vaddr = 0;
let mut total_syms_to_write = 0;

for entry in symbol_table {
if !symbol_to_write(entry.vaddr, text_vaddr, etext_vaddr) || entry.vaddr == last_vaddr {
continue;
}

println!("\t.quad\t{:#x}", entry.vaddr);
total_syms_to_write += 1;
last_vaddr = entry.vaddr;
}

println!("\n.global kallsyms_num");
println!(".align 8");
println!("kallsyms_num:");
println!("\t.quad\t{}", total_syms_to_write);

println!("\n.global kallsyms_names_index");
println!(".align 8");
println!("kallsyms_names_index:");

let mut position = 0;
last_vaddr = 0;

for entry in symbol_table {
if !symbol_to_write(entry.vaddr, text_vaddr, etext_vaddr) || entry.vaddr == last_vaddr {
continue;
}

println!("\t.quad\t{}", position);
position += entry.symbol_length;
last_vaddr = entry.vaddr;
}

println!("\n.global kallsyms_names");
println!(".align 8");
println!("kallsyms_names:");

last_vaddr = 0;

for entry in symbol_table {
if !symbol_to_write(entry.vaddr, text_vaddr, etext_vaddr) || entry.vaddr == last_vaddr {
continue;
}

println!("\t.asciz\t\"{}\"", entry.symbol);
last_vaddr = entry.vaddr;
}
}

fn main() {
let (symbol_table, text_vaddr, etext_vaddr) = read_map();
generate_result(&symbol_table, text_vaddr, etext_vaddr);
}
20 changes: 0 additions & 20 deletions build-scripts/kernel_build/src/bindgen/arch/mod.rs

This file was deleted.

10 changes: 0 additions & 10 deletions build-scripts/kernel_build/src/bindgen/arch/riscv64.rs

This file was deleted.

11 changes: 0 additions & 11 deletions build-scripts/kernel_build/src/bindgen/arch/x86_64.rs

This file was deleted.

Loading