lib.rs 925 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #![no_std] // <1>
  2. #![no_main] // <1>
  3. #![feature(core_intrinsics)] // <2>
  4. #![feature(alloc_error_handler)]
  5. #[allow(non_upper_case_globals)]
  6. #[allow(non_camel_case_types)]
  7. #[allow(non_snake_case)]
  8. use core::intrinsics; // <2>
  9. use core::panic::PanicInfo;
  10. #[macro_use]
  11. mod mm;
  12. mod include;
  13. mod libs;
  14. extern crate alloc;
  15. use mm::allocator::KernelAllocator;
  16. // <3>
  17. use crate::include::bindings::bindings::{BLACK, GREEN};
  18. // 声明全局的slab分配器
  19. #[cfg_attr(not(test), global_allocator)]
  20. pub static KERNEL_ALLOCATOR: KernelAllocator = KernelAllocator {};
  21. /// 全局的panic处理函数
  22. #[panic_handler]
  23. #[no_mangle]
  24. pub fn panic(_info: &PanicInfo) -> ! {
  25. intrinsics::abort(); // <4>
  26. }
  27. /// 该函数用作测试,在process.c的initial_kernel_thread()中调用了此函数
  28. #[no_mangle]
  29. pub extern "C" fn __rust_demo_func() -> i32 {
  30. printk_color!(GREEN, BLACK, "__rust_demo_func()\n");
  31. return 0;
  32. }