stuff
This commit is contained in:
parent
6c252fb5da
commit
aec4b53e53
3 changed files with 27 additions and 50 deletions
|
|
@ -142,8 +142,9 @@ enable_paging:
|
|||
|
||||
ret
|
||||
|
||||
|
||||
section .bss
|
||||
align 4096
|
||||
align 4096
|
||||
p4_table:
|
||||
resb 4096
|
||||
p3_table:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#![feature(lang_items)]
|
||||
#![feature(const_fn)]
|
||||
#![feature(ptr_internals)]
|
||||
#![feature(asm)]
|
||||
#![no_std]
|
||||
|
||||
extern crate rlibc;
|
||||
|
|
@ -8,55 +9,30 @@ extern crate volatile;
|
|||
extern crate spin;
|
||||
extern crate multiboot2;
|
||||
#[macro_use] extern crate bitflags;
|
||||
|
||||
#[macro_use] mod vga_buffer;
|
||||
mod memory;
|
||||
|
||||
|
||||
// mod memory;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn rust_main(multiboot_information_address: usize) {
|
||||
use memory::FrameAllocator;
|
||||
|
||||
vga_buffer::clear_screen();
|
||||
println!("Hello World {}", "!");
|
||||
|
||||
let boot_info = unsafe{ multiboot2::load(multiboot_information_address)};
|
||||
use core::ptr::{read_volatile, write_volatile};
|
||||
let kbd1 = &0x60 as *const i32;
|
||||
let kbd2 = &0x64 as *const i32;
|
||||
|
||||
let memory_map_tag = boot_info.memory_map_tag()
|
||||
.expect("Memory map tag required");
|
||||
println!("memory areas:");
|
||||
for area in memory_map_tag.memory_areas() {
|
||||
println!(" start: 0x{:x}, length: 0x{:x}",
|
||||
area.base_addr, area.length);
|
||||
}
|
||||
|
||||
let elf_sections_tag = boot_info.elf_sections_tag()
|
||||
.expect("ELF sections tag required");
|
||||
println!("kernel sections:");
|
||||
for section in elf_sections_tag.sections() {
|
||||
println!(" addr: 0x{:x}, length: 0x{:x}, flags: 0x{:x}",
|
||||
section.addr, section.size, section.flags);
|
||||
}
|
||||
|
||||
let kernel_start = elf_sections_tag.sections().map(|s| s.addr)
|
||||
.min().unwrap();
|
||||
let kernel_end = elf_sections_tag.sections().map(|s| s.addr + s.size)
|
||||
.max().unwrap();
|
||||
|
||||
let multiboot_start = multiboot_information_address;
|
||||
let multiboot_end = multiboot_start + (boot_info.total_size as usize);
|
||||
|
||||
let mut frame_allocator = memory::AreaFrameAllocator::new(
|
||||
kernel_start as usize, kernel_end as usize, multiboot_start,
|
||||
multiboot_end, memory_map_tag.memory_areas()
|
||||
);
|
||||
|
||||
for i in 0.. {
|
||||
if let None = frame_allocator.allocate_frame() {
|
||||
println!("allocated {} frames", i);
|
||||
break;
|
||||
loop{
|
||||
unsafe {
|
||||
if (read_volatile(kbd1) != 96) {
|
||||
println!("0x60: {} !!!!!!", read_volatile(kbd1));
|
||||
break;
|
||||
}
|
||||
println!("0x60: {} 0x64: {}",
|
||||
read_volatile(kbd1), read_volatile(kbd2) );
|
||||
}
|
||||
}
|
||||
|
||||
loop{};
|
||||
};
|
||||
}
|
||||
|
||||
#[lang = "eh_personality"] #[no_mangle] pub extern fn eh_personality() {}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use spin::Mutex;
|
|||
|
||||
pub static WRITER: Mutex<Writer> = Mutex::new(Writer {
|
||||
column_position: 0,
|
||||
color_code: ColorCode::new(Color::LightRed, Color::Black),
|
||||
color_code: ColorCode::new(Color::Green, Color::Black),
|
||||
buffer: unsafe { Unique::new_unchecked(0xb8000 as *mut _) },
|
||||
});
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ pub fn print(args: fmt::Arguments) {
|
|||
impl fmt::Write for Writer {
|
||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||
for byte in s.bytes() {
|
||||
self.write_byte(byte)
|
||||
self.putchar(byte)
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -87,12 +87,12 @@ pub struct Writer {
|
|||
|
||||
#[allow(dead_code)]
|
||||
impl Writer {
|
||||
pub fn write_byte(&mut self, byte: u8) {
|
||||
pub fn putchar(&mut self, byte: u8) {
|
||||
match byte {
|
||||
b'\n' => self.new_line(),
|
||||
b'\n' => self.put_endl(),
|
||||
byte => {
|
||||
if self.column_position >= BUFFER_WIDTH {
|
||||
self.new_line();
|
||||
self.put_endl();
|
||||
}
|
||||
|
||||
let row = BUFFER_HEIGHT - 1;
|
||||
|
|
@ -108,9 +108,9 @@ impl Writer {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn write_str(&mut self, s: &str) {
|
||||
pub fn putstr(&mut self, s: &str) {
|
||||
for byte in s.bytes() {
|
||||
self.write_byte(byte)
|
||||
self.putchar(byte)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -118,7 +118,7 @@ impl Writer {
|
|||
unsafe{ self.buffer.as_mut()}
|
||||
}
|
||||
|
||||
fn new_line(&mut self) {
|
||||
fn put_endl(&mut self) {
|
||||
for row in 1..BUFFER_HEIGHT {
|
||||
for col in 0..BUFFER_WIDTH {
|
||||
let buffer = self.buffer();
|
||||
|
|
|
|||
Loading…
Reference in a new issue