new: 暂时移除cbindgen (#82)

This commit is contained in:
login 2022-11-12 15:25:54 +08:00 committed by GitHub
parent 2aaf7808ef
commit 82d2e446a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 42 additions and 14 deletions

View File

@ -23,6 +23,7 @@ fn main() {
// The input header we would like to generate
// bindings for.
.header("src/include/bindings/wrapper.h")
.blocklist_file("src/include/bindings/bindings.h")
.clang_arg("--target=x86_64-none-none")
.clang_arg("-v")
// 使用core并将c语言的类型改为core::ffi而不是使用std库。
@ -41,8 +42,4 @@ fn main() {
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}
cbindgen::generate(crate_dir)
.unwrap()
.write_to_file(out_path.join("bindings.h"));
}

View File

@ -51,12 +51,12 @@ namespace = "ffi"
# A list of sys headers to #include (with angle brackets)
# default: []
sys_includes = []
sys_includes = ["stdint.h"]
# 生成的binding文件要include的头文件
# A list of headers to #include (with quotes)
# default: []
includes = ["stdint.h"]
includes = []
# Whether cbindgen's default C/C++ standard imports should be suppressed. These
# imports are included by default because our generated headers tend to require
@ -584,7 +584,7 @@ clean = false
# bindings for.
#
# default: []
extra_bindings = ["my_awesome_dep"]
# extra_bindings = ["my_awesome_dep"]
[parse.expand]
# A list of crate names that should be run through `cargo expand` before
@ -614,7 +614,7 @@ default_features = true
# appropriate features in its dependencies
#
# default: []
features = ["cbindgen"]
# features = ["cbindgen"]
[ptr]
# An optional string to decorate all pointers that are

View File

@ -31,10 +31,11 @@ main.o: main.c
# The -m64 option sets int to 32bits and long and pointer to 64 bits and generates code for AMDs x86-64 architecture.
$(CC) $(CFLAGS) -c main.c -o main.o
all: kernel
kernel_rust:
rustup default nightly
cargo +nightly build --release --target ./arch/x86_64/x86_64-unknown-none.json
all: kernel_rust
$(MAKE) kernel || exit 1
@echo "Linking kernel..."
ld -b elf64-x86-64 -z muldefs -o kernel head.o main.o $(shell find . -name "*.o") ../target/x86_64-unknown-none/release/libdragonos_kernel.a -T link.lds
# 生成kallsyms

View File

@ -0,0 +1 @@
pub mod bindings;

View File

@ -21,5 +21,7 @@
#include <common/printk.h>
#include <common/spinlock.h>
#include <common/unistd.h>
#include <mm/mm.h>
#include <mm/slab.h>
#include <sched/cfs.h>
#include <sched/sched.h>

View File

@ -0,0 +1 @@
pub mod bindings;

View File

@ -5,10 +5,16 @@
#[allow(non_camel_case_types)]
#[allow(non_snake_case)]
#[macro_use]
mod mm;
mod include;
use crate::mm::allocator;
use core::ffi::c_char;
use core::intrinsics; // <2>
use core::panic::PanicInfo; // <3>
include!("include/bindings/bindings.rs");
use crate::include::bindings::bindings::{printk_color, GREEN, BLACK};
#[panic_handler]
#[no_mangle]

View File

@ -42,8 +42,6 @@
ul bsp_idt_size, bsp_gdt_size;
#include <include/bindings/bindings.h>
#pragma GCC push_options
#pragma GCC optimize("O0")
struct gdtr gdtp;
@ -167,7 +165,6 @@ void system_initialize()
// 启用double buffer
// scm_enable_double_buffer(); // 因为时序问题, 该函数调用被移到 initial_kernel_thread
io_mfence();
__rust_demo_func();
// fat32_init();
HPET_enable();

View File

@ -0,0 +1,22 @@
use crate::include::bindings::bindings::{gfp_t, PAGE_2M_SIZE, kmalloc};
use core::alloc::{GlobalAlloc, Layout};
/// 类kmalloc的分配器应当实现的trait
pub trait LocalAlloc {
unsafe fn alloc(&mut self, layout: Layout, gfp: gfp_t) -> *mut u8;
unsafe fn dealloc(&mut self, ptr: *mut u8, layout: Layout);
}
pub struct KernelAllocator {}
impl LocalAlloc for KernelAllocator {
unsafe fn alloc(&mut self, layout: Layout, gfp: gfp_t) -> *mut u8 {
if layout.size() > (PAGE_2M_SIZE as usize / 2) {
return core::ptr::null_mut();
}
return kmalloc(layout.size() as u64, gfp) as *mut u8;
}
unsafe fn dealloc(&mut self, ptr: *mut u8, layout: Layout){
// todo:
}
}

1
kernel/src/mm/mod.rs Normal file
View File

@ -0,0 +1 @@
pub mod allocator;