init kfs_2
This commit is contained in:
parent
097dfd7ddc
commit
37d51d2afe
6 changed files with 92 additions and 35 deletions
|
|
@ -12,6 +12,7 @@ project := bluesnow
|
|||
arch ?= x86
|
||||
NASM := nasm -f elf
|
||||
LD := ld -m elf_i386 -n --gc-sections
|
||||
# QEMU := qemu-system-x86_64 -device isa-debug-exit,iobase=0xf4,iosize=0x04 -gdb tcp::$(PORTG) -enable-kvm -monitor telnet:127.0.0.1:$(PORT),server,nowait
|
||||
QEMU := qemu-system-x86_64 -gdb tcp::$(PORTG) -enable-kvm -monitor telnet:127.0.0.1:$(PORT),server,nowait
|
||||
|
||||
kernel := build/kernel-$(arch).bin
|
||||
|
|
|
|||
|
|
@ -6,18 +6,30 @@ bits 32
|
|||
start:
|
||||
; print `OK` to screen
|
||||
; mov dword [0xb8000], 0x2f4b2f4f
|
||||
mov word [0xb8000], 0x0248 ; H
|
||||
mov word [0xb8002], 0x0265 ; e
|
||||
mov word [0xb8004], 0x026c ; l
|
||||
mov word [0xb8006], 0x026c ; l
|
||||
mov word [0xb8008], 0x026f ; o
|
||||
mov word [0xb800a], 0x022c ; ,
|
||||
mov word [0xb800c], 0x0220 ;
|
||||
mov word [0xb800e], 0x0277 ; w
|
||||
mov word [0xb8010], 0x026f ; o
|
||||
mov word [0xb8012], 0x0272 ; r
|
||||
mov word [0xb8014], 0x026c ; l
|
||||
mov word [0xb8016], 0x0264 ; d
|
||||
mov word [0xb8018], 0x0221 ; !
|
||||
; mov word [0xb8000], 0x0248 ; H
|
||||
; mov word [0xb8002], 0x0265 ; e
|
||||
; mov word [0xb8004], 0x026c ; l
|
||||
; mov word [0xb8006], 0x026c ; l
|
||||
; mov word [0xb8008], 0x026f ; o
|
||||
; mov word [0xb800a], 0x022c ; ,
|
||||
; mov word [0xb800c], 0x0220 ;
|
||||
; mov word [0xb800e], 0x0277 ; w
|
||||
; mov word [0xb8010], 0x026f ; o
|
||||
; mov word [0xb8012], 0x0272 ; r
|
||||
; mov word [0xb8014], 0x026c ; l
|
||||
; mov word [0xb8016], 0x0264 ; d
|
||||
; mov word [0xb8018], 0x0221 ; !
|
||||
lgdt [gdt_info]
|
||||
call kmain
|
||||
hlt
|
||||
|
||||
; WARNING: Do not insert random label/lines between gdt_xxx label
|
||||
gdt_start:
|
||||
;TODO GDT entries, like null, kernel code, kernel data, user code, user data, TSS...
|
||||
gdt_info:
|
||||
dw gdt_info - gdt_start - 1
|
||||
dq gdt_start
|
||||
|
||||
section .bss
|
||||
resb 64
|
||||
head_stack:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
set timeout=5
|
||||
set timeout=0
|
||||
set default=0
|
||||
|
||||
menuentry "Blue Snow" {
|
||||
|
|
|
|||
|
|
@ -12,4 +12,8 @@ SECTIONS {
|
|||
.text : {
|
||||
*(.text)
|
||||
}
|
||||
|
||||
.stack : {
|
||||
*(.bss)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,39 +1,45 @@
|
|||
//! Rust wrappers around the x86-family I/O instructions.
|
||||
|
||||
/// Read a `u8`-sized value from `port`.
|
||||
pub unsafe fn inb(port: u16) -> u8 {
|
||||
pub fn inb(port: u16) -> u8 {
|
||||
// The registers for the `in` and `out` instructions are always the
|
||||
// same: `a` for value, and `d` for the port address.
|
||||
let result: u8;
|
||||
asm!("inb %dx, %al" : "={al}"(result) : "{dx}"(port) :: "volatile");
|
||||
unsafe {asm!("inb %dx, %al" : "={al}"(result) : "{dx}"(port) :: "volatile")};
|
||||
result
|
||||
}
|
||||
|
||||
/// Write a `u8`-sized `value` to `port`.
|
||||
pub unsafe fn outb(value: u8, port: u16) {
|
||||
asm!("outb %al, %dx" :: "{dx}"(port), "{al}"(value) :: "volatile");
|
||||
pub fn outb(value: u8, port: u16) {
|
||||
unsafe {asm!("outb %al, %dx" :: "{dx}"(port), "{al}"(value) :: "volatile")};
|
||||
}
|
||||
|
||||
/// Read a `u16`-sized value from `port`.
|
||||
pub unsafe fn inw(port: u16) -> u16 {
|
||||
pub fn inw(port: u16) -> u16 {
|
||||
let result: u16;
|
||||
asm!("inw %dx, %ax" : "={ax}"(result) : "{dx}"(port) :: "volatile");
|
||||
unsafe {asm!("inw %dx, %ax" : "={ax}"(result) : "{dx}"(port) :: "volatile")};
|
||||
result
|
||||
}
|
||||
|
||||
/// Write a `u8`-sized `value` to `port`.
|
||||
pub unsafe fn outw(value: u16, port: u16) {
|
||||
asm!("outw %ax, %dx" :: "{dx}"(port), "{ax}"(value) :: "volatile");
|
||||
pub fn outw(value: u16, port: u16) {
|
||||
unsafe {asm!("outw %ax, %dx" :: "{dx}"(port), "{ax}"(value) :: "volatile")};
|
||||
}
|
||||
|
||||
/// Read a `u32`-sized value from `port`.
|
||||
pub unsafe fn inl(port: u16) -> u32 {
|
||||
pub fn inl(port: u16) -> u32 {
|
||||
let result: u32;
|
||||
asm!("inl %dx, %eax" : "={eax}"(result) : "{dx}"(port) :: "volatile");
|
||||
unsafe {asm!("inl %dx, %eax" : "={eax}"(result) : "{dx}"(port) :: "volatile")};
|
||||
result
|
||||
}
|
||||
|
||||
/// Write a `u32`-sized `value` to `port`.
|
||||
pub unsafe fn outl(value: u32, port: u16) {
|
||||
asm!("outl %eax, %dx" :: "{dx}"(port), "{eax}"(value) :: "volatile");
|
||||
pub fn outl(value: u32, port: u16) {
|
||||
unsafe {asm!("outl %eax, %dx" :: "{dx}"(port), "{eax}"(value) :: "volatile")};
|
||||
}
|
||||
|
||||
pub fn halt() -> ! {
|
||||
loop {
|
||||
unsafe {asm!("hlt")}; //TODO volatile ?????
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,15 +19,40 @@ mod keyboard;
|
|||
#[allow(dead_code)]
|
||||
mod cpuio;
|
||||
|
||||
// fn check_shift(key: u8) -> u8 {
|
||||
// print!("{:b} vs {:b}\n", key as u8, (1<<7) as u8);
|
||||
// if (key >> 7 & 1) == 1 {
|
||||
// print!("MATCH");
|
||||
// key - (1 << 7)
|
||||
// } else {
|
||||
// key
|
||||
// }
|
||||
// }
|
||||
|
||||
//TODO implement ACPI to have such functionality
|
||||
/// Reboot the kernel
|
||||
///
|
||||
/// If reboot failed, will loop on a halt cmd
|
||||
///
|
||||
#[allow(dead_code)]
|
||||
fn reboot() {
|
||||
//TODO disable interrupt here something like : asm volatile ("cli");
|
||||
|
||||
// I will now clear the keyboard buffer
|
||||
let mut buffer: u8 = 0x02;
|
||||
while buffer == 0x02 {
|
||||
buffer = cpuio::inb(0x64);
|
||||
}
|
||||
cpuio::outb(0x64, 0xFE);//Send reset value to CPU //TODO doesn't work
|
||||
println!("Reicv reboot command. System cannot reboot yet, he is now halt\n");
|
||||
cpuio::halt();
|
||||
}
|
||||
|
||||
/// Shutdown the kernel
|
||||
///
|
||||
/// # Pre-requist:
|
||||
/// Seems that he have to use following line command :
|
||||
/// `-device isa-debug-exit,iobase=0xf4,iosize=0x04`
|
||||
///
|
||||
/// If shutdown failed, will loop on a halt cmd
|
||||
///
|
||||
#[allow(dead_code)]
|
||||
fn shutdown() -> ! {
|
||||
cpuio::outb(0xf4, 0x00);//TODO doesn't work :(
|
||||
println!("Reicv shutdown command. System cannot shutdown properly yet, he is now halt\n");
|
||||
cpuio::halt();
|
||||
}
|
||||
#[no_mangle]
|
||||
pub extern fn kmain() -> ! {
|
||||
// use vga::VgaScreen;
|
||||
|
|
@ -53,6 +78,15 @@ pub extern fn kmain() -> ! {
|
|||
loop {
|
||||
keyboard::kbd_callback();
|
||||
}
|
||||
// let control = unsafe { cpuio::inb(0x64) };
|
||||
// if (control & 1) == 1 {
|
||||
// let keycode = unsafe { cpuio::inb(0x60) };
|
||||
// match keyboard::KEY_CODE_TO_ASCII.get(keycode as usize) {
|
||||
// Some(ascii) => print!("{}", *ascii as char),
|
||||
// None =>{},
|
||||
// // None => println!("nokey ctrl {:x}", control),
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
#[lang = "eh_personality"] #[no_mangle]
|
||||
|
|
|
|||
Loading…
Reference in a new issue