You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

107 lines
3.8 KiB

#![no_std]
#![no_main]
#![feature(asm)]
#![feature(maybe_uninit)]
mod screen;
mod limited_pointer;
mod rlibc;
mod gdt;
mod idt;
mod ring;
use core::{fmt::Write, mem::{MaybeUninit, size_of}, panic::PanicInfo};
#[panic_handler]
pub fn panic(_info: &PanicInfo) -> !
{
loop {};
}
unsafe fn inportb(port: u16) -> u8
{
let rv: u8;
asm!("inb {1:x}, {0}", out(reg_byte) rv, in(reg) port);
return rv;
}
unsafe fn outportb(port: u16, byte: u8)
{
asm!("outb {1:x}, {0}", in(reg_byte) byte, in(reg) port);
}
#[export_name = "main"]
fn main() {
screen::print("Hello, world!\ntest new line\n");
/*
for i in 0..80 {
let chars: &[u8] = "abcdefghijklmnopqrstuvwxyz".as_bytes();
screen.putc(screen::BackgroundColor::Black, screen::ForegroundColor::White, chars[i % chars.len()] as char)
}
*/
/*
for i in 0..31 {
let chars: &[u8] = "abcdefghijklmnopqrstuvwx0123456".as_bytes();
screen.putc(screen::BackgroundColor::Black, screen::ForegroundColor::White, chars[i % chars.len()] as char);
screen.putc(screen::BackgroundColor::Black, screen::ForegroundColor::White, '\n');
};
*/
unsafe {
gdt::GDT =
[ MaybeUninit::zeroed(),
MaybeUninit::new(gdt::Entry::new(0, 0xFFFFFFFF, 0x9A.into(), 0xCF.into())),
MaybeUninit::new(gdt::Entry::new(0, 0xFFFFFFFF, 0x92.into(), 0xCF.into())),
];
gdt::GDT_PTR =
MaybeUninit::new(
limited_pointer::LimitedPointer
{ limit: ((size_of::<gdt::Entry>() * 3) - 1) as u16,
base: (&gdt::GDT as *const _) as u64
});
gdt::gdt_flush();
screen::print("\n\nHello");
idt::IDT[0] = idt::Entry::new(idt::isr0 as u32, 0x08, 0x8E.into());
idt::IDT[1] = idt::Entry::new(idt::isr1 as u32, 0x08, 0x8E.into());
idt::IDT[2] = idt::Entry::new(idt::isr2 as u32, 0x08, 0x8E.into());
idt::IDT[3] = idt::Entry::new(idt::isr3 as u32, 0x08, 0x8E.into());
idt::IDT[4] = idt::Entry::new(idt::isr4 as u32, 0x08, 0x8E.into());
idt::IDT[5] = idt::Entry::new(idt::isr5 as u32, 0x08, 0x8E.into());
idt::IDT[6] = idt::Entry::new(idt::isr6 as u32, 0x08, 0x8E.into());
idt::IDT[7] = idt::Entry::new(idt::isr7 as u32, 0x08, 0x8E.into());
idt::IDT[8] = idt::Entry::new(idt::isr8 as u32, 0x08, 0x8E.into());
idt::IDT[9] = idt::Entry::new(idt::isr9 as u32, 0x08, 0x8E.into());
idt::IDT[10] = idt::Entry::new(idt::isr10 as u32, 0x08, 0x8E.into());
idt::IDT[11] = idt::Entry::new(idt::isr11 as u32, 0x08, 0x8E.into());
idt::IDT[12] = idt::Entry::new(idt::isr12 as u32, 0x08, 0x8E.into());
idt::IDT[13] = idt::Entry::new(idt::isr13 as u32, 0x08, 0x8E.into());
idt::IDT[14] = idt::Entry::new(idt::isr14 as u32, 0x08, 0x8E.into());
idt::IDT[15] = idt::Entry::new(idt::isr15 as u32, 0x08, 0x8E.into());
idt::IDT[16] = idt::Entry::new(idt::isr16 as u32, 0x08, 0x8E.into());
idt::IDT[17] = idt::Entry::new(idt::isr17 as u32, 0x08, 0x8E.into());
idt::IDT[18] = idt::Entry::new(idt::isr18 as u32, 0x08, 0x8E.into());
idt::IDT[19] = idt::Entry::new(idt::isr19 as u32, 0x08, 0x8E.into());
idt::IDT[20] = idt::Entry::new(idt::isr20 as u32, 0x08, 0x8E.into());
idt::IDT[21] = idt::Entry::new(idt::isr21 as u32, 0x08, 0x8E.into());
idt::IDT[22] = idt::Entry::new(idt::isr22 as u32, 0x08, 0x8E.into());
idt::IDT[23] = idt::Entry::new(idt::isr23 as u32, 0x08, 0x8E.into());
idt::IDT[24] = idt::Entry::new(idt::isr24 as u32, 0x08, 0x8E.into());
idt::IDT[25] = idt::Entry::new(idt::isr25 as u32, 0x08, 0x8E.into());
idt::IDT[26] = idt::Entry::new(idt::isr26 as u32, 0x08, 0x8E.into());
idt::IDT[27] = idt::Entry::new(idt::isr27 as u32, 0x08, 0x8E.into());
idt::IDT[28] = idt::Entry::new(idt::isr28 as u32, 0x08, 0x8E.into());
idt::IDT[29] = idt::Entry::new(idt::isr29 as u32, 0x08, 0x8E.into());
idt::IDT[30] = idt::Entry::new(idt::isr30 as u32, 0x08, 0x8E.into());
idt::IDT[31] = idt::Entry::new(idt::isr31 as u32, 0x08, 0x8E.into());
idt::idt_load();
screen::print("\n\nIDT");
}
}