88 lines
2.2 KiB

  1. #![feature(asm)]
  2. #![feature(unique)]
  3. #![feature(const_fn)]
  4. #![feature(lang_items)]
  5. #![feature(const_unique_new)]
  6. #![feature(alloc)]
  7. #![feature(allocator_api)]
  8. #![feature(global_allocator)]
  9. #![no_std]
  10. #[macro_use]
  11. extern crate log;
  12. #[macro_use]
  13. extern crate once;
  14. #[macro_use]
  15. extern crate alloc;
  16. extern crate rlibc;
  17. extern crate spin;
  18. extern crate volatile;
  19. #[macro_use]
  20. extern crate bitflags;
  21. extern crate multiboot2;
  22. extern crate linked_list_allocator;
  23. extern crate x86_64 as x86;
  24. // sparkle-* libs
  25. #[macro_use]
  26. pub mod macros;
  27. mod alloca;
  28. mod misc;
  29. mod logger;
  30. mod arch;
  31. use arch::x86_64;
  32. use arch::x86_64::device::vga_console;
  33. use arch::x86_64::memory;
  34. use arch::x86_64::memory::FrameAllocator;
  35. use arch::x86_64::interrupts;
  36. use alloca::Allocator;
  37. use alloc::boxed::Box;
  38. /// Our globally-visible allocator. Plugs into whatever allocator we set up in [`alloca`].
  39. //
  40. /// [`alloca`]: alloca/index.html
  41. #[global_allocator]
  42. static GLOBAL_ALLOC: Allocator = Allocator;
  43. /// Kernel main function. Called by the bootstrapping assembly stub.
  44. #[no_mangle]
  45. pub extern fn kernel_main(multiboot_info_pointer: usize) {
  46. vga_console::WRITER.lock().clear_screen();
  47. println!("--- Sparkle v{} booting! ---", ::misc::VERSION);
  48. logger::init().expect("Logger failed to launch!");
  49. let boot_info = unsafe {multiboot2::load(multiboot_info_pointer)};
  50. memory::init(boot_info);
  51. info!("* memory::init(): success! *");
  52. info!("kheap: smoke test (boxing): {:?}", Box::new("hello world"));
  53. loop {}
  54. }
  55. /// Related to stack landing pads. Don't care, do nothing.
  56. #[lang = "eh_personality"]
  57. #[no_mangle]
  58. pub extern fn eh_personality() {}
  59. /// Dumps panics to the console.
  60. #[lang = "panic_fmt"]
  61. #[no_mangle]
  62. pub extern fn panic_fmt(fmt: core::fmt::Arguments, file: &'static str, line: u32) -> ! {
  63. vga_console::WRITER.lock().set_style(vga_console::CharStyle::new(vga_console::Color::Black, vga_console::Color::Red));
  64. println!();
  65. println!("!!! PANIC in {} on line {} !!!", file, line);
  66. println!(" {}", fmt);
  67. unsafe{loop{x86::instructions::halt();}};
  68. }
  69. /// Stack unwinding. Don't care, just halt.
  70. #[allow(non_snake_case)]
  71. #[no_mangle]
  72. pub extern "C" fn _Unwind_Resume() -> ! {
  73. unsafe{loop{x86::instructions::halt();}};
  74. }