Skip to content

Instantly share code, notes, and snippets.

@agrif
Created July 12, 2020 03:01
Show Gist options
  • Save agrif/f7322ba16fba7843ab9502b62eb7dcb9 to your computer and use it in GitHub Desktop.
Save agrif/f7322ba16fba7843ab9502b62eb7dcb9 to your computer and use it in GitHub Desktop.
#![no_std]
#![no_main]
#![feature(never_type)]
#![feature(unwrap_infallible)]
#![feature(arbitrary_self_types)]
#![feature(alloc_error_handler)]
// unfortunately new asm doesn't let you set stack pointer...
#![feature(llvm_asm)]
#[macro_use]
extern crate core;
#[macro_use]
extern crate alloc;
mod console;
mod bootinfo;
mod framebuffer;
mod frames;
mod memory;
mod allocator;
#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
println!("{}", info);
loop {}
}
blueloader_info::entry_point!(kmain);
fn kmain(info: &'static blueloader_info::BootInfo) -> ! {
unsafe { bootinfo::set_bootinfo(info); }
memory::MEMORY.lock().switch_to_stack(kmain_stack);
}
fn kmain_stack() -> ! {
memory::MEMORY.lock().after_stack_switch_cleanup();
println!("Hello, world!");
println!("{:#?}", bootinfo::get_bootinfo());
let a = 2;
println!("example stack address: {:?}", &a as *const i32);
println!("allocating small vector");
let v = vec![1, 2, 3];
println!("{:?}", v);
println!("allocating large vector");
let u = vec![0; 4096];
println!("{:?}", u.len());
println!("free and re-allocating large vector");
core::mem::drop(u);
let u = vec![0; 4096];
println!("{:?}", u.len());
loop {
x86_64::instructions::hlt();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment