init kfs_2

This commit is contained in:
wescande 2018-02-12 17:08:06 +01:00
parent 097dfd7ddc
commit 37d51d2afe
6 changed files with 92 additions and 35 deletions

View file

@ -12,6 +12,7 @@ project := bluesnow
arch ?= x86 arch ?= x86
NASM := nasm -f elf NASM := nasm -f elf
LD := ld -m elf_i386 -n --gc-sections 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 QEMU := qemu-system-x86_64 -gdb tcp::$(PORTG) -enable-kvm -monitor telnet:127.0.0.1:$(PORT),server,nowait
kernel := build/kernel-$(arch).bin kernel := build/kernel-$(arch).bin

View file

@ -6,18 +6,30 @@ bits 32
start: start:
; print `OK` to screen ; print `OK` to screen
; mov dword [0xb8000], 0x2f4b2f4f ; mov dword [0xb8000], 0x2f4b2f4f
mov word [0xb8000], 0x0248 ; H ; mov word [0xb8000], 0x0248 ; H
mov word [0xb8002], 0x0265 ; e ; mov word [0xb8002], 0x0265 ; e
mov word [0xb8004], 0x026c ; l ; mov word [0xb8004], 0x026c ; l
mov word [0xb8006], 0x026c ; l ; mov word [0xb8006], 0x026c ; l
mov word [0xb8008], 0x026f ; o ; mov word [0xb8008], 0x026f ; o
mov word [0xb800a], 0x022c ; , ; mov word [0xb800a], 0x022c ; ,
mov word [0xb800c], 0x0220 ; ; mov word [0xb800c], 0x0220 ;
mov word [0xb800e], 0x0277 ; w ; mov word [0xb800e], 0x0277 ; w
mov word [0xb8010], 0x026f ; o ; mov word [0xb8010], 0x026f ; o
mov word [0xb8012], 0x0272 ; r ; mov word [0xb8012], 0x0272 ; r
mov word [0xb8014], 0x026c ; l ; mov word [0xb8014], 0x026c ; l
mov word [0xb8016], 0x0264 ; d ; mov word [0xb8016], 0x0264 ; d
mov word [0xb8018], 0x0221 ; ! ; mov word [0xb8018], 0x0221 ; !
lgdt [gdt_info]
call kmain call kmain
hlt 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:

View file

@ -1,4 +1,4 @@
set timeout=5 set timeout=0
set default=0 set default=0
menuentry "Blue Snow" { menuentry "Blue Snow" {

View file

@ -12,4 +12,8 @@ SECTIONS {
.text : { .text : {
*(.text) *(.text)
} }
.stack : {
*(.bss)
}
} }

View file

@ -1,39 +1,45 @@
//! Rust wrappers around the x86-family I/O instructions. //! Rust wrappers around the x86-family I/O instructions.
/// Read a `u8`-sized value from `port`. /// 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 // The registers for the `in` and `out` instructions are always the
// same: `a` for value, and `d` for the port address. // same: `a` for value, and `d` for the port address.
let result: u8; let result: u8;
asm!("inb %dx, %al" : "={al}"(result) : "{dx}"(port) :: "volatile"); unsafe {asm!("inb %dx, %al" : "={al}"(result) : "{dx}"(port) :: "volatile")};
result result
} }
/// Write a `u8`-sized `value` to `port`. /// Write a `u8`-sized `value` to `port`.
pub unsafe fn outb(value: u8, port: u16) { pub fn outb(value: u8, port: u16) {
asm!("outb %al, %dx" :: "{dx}"(port), "{al}"(value) :: "volatile"); unsafe {asm!("outb %al, %dx" :: "{dx}"(port), "{al}"(value) :: "volatile")};
} }
/// Read a `u16`-sized value from `port`. /// Read a `u16`-sized value from `port`.
pub unsafe fn inw(port: u16) -> u16 { pub fn inw(port: u16) -> u16 {
let result: u16; let result: u16;
asm!("inw %dx, %ax" : "={ax}"(result) : "{dx}"(port) :: "volatile"); unsafe {asm!("inw %dx, %ax" : "={ax}"(result) : "{dx}"(port) :: "volatile")};
result result
} }
/// Write a `u8`-sized `value` to `port`. /// Write a `u8`-sized `value` to `port`.
pub unsafe fn outw(value: u16, port: u16) { pub fn outw(value: u16, port: u16) {
asm!("outw %ax, %dx" :: "{dx}"(port), "{ax}"(value) :: "volatile"); unsafe {asm!("outw %ax, %dx" :: "{dx}"(port), "{ax}"(value) :: "volatile")};
} }
/// Read a `u32`-sized value from `port`. /// Read a `u32`-sized value from `port`.
pub unsafe fn inl(port: u16) -> u32 { pub fn inl(port: u16) -> u32 {
let result: u32; let result: u32;
asm!("inl %dx, %eax" : "={eax}"(result) : "{dx}"(port) :: "volatile"); unsafe {asm!("inl %dx, %eax" : "={eax}"(result) : "{dx}"(port) :: "volatile")};
result result
} }
/// Write a `u32`-sized `value` to `port`. /// Write a `u32`-sized `value` to `port`.
pub unsafe fn outl(value: u32, port: u16) { pub fn outl(value: u32, port: u16) {
asm!("outl %eax, %dx" :: "{dx}"(port), "{eax}"(value) :: "volatile"); unsafe {asm!("outl %eax, %dx" :: "{dx}"(port), "{eax}"(value) :: "volatile")};
}
pub fn halt() -> ! {
loop {
unsafe {asm!("hlt")}; //TODO volatile ?????
}
} }

View file

@ -19,15 +19,40 @@ mod keyboard;
#[allow(dead_code)] #[allow(dead_code)]
mod cpuio; mod cpuio;
// fn check_shift(key: u8) -> u8 {
// print!("{:b} vs {:b}\n", key as u8, (1<<7) as u8); //TODO implement ACPI to have such functionality
// if (key >> 7 & 1) == 1 { /// Reboot the kernel
// print!("MATCH"); ///
// key - (1 << 7) /// If reboot failed, will loop on a halt cmd
// } else { ///
// key #[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] #[no_mangle]
pub extern fn kmain() -> ! { pub extern fn kmain() -> ! {
// use vga::VgaScreen; // use vga::VgaScreen;
@ -53,6 +78,15 @@ pub extern fn kmain() -> ! {
loop { loop {
keyboard::kbd_callback(); 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] #[lang = "eh_personality"] #[no_mangle]