mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-19 00:46:31 +00:00
new: 暂时移除cbindgen (#82)
This commit is contained in:
@ -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 AMD’s 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
|
||||
|
1
kernel/src/include/bindings/mod.rs
Normal file
1
kernel/src/include/bindings/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod bindings;
|
@ -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>
|
1
kernel/src/include/mod.rs
Normal file
1
kernel/src/include/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod bindings;
|
@ -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]
|
||||
|
@ -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();
|
||||
|
||||
|
22
kernel/src/mm/allocator.rs
Normal file
22
kernel/src/mm/allocator.rs
Normal 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
1
kernel/src/mm/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod allocator;
|
Reference in New Issue
Block a user