fuck it we're using the x86_64 crate

This commit is contained in:
husky 2022-04-19 23:49:19 -07:00
parent 2c740c9d8a
commit b81c5a76d8
Signed by: MlCROSOFT
GPG key ID: E00F7FA3381F0647
4 changed files with 26 additions and 218 deletions

View file

@ -11,6 +11,7 @@ members = [
[dependencies] [dependencies]
bootloader = "0.10.12" bootloader = "0.10.12"
spin = "0.9.1" spin = "0.9.1"
x86_64 = "0.14.9"
[dependencies.lazy_static] [dependencies.lazy_static]
version = "1.4.0" version = "1.4.0"
features = ["spin_no_std"] features = ["spin_no_std"]

View file

@ -88,73 +88,34 @@ fn draw_char(x: usize, y: usize, c: char, color: Colour, mut fb: &mut [u8]) {
} }
} }
fn draw_horizcentre_string(y: usize, s: &str, color: Colour, fb: &mut [u8]) { fn draw_horizcentre_string(width: usize, y: usize, s: &str, color: Colour, fb: &mut [u8]) {
let fb_width = FACEBOOK.fb_width.lock(); let mut x_tmp = (width - s.len() * 8) / 2;
let mut x_tmp = (*fb_width - s.len() * 8) / 2;
let mut y_tmp = y; let mut y_tmp = y;
for c in s.chars() { for c in s.chars() {
if c == '\n' { if c == '\n' {
x_tmp = (*fb_width - s.len() * 8) / 2; x_tmp = (width - s.len() * 8) / 2;
y_tmp += 8; y_tmp += 8;
} else { } else {
draw_char(x_tmp, y_tmp, c, color, fb.borrow_mut()); draw_char(x_tmp, y_tmp, c, color, fb.borrow_mut());
x_tmp += 8; x_tmp += 8;
} }
} }
}
pub extern "x86-interrupt" fn breakpoint_exception(stack_frame: InterruptStackFrame) {
// cover the screen in a nice communist red (:
let mut fb = FACEBOOK.fb_mutex.lock();
let fb_width = FACEBOOK.fb_width.lock();
let fb_height = FACEBOOK.fb_height.lock();
draw_box(0,0,*fb_width,*fb_height, COMMUNIST_RED, fb.borrow_mut());
// draw our funny text
draw_horizcentre_string(*fb_width,(*fb_height / 2) - (14 * (8/2)), "OOPSY WOOPSY, THE KERNEL HAD A FUCKY WUCKY UWU", CUM_WHITE, fb.borrow_mut());
draw_horizcentre_string(*fb_width,(*fb_height / 2) - (10 * (8/2)), "WHOEVER WAS PROGRAMMING THE KERNEL DECIDED TO LEAVE A BREAKPOINT IN IT, OOPS (:", CUM_WHITE, fb.borrow_mut());
draw_horizcentre_string(*fb_width,(*fb_height / 2) - (4 * (8/2)), "THE KERNEL IS NOW HALTED, YOU CAN'T DO ANYTHING UNTIL YOU RESTART THE KERNEL", CUM_WHITE, fb.borrow_mut());
drop(fb_width); drop(fb_width);
} drop(fb_height);
drop(fb);
pub extern "x86-interrupt" fn generic_error(stack_frame: InterruptStackFrame) {
// cover the screen in a nice communist red (:
let mut fb = FACEBOOK.fb_mutex.lock();
let fb_width = FACEBOOK.fb_width.lock();
let fb_height = FACEBOOK.fb_height.lock();
draw_box(0,0,*fb_width,*fb_height, COMMUNIST_RED, fb.borrow_mut());
// draw our funny text
draw_horizcentre_string((*fb_height / 2) - ((3 * 8)/2), "OOPSY WOOPSY, THE KERNEL HAD A FUCKY WUCKY UWU", CUM_WHITE, fb.borrow_mut());
loop {}
}
pub extern "x86-interrupt" fn generic_error_with_code(stack_frame: InterruptStackFrame, error_code: u32) {
// cover the screen in a nice communist red (:
let mut fb = FACEBOOK.fb_mutex.lock();
let fb_width = FACEBOOK.fb_width.lock();
let fb_height = FACEBOOK.fb_height.lock();
draw_box(0,0,*fb_width,*fb_height, COMMUNIST_RED, fb.borrow_mut());
// draw our funny text
draw_horizcentre_string((*fb_height / 2) - ((3 * 8)/2), "OOPSY WOOPSY, THE KERNEL HAD A FUCKY WUCKY UWU", CUM_WHITE, fb.borrow_mut());
loop {}
}
pub extern "x86-interrupt" fn super_fuck_up_error(stack_frame: InterruptStackFrame) -> ! {
// cover the screen in a nice communist red (:
let mut fb = FACEBOOK.fb_mutex.lock();
let fb_width = FACEBOOK.fb_width.lock();
let fb_height = FACEBOOK.fb_height.lock();
draw_box(0,0,*fb_width,*fb_height, COMMUNIST_RED, fb.borrow_mut());
// draw our funny text
draw_horizcentre_string((*fb_height / 2) - ((3 * 8)/2), "OOPSY WOOPSY, THE KERNEL HAD A FUCKY WUCKY UWU", CUM_WHITE, fb.borrow_mut());
loop {}
}
pub extern "x86-interrupt" fn super_fuck_up_error_with_code(stack_frame: InterruptStackFrame, error_code: u32) -> ! {
// cover the screen in a nice communist red (:
let mut fb = FACEBOOK.fb_mutex.lock();
let fb_width = FACEBOOK.fb_width.lock();
let fb_height = FACEBOOK.fb_height.lock();
draw_box(0,0,*fb_width,*fb_height, COMMUNIST_RED, fb.borrow_mut());
// draw our funny text
draw_horizcentre_string((*fb_height / 2) - ((3 * 8)/2), "OOPSY WOOPSY, THE KERNEL HAD A FUCKY WUCKY UWU", CUM_WHITE, fb.borrow_mut());
loop {}
} }

