lib.rs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #![no_main] // <1>
  2. #![feature(alloc_error_handler)]
  3. #![feature(allocator_api)]
  4. #![feature(arbitrary_self_types)]
  5. #![feature(asm_const)]
  6. #![feature(const_mut_refs)]
  7. #![feature(const_trait_impl)]
  8. #![feature(const_refs_to_cell)]
  9. #![feature(core_intrinsics)]
  10. #![feature(c_void_variant)]
  11. #![feature(drain_filter)]
  12. #![feature(is_some_and)]
  13. #![feature(naked_functions)]
  14. #![feature(panic_info_message)]
  15. #![feature(ptr_internals)]
  16. #![feature(trait_upcasting)]
  17. #![feature(slice_ptr_get)]
  18. #![feature(vec_into_raw_parts)]
  19. #![feature(new_uninit)]
  20. #![feature(ptr_to_from_bits)]
  21. #![feature(concat_idents)]
  22. #![cfg_attr(target_os = "none", no_std)]
  23. #[cfg(test)]
  24. #[macro_use]
  25. extern crate std;
  26. #[allow(non_upper_case_globals)]
  27. #[allow(non_camel_case_types)]
  28. #[allow(non_snake_case)]
  29. use core::panic::PanicInfo;
  30. /// 导出x86_64架构相关的代码,命名为arch模块
  31. #[macro_use]
  32. mod arch;
  33. #[macro_use]
  34. mod libs;
  35. #[macro_use]
  36. mod include;
  37. mod driver; // 如果driver依赖了libs,应该在libs后面导出
  38. mod exception;
  39. mod filesystem;
  40. mod init;
  41. mod ipc;
  42. mod mm;
  43. mod net;
  44. mod process;
  45. mod sched;
  46. mod smp;
  47. mod syscall;
  48. mod time;
  49. mod virt;
  50. #[macro_use]
  51. extern crate alloc;
  52. #[macro_use]
  53. extern crate bitflags;
  54. extern crate elf;
  55. #[macro_use]
  56. extern crate lazy_static;
  57. extern crate memoffset;
  58. extern crate num;
  59. #[macro_use]
  60. extern crate num_derive;
  61. extern crate smoltcp;
  62. extern crate thingbuf;
  63. #[macro_use]
  64. extern crate intertrait;
  65. #[cfg(target_arch = "x86_64")]
  66. extern crate x86;
  67. use crate::mm::allocator::kernel_allocator::KernelAllocator;
  68. use crate::process::ProcessManager;
  69. // 声明全局的分配器
  70. #[cfg_attr(not(test), global_allocator)]
  71. pub static KERNEL_ALLOCATOR: KernelAllocator = KernelAllocator;
  72. /// 全局的panic处理函数
  73. #[cfg(target_os = "none")]
  74. #[panic_handler]
  75. #[no_mangle]
  76. pub fn panic(info: &PanicInfo) -> ! {
  77. kerror!("Kernel Panic Occurred.");
  78. match info.location() {
  79. Some(loc) => {
  80. println!(
  81. "Location:\n\tFile: {}\n\tLine: {}, Column: {}",
  82. loc.file(),
  83. loc.line(),
  84. loc.column()
  85. );
  86. }
  87. None => {
  88. println!("No location info");
  89. }
  90. }
  91. match info.message() {
  92. Some(msg) => {
  93. println!("Message:\n\t{}", msg);
  94. }
  95. None => {
  96. println!("No panic message.");
  97. }
  98. }
  99. println!("Current PCB:\n\t{:?}", *(ProcessManager::current_pcb()));
  100. ProcessManager::exit(usize::MAX);
  101. }