From f2ff9da1fb5522ed22e05d0e59cea2b4ebfd176a Mon Sep 17 00:00:00 2001 From: cooldeveloperperson <78451197+cooldeveloperperson@users.noreply.github.com> Date: Tue, 25 Oct 2022 15:27:11 -0700 Subject: [PATCH] major code refactoring --- Cargo.toml | 10 +-- assembly/boot.asm | 44 ++++++---- build.rs | 3 + linker.ld | 29 +++++++ rust-toolchain | 1 + src/main.rs | 217 +--------------------------------------------- 6 files changed, 63 insertions(+), 241 deletions(-) create mode 100644 build.rs create mode 100644 linker.ld create mode 100644 rust-toolchain diff --git a/Cargo.toml b/Cargo.toml index 30174dd..e6f9b8c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,17 +1,11 @@ [package] -name = "windows" +name = "wukkOS" version = "0.1.0" edition = "2021" -[workspace] -members = [ - "simple_boot", -] - [dependencies] -bootloader = "0.10.12" spin = "0.9.1" -x86_64 = "0.14.9" +x86_64 = "0.14.10" [dependencies.lazy_static] version = "1.4.0" features = ["spin_no_std"] \ No newline at end of file diff --git a/assembly/boot.asm b/assembly/boot.asm index a8bd353..01b7946 100644 --- a/assembly/boot.asm +++ b/assembly/boot.asm @@ -1,23 +1,31 @@ -[bits 16] -[org 0x7c00] + ;; bootstrap code from osdev.org + MBALIGN equ 1 << 0 + MEMINFO equ 1 << 1 + FLAGS equ MBALIGN | MEMINFO + MAGIC equ 0x1BADB002 + CHECKSUM equ -(MAGIC + FLAGS) + section .multiboot + align 4 + dd MAGIC + dd FLAGS + dd CHECKSUM -xor ax, ax -mov ds, ax -mov es,ax + section .bss + align 16 +stack_bottom: + resb 16384 ; 16 KiB stack +stack_top: -cli -mov ss,bx -mov sp,ax -sti + section .text + global _start:function (_start.end - _start) +_start: + mov esp, stack_top -; set graphics mode -mov ax, 00h -mov ah, 0x00 -int 0x10 + extern kernel_main + call kernel_main -; jump after bootloader -jmp 0x07E0:0x0000 - -times 510-($-$$) db 0 -dw 0xAA55 \ No newline at end of file + cli +.hang: hlt + jmp .hang +.end: diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..6583960 --- /dev/null +++ b/build.rs @@ -0,0 +1,3 @@ +fn main() { + println!("cargo:rustc-link-arg=-Tlinker.ld"); +} \ No newline at end of file diff --git a/linker.ld b/linker.ld new file mode 100644 index 0000000..e1203ca --- /dev/null +++ b/linker.ld @@ -0,0 +1,29 @@ +ENTRY(_start) + +SECTIONS +{ + . = 1M; + + .text BLOCK(4K) : ALIGN(4K) + { + *(.multiboot) + *(.text) + } + + .rodata BLOCK(4K) : ALIGN(4K) + { + *(.rodata) + } + + .data BLOCK(4K) : ALIGN(4K) + { + *(.data) + } + + .bss BLOCK(4K) : ALIGN(4K) + { + *(COMMON) + *(.bss) + } + +} diff --git a/rust-toolchain b/rust-toolchain new file mode 100644 index 0000000..07ade69 --- /dev/null +++ b/rust-toolchain @@ -0,0 +1 @@ +nightly \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 6cbddff..722e9be 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,9 +11,7 @@ use alloc::vec::Vec; use spin::Mutex; use core::arch::asm; use lazy_static::lazy_static; -use bootloader::{entry_point, BootInfo, boot_info}; use core::panic::PanicInfo; -use bootloader::boot_info::{FrameBuffer, FrameBufferInfo, PixelFormat}; use crate::internals::WhyDoTheyCallItOvenWhenYouOfInTheColdFoodOfOutHotEatTheFood::*; use crate::serial::potential_serial_ports; use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame}; @@ -23,15 +21,6 @@ mod serial; mod internals; mod allocator; -pub struct FBInfo { - pub fb_mutex: Mutex>, - pub fb_pixelwidth: Mutex, - pub fb_colourtype: Mutex, - pub fb_pitch: Mutex, - pub fb_width: Mutex, - pub fb_height: Mutex, -} - // THIS IS THE ONLY GLOBAL VARIABLE WE WILL EVER HAVE, MARK THIS ON MY FUCKING GRAVE //pub static mut FRAMEBUFFER: Option = None; @@ -41,17 +30,6 @@ lazy_static! { idt.breakpoint.set_handler_fn(internals::errors::breakpoint_exception); idt }; - - static ref FACEBOOK : FBInfo = { - FBInfo { - fb_mutex: Mutex::new(Vec::new()), - fb_pixelwidth: Mutex::new(0), - fb_colourtype: Mutex::new(0), - fb_pitch: Mutex::new(0), - fb_width: Mutex::new(0), - fb_height: Mutex::new(0), - } - }; } @@ -63,201 +41,10 @@ fn panic(_info: &PanicInfo) -> ! { loop {} } fn KernelPanic(msg: KernelError, fb: &mut FrameBuffer) { // cover the screen in red - for y in 0..fb.info().vertical_resolution { - for x in 0..fb.info().horizontal_resolution { - put_pixel(x, y, COMMUNIST_RED, fb); - } - } } -pub fn put_pixel(x: usize, y: usize, color: Colour, fb: &mut FrameBuffer) { - let pixelwidth = fb.info().bytes_per_pixel; - let pitch = fb.info().stride * pixelwidth; - - let pixel = (y * pitch) + (x * pixelwidth); - - if fb.info().pixel_format == PixelFormat::BGR { - fb.buffer_mut()[pixel + 0] = color.b; - fb.buffer_mut()[pixel + 1] = color.g; - fb.buffer_mut()[pixel + 2] = color.r; - } else if fb.info().pixel_format == PixelFormat::RGB { - fb.buffer_mut()[pixel + 0] = color.r; - fb.buffer_mut()[pixel + 1] = color.g; - fb.buffer_mut()[pixel + 2] = color.b; - } else { - // average values - let avg = (color.r as u16 + color.g as u16 + color.b as u16) / 3; - fb.buffer_mut()[pixel + 0] = avg as u8; - } -} - -pub fn draw_box(x: usize, y: usize, width: usize, height: usize, color: Colour, fb: &mut FrameBuffer) { - let pixelwidth = fb.info().bytes_per_pixel; - let pitch = fb.info().stride * pixelwidth; - - for i in 0..width { - for j in 0..height { - let pixel = (y * pitch) + (x * pixelwidth) + (i * pixelwidth) + (j * pitch); - if fb.info().pixel_format == PixelFormat::BGR { - fb.buffer_mut()[pixel + 0] = color.b; - fb.buffer_mut()[pixel + 1] = color.g; - fb.buffer_mut()[pixel + 2] = color.r; - } else if fb.info().pixel_format == PixelFormat::RGB { - fb.buffer_mut()[pixel + 0] = color.r; - fb.buffer_mut()[pixel + 1] = color.g; - fb.buffer_mut()[pixel + 2] = color.b; - } else { - // average values - let avg = (color.r as u16 + color.g as u16 + color.b as u16) / 3; - fb.buffer_mut()[pixel + 0] = avg as u8; - } - } - } -} - -fn draw_char(x: usize, y: usize, c: char, color: Colour, fb: &mut FrameBuffer) { - let font = font::BASIC_LEGACY; - // font is 8x8, stored in a 2d array of bytes - let char_width = 8; - let char_height = 8; - - let char_index = c as usize; - let char_data = font[char_index]; - - for row in 0..char_height { - for col in 0..char_width { - let bit = (char_data[row] >> col) & 1; - if bit >= 1 { - put_pixel(x + col, y + row, color, fb); - } - } - } -} - -pub fn draw_string(x: usize, y: usize, s: &str, color: Colour, fb: &mut FrameBuffer) { - let mut x_tmp = x; - let mut y_tmp = y; - - for c in s.chars() { - if c == '\n' { - x_tmp = x; - y_tmp += 8; - } else { - draw_char(x_tmp, y_tmp, c, color, fb); - x_tmp += 8; - } - } -} - -pub fn draw_horizcentre_string(y: usize, s: &str, color: Colour, fb: &mut FrameBuffer) { - let mut x_tmp = (fb.info().horizontal_resolution - s.len() * 8) / 2; - let mut y_tmp = y; - - for c in s.chars() { - if c == '\n' { - x_tmp = (fb.info().horizontal_resolution - s.len() * 8) / 2; - y_tmp += 8; - } else { - draw_char(x_tmp, y_tmp, c, color, fb); - x_tmp += 8; - } - } -} - -pub fn draw_rainbow_string(x: usize, y: usize, s: &str, fb: &mut FrameBuffer) { - let mut x_tmp = x; - let mut y_tmp = y; - - let mut i = 0; - - for c in s.chars() { - if c == '\n' { - x_tmp = x; - y_tmp += 8; - } else { - let color = RAINBOW[i % RAINBOW.len() as usize]; - draw_char(x_tmp, y_tmp, c, color, fb); - x_tmp += 8; - i += 1; - } - } -} - - -entry_point!(main); - -fn main(boot_info: &'static mut BootInfo) -> ! { - - if let Some(framebuffer) = boot_info.framebuffer.as_mut() { - // set up the framebuffer - unsafe { - let mut colourtype: u8; - if framebuffer.info().pixel_format == PixelFormat::RGB { - colourtype = 1; - } else { - colourtype = 0; - } - let mut temp_fb = FACEBOOK.fb_mutex.lock(); - *temp_fb = Vec::from_raw_parts(framebuffer.buffer_mut().as_mut_ptr(), framebuffer.buffer_mut().len(), framebuffer.buffer_mut().len()); - drop(temp_fb); - - let mut temp_fb_pixel_width = FACEBOOK.fb_pixelwidth.lock(); - *temp_fb_pixel_width = framebuffer.info().bytes_per_pixel; - drop(temp_fb_pixel_width); - - let mut temp_fb_fb_colourtype = FACEBOOK.fb_colourtype.lock(); - *temp_fb_fb_colourtype = colourtype; - drop(temp_fb_fb_colourtype); - - let mut temp_fb_fb_width = FACEBOOK.fb_width.lock(); - *temp_fb_fb_width = framebuffer.info().horizontal_resolution; - drop(temp_fb_fb_width); - - let mut temp_fb_fb_height = FACEBOOK.fb_height.lock(); - *temp_fb_fb_height = framebuffer.info().vertical_resolution; - drop(temp_fb_fb_height); - - let mut temp_fb_fb_pitch = FACEBOOK.fb_pitch.lock(); - *temp_fb_fb_pitch = framebuffer.info().stride * framebuffer.info().bytes_per_pixel; - drop(temp_fb_fb_pitch); - } - // cover the screen in a nice blue - draw_box(0, 0, framebuffer.info().horizontal_resolution, framebuffer.info().vertical_resolution, Colour{r:30,g:129,b:176}, framebuffer); - - let fb_width = framebuffer.info().horizontal_resolution; - let fb_height = framebuffer.info().vertical_resolution; - - IDT.load(); - - // draw a test string - //draw_string(20, 20, "i love drinking cum\nnewline test", Colour { r: 255, g: 0, b: 255 }, framebuffer); - //draw_rainbow_string(20, 40, "gay sex", 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); - - x86_64::instructions::interrupts::int3(); - /* - - draw_horizcentre_string(((fb_height/2)-4)-16, "welcome to windows 12! here is info:", CUM_WHITE, framebuffer); - - // time for some funny com port stuff - let serial_ports = serial::init_serial(); - draw_horizcentre_string(((fb_height/2)-4)-8, "serial ports:", CUM_WHITE, framebuffer); - - for port in 0..serial_ports.ports_enabled.len() { - if serial_ports.ports_enabled[port] { - draw_horizcentre_string(((fb_height/2)-4)+(port as usize*8), serial_ports.ports[port].base.to_string(), CUM_WHITE, framebuffer); - } else { // draw in grey - draw_horizcentre_string(((fb_height/2)-4)+(port as usize*8), serial_ports.ports[port].base.to_string(), COMMUNIST_RED, framebuffer); - } - } - - - //draw_rainbow_string((fb_width/2) - ((7*8)/2), (fb_height/2) - 4, "gay sex", framebuffer); - - */ - } - +#[no_mangle] +fn kernel_main() -> ! { loop{} } \ No newline at end of file