View file

@ -22,142 +22,6 @@ pub mod WhyDoTheyCallItOvenWhenYouOfInTheColdFoodOfOutHotEatTheFood {
pub const COMMUNIST_RED: Colour = Colour{r:245,g:77,b:30}; pub const COMMUNIST_RED: Colour = Colour{r:245,g:77,b:30};
pub const CUM_WHITE: Colour = Colour{r:255,g:255,b:255}; pub const CUM_WHITE: Colour = Colour{r:255,g:255,b:255};
#[derive(Clone, Copy)]
pub struct IDTEntry<F> {
based_offset: u16,
code_selector: u16,
ist_offset_wastes_6_bits: u8,
attributes: u8,
offset_popping_off: u16,
what: PhantomData<F>
}
impl<F> IDTEntry<F> {
pub fn default() -> Self {
IDTEntry {
based_offset: 0,
code_selector: 0,
ist_offset_wastes_6_bits: 0,
attributes: 0,
offset_popping_off: 0,
what: PhantomData
}
}
}
macro_rules! impl_idtentry {
($f:ty) => {
impl IDTEntry<$f> {
pub fn set_handler(&mut self, handler: $f) {
unsafe { // no shit this is unsafe, i wrote it (:
let handler_addr = handler as u32;
self.based_offset = handler_addr as u16;
self.offset_popping_off = (handler_addr >> 16) as u16;
let code_selector : u16;
asm!("mov {0:x}, cs", out(reg) code_selector, options(nomem, nostack, preserves_flags));
self.code_selector = code_selector;
self.attributes = 0b10001110;
}
}
}
};
}
pub struct InterruptDescriptorTable {
pub divide_error: IDTEntry<InterruptHandler>,
pub debug: IDTEntry<InterruptHandler>,
pub dream_mask_sus_version: IDTEntry<InterruptHandler>, // non-maskable interrupt
pub breakpoint: IDTEntry<InterruptHandler>,
pub into_detected_overflow: IDTEntry<InterruptHandler>,
pub in_the_fortnite_storm: IDTEntry<InterruptHandler>, // bound range exceeded
pub owo_whats_this: IDTEntry<InterruptHandler>, // invalid opcode
pub device_not_available: IDTEntry<InterruptHandler>,
pub fucky_wucky_twice: IDTEntry<SeriousFuckUpWithErrorCodeHandler>, // double fault
we_are_all_about_backwards_compatibility: IDTEntry<InterruptHandler>, // coprocessor segment overrun
pub invalid_tss: IDTEntry<ErrorWithErrorCodeHandler>,
pub segment_not_present: IDTEntry<ErrorWithErrorCodeHandler>,
pub stack_segment_fault: IDTEntry<ErrorWithErrorCodeHandler>,
pub uh_oh_we_gotta_hacker_here: IDTEntry<ErrorWithErrorCodeHandler>, // general protection fault
pub page_fault: IDTEntry<ErrorWithErrorCodeHandler>,
reserved_1: IDTEntry<InterruptHandler>, // what the fuck is this?? the only comment is "vector nr.15"
pub x87_floating_point_exception: IDTEntry<InterruptHandler>, // compatibility B)
pub alignment_check: IDTEntry<ErrorWithErrorCodeHandler>,
pub machine_check: IDTEntry<SeriousFuckUpHandler>,
pub the_point_of_the_mask_float_exception: IDTEntry<InterruptHandler>, // simd floating point exception
pub virtualization_exception: IDTEntry<InterruptHandler>, // qemu WILL be added to windows 12 B)
reserved_2: IDTEntry<InterruptHandler>, // another reserved
pub vmm_communication_exception: IDTEntry<ErrorWithErrorCodeHandler>, // honestly too tired to check what this is
pub security_exception: IDTEntry<ErrorWithErrorCodeHandler>,
reserved_3: IDTEntry<InterruptHandler>,
pub interrupts: [IDTEntry<InterruptHandler>; 256 - 32], // the original one didn't make this public, but who care (:
}
impl InterruptDescriptorTable {
pub fn new() -> InterruptDescriptorTable {
InterruptDescriptorTable {
divide_error: IDTEntry::default(),
debug: IDTEntry::default(),
dream_mask_sus_version: IDTEntry::default(),
breakpoint: IDTEntry::default(),
into_detected_overflow: IDTEntry::default(),
in_the_fortnite_storm: IDTEntry::default(),
owo_whats_this: IDTEntry::default(),
device_not_available: IDTEntry::default(),
fucky_wucky_twice: IDTEntry::default(),
we_are_all_about_backwards_compatibility: IDTEntry::default(),
invalid_tss: IDTEntry::default(),
segment_not_present: IDTEntry::default(),
stack_segment_fault: IDTEntry::default(),
uh_oh_we_gotta_hacker_here: IDTEntry::default(),
page_fault: IDTEntry::default(),
reserved_1: IDTEntry::default(),
x87_floating_point_exception: IDTEntry::default(),
alignment_check: IDTEntry::default(),
machine_check: IDTEntry::default(),
the_point_of_the_mask_float_exception: IDTEntry::default(),
virtualization_exception: IDTEntry::default(),
reserved_2: IDTEntry::default(),
vmm_communication_exception: IDTEntry::default(),
security_exception: IDTEntry::default(),
reserved_3: IDTEntry::default(),
interrupts: [IDTEntry::default(); 256 - 32]
}
}
pub fn load(&'static self) {
unsafe {
// load the IDT
let idt_ptr = &self as *const _ as *const _;
asm!("lidt [{}]", in(reg) idt_ptr, options(readonly, nostack, preserves_flags));
}
}
}
pub type InterruptHandler = extern "x86-interrupt" fn(_: InterruptStackFrame);
pub type ErrorWithErrorCodeHandler = extern "x86-interrupt" fn(_: InterruptStackFrame, error_code: u32);
pub type SeriousFuckUpHandler = extern "x86-interrupt" fn(_: InterruptStackFrame) -> !;
pub type SeriousFuckUpWithErrorCodeHandler = extern "x86-interrupt" fn(_: InterruptStackFrame, error_code: u32) -> !;
impl_idtentry!(InterruptHandler);
impl_idtentry!(ErrorWithErrorCodeHandler);
impl_idtentry!(SeriousFuckUpHandler);
impl_idtentry!(SeriousFuckUpWithErrorCodeHandler);
// y'know the x86 crate has a point with doing it this way, so i'm gonna do the same (:
pub struct InterruptStackFrame {
pub value: InterruptStackValues,
}
pub struct InterruptStackValues {
pub instruction_pointer: u32,
pub code_segment: u32,
pub cpu_flags: u32,
pub stack_pointer: u32,
}
pub enum ErrorKind { pub enum ErrorKind {
HardwareFuckUp, HardwareFuckUp,
} }

View file

@ -16,6 +16,7 @@ use core::panic::PanicInfo;
use bootloader::boot_info::{FrameBuffer, FrameBufferInfo, PixelFormat}; use bootloader::boot_info::{FrameBuffer, FrameBufferInfo, PixelFormat};
use crate::internals::WhyDoTheyCallItOvenWhenYouOfInTheColdFoodOfOutHotEatTheFood::*; use crate::internals::WhyDoTheyCallItOvenWhenYouOfInTheColdFoodOfOutHotEatTheFood::*;
use crate::serial::potential_serial_ports; use crate::serial::potential_serial_ports;
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
mod font; mod font;
mod serial; mod serial;
@ -37,27 +38,7 @@ pub struct FBInfo {
lazy_static! { lazy_static! {
static ref IDT : InterruptDescriptorTable = { static ref IDT : InterruptDescriptorTable = {
let mut idt = InterruptDescriptorTable::new(); let mut idt = InterruptDescriptorTable::new();
idt.divide_error.set_handler(internals::errors::generic_error); idt.breakpoint.set_handler_fn(internals::errors::breakpoint_exception);
idt.debug.set_handler(internals::errors::generic_error);
idt.dream_mask_sus_version.set_handler(internals::errors::generic_error);
idt.breakpoint.set_handler(internals::errors::generic_error);
idt.into_detected_overflow.set_handler(internals::errors::generic_error);
idt.in_the_fortnite_storm.set_handler(internals::errors::generic_error);
idt.owo_whats_this.set_handler(internals::errors::generic_error);
idt.device_not_available.set_handler(internals::errors::generic_error);
idt.fucky_wucky_twice.set_handler(internals::errors::super_fuck_up_error_with_code);
idt.invalid_tss.set_handler(internals::errors::generic_error_with_code);
idt.segment_not_present.set_handler(internals::errors::generic_error_with_code);
idt.stack_segment_fault.set_handler(internals::errors::generic_error_with_code);
idt.uh_oh_we_gotta_hacker_here.set_handler(internals::errors::generic_error_with_code);
idt.page_fault.set_handler(internals::errors::generic_error_with_code);
idt.x87_floating_point_exception.set_handler(internals::errors::generic_error);
idt.alignment_check.set_handler(internals::errors::generic_error_with_code);
idt.machine_check.set_handler(internals::errors::super_fuck_up_error);
idt.the_point_of_the_mask_float_exception.set_handler(internals::errors::generic_error);
idt.virtualization_exception.set_handler(internals::errors::generic_error);
idt.vmm_communication_exception.set_handler(internals::errors::generic_error_with_code);
idt.security_exception.set_handler(internals::errors::generic_error_with_code);
idt idt
}; };
@ -237,7 +218,7 @@ fn main(boot_info: &'static mut BootInfo) -> ! {
drop(temp_fb_fb_height); drop(temp_fb_fb_height);
let mut temp_fb_fb_pitch = FACEBOOK.fb_pitch.lock(); let mut temp_fb_fb_pitch = FACEBOOK.fb_pitch.lock();
*temp_fb_fb_pitch = framebuffer.info().stride; *temp_fb_fb_pitch = framebuffer.info().stride * framebuffer.info().bytes_per_pixel;
drop(temp_fb_fb_pitch); drop(temp_fb_fb_pitch);
} }
// cover the screen in a nice blue // cover the screen in a nice blue
@ -254,9 +235,8 @@ fn main(boot_info: &'static mut BootInfo) -> ! {
//draw_string(20,20, "),:\n\n\n\nuh oh! windows error! your computer is not compatible with windows 12\n\ncontact billgate@realmicrosoft.com to fix this issue!", Colour { r: 255, g: 255, b: 255}, framebuffer); //draw_string(20,20, "),:\n\n\n\nuh oh! windows error! your computer is not compatible with windows 12\n\ncontact billgate@realmicrosoft.com to fix this issue!", Colour { r: 255, g: 255, b: 255}, framebuffer);
unsafe { x86_64::instructions::interrupts::int3();
asm!("int3", options(nomem, nostack)); /*
}
draw_horizcentre_string(((fb_height/2)-4)-16, "welcome to windows 12! here is info:", CUM_WHITE, framebuffer); draw_horizcentre_string(((fb_height/2)-4)-16, "welcome to windows 12! here is info:", CUM_WHITE, framebuffer);
@ -275,7 +255,9 @@ fn main(boot_info: &'static mut BootInfo) -> ! {
//draw_rainbow_string((fb_width/2) - ((7*8)/2), (fb_height/2) - 4, "gay sex", framebuffer); //draw_rainbow_string((fb_width/2) - ((7*8)/2), (fb_height/2) - 4, "gay sex", framebuffer);
*/
} }
loop{} loop{}
} }