diff --git a/GNUmakefile b/GNUmakefile index d72ede7..b506623 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -33,7 +33,7 @@ all-hdd: $(IMAGE_NAME).hdd .PHONY: run run: $(IMAGE_NAME).iso - qemu-system-x86_64 -M q35 -m 2G -cdrom $(IMAGE_NAME).iso -boot d -serial stdio -full-screen + qemu-system-x86_64 -M q35 -m 2G -cdrom $(IMAGE_NAME).iso -boot d -full-screen -serial telnet::4444,server=on,wait=off .PHONY: run-uefi run-uefi: ovmf $(IMAGE_NAME).iso diff --git a/PROGRAM.SYS b/PROGRAM.SYS index a088a7f..12dc418 100644 Binary files a/PROGRAM.SYS and b/PROGRAM.SYS differ diff --git a/antos.iso b/antos.iso index 7d40137..572af0c 100644 Binary files a/antos.iso and b/antos.iso differ diff --git a/kernel/..kernel_expanded.rs b/kernel/..kernel_expanded.rs index 9208ebd..22e0d8d 100644 --- a/kernel/..kernel_expanded.rs +++ b/kernel/..kernel_expanded.rs @@ -1,30 +1,219 @@ #![feature(prelude_import)] +#![recursion_limit = "225"] #![no_std] #![no_main] -#![allow(deprecated)] -#![feature(panic_info_message)] -#![feature(unboxed_closures)] -#![feature(core_intrinsics)] -#![feature(decl_macro)] -#![feature(ptr_from_ref)] -#![feature(inherent_associated_types)] -#![feature(adt_const_params)] -#![feature(abi_x86_interrupt)] -#![recursion_limit = "2000"] +#![allow(deprecated, incomplete_features, internal_features)] +#![feature( + panic_info_message, + unboxed_closures, + core_intrinsics, + decl_macro, + ptr_from_ref, + inherent_associated_types, + adt_const_params, + abi_x86_interrupt, + allocator_api, + const_mut_refs, + portable_simd, + strict_provenance, + sync_unsafe_cell, + debug_closure_helpers, + if_let_guard, + let_chains, + panic_internals, + marker_trait_attr, + asm_const, + type_name_of_val, + alloc_internals, + lazy_cell, +)] #[prelude_import] use core::prelude::rust_2021::*; #[macro_use] extern crate core; extern crate compiler_builtins as _; +extern crate alloc; +pub mod alloc_impl { + use core::alloc::AllocError; + use core::any::type_name_of_val; + use core::cell::{self, Cell, RefCell, UnsafeCell}; + use core::mem::MaybeUninit; + use core::ops::Deref; + use core::ptr::NonNull; + use core::sync::atomic::{AtomicPtr, AtomicBool}; + use core::{ + sync::atomic::AtomicUsize, cell::SyncUnsafeCell, alloc::Layout, ptr::null_mut, + }; + use core::sync::atomic::Ordering::SeqCst; + pub use alloc::*; + use limine::NonNullPtr; + use crate::kprint; + use crate::paging::{pf_allocator, frame_allocator}; + pub extern crate alloc; + const ARENA_SIZE: usize = 558 * 1024; + const MAX_SUPPORTED_ALIGN: usize = 4096; + const FREE_BLOCKS_SIZE: usize = 8; + #[repr(C)] + pub struct UnsafePtrArray(*mut T, usize); + impl UnsafePtrArray { + pub fn new(value: *mut T, size: usize) -> Self { + Self(unsafe { core::mem::transmute(value) }, size) + } + pub unsafe fn get(&self) -> *mut T { + self.0 + } + } + #[repr(C, align(4096))] + pub struct KernelAllocator { + arena: SyncUnsafeCell<[u8; ARENA_SIZE]>, + is_initialized: AtomicBool, + size: AtomicUsize, + remaining: AtomicUsize, + } + static mut FREE_BLOCK_STORAGE: heapless::Vec<(usize, usize), FREE_BLOCKS_SIZE> = heapless::Vec::< + (usize, usize), + FREE_BLOCKS_SIZE, + >::new(); + impl KernelAllocator { + const unsafe fn new() -> Self { + KernelAllocator { + arena: SyncUnsafeCell::<[u8; ARENA_SIZE]>::new([0x0; ARENA_SIZE]), + is_initialized: AtomicBool::new(false), + size: AtomicUsize::new(ARENA_SIZE), + remaining: AtomicUsize::new(ARENA_SIZE), + } + } + pub const unsafe fn assume_init(&'_ self) {} + pub fn get_arena_size(&self) -> usize { + self.size.load(core::sync::atomic::Ordering::Relaxed) + } + pub fn initialize(&mut self) -> Result<(), frame_allocator::Error> { + let size = self.size.load(SeqCst); + let arena = pf_allocator().request_memory_area(size)?; + self.is_initialized.store(true, SeqCst); + Ok(()) + } + pub unsafe fn get_arena(&mut self) -> *mut u8 { + self.arena.get_mut().as_mut_ptr() + } + } + #[doc(hidden)] + unsafe fn __rustc_dealloc(ptr: *mut u8, layout: core::alloc::Layout) {} + unsafe impl Sync for KernelAllocator {} + /// The Kernel's Global Allocator. + #[doc(hidden)] + #[repr(C, packed)] + struct GlobalAllocImpl; + unsafe impl Sync for GlobalAllocImpl {} + impl KernelAllocator { + unsafe fn allocate( + &mut self, + layout: Layout, + ) -> Result<*mut u8, core::alloc::AllocError> { + if !self.is_initialized.load(SeqCst) { + return Err(AllocError); + } + let size = layout.size(); + let align = layout.align(); + let align_mask_to_round_down = !(align - 1); + if align > MAX_SUPPORTED_ALIGN { + return Err(AllocError); + } + let mut allocated = 0; + if self + .remaining + .fetch_update( + SeqCst, + SeqCst, + |mut remaining| { + if size > remaining { + return None; + } + remaining -= size; + remaining &= align_mask_to_round_down; + allocated = remaining; + Some(remaining) + }, + ) + .is_err() + { + return Err(AllocError); + } + Ok(self.get_arena().cast::().add(allocated)) + } + unsafe fn deallocate(&self, ptr: *mut u8, layout: Layout) { + if !self.is_initialized.load(SeqCst) { + return; + } + self.remaining.fetch_add(layout.size(), SeqCst); + __rustc_dealloc(ptr, layout) + } + } + unsafe impl alloc::alloc::GlobalAlloc for GlobalAllocImpl { + unsafe fn alloc(&self, layout: Layout) -> *mut u8 { + match KERNEL_ALLOCATOR.allocate(layout) { + Ok(ptr) => ptr, + Err(_) => null_mut(), + } + } + unsafe fn dealloc(&self, ptr: *mut u8, layout: core::alloc::Layout) { + KERNEL_ALLOCATOR.deallocate(ptr, layout) + } + } + #[doc(hidden)] + pub static mut GLOBAL_ALLOC: GlobalAllocImpl = GlobalAllocImpl; + const _: () = { + #[rustc_std_internal_symbol] + unsafe fn __rust_alloc(size: usize, align: usize) -> *mut u8 { + ::core::alloc::GlobalAlloc::alloc( + &GLOBAL_ALLOC, + ::core::alloc::Layout::from_size_align_unchecked(size, align), + ) + } + #[rustc_std_internal_symbol] + unsafe fn __rust_dealloc(ptr: *mut u8, size: usize, align: usize) -> () { + ::core::alloc::GlobalAlloc::dealloc( + &GLOBAL_ALLOC, + ptr, + ::core::alloc::Layout::from_size_align_unchecked(size, align), + ) + } + #[rustc_std_internal_symbol] + unsafe fn __rust_realloc( + ptr: *mut u8, + size: usize, + align: usize, + new_size: usize, + ) -> *mut u8 { + ::core::alloc::GlobalAlloc::realloc( + &GLOBAL_ALLOC, + ptr, + ::core::alloc::Layout::from_size_align_unchecked(size, align), + new_size, + ) + } + #[rustc_std_internal_symbol] + unsafe fn __rust_alloc_zeroed(size: usize, align: usize) -> *mut u8 { + ::core::alloc::GlobalAlloc::alloc_zeroed( + &GLOBAL_ALLOC, + ::core::alloc::Layout::from_size_align_unchecked(size, align), + ) + } + }; + #[doc(hidden)] + pub(crate) static mut KERNEL_ALLOCATOR: KernelAllocator = unsafe { + KernelAllocator::new() + }; +} pub mod bitmap_font { pub type BitmapChar = [u16; 8]; pub type BitmapFont = [BitmapChar; 128]; - pub trait BitmapCharImpl { + pub trait DisplayChar { fn is_set(&self, x: usize, y: usize) -> bool; } - impl BitmapCharImpl for BitmapChar { + impl DisplayChar for BitmapChar { fn is_set(&self, x: usize, y: usize) -> bool { - (self[x] & 1 << (y as i8)) != 0 + (self[y] & 1 << (x as i8)) != 0 } } } @@ -51,22 +240,38 @@ pub mod common { ); value } - pub unsafe fn io_wait() { - ::core::panicking::panic("not implemented"); - } + #[inline(always)] + pub unsafe fn io_wait() {} } pub mod macros {} + use core::{ + simd::ptr::SimdConstPtr, ptr::NonNull, mem::{size_of_val, size_of}, + sync::atomic::AtomicPtr, ops::Deref, + }; pub use limine::*; pub mod idt { //! Interrupt Descriptor Table - use core::arch::asm; + use core::{arch::asm, alloc::Layout, sync::atomic::AtomicPtr}; use bitflags::bitflags; - const GDT_KERNEL_CODE: u16 = 1; + use crate::{alloc_impl::KERNEL_ALLOCATOR, paging::pt_manager}; + const GDT_KERNEL_CODE: u16 = 0x8; pub type IdtEntries = [IdtEntry; 256]; #[repr(C)] pub struct Idt { pub entries: IdtEntries, } + #[automatically_derived] + impl ::core::fmt::Debug for Idt { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_struct_field1_finish( + f, + "Idt", + "entries", + &&self.entries, + ) + } + } impl Idt { pub const fn new() -> Self { Self { @@ -1193,12 +1398,47 @@ pub mod common { self.set_flags( IdtFlags::PRESENT | IdtFlags::RING_0 | IdtFlags::INTERRUPT, ); - self.set_offset((GDT_KERNEL_CODE as u16) << 3, func as usize); + self.set_offset(0x8, func as usize); + } + } + #[allow(missing_copy_implementations)] + #[allow(non_camel_case_types)] + #[allow(dead_code)] + pub struct KERNEL_IDT { + __private_field: (), + } + #[doc(hidden)] + pub static KERNEL_IDT: KERNEL_IDT = KERNEL_IDT { __private_field: () }; + impl ::lazy_static::__Deref for KERNEL_IDT { + type Target = AtomicPtr; + fn deref(&self) -> &AtomicPtr { + #[inline(always)] + fn __static_ref_initialize() -> AtomicPtr { + unsafe { + KERNEL_ALLOCATOR.assume_init(); + let idt = alloc::boxed::Box::< + Idt, + >::into_raw(alloc::boxed::Box::::new(Idt::new())); + AtomicPtr::new(idt) + } + } + #[inline(always)] + fn __stability() -> &'static AtomicPtr { + static LAZY: ::lazy_static::lazy::Lazy> = ::lazy_static::lazy::Lazy::INIT; + LAZY.get(__static_ref_initialize) + } + __stability() + } + } + impl ::lazy_static::LazyStatic for KERNEL_IDT { + fn initialize(lazy: &Self) { + let _ = &**lazy; } } } pub mod gdt { //! Global Descriptor Table + use super::{AtomicRef, DescriptorTablePointer}; pub const GDT_NULL: usize = 0; pub const GDT_KERNEL_CODE: usize = 1; pub const GDT_KERNEL_DATA: usize = 2; @@ -1222,22 +1462,6 @@ pub mod common { pub const GDT_F_PAGE_SIZE: u8 = 1 << 7; pub const GDT_F_PROTECTED_MODE: u8 = 1 << 6; pub const GDT_F_LONG_MODE: u8 = 1 << 5; - pub(crate) static mut INIT_GDT: [GdtEntry; 3] = [ - GdtEntry::new(0, 0, 0, 0), - GdtEntry::new( - 0, - 0, - GDT_A_PRESENT | GDT_A_RING_0 | GDT_A_SYSTEM | GDT_A_EXECUTABLE - | GDT_A_PRIVILEGE, - GDT_F_LONG_MODE, - ), - GdtEntry::new( - 0, - 0, - GDT_A_PRESENT | GDT_A_RING_0 | GDT_A_SYSTEM | GDT_A_PRIVILEGE, - GDT_F_LONG_MODE, - ), - ]; #[repr(packed)] pub struct GdtEntry { pub limitl: u16, @@ -1310,7 +1534,89 @@ pub mod common { } } } + pub mod handler { + use core::{cell::UnsafeCell, default}; + use core::marker; + use core::sync::atomic::AtomicPtr; + use alloc::sync::Arc; + use limine::NonNullPtr; + use lock_api::{RwLock, GuardSend}; + #[marker] + pub trait Handler {} + pub fn get_data_for_handler(handle: Handle) -> Option<*mut dyn Handler> { + None + } + #[repr(transparent)] + pub struct Handle { + pub(self) inner: u64, + } + impl Handle { + pub fn new(offset: u64) -> Self { + Self { inner: offset } + } + } + } pub type Unit = (); + pub use x86_64::structures::idt::ExceptionVector; + pub use x86_64::structures::idt::InterruptStackFrame; + ///A [AtomicPtr] wrapper that implements [Deref]. + #[repr(transparent)] + struct AtomicRef { + inner: AtomicPtr, + } + unsafe impl Sync for AtomicRef {} + /// It's just an [AtomicPtr] internally so it's "thread-safe". + impl AtomicRef { + ///Create a new [AtomicRef]. + fn new(inner: *mut T) -> Self { + Self { + inner: AtomicPtr::new(inner), + } + } + } + impl Deref for AtomicRef { + type Target = T; + ///Loads(Relaxed) and then Dereferences the pointer stored by the inner [AtomicRef]. **Panics** when the inner pointer is null. + fn deref(&self) -> &Self::Target { + unsafe { + self.inner + .load(core::sync::atomic::Ordering::Relaxed) + .as_ref() + .expect("AtomicPtr was null.") + } + } + } + ///Utility Trait + pub(crate) unsafe trait TransmuteIntoPointer { + /// Calls [core::intrinsics::transmute_unchecked]. + #[inline(always)] + unsafe fn ptr(self) -> *mut T + where + Self: Sized, + { + core::intrinsics::transmute_unchecked::(self) + } + } + ///Utility Trait + pub(crate) unsafe trait TransmuteInto { + /// Calls [core::intrinsics::transmute_unchecked] + #[inline(always)] + unsafe fn transmute(self) -> T + where + Self: Sized, + { + core::intrinsics::transmute_unchecked::(self) + } + } + unsafe impl TransmuteIntoPointer for usize {} + unsafe impl TransmuteInto> for NonNull {} + unsafe impl TransmuteInto> for AtomicRef {} + unsafe impl TransmuteInto for u8 {} + #[cfg(target_pointer_width = "64")] + unsafe impl TransmuteInto for usize {} + unsafe impl TransmuteInto for &'_ mut T {} + unsafe impl TransmuteInto for *mut T {} + unsafe impl TransmuteInto for *const T {} #[repr(C, packed(2))] pub struct DescriptorTablePointer { /// Size of the DT. @@ -1346,9 +1652,7 @@ pub mod common { #[inline] pub unsafe fn lidt(ptr: &DescriptorTablePointer) { unsafe { - asm!( - "lidt [{0}]", in (reg) ptr, options(readonly, preserves_flags, nostack) - ); + asm!("lidt [{0}]", in (reg) ptr, options(preserves_flags, nostack)); } } #[inline] @@ -1367,14 +1671,14 @@ pub mod common { core::intrinsics::transmute_unchecked::< *mut (), *mut T, - >( - (unsafe { &mut *crate::PAGE_FRAME_ALLOCATOR.as_mut_ptr() }) - .request_page()? as *mut (), - ) + >(crate::pf_allocator().request_page()? as *mut ()) }) } + pub(crate) macro __kdebug_newline { + () => { debug!("\n") } + } pub macro endl { - () => { "\n\r" } + () => { "\n" } } } pub mod device { @@ -1428,1029 +1732,314 @@ pub mod device { pub mod framebuffer { pub use limine::Framebuffer; } -pub mod paging { - use bit::BitIndex; - use crate::memory::PhysicalAddress; - pub mod frame_allocator { - use crate::{ - consts::{INVALID_PAGE_STATE, PAGE_SIZE}, - debug, endl, extra_features, - }; - use limine::{MemmapEntry, MemmapResponse, MemoryMapEntryType, NonNullPtr}; - pub type PageBitmap = bitmap::Bitmap, bitmap::OneBit>; - pub struct PageFrameAllocator { - pub bitmap: &'static mut PageBitmap, - used_memory: usize, - free_memory: usize, - reserved_memory: usize, - total_memory: usize, - _initialized: bool, - _bitmap_index: usize, +pub mod graphics { + use core::ops::Deref; + use alloc::boxed::Box; + #[repr(transparent)] + pub struct Color(u32); + #[automatically_derived] + impl ::core::fmt::Debug for Color { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Color", &&self.0) } - macro decl_multi_page_fn { - ([$_meta : vis] $name : ident => $target_name : ident(...)) => { $_meta fn - $name (& mut self, addr : usize, num : usize) -> Result < (), Error > { for i - in 0..num { self.$target_name (addr + (i * crate ::consts::PAGE_SIZE as - usize)) ?; } Ok(()) } } + } + #[automatically_derived] + impl ::core::clone::Clone for Color { + #[inline] + fn clone(&self) -> Color { + let _: ::core::clone::AssertParamIsClone; + *self } - pub enum Error { - UninitializedAllocator, - OutOfMemory, - AlreadyDone, - CorruptedBitmap, - OutOfBitmapBounds, - InvalidPointer, - InvalidAlignment, - Continue, + } + #[automatically_derived] + impl ::core::marker::Copy for Color {} + #[automatically_derived] + impl ::core::marker::StructuralPartialEq for Color {} + #[automatically_derived] + impl ::core::cmp::PartialEq for Color { + #[inline] + fn eq(&self, other: &Color) -> bool { + self.0 == other.0 } - #[automatically_derived] - impl ::core::fmt::Debug for Error { - #[inline] - fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { - ::core::fmt::Formatter::write_str( - f, - match self { - Error::UninitializedAllocator => "UninitializedAllocator", - Error::OutOfMemory => "OutOfMemory", - Error::AlreadyDone => "AlreadyDone", - Error::CorruptedBitmap => "CorruptedBitmap", - Error::OutOfBitmapBounds => "OutOfBitmapBounds", - Error::InvalidPointer => "InvalidPointer", - Error::InvalidAlignment => "InvalidAlignment", - Error::Continue => "Continue", - }, - ) - } + } + #[automatically_derived] + impl ::core::marker::StructuralEq for Color {} + #[automatically_derived] + impl ::core::cmp::Eq for Color { + #[inline] + #[doc(hidden)] + #[coverage(off)] + fn assert_receiver_is_total_eq(&self) -> () { + let _: ::core::cmp::AssertParamIsEq; } - #[automatically_derived] - impl ::core::marker::StructuralEq for Error {} - #[automatically_derived] - impl ::core::cmp::Eq for Error { - #[inline] - #[doc(hidden)] - #[coverage(off)] - fn assert_receiver_is_total_eq(&self) -> () {} + } + const CHANNEL_MASK: u32 = 0b11000000; + #[repr(packed)] + pub struct RGBA { + pub red: u8, + pub green: u8, + pub blue: u8, + pub alpha: u8, + } + #[automatically_derived] + impl ::core::fmt::Debug for RGBA { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_struct_field4_finish( + f, + "RGBA", + "red", + &{ self.red }, + "green", + &{ self.green }, + "blue", + &{ self.blue }, + "alpha", + &&{ self.alpha }, + ) } - #[automatically_derived] - impl ::core::marker::StructuralPartialEq for Error {} - #[automatically_derived] - impl ::core::cmp::PartialEq for Error { - #[inline] - fn eq(&self, other: &Error) -> bool { - let __self_tag = ::core::intrinsics::discriminant_value(self); - let __arg1_tag = ::core::intrinsics::discriminant_value(other); - __self_tag == __arg1_tag - } + } + #[automatically_derived] + impl ::core::marker::StructuralPartialEq for RGBA {} + #[automatically_derived] + impl ::core::cmp::PartialEq for RGBA { + #[inline] + fn eq(&self, other: &RGBA) -> bool { + ({ self.red }) == ({ other.red }) && ({ self.green }) == ({ other.green }) + && ({ self.blue }) == ({ other.blue }) + && ({ self.alpha }) == ({ other.alpha }) } - pub enum PageState { - Reserved, - Free, - Used, + } + #[automatically_derived] + impl ::core::marker::StructuralEq for RGBA {} + #[automatically_derived] + impl ::core::cmp::Eq for RGBA { + #[inline] + #[doc(hidden)] + #[coverage(off)] + fn assert_receiver_is_total_eq(&self) -> () { + let _: ::core::cmp::AssertParamIsEq; } - #[automatically_derived] - impl ::core::marker::ConstParamTy for PageState {} - #[automatically_derived] - impl ::core::marker::StructuralPartialEq for PageState {} - #[automatically_derived] - impl ::core::cmp::PartialEq for PageState { - #[inline] - fn eq(&self, other: &PageState) -> bool { - let __self_tag = ::core::intrinsics::discriminant_value(self); - let __arg1_tag = ::core::intrinsics::discriminant_value(other); - __self_tag == __arg1_tag - } + } + impl Color { + #[inline(always)] + pub const fn new(code: u32) -> Self { + Self(code) } - #[automatically_derived] - impl ::core::marker::StructuralEq for PageState {} - #[automatically_derived] - impl ::core::cmp::Eq for PageState { - #[inline] - #[doc(hidden)] - #[coverage(off)] - fn assert_receiver_is_total_eq(&self) -> () {} + #[inline(always)] + pub const fn rgb(&self) -> (u8, u8, u8) { + ( + (self.0 & (CHANNEL_MASK >> 0)) as u8, + (self.0 & (CHANNEL_MASK >> 2)) as u8, + (self.0 & (CHANNEL_MASK >> 4)) as u8, + ) } - impl PageFrameAllocator { - pub unsafe fn from_response(resp: &MemmapResponse) -> PageFrameAllocator { - if core::intrinsics::unlikely((resp).entry_count == 0) { - ::core::panicking::panic("not implemented") - } - let mut largest_free_segment = None; - let mut largest_free_segment_size = 0; - let mut total_memory = 0; - for entry in (resp).memmap().iter() { - if entry.typ == MemoryMapEntryType::Usable - && entry.len > largest_free_segment_size - { - largest_free_segment = Some(entry); - largest_free_segment_size = entry.len; - } - total_memory += entry.len; - } - let mut bitmap = unsafe { - &mut *Self::place_bitmap_in_segment( - largest_free_segment, - (total_memory / crate::consts::PAGE_SIZE) as usize, - ) - .as_mut_ptr() - }; - bitmap.set(10, 1); - let mut _self = PageFrameAllocator { - bitmap: bitmap, - used_memory: 0x0, - free_memory: total_memory as usize, - reserved_memory: 0x0, - total_memory: total_memory as usize, - _initialized: false, - _bitmap_index: 0, - }; - _self.initialize(resp, largest_free_segment.unwrap()); - _self - } - pub fn get_free(&mut self) -> usize { - self.free_memory - } - pub fn get_used(&mut self) -> usize { - self.used_memory - } - pub fn get_reserved(&mut self) -> usize { - self.reserved_memory - } - pub fn get_total(&mut self) -> usize { - self.total_memory - } - pub fn place_bitmap_in_segment( - segment: Option<&NonNullPtr>, - pages: usize, - ) -> &mut core::mem::MaybeUninit { - if core::intrinsics::unlikely(segment.is_none()) { - ::core::panicking::panic("not implemented") - } - static mut _BITMAP: core::mem::MaybeUninit = core::mem::MaybeUninit::uninit(); - if let Some(_seg) = segment { - *(unsafe { - &mut _BITMAP - }) = core::mem::MaybeUninit::< - PageBitmap, - >::new( - (unsafe { - PageBitmap::from_storage( - pages + 1, - (), - PtrWrapper::< - [usize], - >::from_raw( - core::slice::from_raw_parts_mut( - _seg.base as *mut usize, - pages + 1, - ), - ), - ) - .unwrap() - }), - ); - return unsafe { &mut _BITMAP }; - } - ::core::panicking::panic("internal error: entered unreachable code"); - } - pub fn initialize( - &mut self, - memmap: &MemmapResponse, - bitmap_segment: &MemmapEntry, - ) -> Option<&mut Self> { - self.reserve_pages(0x0, self.total_memory / (PAGE_SIZE + 1) as usize); - for entry in memmap.memmap() { - if entry.typ == MemoryMapEntryType::Usable { - self.unreserve_pages( - entry.base as usize, - entry.len as usize / (PAGE_SIZE as usize) + 1 as usize, - ); - } - } - self.reserve_pages(0x0, 0x100); - self.lock_pages( - bitmap_segment.base as usize, - bitmap_segment.len as usize / (PAGE_SIZE + 1) as usize, - ); - self._initialized = true; - Some(self) - } - fn mark_page_as( - &mut self, - index: usize, - ) -> Result<(), Error> { - return match _state { - PageState::Reserved => { - self.bitmap.set(index, 1); - self.reserved_memory += PAGE_SIZE as usize; - self.free_memory -= PAGE_SIZE as usize; - Ok(()) - } - PageState::Free => { - self.bitmap.set(index, 0); - self.free_memory += PAGE_SIZE as usize; - self.used_memory -= PAGE_SIZE as usize; - Ok(()) - } - PageState::Used => { - self.bitmap.set(index, 1); - self.used_memory += PAGE_SIZE as usize; - self.free_memory -= PAGE_SIZE as usize; - Ok(()) - } - _ => { - ::core::panicking::panic( - "internal error: entered unreachable code", - ) - } - }; - } - fn disable_page_mark( - &mut self, - index: usize, - ) -> Result<(), Error> { - return match _state { - PageState::Reserved => { - self.bitmap.set(index, 0); - self.reserved_memory -= PAGE_SIZE as usize; - self.free_memory += PAGE_SIZE as usize; - Ok(()) - } - PageState::Free => ::core::panicking::panic("not implemented"), - PageState::Used => { - self.bitmap.set(index, 0); - self.used_memory -= PAGE_SIZE as usize; - self.free_memory += PAGE_SIZE as usize; - Ok(()) - } - _ => { - ::core::panicking::panic( - "internal error: entered unreachable code", - ) - } - }; - } - pub fn is_used_or_reserved(&mut self, addr: usize) -> bool { - let index = addr / PAGE_SIZE as usize; - return match self.bitmap.get(index).unwrap_or(INVALID_PAGE_STATE) { - 0 => false, - 1 => true, - _ => ::core::panicking::panic("not implemented"), - }; - } - pub fn free_page(&mut self, addr: usize) -> Result<(), Error> { - let index: usize = (addr / crate::consts::PAGE_SIZE as usize); - let state = self.bitmap.get(index).unwrap_or(INVALID_PAGE_STATE); - return match state { - 0 => Err(Error::AlreadyDone), - 1 => { - self.mark_page_as::<{ PageState::Used }>(index); - if self._bitmap_index > index { - self._bitmap_index = index; - } else { - return Ok(()); - } - Ok(()) - } - _ => Err(Error::OutOfBitmapBounds), - }; - ::core::panicking::panic("internal error: entered unreachable code"); - } - pub fn free_pages(&mut self, addr: usize, num: usize) -> Result<(), Error> { - for i in 0..num { - self.free_page(addr + (i * crate::consts::PAGE_SIZE as usize))?; - } - Ok(()) - } - pub fn lock_page(&mut self, addr: usize) -> Result<(), Error> { - let index: usize = addr / crate::consts::PAGE_SIZE as usize; - let state = self.bitmap.get(addr).unwrap_or(INVALID_PAGE_STATE); - return match state { - 0 => self.mark_page_as::<{ PageState::Used }>(index), - 1 => Err(Error::AlreadyDone), - _ => Err(Error::OutOfBitmapBounds), - }; - ::core::panicking::panic("internal error: entered unreachable code"); - } - pub fn lock_pages(&mut self, addr: usize, num: usize) -> Result<(), Error> { - for i in 0..num { - self.lock_page(addr + (i * crate::consts::PAGE_SIZE as usize))?; - } - Ok(()) - } - pub fn request_page(&mut self) -> Result { - while self._bitmap_index < self.bitmap.len() * 8 { - { - let state = self - .bitmap - .get(self._bitmap_index) - .unwrap_or(INVALID_PAGE_STATE); - let matched_state = match state { - 1 => Err(Error::Continue), - 0 => { - self.mark_page_as::< - { PageState::Used }, - >(self._bitmap_index)?; - return Ok(self._bitmap_index * PAGE_SIZE as usize); - } - _ => Err(Error::OutOfBitmapBounds), - }; - if matched_state != Err(Error::Continue) - && matched_state.is_err() + #[inline(always)] + pub const fn rgba(&self) -> (u8, u8, u8, u8) { + ( + (self.0 & (CHANNEL_MASK >> 0)) as u8, + (self.0 & (CHANNEL_MASK >> 2)) as u8, + (self.0 & (CHANNEL_MASK >> 4)) as u8, + (self.0 & (CHANNEL_MASK >> 6)) as u8, + ) + } + #[inline(always)] + pub const fn from_rgb(r: u8, b: u8, g: u8) -> Self { + Self::new( + ((r as u32) << 6) | ((r as u32) << 4) | ((r as u32) << 2) | 0x000000FF, + ) + } + #[inline(always)] + pub const fn inner(&self) -> u32 { + self.0 + } + } + impl Deref for Color { + type Target = RGBA; + #[inline] + fn deref(&'_ self) -> &'_ Self::Target { + let rgba = self.rgba(); + unsafe { core::mem::transmute(self) } + } + } +} +pub mod kernel_logger { + use core::sync::atomic::AtomicBool; + use alloc::format; + use log; + use crate::{ + kprint, tty::KERNEL_CONSOLE, device::character::UnsafeCharacterDevice, + renderer::Renderer, + }; + pub struct KernelLogger { + pub is_enabled: AtomicBool, + } + impl log::Log for KernelLogger { + fn enabled(&self, metadata: &log::Metadata) -> bool { + self.is_enabled.load(core::sync::atomic::Ordering::Relaxed) + } + fn log(&self, record: &log::Record) { + unsafe { + crate::KERNEL_CONSOLE + .write_str( { - return matched_state; - } else if matched_state.is_ok() { - return matched_state; + let res = ::alloc::fmt::format( + format_args!( + "[{0} {1}:{2}] {3}: {4}", + record.level(), + record.file().unwrap_or(""), + record.line().unwrap_or(0), + record.target(), + record.args(), + ), + ); + res } - } - self._bitmap_index += 1; - } - Err(Error::OutOfMemory) - } - fn reserve_page(&mut self, addr: usize) -> Result<(), Error> { - let index: usize = (addr / crate::consts::PAGE_SIZE as usize); - let state = self.bitmap.get(addr).unwrap_or(INVALID_PAGE_STATE); - return match state { - 0 => self.mark_page_as::<{ PageState::Reserved }>(index), - 1 => Err(Error::AlreadyDone), - _ => Err(Error::OutOfBitmapBounds), - }; - } - pub(self) fn reserve_pages( - &mut self, - addr: usize, - num: usize, - ) -> Result<(), Error> { - for i in 0..num { - self.reserve_page(addr + (i * crate::consts::PAGE_SIZE as usize))?; - } - Ok(()) - } - fn unreserve_page(&mut self, addr: usize) -> Result<(), Error> { - let index: usize = (addr / crate::consts::PAGE_SIZE as usize); - let state = self.bitmap.get(addr).unwrap_or(INVALID_PAGE_STATE); - return match state { - 1 => self.disable_page_mark::<{ PageState::Reserved }>(index), - 0 => Err(Error::AlreadyDone), - _ => Err(Error::OutOfBitmapBounds), - }; - } - pub(self) fn unreserve_pages( - &mut self, - addr: usize, - num: usize, - ) -> Result<(), Error> { - for i in 0..num { - self.unreserve_page(addr + (i * crate::consts::PAGE_SIZE as usize))?; - } - Ok(()) - } - pub fn is_initialized(&self) -> bool { - return self._initialized; - } - /// Safe version of `request_page`. - pub fn request_safe_page<'a>( - &mut self, - ) -> Result { - Ok(unsafe { super::SafePagePtr::unsafe_from_addr(self.request_page()?) }) - } - } - pub struct PtrWrapper(*mut T); - impl PtrWrapper { - pub unsafe fn from_raw(_val: &mut T) -> PtrWrapper { - Self(&mut *_val as *mut T) - } - } - impl bitmap::Storage for PtrWrapper<[usize]> { - fn as_ref(&self) -> &[usize] { - unsafe { &*self.0 } - } - fn as_mut(&mut self) -> &mut [usize] { - unsafe { &mut *self.0 } - } - } - } - pub mod table_manager { - use core::{ptr::NonNull, char::UNICODE_VERSION, f64::consts::E}; - use limine::NonNullPtr; - use crate::{common::_alloc_frame_as_mut_t, debug}; - use super::{PageTable, indexer::PageMapIndexer, PageTableEntry}; - use crate::memory::{PhysicalAddress, VirtualAddress}; - pub enum MemoryMapError { - FrameAllocator(super::frame_allocator::Error), - InvalidAddress, - TableNotFound, - } - #[automatically_derived] - impl ::core::fmt::Debug for MemoryMapError { - #[inline] - fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { - match self { - MemoryMapError::FrameAllocator(__self_0) => { - ::core::fmt::Formatter::debug_tuple_field1_finish( - f, - "FrameAllocator", - &__self_0, - ) - } - MemoryMapError::InvalidAddress => { - ::core::fmt::Formatter::write_str(f, "InvalidAddress") - } - MemoryMapError::TableNotFound => { - ::core::fmt::Formatter::write_str(f, "TableNotFound") - } - } + .as_str(), + ); + crate::KERNEL_CONSOLE.newline(); + }; + } + fn flush(&self) {} + } + pub(super) static mut KERNEL_LOGGER: KernelLogger = KernelLogger { + is_enabled: AtomicBool::new(true), + }; +} +pub mod legacy_pic { + //! Legacy PIC. + const PIC1_COMMAND: u16 = 0x20; + const PIC1_DATA: u16 = 0x21; + const PIC2_COMMAND: u16 = 0xA0; + const PIC2_DATA: u16 = 0xA1; + const PIC_EOI: u8 = 0x20; + const ICW1_INIT: u8 = 0x10; + const ICW1_ICW4: u8 = 0x01; + const ICW4_8086: u8 = 0x01; + use bit::BitIndex; + use super::io::{outb, inb, io_wait}; + pub struct PIC { + pub(self) master_mask: u8, + pub(self) slave_mask: u8, + } + pub enum Interrupt { + PIT, + } + #[automatically_derived] + impl ::core::fmt::Debug for Interrupt { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::write_str(f, "PIT") + } + } + impl Interrupt { + pub fn enable_in(self, pic: &'_ mut PIC, value: bool) { + match self { + Interrupt::PIT => pic.master_mask.set_bit(0, value), + _ => ::core::panicking::panic("not yet implemented"), + }; + } + } + impl PIC { + #[inline] + pub const fn new() -> Self { + Self { + master_mask: 0x00, + slave_mask: 0x00, } } - #[allow(non_snake_case)] - pub struct PageTableManager { - PML4: NonNullPtr, + pub unsafe fn remap(&self) { + let a1 = inb(PIC1_DATA); + io_wait(); + let a2 = inb(PIC2_DATA); + io_wait(); + outb(PIC1_COMMAND, ICW1_INIT | ICW1_ICW4); + io_wait(); + outb(PIC2_COMMAND, ICW1_INIT | ICW1_ICW4); + io_wait(); + outb(PIC1_DATA, 0x20); + io_wait(); + outb(PIC2_DATA, 0x28); + io_wait(); + outb(PIC1_DATA, 4); + io_wait(); + outb(PIC2_DATA, 2); + io_wait(); + outb(PIC1_DATA, ICW4_8086); + io_wait(); + outb(PIC2_DATA, ICW4_8086); + io_wait(); + outb(PIC1_DATA, a1); + io_wait(); + outb(PIC2_DATA, a2); } - pub(self) macro _page_table { - ($table : expr, $index : expr) => { { let mut entry = (& mut (& mut * - ($table).as_ptr()).entries[$index]); let result : NonNullPtr < PageTable > = - if ! entry.present() { let new_table = core::mem::transmute:: < NonNull < - PageTable >, NonNullPtr < PageTable >> (NonNull:: < PageTable > - ::new(_alloc_frame_as_mut_t:: < PageTable > ().map_err(| err | - MemoryMapError::FrameAllocator(err)) ?) - .ok_or(MemoryMapError::FrameAllocator(super::frame_allocator::Error::OutOfMemory)) - ?); entry.set_addr(new_table.as_ptr() as usize); entry.set_present(true); - entry.set_rw(true); new_table } else { - core::mem::transmute(NonNull::new(core::mem::transmute:: < usize, * mut - PageTable > (entry.addr().data())).ok_or(MemoryMapError::TableNotFound) ?) }; - result } } + pub unsafe fn needs_sync(&self) -> bool { + (self.master_mask != inb(PIC1_DATA)) || (self.slave_mask != inb(PIC2_DATA)) } - impl PageTableManager { - pub fn new() -> Option { - Some(PageTableManager { - PML4: unsafe { - core::mem::transmute( - NonNull::< - PageTable, - >::new(_alloc_frame_as_mut_t::().ok()?)?, - ) - }, - }) - } - pub fn from_pml4(pml4: NonNullPtr) -> Option { - Some(PageTableManager { PML4: pml4 }) - } - /// Internal Function for Mapping Memory. - pub(crate) unsafe fn map_memory_internal( - &self, - virtual_addr: VirtualAddress, - physical_addr: PhysicalAddress, - ) -> Result<(), MemoryMapError> { - let indexer = PageMapIndexer::for_addr(virtual_addr.data()); - let pdp = { - let mut entry = (&mut (&mut *(self.PML4).as_ptr()) - .entries[indexer.pdp]); - let result: NonNullPtr = if !entry.present() { - let new_table = core::mem::transmute::< - NonNull, - NonNullPtr, - >( - NonNull::< - PageTable, - >::new( - _alloc_frame_as_mut_t::() - .map_err(|err| MemoryMapError::FrameAllocator(err))?, - ) - .ok_or( - MemoryMapError::FrameAllocator( - super::frame_allocator::Error::OutOfMemory, - ), - )?, - ); - entry.set_addr(new_table.as_ptr() as usize); - entry.set_present(true); - entry.set_rw(true); - new_table - } else { - core::mem::transmute( - NonNull::new( - core::mem::transmute::< - usize, - *mut PageTable, - >(entry.addr().data()), - ) - .ok_or(MemoryMapError::TableNotFound)?, - ) - }; - result - }; - let pd = { - let mut entry = (&mut (&mut *(pdp).as_ptr()).entries[indexer.pd]); - let result: NonNullPtr = if !entry.present() { - let new_table = core::mem::transmute::< - NonNull, - NonNullPtr, - >( - NonNull::< - PageTable, - >::new( - _alloc_frame_as_mut_t::() - .map_err(|err| MemoryMapError::FrameAllocator(err))?, - ) - .ok_or( - MemoryMapError::FrameAllocator( - super::frame_allocator::Error::OutOfMemory, - ), - )?, - ); - entry.set_addr(new_table.as_ptr() as usize); - entry.set_present(true); - entry.set_rw(true); - new_table - } else { - core::mem::transmute( - NonNull::new( - core::mem::transmute::< - usize, - *mut PageTable, - >(entry.addr().data()), - ) - .ok_or(MemoryMapError::TableNotFound)?, - ) - }; - result - }; - let pt = { - let mut entry = (&mut (&mut *(pd).as_ptr()).entries[indexer.pt]); - let result: NonNullPtr = if !entry.present() { - let new_table = core::mem::transmute::< - NonNull, - NonNullPtr, - >( - NonNull::< - PageTable, - >::new( - _alloc_frame_as_mut_t::() - .map_err(|err| MemoryMapError::FrameAllocator(err))?, - ) - .ok_or( - MemoryMapError::FrameAllocator( - super::frame_allocator::Error::OutOfMemory, - ), - )?, - ); - entry.set_addr(new_table.as_ptr() as usize); - entry.set_present(true); - entry.set_rw(true); - new_table - } else { - core::mem::transmute( - NonNull::new( - core::mem::transmute::< - usize, - *mut PageTable, - >(entry.addr().data()), - ) - .ok_or(MemoryMapError::TableNotFound)?, - ) - }; - result - }; - let mut entry = &mut (&mut *pt.as_ptr()).entries[indexer.p]; - entry.set_addr(physical_addr.data()); - entry.set_present(true); - entry.set_rw(true); - Ok(()) - } - /// Internal Function for Mapping Memory. - pub(crate) unsafe fn get_page_entry( - &self, - virtual_addr: VirtualAddress, - ) -> Result { - let indexer = PageMapIndexer::for_addr(virtual_addr.data()); - let pdp = { - let mut entry = (&mut (&mut *(self.PML4).as_ptr()) - .entries[indexer.pdp]); - let result: NonNullPtr = if !entry.present() { - let new_table = core::mem::transmute::< - NonNull, - NonNullPtr, - >( - NonNull::< - PageTable, - >::new( - _alloc_frame_as_mut_t::() - .map_err(|err| MemoryMapError::FrameAllocator(err))?, - ) - .ok_or( - MemoryMapError::FrameAllocator( - super::frame_allocator::Error::OutOfMemory, - ), - )?, - ); - entry.set_addr(new_table.as_ptr() as usize); - entry.set_present(true); - entry.set_rw(true); - new_table - } else { - core::mem::transmute( - NonNull::new( - core::mem::transmute::< - usize, - *mut PageTable, - >(entry.addr().data()), - ) - .ok_or(MemoryMapError::TableNotFound)?, - ) - }; - result - }; - let pd = { - let mut entry = (&mut (&mut *(pdp).as_ptr()).entries[indexer.pd]); - let result: NonNullPtr = if !entry.present() { - let new_table = core::mem::transmute::< - NonNull, - NonNullPtr, - >( - NonNull::< - PageTable, - >::new( - _alloc_frame_as_mut_t::() - .map_err(|err| MemoryMapError::FrameAllocator(err))?, - ) - .ok_or( - MemoryMapError::FrameAllocator( - super::frame_allocator::Error::OutOfMemory, - ), - )?, - ); - entry.set_addr(new_table.as_ptr() as usize); - entry.set_present(true); - entry.set_rw(true); - new_table - } else { - core::mem::transmute( - NonNull::new( - core::mem::transmute::< - usize, - *mut PageTable, - >(entry.addr().data()), - ) - .ok_or(MemoryMapError::TableNotFound)?, - ) - }; - result - }; - let pt = { - let mut entry = (&mut (&mut *(pd).as_ptr()).entries[indexer.pt]); - let result: NonNullPtr = if !entry.present() { - let new_table = core::mem::transmute::< - NonNull, - NonNullPtr, - >( - NonNull::< - PageTable, - >::new( - _alloc_frame_as_mut_t::() - .map_err(|err| MemoryMapError::FrameAllocator(err))?, - ) - .ok_or( - MemoryMapError::FrameAllocator( - super::frame_allocator::Error::OutOfMemory, - ), - )?, - ); - entry.set_addr(new_table.as_ptr() as usize); - entry.set_present(true); - entry.set_rw(true); - new_table - } else { - core::mem::transmute( - NonNull::new( - core::mem::transmute::< - usize, - *mut PageTable, - >(entry.addr().data()), - ) - .ok_or(MemoryMapError::TableNotFound)?, - ) - }; - result - }; - let entry = &pt.entries[indexer.p]; - Ok(entry.data()) - } + pub unsafe fn sync(&self) { + self.remap(); + outb(PIC1_DATA, self.master_mask); + outb(PIC2_DATA, self.slave_mask); } - } - pub mod indexer { - pub struct PageMapIndexer { - pub pdp: usize, - pub pd: usize, - pub pt: usize, - pub p: usize, + pub fn enable(&mut self, int: Interrupt) { + int.enable_in(self, false) } - impl PageMapIndexer { - pub fn for_addr(addr: usize) -> Self { - let mut virtualAddress = addr; - virtualAddress >>= 12; - let p = virtualAddress & 0x1ff; - virtualAddress >>= 9; - let pt = virtualAddress & 0x1ff; - virtualAddress >>= 9; - let pd = virtualAddress & 0x1ff; - virtualAddress >>= 9; - let pdp = virtualAddress & 0x1ff; - virtualAddress >>= 9; - Self { pdp, pd, pt, p } - } + pub fn disable(&mut self, int: Interrupt) { + int.enable_in(self, true) } } - pub macro pf_allocator { - () => { (unsafe { & mut * crate ::PAGE_FRAME_ALLOCATOR.as_mut_ptr() }) } + pub(crate) static mut PRIMARY_PIC: PIC = PIC::new(); +} +pub mod memory { + //! Common Memory Structures, e.g [VirtualAddress]. + use numtoa::NumToA as _; + use x86_64::{VirtAddr, structures::paging::PageTable}; + /// Specific table to be used, needed on some architectures + pub enum TableKind { + /// Userspace page table + User, + /// Kernel page table + Kernel, } - #[must_use] - pub struct SafePagePtr( - usize, - ) - where - Self: Sync + Sized; - impl SafePagePtr { + #[automatically_derived] + impl ::core::clone::Clone for TableKind { #[inline] - pub fn new() -> Self { - ::core::panicking::panic("not implemented"); + fn clone(&self) -> TableKind { + *self } + } + #[automatically_derived] + impl ::core::marker::Copy for TableKind {} + #[automatically_derived] + impl ::core::fmt::Debug for TableKind { #[inline] - pub unsafe fn unsafe_from_addr(addr: usize) -> Self { - core::intrinsics::assume(addr != 0); - core::intrinsics::assume(addr != usize::MAX); - core::intrinsics::transmute::(addr) + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::write_str( + f, + match self { + TableKind::User => "User", + TableKind::Kernel => "Kernel", + }, + ) } + } + #[automatically_derived] + impl ::core::marker::StructuralEq for TableKind {} + #[automatically_derived] + impl ::core::cmp::Eq for TableKind { #[inline] - pub unsafe fn as_ptr(self) -> *const u8 { - core::intrinsics::transmute::(self) - } + #[doc(hidden)] + #[coverage(off)] + fn assert_receiver_is_total_eq(&self) -> () {} + } + #[automatically_derived] + impl ::core::cmp::Ord for TableKind { #[inline] - pub unsafe fn as_mut_ptr(self) -> *mut u8 { - core::intrinsics::transmute::(self) - } - #[inline] - pub unsafe fn to_ref_t(&self) -> &T { - core::intrinsics::transmute::<&Self, &T>(self) - } - #[inline] - pub unsafe fn to_mut_ref_t(&mut self) -> &mut Ptr { - core::intrinsics::transmute::<&mut Self, &mut Ptr>(self) - } - #[inline] - pub unsafe fn unchecked_raw_transmute(self) -> *mut T { - core::intrinsics::assume( - core::mem::size_of::() <= crate::consts::PAGE_SIZE as usize, - ); - core::intrinsics::transmute_unchecked::(self) - } - #[inline] - #[must_use] - pub fn free(&mut self) { - (unsafe { &mut *crate::PAGE_FRAME_ALLOCATOR.as_mut_ptr() }) - .free_page(self.0) - .unwrap(); - } - } - impl Drop for SafePagePtr { - fn drop(&mut self) { - self.free(); - } - } - pub struct PageTableEntry(usize); - impl PageTableEntry { - pub fn present(&self) -> bool { - self.0.bit(1) - } - pub fn set_present(&mut self, value: bool) { - self.0.set_bit(0, value); - } - pub fn rw(&self) -> bool { - self.0.bit(1) - } - pub fn set_rw(&mut self, value: bool) { - self.0.set_bit(1, value); - } - pub fn addr(&self) -> PhysicalAddress { - PhysicalAddress::new(self.0 & 0x0000_FFFF_FFFF_F000) - } - pub fn set_addr(&mut self, value: usize) { - self.0.set_bit_range(12..64, value); - } - pub fn data(&self) -> usize { - self.0 - } - } - #[repr(align(0x1000))] - pub struct PageTable { - pub entries: [PageTableEntry; 512], - } -} -pub mod renderer { - type Color = u32; - use crate::bitmap_font::{BitmapCharImpl, BitmapFont}; - use crate::framebuffer::Framebuffer; - pub struct Renderer { - target_fb: &'static Framebuffer, - foreground_color: Color, - background_color: Color, - bitmap_font: &'static BitmapFont, - } - pub enum RendererError { - OutOfBounds, - } - impl Renderer { - pub fn new(fb: &'static Framebuffer, font: &'static BitmapFont) -> Renderer { - Self { - target_fb: fb, - foreground_color: 0xFFFFFFFF, - background_color: 0x00000000, - bitmap_font: font, - } - } - pub unsafe fn unsafe_put_pixel(&self, x: usize, y: usize, color: Color) { - let pixel_offset = x * (self.target_fb.pitch as usize + y); - *(self.target_fb.address.as_ptr().unwrap().offset(pixel_offset as isize) - as *mut Color) = color; - } - pub unsafe fn unsafe_pull_pixel(&self, x: usize, y: usize) -> Color { - let pixel_offset = x * (self.target_fb.pitch as usize + y); - *(self.target_fb.address.as_ptr().unwrap().offset(pixel_offset as isize) - as *mut Color) - } - pub unsafe fn unsafe_draw_char(&self, off_x: usize, off_y: usize, chr: i8) { - for x in 0..8 as usize { - for y in 0..8 as usize { - self.unsafe_put_pixel( - off_x + x, - off_y + y, - if self.bitmap_font[chr as usize].is_set(x, y) { - self.foreground_color - } else { - self.background_color - }, - ); - } - } - } - } -} -pub mod serial { - #[macro_use] - use crate::common::macros; - use crate::common::io::{inb, io_wait, outb}; - use crate::device::{ - character::{CharacterDeviceMode, TimedCharacterDevice, UnsafeCharacterDevice}, - Device, GeneralDevice, - }; - pub enum Port { - COM1 = 0x3F8, - COM2 = 0x2F8, - COM3 = 0x3E8, - COM4 = 0x2E8, - COM5 = 0x5F8, - COM6 = 0x4F8, - COM7 = 0x5E8, - COM8 = 0x4E8, - } - impl Port { - pub fn get_addr(&self) -> u16 { - match self { - Port::COM1 => 0x3F8, - Port::COM2 => 0x2F8, - Port::COM3 => 0x3E8, - Port::COM4 => 0x2E8, - Port::COM5 => 0x5F8, - Port::COM6 => 0x4F8, - Port::COM7 => 0x5E8, - Port::COM8 => 0x4E8, - } - } - } - impl GeneralDevice for Port { - fn as_device(&self) -> crate::device::Device<'_> { - Device::Character(self) - } - } - impl UnsafeCharacterDevice for Port { - unsafe fn read_raw(&self) -> u8 { - inb(self.get_addr()) as u8 - } - unsafe fn write_raw(&self, data: u8) { - outb(self.get_addr(), data as u8); - } - unsafe fn test(&self) -> bool { - outb(self.get_addr() + 1, 0x00); - outb(self.get_addr() + 3, 0x80); - outb(self.get_addr() + 0, 0x03); - outb(self.get_addr() + 1, 0x00); - outb(self.get_addr() + 3, 0x03); - outb(self.get_addr() + 2, 0xC7); - outb(self.get_addr() + 4, 0x0B); - outb(self.get_addr() + 4, 0x1E); - outb(self.get_addr() + 0, 0xAE); - if (inb(self.get_addr() + 0) != 0xAE) { - return true; - } - outb(self.get_addr() + 4, 0x0F); - return false; - } - unsafe fn init(&mut self) -> bool { - true - } - unsafe fn received(&self) -> bool { - (inb(self.get_addr() + 5) & 1) != 0 - } - unsafe fn is_transmit_empty(&self) -> bool { - (inb(self.get_addr() + 5) & 0x20) != 0 - } - fn set_mode(&mut self, mode: CharacterDeviceMode) {} - fn get_mode(&self) -> CharacterDeviceMode { - CharacterDeviceMode::Normal - } - } - impl TimedCharacterDevice for Port { - unsafe fn read(&self) -> u8 { - while !self.received() {} - self.read_raw() - } - unsafe fn write(&self, data: u8) { - while !self.is_transmit_empty() {} - self.write_raw(data) - } - unsafe fn wait(&self) {} - } - impl Port - where - Self: UnsafeCharacterDevice, - Self: TimedCharacterDevice, - { - pub fn wait_for_connection(&self) { - unsafe { - while self.test() {} - self.unsafe_write_string("(CONNECTED)\n\r"); - } - } - pub unsafe fn unsafe_write_string(&self, _str: &'static str) { - for chr in _str.chars() { - self.write(chr as u8); - } - } - pub unsafe fn unsafe_write_line(&self, _str: &'static str) { - self.unsafe_write_string(_str); - self.unsafe_write_string("\n\r"); - } - pub unsafe fn unsafe_read_string(&self, len: usize) -> &'static str { - ::core::panicking::panic("not implemented"); - } - } -} -pub mod status {} -pub mod memory { - //! Common Memory Structures, e.g [VirtualAddress]. - /// Specific table to be used, needed on some architectures - pub enum TableKind { - /// Userspace page table - User, - /// Kernel page table - Kernel, - } - #[automatically_derived] - impl ::core::clone::Clone for TableKind { - #[inline] - fn clone(&self) -> TableKind { - *self - } - } - #[automatically_derived] - impl ::core::marker::Copy for TableKind {} - #[automatically_derived] - impl ::core::fmt::Debug for TableKind { - #[inline] - fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { - ::core::fmt::Formatter::write_str( - f, - match self { - TableKind::User => "User", - TableKind::Kernel => "Kernel", - }, - ) - } - } - #[automatically_derived] - impl ::core::marker::StructuralEq for TableKind {} - #[automatically_derived] - impl ::core::cmp::Eq for TableKind { - #[inline] - #[doc(hidden)] - #[coverage(off)] - fn assert_receiver_is_total_eq(&self) -> () {} - } - #[automatically_derived] - impl ::core::cmp::Ord for TableKind { - #[inline] - fn cmp(&self, other: &TableKind) -> ::core::cmp::Ordering { - let __self_tag = ::core::intrinsics::discriminant_value(self); - let __arg1_tag = ::core::intrinsics::discriminant_value(other); - ::core::cmp::Ord::cmp(&__self_tag, &__arg1_tag) + fn cmp(&self, other: &TableKind) -> ::core::cmp::Ordering { + let __self_tag = ::core::intrinsics::discriminant_value(self); + let __arg1_tag = ::core::intrinsics::discriminant_value(other); + ::core::cmp::Ord::cmp(&__self_tag, &__arg1_tag) } } #[automatically_derived] @@ -2476,6 +2065,18 @@ pub mod memory { ::core::cmp::PartialOrd::partial_cmp(&__self_tag, &__arg1_tag) } } + pub(crate) const PHYSICAL_MEMORY_OFFSET: usize = 0xffffffff80000000; + pub(crate) const PHYSICAL_BOOTLOADER_MEMORY_OFFSET: u64 = 0x00; + pub(crate) unsafe fn active_level_4_table( + physical_memory_offset: VirtAddr, + ) -> &'static mut PageTable { + use x86_64::registers::control::Cr3; + let (level_4_table_frame, _) = Cr3::read(); + let phys = level_4_table_frame.start_address(); + let virt = VirtAddr::new_unsafe(phys.as_u64()); + let page_table_ptr: *mut PageTable = virt.as_mut_ptr(); + &mut *page_table_ptr + } /// Physical memory address #[repr(transparent)] pub struct PhysicalAddress(usize); @@ -2550,6 +2151,12 @@ pub mod memory { pub fn add(self, offset: usize) -> Self { Self(self.0 + offset) } + pub fn as_str<'a>(&self) -> &'a str { + self.0.numtoa_str(16, unsafe { &mut crate::GENERIC_STATIC_BUFFER }) + } + pub fn to_virtual(&self) -> VirtualAddress { + VirtualAddress::new(PHYSICAL_MEMORY_OFFSET + (self.data() >> 12)) + } } /// Virtual memory address #[repr(transparent)] @@ -2618,16 +2225,29 @@ pub mod memory { pub fn kind(&self) -> TableKind { if (self.0 as isize) < 0 { TableKind::Kernel } else { TableKind::User } } + pub fn as_str<'a>(&self) -> &'a str { + self.0.numtoa_str(16, unsafe { &mut crate::GENERIC_STATIC_BUFFER }) + } + pub unsafe fn as_ptr(&self) -> *mut u8 { + core::mem::transmute::<_, *mut u8>(self.0) + } + } + impl alloc::fmt::Debug for VirtualAddress { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_tuple("VirtualAddress") + .field_with(|v| v.write_fmt(format_args!("{0:#x}", &self.0))) + .finish() + } } pub struct MemoryArea { - pub base: PhysicalAddress, + pub base: VirtualAddress, pub size: usize, } #[automatically_derived] impl ::core::clone::Clone for MemoryArea { #[inline] fn clone(&self) -> MemoryArea { - let _: ::core::clone::AssertParamIsClone; + let _: ::core::clone::AssertParamIsClone; let _: ::core::clone::AssertParamIsClone; *self } @@ -2648,344 +2268,6111 @@ pub mod memory { ) } } + impl MemoryArea { + pub const fn new(base: usize, size: usize) -> Self { + Self { + base: VirtualAddress::new(base), + size, + } + } + } } -use crate::common::*; -use crate::device::{ - character::{TimedCharacterDevice, *}, - Device, GeneralDevice, -}; -use crate::memory::{VirtualAddress, PhysicalAddress}; -use crate::paging::table_manager::PageTableManager; -use core::arch::asm; -use core::ffi::CStr; -#[macro_use] -use core::intrinsics::{likely, unlikely}; -#[macro_use] -use core::fmt::*; -use core::mem; -use crate::paging::{pf_allocator, PageTable}; -#[macro_use] -extern crate bitfield; -static TERMINAL_REQUEST: limine::TerminalRequest = limine::TerminalRequest::new(0); -static MEMMAP_REQUEST: limine::MemmapRequest = limine::MemmapRequest::new(0); -static KERNEL_ADDRESS_REQUEST: limine::KernelAddressRequest = limine::KernelAddressRequest::new( - 0, -); -static KERNEL_FILE_REQUEST: limine::KernelFileRequest = limine::KernelFileRequest::new( - 0, -); -static MODULE_REQUEST: limine::ModuleRequest = limine::ModuleRequest::new(0); -static TEST1: &'static str = "Hello Paging!"; -static TEST2: &'static str = "):"; -static mut PAGE_FRAME_ALLOCATOR: core::mem::MaybeUninit< - crate::paging::frame_allocator::PageFrameAllocator, -> = core::mem::MaybeUninit::uninit(); -static mut ITOA_BUFFER: core::mem::MaybeUninit = core::mem::MaybeUninit::uninit(); -static mut PRIMARY_FRAMEBUFFER: core::mem::MaybeUninit< - crate::framebuffer::Framebuffer, -> = core::mem::MaybeUninit::uninit(); -static mut KERNEL_CMDLINE: core::mem::MaybeUninit<&'static str> = core::mem::MaybeUninit::uninit(); -static mut KERNEL_PATH: core::mem::MaybeUninit<&'static str> = core::mem::MaybeUninit::uninit(); -pub const FONT_BITMAP: bitmap_font::BitmapFont = [ - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x18, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18, 0x00], - [0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x36, 0x36, 0x7F, 0x36, 0x7F, 0x36, 0x36, 0x00], - [0x0C, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x0C, 0x00], - [0x00, 0x63, 0x33, 0x18, 0x0C, 0x66, 0x63, 0x00], - [0x1C, 0x36, 0x1C, 0x6E, 0x3B, 0x33, 0x6E, 0x00], - [0x06, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x18, 0x0C, 0x06, 0x06, 0x06, 0x0C, 0x18, 0x00], - [0x06, 0x0C, 0x18, 0x18, 0x18, 0x0C, 0x06, 0x00], - [0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00], - [0x00, 0x0C, 0x0C, 0x3F, 0x0C, 0x0C, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x06], - [0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x00], - [0x60, 0x30, 0x18, 0x0C, 0x06, 0x03, 0x01, 0x00], - [0x3E, 0x63, 0x73, 0x7B, 0x6F, 0x67, 0x3E, 0x00], - [0x0C, 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x3F, 0x00], - [0x1E, 0x33, 0x30, 0x1C, 0x06, 0x33, 0x3F, 0x00], - [0x1E, 0x33, 0x30, 0x1C, 0x30, 0x33, 0x1E, 0x00], - [0x38, 0x3C, 0x36, 0x33, 0x7F, 0x30, 0x78, 0x00], - [0x3F, 0x03, 0x1F, 0x30, 0x30, 0x33, 0x1E, 0x00], - [0x1C, 0x06, 0x03, 0x1F, 0x33, 0x33, 0x1E, 0x00], - [0x3F, 0x33, 0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x00], - [0x1E, 0x33, 0x33, 0x1E, 0x33, 0x33, 0x1E, 0x00], - [0x1E, 0x33, 0x33, 0x3E, 0x30, 0x18, 0x0E, 0x00], - [0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x00], - [0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x06], - [0x18, 0x0C, 0x06, 0x03, 0x06, 0x0C, 0x18, 0x00], - [0x00, 0x00, 0x3F, 0x00, 0x00, 0x3F, 0x00, 0x00], - [0x06, 0x0C, 0x18, 0x30, 0x18, 0x0C, 0x06, 0x00], - [0x1E, 0x33, 0x30, 0x18, 0x0C, 0x00, 0x0C, 0x00], - [0x3E, 0x63, 0x7B, 0x7B, 0x7B, 0x03, 0x1E, 0x00], - [0x0C, 0x1E, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x00], - [0x3F, 0x66, 0x66, 0x3E, 0x66, 0x66, 0x3F, 0x00], - [0x3C, 0x66, 0x03, 0x03, 0x03, 0x66, 0x3C, 0x00], - [0x1F, 0x36, 0x66, 0x66, 0x66, 0x36, 0x1F, 0x00], - [0x7F, 0x46, 0x16, 0x1E, 0x16, 0x46, 0x7F, 0x00], - [0x7F, 0x46, 0x16, 0x1E, 0x16, 0x06, 0x0F, 0x00], - [0x3C, 0x66, 0x03, 0x03, 0x73, 0x66, 0x7C, 0x00], - [0x33, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x33, 0x00], - [0x1E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00], - [0x78, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E, 0x00], - [0x67, 0x66, 0x36, 0x1E, 0x36, 0x66, 0x67, 0x00], - [0x0F, 0x06, 0x06, 0x06, 0x46, 0x66, 0x7F, 0x00], - [0x63, 0x77, 0x7F, 0x7F, 0x6B, 0x63, 0x63, 0x00], - [0x63, 0x67, 0x6F, 0x7B, 0x73, 0x63, 0x63, 0x00], - [0x1C, 0x36, 0x63, 0x63, 0x63, 0x36, 0x1C, 0x00], - [0x3F, 0x66, 0x66, 0x3E, 0x06, 0x06, 0x0F, 0x00], - [0x1E, 0x33, 0x33, 0x33, 0x3B, 0x1E, 0x38, 0x00], - [0x3F, 0x66, 0x66, 0x3E, 0x36, 0x66, 0x67, 0x00], - [0x1E, 0x33, 0x07, 0x0E, 0x38, 0x33, 0x1E, 0x00], - [0x3F, 0x2D, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00], - [0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x3F, 0x00], - [0x33, 0x33, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00], - [0x63, 0x63, 0x63, 0x6B, 0x7F, 0x77, 0x63, 0x00], - [0x63, 0x63, 0x36, 0x1C, 0x1C, 0x36, 0x63, 0x00], - [0x33, 0x33, 0x33, 0x1E, 0x0C, 0x0C, 0x1E, 0x00], - [0x7F, 0x63, 0x31, 0x18, 0x4C, 0x66, 0x7F, 0x00], - [0x1E, 0x06, 0x06, 0x06, 0x06, 0x06, 0x1E, 0x00], - [0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x40, 0x00], - [0x1E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1E, 0x00], - [0x08, 0x1C, 0x36, 0x63, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF], - [0x0C, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x1E, 0x30, 0x3E, 0x33, 0x6E, 0x00], - [0x07, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x3B, 0x00], - [0x00, 0x00, 0x1E, 0x33, 0x03, 0x33, 0x1E, 0x00], - [0x38, 0x30, 0x30, 0x3e, 0x33, 0x33, 0x6E, 0x00], - [0x00, 0x00, 0x1E, 0x33, 0x3f, 0x03, 0x1E, 0x00], - [0x1C, 0x36, 0x06, 0x0f, 0x06, 0x06, 0x0F, 0x00], - [0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x1F], - [0x07, 0x06, 0x36, 0x6E, 0x66, 0x66, 0x67, 0x00], - [0x0C, 0x00, 0x0E, 0x0C, 0x0C, 0x0C, 0x1E, 0x00], - [0x30, 0x00, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E], - [0x07, 0x06, 0x66, 0x36, 0x1E, 0x36, 0x67, 0x00], - [0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00], - [0x00, 0x00, 0x33, 0x7F, 0x7F, 0x6B, 0x63, 0x00], - [0x00, 0x00, 0x1F, 0x33, 0x33, 0x33, 0x33, 0x00], - [0x00, 0x00, 0x1E, 0x33, 0x33, 0x33, 0x1E, 0x00], - [0x00, 0x00, 0x3B, 0x66, 0x66, 0x3E, 0x06, 0x0F], - [0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x78], - [0x00, 0x00, 0x3B, 0x6E, 0x66, 0x06, 0x0F, 0x00], - [0x00, 0x00, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x00], - [0x08, 0x0C, 0x3E, 0x0C, 0x0C, 0x2C, 0x18, 0x00], - [0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x6E, 0x00], - [0x00, 0x00, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00], - [0x00, 0x00, 0x63, 0x6B, 0x7F, 0x7F, 0x36, 0x00], - [0x00, 0x00, 0x63, 0x36, 0x1C, 0x36, 0x63, 0x00], - [0x00, 0x00, 0x33, 0x33, 0x33, 0x3E, 0x30, 0x1F], - [0x00, 0x00, 0x3F, 0x19, 0x0C, 0x26, 0x3F, 0x00], - [0x38, 0x0C, 0x0C, 0x07, 0x0C, 0x0C, 0x38, 0x00], - [0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00], - [0x07, 0x0C, 0x0C, 0x38, 0x0C, 0x0C, 0x07, 0x00], - [0x6E, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], -]; -pub const DEBUG_LINE: serial::Port = serial::Port::COM1; -pub fn integer_to_string<'_str, I: itoa::Integer>(value: I) -> &'_str str { - let mut buf = unsafe { &mut ITOA_BUFFER }; - *(unsafe { - &mut ITOA_BUFFER - }) = core::mem::MaybeUninit::::new(({ itoa::Buffer::new() })); - unsafe { (*(*buf).as_mut_ptr()).format::(value) } -} -struct Person { - id: i32, - age: i32, - name: &'static str, -} -pub unsafe extern "C" fn irq0_timer() { - unsafe { DEBUG_LINE.unsafe_write_line("Tick!") } +pub mod debug { + use core::{ + sync::atomic::{AtomicBool, Ordering::SeqCst}, + arch, + }; + use crate::{serial::Port, device::character::UnsafeCharacterDevice}; + static DEBUG_ENABLED: AtomicBool = AtomicBool::new(false); + pub fn toggle_debug(boolean: bool) { + DEBUG_ENABLED.store(boolean, SeqCst); + } + pub fn is_debug_enabled() -> bool { + DEBUG_ENABLED.load(SeqCst) + } } -#[no_mangle] -unsafe extern "C" fn _start<'_kernel>() -> ! { - DEBUG_LINE.wait_for_connection(); - let mut total_memory = 0; - if let Some(memmap_response) = MEMMAP_REQUEST.get_response().get() { - DEBUG_LINE.unsafe_write_line("Got Memory Map Response"); - if core::intrinsics::likely(memmap_response.entry_count > 0) { - for (index, entry) in memmap_response.memmap().iter().enumerate() { - DEBUG_LINE.unsafe_write_string("MemoryMapEntry { index = "); - DEBUG_LINE.unsafe_write_string(integer_to_string(index)); - DEBUG_LINE.unsafe_write_string(", base = "); - DEBUG_LINE.unsafe_write_string(integer_to_string(entry.base)); - DEBUG_LINE.unsafe_write_string(", length = "); - DEBUG_LINE.unsafe_write_string(integer_to_string(entry.len)); - DEBUG_LINE.unsafe_write_string(", type = \""); - DEBUG_LINE - .unsafe_write_string( - match entry.typ { - MemoryMapEntryType::Usable => "Usable", - MemoryMapEntryType::Reserved => "Reserved", - MemoryMapEntryType::KernelAndModules - | MemoryMapEntryType::Framebuffer => "Kernel/Framebuffer", - _ => "Other", - }, - ); - DEBUG_LINE.unsafe_write_string("\", }\n\r"); - total_memory += entry.len; +pub mod paging { + use core::marker; + use bit::BitIndex; + use numtoa::NumToA; + use crate::memory::PhysicalAddress; + pub mod frame_allocator { + use core::{ptr::NonNull, sync::atomic::AtomicPtr}; + use crate::{ + consts::{INVALID_PAGE_STATE, PAGE_SIZE}, + debug, endl, extra_features, memory::{MemoryArea, PhysicalAddress}, + }; + use alloc::sync::Arc; + use limine::{MemmapEntry, MemmapResponse, MemoryMapEntryType, NonNullPtr}; + use x86_64::{ + structures::paging::{Size4KiB, PhysFrame}, + PhysAddr, + }; + pub type PageBitmap = bitmap::Bitmap, bitmap::OneBit>; + pub struct PageFrameAllocator { + pub bitmap: &'static mut PageBitmap, + used_memory: usize, + free_memory: usize, + reserved_memory: usize, + total_memory: usize, + _initialized: bool, + _bitmap_index: usize, + } + macro decl_multi_page_fn { + ([$_meta : vis] $name : ident => $target_name : ident(...)) => { $_meta fn + $name (& mut self, addr : usize, num : usize) -> Result < (), Error > { for i + in 0..num { self.$target_name (addr + (i * crate ::consts::PAGE_SIZE as + usize)) ?; } Ok(()) } } + } + pub enum Error { + UninitializedAllocator, + OutOfMemory, + AlreadyDone, + CorruptedBitmap, + OutOfBitmapBounds, + InvalidPointer, + InvalidAlignment, + Continue, + } + #[automatically_derived] + impl ::core::fmt::Debug for Error { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::write_str( + f, + match self { + Error::UninitializedAllocator => "UninitializedAllocator", + Error::OutOfMemory => "OutOfMemory", + Error::AlreadyDone => "AlreadyDone", + Error::CorruptedBitmap => "CorruptedBitmap", + Error::OutOfBitmapBounds => "OutOfBitmapBounds", + Error::InvalidPointer => "InvalidPointer", + Error::InvalidAlignment => "InvalidAlignment", + Error::Continue => "Continue", + }, + ) + } + } + #[automatically_derived] + impl ::core::marker::StructuralEq for Error {} + #[automatically_derived] + impl ::core::cmp::Eq for Error { + #[inline] + #[doc(hidden)] + #[coverage(off)] + fn assert_receiver_is_total_eq(&self) -> () {} + } + #[automatically_derived] + impl ::core::marker::StructuralPartialEq for Error {} + #[automatically_derived] + impl ::core::cmp::PartialEq for Error { + #[inline] + fn eq(&self, other: &Error) -> bool { + let __self_tag = ::core::intrinsics::discriminant_value(self); + let __arg1_tag = ::core::intrinsics::discriminant_value(other); + __self_tag == __arg1_tag + } + } + pub enum PageState { + Reserved, + Free, + Used, + } + #[automatically_derived] + impl ::core::marker::ConstParamTy for PageState {} + #[automatically_derived] + impl ::core::marker::StructuralPartialEq for PageState {} + #[automatically_derived] + impl ::core::cmp::PartialEq for PageState { + #[inline] + fn eq(&self, other: &PageState) -> bool { + let __self_tag = ::core::intrinsics::discriminant_value(self); + let __arg1_tag = ::core::intrinsics::discriminant_value(other); + __self_tag == __arg1_tag + } + } + #[automatically_derived] + impl ::core::marker::StructuralEq for PageState {} + #[automatically_derived] + impl ::core::cmp::Eq for PageState { + #[inline] + #[doc(hidden)] + #[coverage(off)] + fn assert_receiver_is_total_eq(&self) -> () {} + } + impl PageFrameAllocator { + pub unsafe fn from_response(resp: &MemmapResponse) -> PageFrameAllocator { + if core::intrinsics::unlikely((resp).entry_count == 0) { + ::core::panicking::panic("not implemented") + } + let mut largest_free_segment = None; + let mut largest_free_segment_size = 0; + let mut total_memory = 0; + for entry in (resp).memmap().iter() { + if entry.typ == MemoryMapEntryType::Usable + && entry.len > largest_free_segment_size + { + largest_free_segment = Some(entry); + largest_free_segment_size = entry.len; + } + total_memory += entry.len; + } + let mut bitmap = unsafe { + &mut *Self::place_bitmap_in_segment( + largest_free_segment, + (total_memory / crate::consts::PAGE_SIZE) as usize, + ) + .as_mut_ptr() + }; + bitmap.set(10, 1); + let mut _self = PageFrameAllocator { + bitmap: bitmap, + used_memory: 0x0, + free_memory: total_memory as usize, + reserved_memory: 0x0, + total_memory: total_memory as usize, + _initialized: false, + _bitmap_index: 0, + }; + _self.initialize(resp, largest_free_segment.unwrap()); + _self + } + pub fn get_free(&mut self) -> usize { + self.free_memory + } + pub fn get_used(&mut self) -> usize { + self.used_memory + } + pub fn get_reserved(&mut self) -> usize { + self.reserved_memory + } + pub fn get_total(&mut self) -> usize { + self.total_memory + } + pub fn place_bitmap_in_segment( + segment: Option<&NonNullPtr>, + pages: usize, + ) -> &mut core::mem::MaybeUninit { + if core::intrinsics::unlikely(segment.is_none()) { + ::core::panicking::panic("not implemented") + } + static mut _BITMAP: core::mem::MaybeUninit = core::mem::MaybeUninit::uninit(); + if let Some(_seg) = segment { + *(unsafe { + &mut _BITMAP + }) = core::mem::MaybeUninit::< + PageBitmap, + >::new( + (unsafe { + PageBitmap::from_storage( + pages + 1, + (), + PtrWrapper::< + [usize], + >::from_raw( + core::slice::from_raw_parts_mut( + _seg.base as *mut usize, + pages + 1, + ), + ), + ) + .unwrap() + }), + ); + return unsafe { &mut _BITMAP }; + } + ::core::panicking::panic("internal error: entered unreachable code"); + } + pub fn initialize( + &mut self, + memmap: &MemmapResponse, + bitmap_segment: &MemmapEntry, + ) -> Option<&mut Self> { + self.reserve_pages(0x0, self.total_memory / (PAGE_SIZE + 1) as usize); + for entry in memmap.memmap() { + if entry.typ == MemoryMapEntryType::Usable { + self.unreserve_pages( + entry.base as usize, + entry.len as usize / (PAGE_SIZE as usize) + 1 as usize, + ); + } + } + self.reserve_pages(0x0, 0x100); + self.lock_pages( + bitmap_segment.base as usize, + (bitmap_segment.len / PAGE_SIZE) as usize + 1 as usize, + ); + self.lock_pages( + crate::KERNEL_BASE.physical_base as usize, + (crate::KERNEL_FILE.length / PAGE_SIZE + 1) as usize, + ); + for fb in crate::FRAMEBUFFERS.iter() { + if let Some(ptr) = fb.address.as_ptr() { + self.lock_pages( + ptr.addr(), + (fb.height * fb.width / PAGE_SIZE) as usize + 1, + ); + } + } + self._initialized = true; + Some(self) + } + fn mark_page_as( + &mut self, + index: usize, + ) -> Result<(), Error> { + return match _state { + PageState::Reserved => { + self.bitmap.set(index, 1); + self.reserved_memory += PAGE_SIZE as usize; + self.free_memory -= PAGE_SIZE as usize; + Ok(()) + } + PageState::Free => { + self.bitmap.set(index, 0); + self.free_memory += PAGE_SIZE as usize; + self.used_memory -= PAGE_SIZE as usize; + Ok(()) + } + PageState::Used => { + self.bitmap.set(index, 1); + self.used_memory += PAGE_SIZE as usize; + self.free_memory -= PAGE_SIZE as usize; + Ok(()) + } + _ => { + ::core::panicking::panic( + "internal error: entered unreachable code", + ) + } + }; + } + fn disable_page_mark( + &mut self, + index: usize, + ) -> Result<(), Error> { + return match _state { + PageState::Reserved => { + self.bitmap.set(index, 0); + self.reserved_memory -= PAGE_SIZE as usize; + self.free_memory += PAGE_SIZE as usize; + Ok(()) + } + PageState::Free => ::core::panicking::panic("not implemented"), + PageState::Used => { + self.bitmap.set(index, 0); + self.used_memory -= PAGE_SIZE as usize; + self.free_memory += PAGE_SIZE as usize; + Ok(()) + } + _ => { + ::core::panicking::panic( + "internal error: entered unreachable code", + ) + } + }; + } + pub fn is_used_or_reserved(&mut self, addr: usize) -> bool { + let index = addr / PAGE_SIZE as usize; + return match self.bitmap.get(index).unwrap_or(INVALID_PAGE_STATE) { + 0 => false, + 1 => true, + _ => ::core::panicking::panic("not implemented"), + }; + } + pub fn free_page(&mut self, addr: usize) -> Result<(), Error> { + let index: usize = (addr / crate::consts::PAGE_SIZE as usize); + let state = self.bitmap.get(index).unwrap_or(INVALID_PAGE_STATE); + return match state { + 0 => Err(Error::AlreadyDone), + 1 => { + self.mark_page_as::<{ PageState::Used }>(index); + if self._bitmap_index > index { + self._bitmap_index = index; + } else { + return Ok(()); + } + Ok(()) + } + _ => Err(Error::OutOfBitmapBounds), + }; + ::core::panicking::panic("internal error: entered unreachable code"); + } + pub fn free_pages(&mut self, addr: usize, num: usize) -> Result<(), Error> { + for i in 0..num { + self.free_page(addr + (i * crate::consts::PAGE_SIZE as usize))?; + } + Ok(()) + } + pub fn lock_page(&mut self, addr: usize) -> Result<(), Error> { + let index: usize = addr / crate::consts::PAGE_SIZE as usize; + let state = self.bitmap.get(addr).unwrap_or(INVALID_PAGE_STATE); + return match state { + 0 => self.mark_page_as::<{ PageState::Used }>(index), + 1 => Err(Error::AlreadyDone), + _ => Err(Error::OutOfBitmapBounds), + }; + ::core::panicking::panic("internal error: entered unreachable code"); + } + pub fn lock_pages(&mut self, addr: usize, num: usize) -> Result<(), Error> { + for i in 0..num { + self.lock_page(addr + (i * crate::consts::PAGE_SIZE as usize))?; + } + Ok(()) + } + pub fn request_page(&mut self) -> Result { + while self._bitmap_index < self.bitmap.len() * 8 { + { + let state = self + .bitmap + .get(self._bitmap_index) + .unwrap_or(INVALID_PAGE_STATE); + let matched_state = match state { + 1 => Err(Error::Continue), + 0 => { + self.mark_page_as::< + { PageState::Used }, + >(self._bitmap_index)?; + return Ok(self._bitmap_index * PAGE_SIZE as usize); + } + _ => Err(Error::OutOfBitmapBounds), + }; + if matched_state != Err(Error::Continue) + && matched_state.is_err() + { + return matched_state; + } else if matched_state.is_ok() { + return matched_state; + } + } + self._bitmap_index += 1; + } + Err(Error::OutOfMemory) + } + #[must_use] + pub fn request_memory_area( + &mut self, + size: usize, + ) -> Result { + let mut pages_left = (size / crate::consts::PAGE_SIZE as usize) + 1; + let mut base: usize = 0; + while self._bitmap_index < self.bitmap.len() * 8 && pages_left > 0 { + { + let state = self + .bitmap + .get(self._bitmap_index) + .unwrap_or(INVALID_PAGE_STATE); + match state { + 1 => { + pages_left = size / crate::consts::PAGE_SIZE as usize; + base = 0; + } + 0 => { + self.mark_page_as::< + { PageState::Used }, + >(self._bitmap_index)?; + if base == 0 { + base = self._bitmap_index * PAGE_SIZE as usize; + } + pages_left -= 1; + } + _ => return Err(Error::OutOfBitmapBounds), + }; + } + self._bitmap_index += 1; + } + if base != 0 { + Ok( + MemoryArea::new( + PhysicalAddress::new(base).to_virtual().data(), + size, + ), + ) + } else { + Err(Error::OutOfMemory) + } + } + fn reserve_page(&mut self, addr: usize) -> Result<(), Error> { + let index: usize = (addr / crate::consts::PAGE_SIZE as usize); + let state = self.bitmap.get(addr).unwrap_or(INVALID_PAGE_STATE); + return match state { + 0 => self.mark_page_as::<{ PageState::Reserved }>(index), + 1 => Err(Error::AlreadyDone), + _ => Err(Error::OutOfBitmapBounds), + }; + } + pub(self) fn reserve_pages( + &mut self, + addr: usize, + num: usize, + ) -> Result<(), Error> { + for i in 0..num { + self.reserve_page(addr + (i * crate::consts::PAGE_SIZE as usize))?; + } + Ok(()) + } + fn unreserve_page(&mut self, addr: usize) -> Result<(), Error> { + let index: usize = (addr / crate::consts::PAGE_SIZE as usize); + let state = self.bitmap.get(addr).unwrap_or(INVALID_PAGE_STATE); + return match state { + 1 => self.disable_page_mark::<{ PageState::Reserved }>(index), + 0 => Err(Error::AlreadyDone), + _ => Err(Error::OutOfBitmapBounds), + }; + } + pub(self) fn unreserve_pages( + &mut self, + addr: usize, + num: usize, + ) -> Result<(), Error> { + for i in 0..num { + self.unreserve_page(addr + (i * crate::consts::PAGE_SIZE as usize))?; + } + Ok(()) + } + pub fn is_initialized(&self) -> bool { + return self._initialized; + } + /// Safe version of `request_page`. + pub fn request_safe_page<'a>( + &mut self, + ) -> Result { + Ok(unsafe { super::SafePagePtr::unsafe_from_addr(self.request_page()?) }) + } + } + pub struct PtrWrapper { + pub(self) inner: NonNull, + } + unsafe impl Sync for PtrWrapper {} + unsafe impl Send for PtrWrapper {} + impl PtrWrapper { + pub unsafe fn from_raw(_val: &mut T) -> PtrWrapper { + Self { + inner: NonNull::new(_val).unwrap(), + } + } + } + impl bitmap::Storage for PtrWrapper<[usize]> { + fn as_ref(&self) -> &[usize] { + unsafe { self.inner.as_ref() } + } + fn as_mut(&mut self) -> &mut [usize] { + unsafe { self.inner.as_mut() } + } + } + unsafe impl x86_64::structures::paging::FrameAllocator + for PageFrameAllocator { + fn allocate_frame( + &mut self, + ) -> Option> { + let page_base_addr = self.request_page().ok()?; + PhysFrame::from_start_address(PhysAddr::new(page_base_addr as u64)).ok() + } + } + } + pub mod table_manager { + use core::{char::UNICODE_VERSION, f64::consts::E, ptr::NonNull}; + use limine::NonNullPtr; + use x86_64::structures::paging::page_table::PageTableEntry; + use crate::{common::_alloc_frame_as_mut_t, debug, endl, assign_uninit}; + use super::{indexer::PageMapIndexer, PageTable}; + use crate::memory::{PhysicalAddress, VirtualAddress}; + pub enum MemoryMapError { + FrameAllocator(super::frame_allocator::Error), + InvalidAddress, + TableNotFound, + } + #[automatically_derived] + impl ::core::fmt::Debug for MemoryMapError { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + match self { + MemoryMapError::FrameAllocator(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish( + f, + "FrameAllocator", + &__self_0, + ) + } + MemoryMapError::InvalidAddress => { + ::core::fmt::Formatter::write_str(f, "InvalidAddress") + } + MemoryMapError::TableNotFound => { + ::core::fmt::Formatter::write_str(f, "TableNotFound") + } + } + } + } + #[allow(non_snake_case)] + pub struct PageTableManager { + PML4: NonNullPtr, + } + impl PageTableManager { + pub fn new() -> Option { + Some(PageTableManager { + PML4: unsafe { + core::mem::transmute( + NonNull::< + PageTable, + >::new(_alloc_frame_as_mut_t::().ok()?)?, + ) + }, + }) + } + pub fn from_pml4(pml4: NonNullPtr) -> Option { + Some(PageTableManager { PML4: pml4 }) + } + pub unsafe fn register(&self) -> &Self { + self.map_memory( + VirtualAddress::new(self.PML4.as_ptr().addr()), + PhysicalAddress::new(self.PML4.as_ptr().addr()), + ); + asm!("mov cr3, {0}", in (reg) self.PML4.as_ptr().addr()); + self + } + /// Internal Function for Mapping Memory. + pub(crate) unsafe fn map_memory_internal( + &self, + virtual_addr: VirtualAddress, + physical_addr: PhysicalAddress, + ) -> Result<(), MemoryMapError> { + let indexer = PageMapIndexer::for_addr(virtual_addr.data()); + unsafe { + crate::DEBUG_LINE + .unsafe_write_string("Not Mapped Virtual Address 0x"); + crate::DEBUG_LINE.unsafe_write_string(virtual_addr.as_str()); + crate::DEBUG_LINE.unsafe_write_string(" to 0x"); + crate::DEBUG_LINE + .unsafe_write_string( + PhysicalAddress::new(physical_addr.data()).as_str(), + ); + crate::DEBUG_LINE.unsafe_write_string("\n"); + }; + Ok(()) + } + pub fn map_memory( + &self, + virtual_addr: VirtualAddress, + physical_addr: PhysicalAddress, + ) -> Result<(), MemoryMapError> { + unsafe { self.map_memory_internal(virtual_addr, physical_addr) } + } + } + } + pub mod indexer { + pub struct PageMapIndexer { + pub pdp: usize, + pub pd: usize, + pub pt: usize, + pub p: usize, + } + impl PageMapIndexer { + pub fn for_addr(addr: usize) -> Self { + let mut virtualAddress = addr; + virtualAddress >>= 12; + let p = virtualAddress & 0x1ff; + virtualAddress >>= 9; + let pt = virtualAddress & 0x1ff; + virtualAddress >>= 9; + let pd = virtualAddress & 0x1ff; + virtualAddress >>= 9; + let pdp = virtualAddress & 0x1ff; + virtualAddress >>= 9; + Self { pdp, pd, pt, p } + } + } + } + use spin::Mutex; + use core::cell::UnsafeCell; + /// Get a mutable reference to the [frame_allocator::PageFrameAllocator]. + /// This is now thread-safe and will not lead to undefined behavior. + pub fn pf_allocator() -> spin::MutexGuard< + 'static, + frame_allocator::PageFrameAllocator, + > { + crate::KERNEL_FRAME_ALLOCATOR.lock() + } + /// Get the Global [table_manager::PageTableManager]. + /// This is now thread-safe and will not lead to undefined behavior. + pub fn pt_manager() -> spin::MutexGuard<'static, table_manager::PageTableManager> { + crate::KERNEL_PAGE_TABLE_MANAGER.lock() + } + #[must_use] + pub struct SafePagePtr( + usize, + ) + where + Self: Sync + Sized; + impl SafePagePtr { + #[inline] + pub fn new() -> Self { + ::core::panicking::panic("not implemented"); + } + #[inline] + pub unsafe fn unsafe_from_addr(addr: usize) -> Self { + core::intrinsics::assume(addr != 0); + core::intrinsics::assume(addr != usize::MAX); + core::intrinsics::transmute::(addr) + } + #[inline] + pub unsafe fn as_ptr(self) -> *const u8 { + core::intrinsics::transmute::(self) + } + #[inline] + pub unsafe fn as_mut_ptr(self) -> *mut u8 { + core::intrinsics::transmute::(self) + } + #[inline] + pub unsafe fn to_ref_t(&self) -> &T { + core::intrinsics::transmute::<&Self, &T>(self) + } + #[inline] + pub unsafe fn to_mut_ref_t(&mut self) -> &mut Ptr { + core::intrinsics::transmute::<&mut Self, &mut Ptr>(self) + } + #[inline] + pub unsafe fn unchecked_raw_transmute(self) -> *mut T { + core::intrinsics::assume( + core::mem::size_of::() <= crate::consts::PAGE_SIZE as usize, + ); + core::intrinsics::transmute_unchecked::(self) + } + #[inline] + #[must_use] + pub fn free(&mut self) { + pf_allocator().free_page(self.0).unwrap(); + } + } + impl Drop for SafePagePtr { + fn drop(&mut self) { + self.free(); + } + } + pub use x86_64::structures::paging::page_table::PageTableEntry; + pub use x86_64::structures::paging::page_table::PageTable; + use self::frame_allocator::PageFrameAllocator; + pub struct PageFrameMapper; +} +pub mod renderer { + pub type Color = u32; + use core::ops::Add; + use core::ptr::{addr_of, NonNull}; + use crate::bitmap_font::{BitmapFont, DisplayChar}; + use crate::common::endl; + use crate::tty::KERNEL_CONSOLE; + use crate::{debug, assign_uninit}; + use crate::framebuffer::Framebuffer; + pub struct Renderer { + target_fb: &'static Framebuffer, + foreground_color: Color, + background_color: Color, + bitmap_font: &'static BitmapFont, + pub optional_font_scaling: Option, + } + fn align_number_to(num: usize, align: usize) -> usize { + num - (num % align) + } + fn mod_max(num: usize, max: usize) -> usize { + if num > max { max } else { num } + } + pub enum RendererError { + OutOfBounds, + } + static mut GLOBAL_RENDERER: core::mem::MaybeUninit = core::mem::MaybeUninit::uninit(); + impl Renderer { + pub fn global<'a>() -> &'a Renderer { + unsafe { &*self::GLOBAL_RENDERER.as_ptr() } + } + pub fn global_mut<'a>() -> &'a mut Renderer { + unsafe { &mut *self::GLOBAL_RENDERER.as_mut_ptr() } + } + pub fn make_global(self) { + *(unsafe { + &mut GLOBAL_RENDERER + }) = core::mem::MaybeUninit::::new((self)); + } + pub fn new(fb: &'static Framebuffer, font: &'static BitmapFont) -> Renderer { + Self { + target_fb: fb, + foreground_color: 0xFFFFFFFF, + background_color: 0x00000000, + bitmap_font: font, + optional_font_scaling: None, + } + } + pub fn get_font_scaling(&self) -> u64 { + self.optional_font_scaling.unwrap_or(10) + } + pub unsafe fn scroll(&mut self, amount: usize, align: usize) { + let mut base = self + .target_fb + .address + .as_ptr() + .map(|p| core::mem::transmute::<*mut u8, *mut Color>(p)) + .unwrap(); + let chunk_size = self.target_fb.width as usize * amount; + let area_size = (self.target_fb.height * self.target_fb.width) as usize + - chunk_size; + let end_area = base.add(chunk_size); + base.copy_from(base.add(chunk_size), area_size); + Self::_fill_with_color( + base.add(area_size), + chunk_size, + self.background_color, + self.background_color, + ) + } + pub unsafe fn clear(&self, color: Color) { + Self::_fill_with_color( + self + .target_fb + .address + .as_ptr() + .map(|p| core::mem::transmute::<*mut u8, *mut Color>(p)) + .unwrap(), + (self.target_fb.height * self.target_fb.width) as usize, + color, + color, + ); + } + pub unsafe fn unsafe_put_pixel(&self, x: usize, y: usize, color: Color) { + let mut pixel_offset = (mod_max(x, self.target_fb.width as usize) * 4) + + self.target_fb.pitch as usize + * mod_max(y, self.target_fb.height as usize); + unsafe { + crate::DEBUG_LINE.unsafe_write_string("unsafe_put_pixel( x="); + crate::DEBUG_LINE.unsafe_write_string(crate::integer_to_string(x)); + crate::DEBUG_LINE.unsafe_write_string(", y="); + crate::DEBUG_LINE.unsafe_write_string(crate::integer_to_string(y)); + crate::DEBUG_LINE.unsafe_write_string(", offset ="); + crate::DEBUG_LINE + .unsafe_write_string(crate::integer_to_string(pixel_offset)); + crate::DEBUG_LINE.unsafe_write_string(" )"); + crate::DEBUG_LINE.unsafe_write_string("\n"); + }; + let mut pix = core::mem::transmute::< + *mut u8, + *mut Color, + >( + self + .target_fb + .address + .as_ptr() + .expect("Failed to get Pointer") + .offset(pixel_offset as isize), + ); + pix.write(color) + } + pub unsafe fn unsafe_pull_pixel(&self, x: usize, y: usize) -> Color { + let pixel_offset = (x * 4) + (self.target_fb.pitch as usize * y); + *(self.target_fb.address.as_ptr().unwrap().offset(pixel_offset as isize) + as *mut Color) + } + pub fn set_text_colors_via_invert(&mut self, color: Color) { + self.foreground_color = color; + self.background_color = !color; + } + pub fn update_colors( + &mut self, + fg_color: Option, + bg_color: Option, + ) { + self.foreground_color = fg_color.unwrap_or(self.foreground_color); + self.background_color = bg_color.unwrap_or(self.background_color); + } + pub unsafe fn _fill_with_color( + base: *mut Color, + amount: usize, + filler: Color, + background_color: Color, + ) { + for offset in 0..amount { + let ptr = base.offset(offset as isize); + let val = ptr.read(); + ptr.write(filler) + } + } + pub unsafe fn unsafe_put_scaled_pixel(&self, x: usize, y: usize, color: Color) { + let scaling = self.optional_font_scaling.unwrap_or(10) as usize; + self.unsafe_fill_square(x * scaling, y * scaling, scaling, scaling, color); + } + pub unsafe fn unsafe_draw_line( + &self, + x0: usize, + y0: usize, + x1: usize, + y1: usize, + color: Color, + ) { + let dx = (x1 as isize - x0 as isize).abs(); + let dy = -(y1 as isize - y0 as isize).abs(); + let sx = if x0 < x1 { 1 as isize } else { -1 }; + let sy = if y0 < y1 { 1 as isize } else { -1 }; + let mut err = dx + dy; + let mut x = x0 as isize; + let mut y = y0 as isize; + while x != (x1 as isize) || y != (y1 as isize) { + self.unsafe_put_scaled_pixel(x as usize, y as usize, color); + let e2 = 2 * err; + if e2 >= dy { + err += dy; + x += sx; + } + if e2 <= dx { + err += dx; + y += sy; + } + } + } + pub unsafe fn unsafe_fill_square( + &self, + x: usize, + y: usize, + w: usize, + h: usize, + color: Color, + ) { + for y_off in y..(y + h) { + Self::_fill_with_color( + self + .target_fb + .address + .as_ptr() + .map(|p| core::mem::transmute::<*mut u8, *mut Color>(p)) + .unwrap() + .offset( + ((x) + (self.target_fb.pitch as usize * (y_off) / 4)) + as isize, + ), + w * 4, + color, + self.background_color, + ); + } + } + pub fn dimensions(&self) -> (usize, usize) { + (self.target_fb.width as usize, self.target_fb.height as usize) + } + pub unsafe fn unsafe_draw_char( + &self, + off_x: usize, + off_y: usize, + chr: u8, + ) -> usize { + let scaling = self.optional_font_scaling.unwrap_or(10) as usize; + let line_off = 0; + for x in 0..8 as usize { + for y in 0..8 as usize { + self.unsafe_fill_square( + off_x + (x * scaling), + off_y + (y * scaling), + scaling, + scaling, + if self.bitmap_font[chr as usize].is_set(x, y) { + self.foreground_color + } else { + self.background_color + }, + ); + } + } + line_off + } + pub unsafe fn draw_raw_image(&self, x: usize, y: usize, pixels: &'_ [u8]) { + self.target_fb + .address + .as_ptr() + .unwrap() + .offset((x + (self.target_fb.pitch as usize * (y))) as isize) + .copy_from(pixels.as_ptr(), pixels.len()); + } + pub unsafe fn unsafe_draw_text( + &self, + x: usize, + y: usize, + text: &'_ str, + ) -> usize { + let scaling = self.optional_font_scaling.unwrap_or(10) as usize; + let mut line_off = 0usize; + for (index, chr) in text.chars().enumerate() { + if chr == '\n' { + line_off += 1; + continue; + } + let x_off = x + (index * (16 * scaling)); + line_off += self.unsafe_draw_char(x_off, y + (line_off * 16), chr as u8); + } + line_off + } + } +} +pub mod serial { + #[macro_use] + use crate::common::macros; + use crate::common::io::{inb, io_wait, outb}; + use crate::device::{ + character::{CharacterDeviceMode, TimedCharacterDevice, UnsafeCharacterDevice}, + Device, GeneralDevice, + }; + use crate::kprint; + pub enum Port { + COM1 = 0x3F8, + COM2 = 0x2F8, + COM3 = 0x3E8, + COM4 = 0x2E8, + COM5 = 0x5F8, + COM6 = 0x4F8, + COM7 = 0x5E8, + COM8 = 0x4E8, + } + impl Port { + pub fn get_addr(&self) -> u16 { + match self { + Port::COM1 => 0x3F8, + Port::COM2 => 0x2F8, + Port::COM3 => 0x3E8, + Port::COM4 => 0x2E8, + Port::COM5 => 0x5F8, + Port::COM6 => 0x4F8, + Port::COM7 => 0x5E8, + Port::COM8 => 0x4E8, + } + } + } + impl GeneralDevice for Port { + fn as_device(&self) -> crate::device::Device<'_> { + Device::Character(self) + } + } + impl UnsafeCharacterDevice for Port { + unsafe fn read_raw(&self) -> u8 { + inb(self.get_addr()) as u8 + } + unsafe fn write_raw(&self, data: u8) { + outb(self.get_addr(), data as u8); + } + unsafe fn test(&self) -> bool { + outb(self.get_addr() + 1, 0x00); + outb(self.get_addr() + 3, 0x80); + outb(self.get_addr() + 0, 0x03); + outb(self.get_addr() + 1, 0x00); + outb(self.get_addr() + 3, 0x03); + outb(self.get_addr() + 2, 0xC7); + outb(self.get_addr() + 4, 0x0B); + outb(self.get_addr() + 4, 0x1E); + outb(self.get_addr() + 0, 0xAE); + if (inb(self.get_addr() + 0) != 0xAE) { + return true; + } + outb(self.get_addr() + 4, 0x0F); + return false; + } + unsafe fn init(&mut self) -> bool { + true + } + unsafe fn received(&self) -> bool { + (inb(self.get_addr() + 5) & 1) != 0 + } + unsafe fn is_transmit_empty(&self) -> bool { + (inb(self.get_addr() + 5) & 0x20) != 0 + } + fn set_mode(&mut self, mode: CharacterDeviceMode) {} + fn get_mode(&self) -> CharacterDeviceMode { + CharacterDeviceMode::Normal + } + } + impl TimedCharacterDevice for Port { + unsafe fn read(&self) -> u8 { + while !self.received() {} + self.read_raw() + } + unsafe fn write(&self, data: u8) { + while !self.is_transmit_empty() {} + self.write_raw(data) + } + unsafe fn wait(&self) {} + } + impl Port + where + Self: UnsafeCharacterDevice, + Self: TimedCharacterDevice, + { + pub fn wait_for_connection(&self) { + unsafe { + while self.test() {} + unsafe { + crate::KERNEL_CONSOLE + .write_str("Successfully connected to serial line."); + crate::KERNEL_CONSOLE.newline(); + } + } + } + pub unsafe fn unsafe_write_string(&self, _str: &'_ str) { + for chr in _str.chars() { + self.write(chr as u8); + } + } + pub unsafe fn unsafe_write_line(&self, _str: &'_ str) { + self.unsafe_write_string(_str); + self.unsafe_write_string("\n\r"); + } + pub unsafe fn unsafe_read_string(&self, len: usize) -> &'static str { + ::core::panicking::panic("not implemented"); + } + } +} +pub mod status {} +pub mod tty { + use alloc::format; + use crate::{ + device::{Device, GeneralDevice, character::UnsafeCharacterDevice}, + common::endl, renderer::{self, Color, Renderer}, + }; + pub struct Console { + pub cursor_pos: (usize, usize), + pub line_padding: usize, + } + #[automatically_derived] + impl ::core::fmt::Debug for Console { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_struct_field2_finish( + f, + "Console", + "cursor_pos", + &self.cursor_pos, + "line_padding", + &&self.line_padding, + ) + } + } + #[automatically_derived] + impl ::core::default::Default for Console { + #[inline] + fn default() -> Console { + Console { + cursor_pos: ::core::default::Default::default(), + line_padding: ::core::default::Default::default(), + } + } + } + impl GeneralDevice for Console { + fn as_device(&self) -> Device<'_> { + Device::Character(self) + } + } + impl UnsafeCharacterDevice for Console { + unsafe fn read_raw(&self) -> u8 { + ::core::panicking::panic("not implemented") + } + unsafe fn write_raw(&self, data: u8) { + let _ = super::renderer::Renderer::global() + .unsafe_draw_char( + self.cursor_pos.0 * 16, + self.cursor_pos.1 * (16 + self.line_padding), + data, + ); + } + unsafe fn received(&self) -> bool { + false + } + unsafe fn is_transmit_empty(&self) -> bool { + true + } + unsafe fn test(&self) -> bool { + true + } + unsafe fn init(&mut self) -> bool { + ::core::panicking::panic("not yet implemented") + } + fn set_mode(&mut self, mode: crate::device::character::CharacterDeviceMode) {} + fn get_mode(&self) -> crate::device::character::CharacterDeviceMode { + crate::device::character::CharacterDeviceMode::Normal + } + } + pub(crate) static mut KERNEL_CONSOLE: Console = Console::new(); + pub const COLORS: [Color; 8] = [ + 0x00000000, + 0xFFFFFFFF, + 0xFFFF0000, + 0xFF00FF00, + 0xFF0000FF, + 0xFFFFFF00, + 0xFFFF00FF, + 0xFF00FFFF, + ]; + impl Console + where + Self: UnsafeCharacterDevice, + { + pub fn write_str(&mut self, _str: &'_ str) { + for (idx, chr) in _str.chars().enumerate() { + if self.cursor_pos.0 > super::Renderer::global().dimensions().0 / 8 { + self.newline() + } + if self.cursor_pos.1 > super::Renderer::global().dimensions().1 { + self.scroll(); + } + if chr == '\n' { + self.newline(); + continue; + } + unsafe { self.write_raw(chr as u8) } + self.cursor_pos.0 += 1; + } + } + pub fn get_line_padding(&mut self) -> usize { + 16 + self.line_padding + } + pub fn print(&mut self, _str: &'_ str) { + self.write_str(_str); + self.newline(); + } + pub fn newline(&mut self) { + self.cursor_pos.1 += 1; + self.cursor_pos.0 = 0; + } + pub fn scroll(&mut self) { + unsafe { Renderer::global_mut().scroll(8, 2) }; + self.cursor_pos.1 -= 1; + } + pub const fn new() -> Self { + Self { + cursor_pos: (0, 0), + line_padding: 0, + } + } + } +} +use alloc::format; +use alloc_impl as _; +use paging::frame_allocator::PageFrameAllocator; +use spin::Mutex; +use x86_64::structures::idt::InterruptStackFrame; +use x86_64::structures::paging::page::PageRange; +use x86_64::structures::paging::{Mapper, PageTableFlags, PhysFrame, Size2MiB, Size4KiB}; +use x86_64::{structures, PhysAddr, VirtAddr}; +use crate::alloc_impl::KERNEL_ALLOCATOR; +use crate::common::idt::{Idt, KERNEL_IDT}; +use crate::common::io::outb; +use crate::common::*; +use crate::device::{ + character::{TimedCharacterDevice, *}, + Device, GeneralDevice, +}; +use crate::memory::{ + active_level_4_table, PhysicalAddress, VirtualAddress, + PHYSICAL_BOOTLOADER_MEMORY_OFFSET, PHYSICAL_MEMORY_OFFSET, +}; +use crate::paging::table_manager::PageTableManager; +use core::arch::asm; +use core::ffi::CStr; +use elf::endian::AnyEndian; +use elf::segment::ProgramHeader; +use memory::MemoryArea; +pub(crate) use tty::KERNEL_CONSOLE; +#[macro_use] +use core::intrinsics::{likely, unlikely}; +#[macro_use] +use core::fmt::*; +use crate::paging::{pf_allocator, pt_manager, PageTable}; +use core::mem; +use core::num::NonZeroUsize; +use core::ptr::NonNull; +#[macro_use] +extern crate bitfield; +use numtoa::NumToA; +use renderer::Renderer; +#[macro_use] +extern crate antos_macros; +static FRAMEBUFFERS_REQUEST: limine::FramebufferRequest = limine::FramebufferRequest::new( + 0, +); +static TERMINAL_REQUEST: limine::TerminalRequest = limine::TerminalRequest::new(0); +static MEMMAP_REQUEST: limine::MemmapRequest = limine::MemmapRequest::new(0); +static KERNEL_ADDRESS_REQUEST: limine::KernelAddressRequest = limine::KernelAddressRequest::new( + 0, +); +static KERNEL_FILE_REQUEST: limine::KernelFileRequest = limine::KernelFileRequest::new( + 0, +); +static MODULE_REQUEST: limine::ModuleRequest = limine::ModuleRequest::new(0); +static mut SYSTEM_IDT: structures::idt::InterruptDescriptorTable = structures::idt::InterruptDescriptorTable::new(); +pub(crate) static mut GENERIC_STATIC_BUFFER: [u8; 25] = [0u8; 25]; +static TEST1: &'static str = "Hello Paging!"; +static TEST2: &'static str = "):"; +static mut ITOA_BUFFER: core::mem::MaybeUninit = core::mem::MaybeUninit::uninit(); +#[allow(missing_copy_implementations)] +#[allow(non_camel_case_types)] +#[allow(dead_code)] +pub(crate) struct FRAMEBUFFERS { + __private_field: (), +} +#[doc(hidden)] +pub(crate) static FRAMEBUFFERS: FRAMEBUFFERS = FRAMEBUFFERS { + __private_field: (), +}; +impl ::lazy_static::__Deref for FRAMEBUFFERS { + type Target = &'static [NonNullPtr]; + fn deref(&self) -> &&'static [NonNullPtr] { + #[inline(always)] + fn __static_ref_initialize() -> &'static [NonNullPtr] { + { + if let Some(fb_resp) = FRAMEBUFFERS_REQUEST.get_response().get() { + unsafe { core::mem::transmute(fb_resp.framebuffers()) } + } else { + unsafe { + crate::DEBUG_LINE.unsafe_write_string("ERROR: "); + crate::DEBUG_LINE + .unsafe_write_string( + "Failed to get the list of System Framebuffers!", + ); + }; + { + ::core::panicking::panic_fmt( + format_args!( + "Failed to get the list of System Framebuffers!", + ), + ); + }; + } + } + } + #[inline(always)] + fn __stability() -> &'static &'static [NonNullPtr] { + static LAZY: ::lazy_static::lazy::Lazy< + &'static [NonNullPtr], + > = ::lazy_static::lazy::Lazy::INIT; + LAZY.get(__static_ref_initialize) + } + __stability() + } +} +impl ::lazy_static::LazyStatic for FRAMEBUFFERS { + fn initialize(lazy: &Self) { + let _ = &**lazy; + } +} +#[allow(missing_copy_implementations)] +#[allow(non_camel_case_types)] +#[allow(dead_code)] +pub(crate) struct KERNEL_BASE { + __private_field: (), +} +#[doc(hidden)] +pub(crate) static KERNEL_BASE: KERNEL_BASE = KERNEL_BASE { __private_field: () }; +impl ::lazy_static::__Deref for KERNEL_BASE { + type Target = &'static limine::KernelAddressResponse; + fn deref(&self) -> &&'static limine::KernelAddressResponse { + #[inline(always)] + fn __static_ref_initialize() -> &'static limine::KernelAddressResponse { + { + if let Some(resp) = KERNEL_ADDRESS_REQUEST + .get_response() + .get::<'static>() + { + resp + } else { + unsafe { + crate::DEBUG_LINE.unsafe_write_string("ERROR: "); + crate::DEBUG_LINE + .unsafe_write_string( + "Failed to get the list of System Framebuffers!", + ); + }; + { + let lvl = ::log::Level::Error; + if lvl <= ::log::STATIC_MAX_LEVEL && lvl <= ::log::max_level() { + ::log::__private_api::log( + format_args!( + "Failed to get the list of System Framebuffers!", + ), + lvl, + &( + "antos_kernel_minimal_generic", + "antos_kernel_minimal_generic", + "src/main.rs", + ), + 124u32, + ::log::__private_api::Option::None, + ); + } + }; + { + ::core::panicking::panic_fmt( + format_args!( + "Failed to get the list of System Framebuffers!", + ), + ); + }; + } + } + } + #[inline(always)] + fn __stability() -> &'static &'static limine::KernelAddressResponse { + static LAZY: ::lazy_static::lazy::Lazy< + &'static limine::KernelAddressResponse, + > = ::lazy_static::lazy::Lazy::INIT; + LAZY.get(__static_ref_initialize) + } + __stability() + } +} +impl ::lazy_static::LazyStatic for KERNEL_BASE { + fn initialize(lazy: &Self) { + let _ = &**lazy; + } +} +#[allow(missing_copy_implementations)] +#[allow(non_camel_case_types)] +#[allow(dead_code)] +struct KERNEL_FRAME_ALLOCATOR { + __private_field: (), +} +#[doc(hidden)] +static KERNEL_FRAME_ALLOCATOR: KERNEL_FRAME_ALLOCATOR = KERNEL_FRAME_ALLOCATOR { + __private_field: (), +}; +impl ::lazy_static::__Deref for KERNEL_FRAME_ALLOCATOR { + type Target = Mutex; + fn deref(&self) -> &Mutex { + #[inline(always)] + fn __static_ref_initialize() -> Mutex { + Mutex::new(unsafe { PageFrameAllocator::from_response(&*KERNEL_MEMMAP) }) + } + #[inline(always)] + fn __stability() -> &'static Mutex { + static LAZY: ::lazy_static::lazy::Lazy> = ::lazy_static::lazy::Lazy::INIT; + LAZY.get(__static_ref_initialize) + } + __stability() + } +} +impl ::lazy_static::LazyStatic for KERNEL_FRAME_ALLOCATOR { + fn initialize(lazy: &Self) { + let _ = &**lazy; + } +} +#[allow(missing_copy_implementations)] +#[allow(non_camel_case_types)] +#[allow(dead_code)] +struct KERNEL_PAGE_TABLE_MANAGER { + __private_field: (), +} +#[doc(hidden)] +static KERNEL_PAGE_TABLE_MANAGER: KERNEL_PAGE_TABLE_MANAGER = KERNEL_PAGE_TABLE_MANAGER { + __private_field: (), +}; +impl ::lazy_static::__Deref for KERNEL_PAGE_TABLE_MANAGER { + type Target = Mutex; + fn deref(&self) -> &Mutex { + #[inline(always)] + fn __static_ref_initialize() -> Mutex { + Mutex::new( + PageTableManager::new().expect("Failed to create Page Table Manager."), + ) + } + #[inline(always)] + fn __stability() -> &'static Mutex { + static LAZY: ::lazy_static::lazy::Lazy> = ::lazy_static::lazy::Lazy::INIT; + LAZY.get(__static_ref_initialize) + } + __stability() + } +} +impl ::lazy_static::LazyStatic for KERNEL_PAGE_TABLE_MANAGER { + fn initialize(lazy: &Self) { + let _ = &**lazy; + } +} +#[allow(missing_copy_implementations)] +#[allow(non_camel_case_types)] +#[allow(dead_code)] +struct KERNEL_PAGE_MAPPER { + __private_field: (), +} +#[doc(hidden)] +static KERNEL_PAGE_MAPPER: KERNEL_PAGE_MAPPER = KERNEL_PAGE_MAPPER { + __private_field: (), +}; +impl ::lazy_static::__Deref for KERNEL_PAGE_MAPPER { + type Target = Mutex>; + fn deref(&self) -> &Mutex> { + #[inline(always)] + fn __static_ref_initialize() -> Mutex< + x86_64::structures::paging::OffsetPageTable<'static>, + > { + Mutex::new(unsafe { + x86_64::structures::paging::mapper::OffsetPageTable::new( + unsafe { active_level_4_table(VirtAddr::zero()) }, + VirtAddr::zero(), + ) + }) + } + #[inline(always)] + fn __stability() -> &'static Mutex< + x86_64::structures::paging::OffsetPageTable<'static>, + > { + static LAZY: ::lazy_static::lazy::Lazy< + Mutex>, + > = ::lazy_static::lazy::Lazy::INIT; + LAZY.get(__static_ref_initialize) + } + __stability() + } +} +impl ::lazy_static::LazyStatic for KERNEL_PAGE_MAPPER { + fn initialize(lazy: &Self) { + let _ = &**lazy; + } +} +#[allow(missing_copy_implementations)] +#[allow(non_camel_case_types)] +#[allow(dead_code)] +pub(crate) struct KERNEL_FILE { + __private_field: (), +} +#[doc(hidden)] +pub(crate) static KERNEL_FILE: KERNEL_FILE = KERNEL_FILE { __private_field: () }; +impl ::lazy_static::__Deref for KERNEL_FILE { + type Target = &'static limine::File; + fn deref(&self) -> &&'static limine::File { + #[inline(always)] + fn __static_ref_initialize() -> &'static limine::File { + { + if let Some(resp) = KERNEL_FILE_REQUEST.get_response().get() { + resp.kernel_file.get::<'static>().unwrap() + } else { + unsafe { + crate::DEBUG_LINE.unsafe_write_string("ERROR: "); + crate::DEBUG_LINE + .unsafe_write_string( + "Failed to get the list of System Framebuffers!", + ); + }; + { + let lvl = ::log::Level::Error; + if lvl <= ::log::STATIC_MAX_LEVEL && lvl <= ::log::max_level() { + ::log::__private_api::log( + format_args!( + "Failed to get the list of System Framebuffers!", + ), + lvl, + &( + "antos_kernel_minimal_generic", + "antos_kernel_minimal_generic", + "src/main.rs", + ), + 136u32, + ::log::__private_api::Option::None, + ); + } + }; + { + ::core::panicking::panic_fmt( + format_args!( + "Failed to get the list of System Framebuffers!", + ), + ); + }; + } + } + } + #[inline(always)] + fn __stability() -> &'static &'static limine::File { + static LAZY: ::lazy_static::lazy::Lazy<&'static limine::File> = ::lazy_static::lazy::Lazy::INIT; + LAZY.get(__static_ref_initialize) + } + __stability() + } +} +impl ::lazy_static::LazyStatic for KERNEL_FILE { + fn initialize(lazy: &Self) { + let _ = &**lazy; + } +} +#[allow(missing_copy_implementations)] +#[allow(non_camel_case_types)] +#[allow(dead_code)] +///The Area of Memory the Kernel Uses. +struct KERNEL_AREA { + __private_field: (), +} +#[doc(hidden)] +static KERNEL_AREA: KERNEL_AREA = KERNEL_AREA { __private_field: () }; +impl ::lazy_static::__Deref for KERNEL_AREA { + type Target = MemoryArea; + fn deref(&self) -> &MemoryArea { + #[inline(always)] + fn __static_ref_initialize() -> MemoryArea { + MemoryArea::new( + KERNEL_BASE.virtual_base as usize, + KERNEL_FILE.length as usize, + ) + } + #[inline(always)] + fn __stability() -> &'static MemoryArea { + static LAZY: ::lazy_static::lazy::Lazy = ::lazy_static::lazy::Lazy::INIT; + LAZY.get(__static_ref_initialize) + } + __stability() + } +} +impl ::lazy_static::LazyStatic for KERNEL_AREA { + fn initialize(lazy: &Self) { + let _ = &**lazy; + } +} +#[allow(missing_copy_implementations)] +#[allow(non_camel_case_types)] +#[allow(dead_code)] +struct L4_PAGE_TABLE { + __private_field: (), +} +#[doc(hidden)] +static L4_PAGE_TABLE: L4_PAGE_TABLE = L4_PAGE_TABLE { + __private_field: (), +}; +impl ::lazy_static::__Deref for L4_PAGE_TABLE { + type Target = &'static mut PageTable; + fn deref(&self) -> &&'static mut PageTable { + #[inline(always)] + fn __static_ref_initialize() -> &'static mut PageTable { + unsafe { active_level_4_table(VirtAddr::zero()) } + } + #[inline(always)] + fn __stability() -> &'static &'static mut PageTable { + static LAZY: ::lazy_static::lazy::Lazy<&'static mut PageTable> = ::lazy_static::lazy::Lazy::INIT; + LAZY.get(__static_ref_initialize) + } + __stability() + } +} +impl ::lazy_static::LazyStatic for L4_PAGE_TABLE { + fn initialize(lazy: &Self) { + let _ = &**lazy; + } +} +#[allow(missing_copy_implementations)] +#[allow(non_camel_case_types)] +#[allow(dead_code)] +struct KERNEL_MEMMAP { + __private_field: (), +} +#[doc(hidden)] +static KERNEL_MEMMAP: KERNEL_MEMMAP = KERNEL_MEMMAP { + __private_field: (), +}; +impl ::lazy_static::__Deref for KERNEL_MEMMAP { + type Target = &'static limine::MemmapResponse; + fn deref(&self) -> &&'static limine::MemmapResponse { + #[inline(always)] + fn __static_ref_initialize() -> &'static limine::MemmapResponse { + { + if let Some(resp) = MEMMAP_REQUEST.get_response().get() { + resp + } else { + unsafe { + crate::DEBUG_LINE.unsafe_write_string("ERROR: "); + crate::DEBUG_LINE + .unsafe_write_string( + "Failed to get the list of System Framebuffers!", + ); + }; + { + let lvl = ::log::Level::Error; + if lvl <= ::log::STATIC_MAX_LEVEL && lvl <= ::log::max_level() { + ::log::__private_api::log( + format_args!( + "Failed to get the list of System Framebuffers!", + ), + lvl, + &( + "antos_kernel_minimal_generic", + "antos_kernel_minimal_generic", + "src/main.rs", + ), + 148u32, + ::log::__private_api::Option::None, + ); + } + }; + { + ::core::panicking::panic_fmt( + format_args!( + "Failed to get the list of System Framebuffers!", + ), + ); + }; + } + } + } + #[inline(always)] + fn __stability() -> &'static &'static limine::MemmapResponse { + static LAZY: ::lazy_static::lazy::Lazy<&'static limine::MemmapResponse> = ::lazy_static::lazy::Lazy::INIT; + LAZY.get(__static_ref_initialize) + } + __stability() + } +} +impl ::lazy_static::LazyStatic for KERNEL_MEMMAP { + fn initialize(lazy: &Self) { + let _ = &**lazy; + } +} +enum OutlineSegment { + MoveTo(f32, f32), + LineTo(f32, f32), + QuadTo(f32, f32, f32, f32), + CurveTo(f32, f32, f32, f32, f32, f32), + Stop, +} +#[automatically_derived] +impl ::core::fmt::Debug for OutlineSegment { + #[inline] + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + match self { + OutlineSegment::MoveTo(__self_0, __self_1) => { + ::core::fmt::Formatter::debug_tuple_field2_finish( + f, + "MoveTo", + __self_0, + &__self_1, + ) + } + OutlineSegment::LineTo(__self_0, __self_1) => { + ::core::fmt::Formatter::debug_tuple_field2_finish( + f, + "LineTo", + __self_0, + &__self_1, + ) + } + OutlineSegment::QuadTo(__self_0, __self_1, __self_2, __self_3) => { + ::core::fmt::Formatter::debug_tuple_field4_finish( + f, + "QuadTo", + __self_0, + __self_1, + __self_2, + &__self_3, + ) + } + OutlineSegment::CurveTo( + __self_0, + __self_1, + __self_2, + __self_3, + __self_4, + __self_5, + ) => { + let values: &[&dyn ::core::fmt::Debug] = &[ + __self_0, + __self_1, + __self_2, + __self_3, + __self_4, + &__self_5, + ]; + ::core::fmt::Formatter::debug_tuple_fields_finish(f, "CurveTo", values) + } + OutlineSegment::Stop => ::core::fmt::Formatter::write_str(f, "Stop"), + } + } +} +#[automatically_derived] +impl ::core::clone::Clone for OutlineSegment { + #[inline] + fn clone(&self) -> OutlineSegment { + let _: ::core::clone::AssertParamIsClone; + *self + } +} +#[automatically_derived] +impl ::core::marker::Copy for OutlineSegment {} +type HugePage = x86_64::structures::paging::Page; +#[no_mangle] +unsafe extern "C" fn __prog_debug_print(__base: *const u8, __len: usize) { + KERNEL_CONSOLE + .write_str( + core::str::from_utf8_unchecked(core::slice::from_raw_parts(__base, __len)), + ); +} +type DbgPrintFn = unsafe extern "C" fn(*const u8, usize); +extern "x86-interrupt" fn handle_pit(_frame: InterruptStackFrame) { + unsafe { + crate::DEBUG_LINE + .unsafe_write_string( + { + let res = ::alloc::fmt::format(format_args!("Tick Tock")); + res + } + .as_str(), + ) + } +} +#[repr(C)] +pub struct KernelProgramMeta { + _dbg_print: *const DbgPrintFn, +} +const MAX_FONT_OUTLINE_SEGMENTS: usize = 25; +pub struct FontOutline(heapless::Vec); +impl FontOutline { + pub const fn new() -> Self { + Self(heapless::Vec::::new()) + } + pub const fn segments( + &self, + ) -> &'_ heapless::Vec { + &(self.0) + } + pub fn push(&mut self, seg: OutlineSegment) { + self.0.push(seg).expect("Failed to push Font Segment"); + } +} +impl ttf_parser::OutlineBuilder for FontOutline { + fn move_to(&mut self, x: f32, y: f32) { + self.push(OutlineSegment::MoveTo(x, y)) + } + fn line_to(&mut self, x: f32, y: f32) { + self.push(OutlineSegment::LineTo(x, y)) + } + fn quad_to(&mut self, x1: f32, y1: f32, x: f32, y: f32) { + self.push(OutlineSegment::QuadTo(x1, y1, x, y)) + } + fn curve_to(&mut self, x1: f32, y1: f32, x2: f32, y2: f32, x: f32, y: f32) { + self.push(OutlineSegment::CurveTo(x1, y1, x2, y2, x, y)) + } + fn close(&mut self) { + self.push(OutlineSegment::Stop) + } +} +pub const FONT_BITMAP: bitmap_font::BitmapFont = [ + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x18, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18, 0x00], + [0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x36, 0x36, 0x7F, 0x36, 0x7F, 0x36, 0x36, 0x00], + [0x0C, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x0C, 0x00], + [0x00, 0x63, 0x33, 0x18, 0x0C, 0x66, 0x63, 0x00], + [0x1C, 0x36, 0x1C, 0x6E, 0x3B, 0x33, 0x6E, 0x00], + [0x06, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x18, 0x0C, 0x06, 0x06, 0x06, 0x0C, 0x18, 0x00], + [0x06, 0x0C, 0x18, 0x18, 0x18, 0x0C, 0x06, 0x00], + [0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00], + [0x00, 0x0C, 0x0C, 0x3F, 0x0C, 0x0C, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x06], + [0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x00], + [0x60, 0x30, 0x18, 0x0C, 0x06, 0x03, 0x01, 0x00], + [0x3E, 0x63, 0x73, 0x7B, 0x6F, 0x67, 0x3E, 0x00], + [0x0C, 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x3F, 0x00], + [0x1E, 0x33, 0x30, 0x1C, 0x06, 0x33, 0x3F, 0x00], + [0x1E, 0x33, 0x30, 0x1C, 0x30, 0x33, 0x1E, 0x00], + [0x38, 0x3C, 0x36, 0x33, 0x7F, 0x30, 0x78, 0x00], + [0x3F, 0x03, 0x1F, 0x30, 0x30, 0x33, 0x1E, 0x00], + [0x1C, 0x06, 0x03, 0x1F, 0x33, 0x33, 0x1E, 0x00], + [0x3F, 0x33, 0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x00], + [0x1E, 0x33, 0x33, 0x1E, 0x33, 0x33, 0x1E, 0x00], + [0x1E, 0x33, 0x33, 0x3E, 0x30, 0x18, 0x0E, 0x00], + [0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x00], + [0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x06], + [0x18, 0x0C, 0x06, 0x03, 0x06, 0x0C, 0x18, 0x00], + [0x00, 0x00, 0x3F, 0x00, 0x00, 0x3F, 0x00, 0x00], + [0x06, 0x0C, 0x18, 0x30, 0x18, 0x0C, 0x06, 0x00], + [0x1E, 0x33, 0x30, 0x18, 0x0C, 0x00, 0x0C, 0x00], + [0x3E, 0x63, 0x7B, 0x7B, 0x7B, 0x03, 0x1E, 0x00], + [0x0C, 0x1E, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x00], + [0x3F, 0x66, 0x66, 0x3E, 0x66, 0x66, 0x3F, 0x00], + [0x3C, 0x66, 0x03, 0x03, 0x03, 0x66, 0x3C, 0x00], + [0x1F, 0x36, 0x66, 0x66, 0x66, 0x36, 0x1F, 0x00], + [0x7F, 0x46, 0x16, 0x1E, 0x16, 0x46, 0x7F, 0x00], + [0x7F, 0x46, 0x16, 0x1E, 0x16, 0x06, 0x0F, 0x00], + [0x3C, 0x66, 0x03, 0x03, 0x73, 0x66, 0x7C, 0x00], + [0x33, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x33, 0x00], + [0x1E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00], + [0x78, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E, 0x00], + [0x67, 0x66, 0x36, 0x1E, 0x36, 0x66, 0x67, 0x00], + [0x0F, 0x06, 0x06, 0x06, 0x46, 0x66, 0x7F, 0x00], + [0x63, 0x77, 0x7F, 0x7F, 0x6B, 0x63, 0x63, 0x00], + [0x63, 0x67, 0x6F, 0x7B, 0x73, 0x63, 0x63, 0x00], + [0x1C, 0x36, 0x63, 0x63, 0x63, 0x36, 0x1C, 0x00], + [0x3F, 0x66, 0x66, 0x3E, 0x06, 0x06, 0x0F, 0x00], + [0x1E, 0x33, 0x33, 0x33, 0x3B, 0x1E, 0x38, 0x00], + [0x3F, 0x66, 0x66, 0x3E, 0x36, 0x66, 0x67, 0x00], + [0x1E, 0x33, 0x07, 0x0E, 0x38, 0x33, 0x1E, 0x00], + [0x3F, 0x2D, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00], + [0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x3F, 0x00], + [0x33, 0x33, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00], + [0x63, 0x63, 0x63, 0x6B, 0x7F, 0x77, 0x63, 0x00], + [0x63, 0x63, 0x36, 0x1C, 0x1C, 0x36, 0x63, 0x00], + [0x33, 0x33, 0x33, 0x1E, 0x0C, 0x0C, 0x1E, 0x00], + [0x7F, 0x63, 0x31, 0x18, 0x4C, 0x66, 0x7F, 0x00], + [0x1E, 0x06, 0x06, 0x06, 0x06, 0x06, 0x1E, 0x00], + [0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x40, 0x00], + [0x1E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1E, 0x00], + [0x08, 0x1C, 0x36, 0x63, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF], + [0x0C, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x1E, 0x30, 0x3E, 0x33, 0x6E, 0x00], + [0x07, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x3B, 0x00], + [0x00, 0x00, 0x1E, 0x33, 0x03, 0x33, 0x1E, 0x00], + [0x38, 0x30, 0x30, 0x3e, 0x33, 0x33, 0x6E, 0x00], + [0x00, 0x00, 0x1E, 0x33, 0x3f, 0x03, 0x1E, 0x00], + [0x1C, 0x36, 0x06, 0x0f, 0x06, 0x06, 0x0F, 0x00], + [0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x1F], + [0x07, 0x06, 0x36, 0x6E, 0x66, 0x66, 0x67, 0x00], + [0x0C, 0x00, 0x0E, 0x0C, 0x0C, 0x0C, 0x1E, 0x00], + [0x30, 0x00, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E], + [0x07, 0x06, 0x66, 0x36, 0x1E, 0x36, 0x67, 0x00], + [0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00], + [0x00, 0x00, 0x33, 0x7F, 0x7F, 0x6B, 0x63, 0x00], + [0x00, 0x00, 0x1F, 0x33, 0x33, 0x33, 0x33, 0x00], + [0x00, 0x00, 0x1E, 0x33, 0x33, 0x33, 0x1E, 0x00], + [0x00, 0x00, 0x3B, 0x66, 0x66, 0x3E, 0x06, 0x0F], + [0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x78], + [0x00, 0x00, 0x3B, 0x6E, 0x66, 0x06, 0x0F, 0x00], + [0x00, 0x00, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x00], + [0x08, 0x0C, 0x3E, 0x0C, 0x0C, 0x2C, 0x18, 0x00], + [0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x6E, 0x00], + [0x00, 0x00, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00], + [0x00, 0x00, 0x63, 0x6B, 0x7F, 0x7F, 0x36, 0x00], + [0x00, 0x00, 0x63, 0x36, 0x1C, 0x36, 0x63, 0x00], + [0x00, 0x00, 0x33, 0x33, 0x33, 0x3E, 0x30, 0x1F], + [0x00, 0x00, 0x3F, 0x19, 0x0C, 0x26, 0x3F, 0x00], + [0x38, 0x0C, 0x0C, 0x07, 0x0C, 0x0C, 0x38, 0x00], + [0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00], + [0x07, 0x0C, 0x0C, 0x38, 0x0C, 0x0C, 0x07, 0x00], + [0x6E, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], +]; +pub const DEBUG_LINE: serial::Port = serial::Port::COM1; +pub fn integer_to_string<'_str, I: itoa::Integer>(value: I) -> &'_str str { + let mut buf = unsafe { &mut ITOA_BUFFER }; + *(unsafe { + &mut ITOA_BUFFER + }) = core::mem::MaybeUninit::::new(({ itoa::Buffer::new() })); + unsafe { (*(*buf).as_mut_ptr()).format::(value) } +} +struct Person { + id: i32, + age: i32, + name: &'static str, +} +#[repr(C)] +pub struct RegisterCapture { + pub rax: u64, + #[deprecated(note = "This register is used by LLVM.")] + pub rbx: u64, + pub rcx: u64, + pub rdx: u64, + pub rsi: u64, + pub rdi: u64, + #[deprecated(note = "This register is used by LLVM.")] + pub rbp: u64, + #[deprecated(note = "This register is used by LLVM.")] + pub rsp: u64, + pub r8: u64, + pub r9: u64, + pub r10: u64, + pub r11: u64, + pub r12: u64, + pub r13: u64, + pub r14: u64, + pub r15: u64, +} +pub static mut INTERRUPT_HANDLERS: [Option< + unsafe fn(InterruptStackFrame, RegisterCapture), +>; 255] = [None; 255]; +/// Captures the Registers of the CPU. +pub macro capture_registers { + () => { { let mut rax = 0; let mut rbx = 0; let mut rcx = 0; let mut rdx = 0; let mut + rsi = 0; let mut rdi = 0; let mut rbp = 0; let mut rsp = 0; let mut r8 = 0; let mut + r9 = 0; let mut r10 = 0; let mut r11 = 0; let mut r12 = 0; let mut r13 = 0; let mut + r14 = 0; let mut r15 = 0; ::core::arch::asm!("#CAPTURE_REGISTERS", out("rax") rax, + out("rcx") rcx, out("rdx") rdx, out("rsi") rsi, out("rdi") rdi, out("r8") r8, + out("r9") r9, out("r10") r10, out("r11") r11, out("r12") r12, out("r13") r13, + out("r14") r14, out("r15") r15, options(nostack, nomem, preserves_flags)); + RegisterCapture { rax, rbx, rcx, rdx, rsi, rdi, rbp, rsp, r8, r9, r10, r11, r12, r13, + r14, r15, } } } +} +/// Apply Registers and Return from Interrupt. +/// ==================================== +/// +/// # Arguments +/// +/// * `registers` - The Registers to apply. +/// * `capture` - The Capture to apply the Registers from. +/// * `frame` - The Interrupt Stack Frame. +/// +/// # Safety +/// This macro is unsafe because it uses inline assembly. +/// +/// See [`InterruptStackFrame::iretq`] for more info. +/// See [`__capture_set_registers`] for more info. +/// +pub macro kernelcall_ret { + ([$($reg : ident)*], $capture : expr, $frame : expr) => { + __capture_set_registers!(($($reg),*), $capture); $frame .iretq(); } +} +pub unsafe fn example_interrupt_handler( + _frame: InterruptStackFrame, + _capture: RegisterCapture, +) { + let mut response = _capture; + response.rdx = 0x1337; + let __macro_capture = response; + asm!( + "#APPLY_REGISTERS_FROM_CAPTURE\nin(\"rdx\") __macro_capture.rdx", options(nomem, + preserves_flags, nostack) + ); + _frame.iretq(); +} +#[no_mangle] +pub extern "x86-interrupt" fn __irq_handler(_frame: InterruptStackFrame) { + let mut capture = unsafe { + { + let mut rax = 0; + let mut rbx = 0; + let mut rcx = 0; + let mut rdx = 0; + let mut rsi = 0; + let mut rdi = 0; + let mut rbp = 0; + let mut rsp = 0; + let mut r8 = 0; + let mut r9 = 0; + let mut r10 = 0; + let mut r11 = 0; + let mut r12 = 0; + let mut r13 = 0; + let mut r14 = 0; + let mut r15 = 0; + asm!( + "#CAPTURE_REGISTERS", out("rax") rax, out("rcx") rcx, out("rdx") rdx, + out("rsi") rsi, out("rdi") rdi, out("r8") r8, out("r9") r9, out("r10") + r10, out("r11") r11, out("r12") r12, out("r13") r13, out("r14") r14, + out("r15") r15, options(nomem, preserves_flags, nostack) + ); + RegisterCapture { + rax, + rbx, + rcx, + rdx, + rsi, + rdi, + rbp, + rsp, + r8, + r9, + r10, + r11, + r12, + r13, + r14, + r15, + } + } + }; + let handler_index = (capture.rax & 0xFF) as u8; + if let Some(handler) = unsafe { INTERRUPT_HANDLERS[handler_index as usize] } { + unsafe { handler(_frame, capture) }; + { + ::core::panicking::panic_fmt( + format_args!( + "internal error: entered unreachable code: {0}", + format_args!("Interrupt Handler returned a value!"), + ), + ); + } + } else { + unsafe { + { + ::core::panicking::panic_fmt( + format_args!( + "Interrupt Handler for Index {0} is not defined!", + handler_index, + ), + ); + }; + } + } +} +static mut has_panicked: bool = false; +/// The Interrupt Handler for all Exceptions. +/// This function is called when an Exception occurs. +/// +/// # Arguments +/// +/// * `stack_frame` - The Interrupt Stack Frame. +/// * `exception_number` - The Exception Number. +/// * `error_code` - The Error Code. +/// +/// # Usage +/// This function is called by the **CPU**. It's not meant to be called manually. +#[no_mangle] +#[inline(never)] +pub fn __generic_error_irq_handler( + stack_frame: InterruptStackFrame, + exception_number: u8, + error_code: Option, +) { + let exception = unsafe { exception_number.transmute() }; + match exception { + _ => { + unsafe { + if !has_panicked { + has_panicked = true; + { + ::core::panicking::panic_fmt( + format_args!( + "Exception: {0:?}\nError Code: {1:?}\nStack Frame: {2:#?}", + exception, + error_code, + stack_frame, + ), + ); + }; + } + } + } + } +} +#[no_mangle] +unsafe extern "C" fn _start<'kernel>() -> ! { + let PRIMARY_FONT: Option = None; + let mut kernel_renderer = renderer::Renderer::new( + FRAMEBUFFERS.get(0).expect("No System Framebuffers."), + &FONT_BITMAP, + ); + let color = graphics::Color::from_rgb(0, 255, 0); + kernel_renderer.update_colors(Some(0xFFFFFFFF), Some(color.inner())); + kernel_renderer.clear(color.inner()); + kernel_renderer.optional_font_scaling = Some(2); + Renderer::make_global(kernel_renderer); + unsafe { + crate::KERNEL_CONSOLE + .write_str( + "(c) 2023 Joscha Egloff & AntOS Project. See README.MD for more info.\n", + ); + crate::KERNEL_CONSOLE.write_str("AntOS Kernel ( "); + crate::KERNEL_CONSOLE + .write_str({ + b"0000000000000000000000000000000000000000 aafa4439414e5db72e63bbdc5b4a4d53b1341cfa Joscha Egloff 1702308920 +0100\tclone: from https://github.com/ant-os/rust-kernel.git\naafa4439414e5db72e63bbdc5b4a4d53b1341cfa 8ba1d638cf70d88819e4ab9fe965769a51660763 Joscha Egloff 1703009034 +0100\tcommit: Merged Local version into Remote.\n8ba1d638cf70d88819e4ab9fe965769a51660763 1b04b2ec00a1c870c59e9fc3e94d86e9f554f941 Joscha Egloff 1703010265 +0100\tpull -f: Fast-forward\n1b04b2ec00a1c870c59e9fc3e94d86e9f554f941 71876d56d968156d466844257faa5895d0dce148 Joscha Egloff 1703011395 +0100\tcommit: Finalized Merge\n71876d56d968156d466844257faa5895d0dce148 71876d56d968156d466844257faa5895d0dce148 Joscha Egloff 1703011502 +0100\tcheckout: moving from trunk to local\n71876d56d968156d466844257faa5895d0dce148 71876d56d968156d466844257faa5895d0dce148 Joscha Egloff 1703011611 +0100\tcheckout: moving from local to master\n71876d56d968156d466844257faa5895d0dce148 71876d56d968156d466844257faa5895d0dce148 Joscha Egloff 1703011655 +0100\tcheckout: moving from master to trunk\n71876d56d968156d466844257faa5895d0dce148 52b9b6143e87e8d17ef514640d2a3e00dba2d8e1 Joscha Egloff 1703011669 +0100\tpull: Merge made by the \'ort\' strategy.\n52b9b6143e87e8d17ef514640d2a3e00dba2d8e1 52b9b6143e87e8d17ef514640d2a3e00dba2d8e1 Joscha Egloff 1703011671 +0100\tcheckout: moving from trunk to trunk\n52b9b6143e87e8d17ef514640d2a3e00dba2d8e1 52b9b6143e87e8d17ef514640d2a3e00dba2d8e1 Joscha Egloff 1703011744 +0100\tcheckout: moving from trunk to trunk\n52b9b6143e87e8d17ef514640d2a3e00dba2d8e1 52b9b6143e87e8d17ef514640d2a3e00dba2d8e1 Joscha Egloff 1703011775 +0100\tcheckout: moving from trunk to trunk\n52b9b6143e87e8d17ef514640d2a3e00dba2d8e1 52b9b6143e87e8d17ef514640d2a3e00dba2d8e1 Joscha Egloff 1703011816 +0100\tcheckout: moving from trunk to trunk\n52b9b6143e87e8d17ef514640d2a3e00dba2d8e1 2528423bac32c819ae275266385ed0985d29d74f Joscha Egloff 1703013350 +0100\tpull --tags origin trunk: Fast-forward\n2528423bac32c819ae275266385ed0985d29d74f 2528423bac32c819ae275266385ed0985d29d74f Joscha Egloff 1703020367 +0100\tcheckout: moving from trunk to refactoring\n2528423bac32c819ae275266385ed0985d29d74f efbbb1bae8ad9bc893d9e45dd5900a4eb5df526b Joscha Egloff 1703020470 +0100\tcommit: Fix memory allocation and mapping issues\nefbbb1bae8ad9bc893d9e45dd5900a4eb5df526b ec9100cde5c851aabcda11fda08093c48c3b27b6 Joscha Egloff 1703021732 +0100\tcommit: Update README.md with AntOS Kernel Rewrite project details\nec9100cde5c851aabcda11fda08093c48c3b27b6 2528423bac32c819ae275266385ed0985d29d74f Joscha Egloff 1703071397 +0100\tcheckout: moving from refactoring to trunk\n2528423bac32c819ae275266385ed0985d29d74f 0f315e6d10c8ddb07235cf7bb106bed3c8fad088 Joscha Egloff 1703071419 +0100\tpull --tags origin trunk: Fast-forward\n0f315e6d10c8ddb07235cf7bb106bed3c8fad088 0f315e6d10c8ddb07235cf7bb106bed3c8fad088 Joscha Egloff 1703071450 +0100\tcheckout: moving from trunk to gdb-protocol\n"; + b"DIRC\x00\x00\x00\x02\x00\x00\x00\\e\x81\xdf\xd9*%J\x98e\x81\xdf\xd9*%J\x98\x00\x00\x00M\x00\x02\x96\xb5\x00\x00\x81\xa4\x00\x00\x03\xe8\x00\x00\x03\xe8\x00\x00\x06\xcf\xad\xcdQ\x1b\xc4\xaf`\x80\xfe\xca\x89\xb5eb\xa1\xe7\xc2\x902\xab\x00!.github/workflows/rust-clippy.yml\x00e\x82\xce\xb99T\x10\xa8e\x82\xce\xb99T\x10\xa8\x00\x00\x00M\x00\x00\x0f\xb4\x00\x00\x81\xa4\x00\x00\x03\xe8\x00\x00\x03\xe8\x00\x00\x01\x95\xe4*]\t\x1c\x13\xa0\xd8\x82\xa9\x84\t\x8f)r\x85\x17\xf2\x02\x8c\x00\x1a.github/workflows/rust.yml\x00\x00\x00\x00\x00\x00\x00\x00e\x80}\x0e\x07\xec\xac\xa0e\x80}\x0e\x07\xec\xac\xa0\x00\x00\x00M\x00\x05\xbf\r\x00\x00\x81\xa4\x00\x00\x03\xe8\x00\x00\x03\xe8\x00\x00\x00\x9e<\xa0\xdd#\xee\x9b\x95!\xf4\x82\x82\xc0\xf8\xf14k\x1d\xfcV\x88\x00\x15.vscode/settings.json\x00\x00\x00\x00\x00e\x82\xce\xb9:E\xe74e\x82\xce\xb9:E\xe74\x00\x00\x00M\x00\x02%\xa2\x00\x00\x81\xa4\x00\x00\x03\xe8\x00\x00\x03\xe8\x00\x00\x14e7B\x9c\x8a\x1e\xb8\xe3\"\x0e\x99\xa3\x99(v\xa0\x9d1\x9cr\x81\x00\x12CODE_OF_CONDUCT.md\x00\x00\x00\x00\x00\x00\x00\x00e\x82\xce\xb9; \x03\xece\x82\xce\xb9; \x03\xec\x00\x00\x00M\x00\x028\xb1\x00\x00\x81\xa4\x00\x00\x03\xe8\x00\x00\x03\xe8\x00\x00\x06<\x07\x8b6\x9f\x1a\xb7\x92\x84\'\xcb4\xe5\xf0e7\x8a\\\xc9\xc8\xbc\x00\x0fCONTRIBUTING.md\x00\x00\x00e}\xaaS%I\xf8\\e}\xaaS%I\xf8\\\x00\x00\x00M\x00\tG@\x00\x00\x81\xa4\x00\x00\x03\xe8\x00\x00\x03\xe8\x00\x00\r\xa7\xd7.\xdep\'\xd8\xa1%\x96\xa56\xfawJC\xed\x00:\x83\xd3\x00\x0bGNUmakefile\x00\x00\x00\x00\x00\x00\x00exq\xc0-\x9c#\xccexq\xc0-\x9c#\xcc\x00\x00\x00M\x00\x01e\xe9\x00\x00\x81\xa4\x00\x00\x03\xe8\x00\x00\x03\xe8\x00\x00\x00\x0c\xc5~\xffU\xeb\xc0\xc5Is\x90:\xf5\xf7+\xacrv,\xf4\xf4\x00\x08INIT.SYS\x00\x00ew,8\'\xe0\x02dew,8\'\xe0\x02d\x00\x00\x00M\x00\tGO\x00\x00\x81\xa4\x00\x00\x03\xe8\x00\x00\x03\xe8\x00\x00\x00\xaa\x8a5\xb8\xf86p\xacX\xe50Go\x8b\xcdI\x01\xb6\xc2J\x1c\x00\x07LICENSE\x00\x00\x00ey\xcd\xdc6\x12\xfe\xa4ey\xcdy\x19e\xc2\xc8\x00\x00\x00M\x00\x02W\x1a\x00\x00\x81\xa4\x00\x00\x03\xe8\x00\x00\x03\xe8\x00\x01 \x00B\xd1l[\xd5\x07?m\xd1\x13\xb1V\xc8&\x1b\xda\xa4cM\xd0\x00\x08LOGO.SYS\x00\x00e}\xaa-\x06D\xe5\xe8e}\xaa-\x06D\xe5\xe8\x00\x00\x00M\x00\x00D\x83\x00\x00\x81\xa4\x00\x00\x03\xe8\x00\x00\x03\xe8\x00\x00\x1f\xd0\xa0\x88\xa7\xf1\xf5\xe2\xa3u~p\x9a\xaa)i\xab\x9b\x9f\xbc\x0cN\x00\x0bPROGRAM.SYS\x00\x00\x00\x00\x00\x00\x00e\x82\xce\xba\x01H\x07de\x82\xce\xba\x01H\x07d\x00\x00\x00M\x00\x00\xafn\x00\x00\x81\xa4\x00\x00\x03\xe8\x00\x00\x03\xe8\x00\x00\x05LC\xc7[\x92F\xd8\x90\xec\x14\x7f\xa4\xc0\x16iSo\xf2\x8d\xdc2\x00\tREADME.md\x00ew,8\'\xf1,\xecew,8\'\xf1,\xec\x00\x00\x00M\x00\tGQ\x00\x00\x81\xa4\x00\x00\x03\xe8\x00\x00\x03\xe8\x00\x00\x00\x00\xe6\x9d\xe2\x9b\xb2\xd1\xd6CK\x8b)\xaewZ\xd8\xc2\xe4\x8cS\x91\x00\x05a.out\x00\x00\x00\x00\x00e\x7fV\xca&\x1bZPe\x7fV\xca&\x1bZP\x00\x00\x00M\x00\x00\x1b\x9c\x00\x00\x81\xa4\x00\x00\x03\xe8\x00\x00\x03\xe8\x04\x00\x00\x00D7\xedC\xef\xc1\x85Z9v\xe8\xb2\xeeQx\xb0lB2\x1a\x00\tantos.hdd\x00e\x82\xce\xba!\x03mO\x066M\x8f\xdcE\x0f\x92w1\x82\x00\x1bkernel/src/kernel_logger.rs\x00\x00\x00\x00\x00\x00\x00e}\x8d\xc2)\x91sTe}\x8d\xc2)\x91sT\x00\x00\x00M\x00\x00\xa9x\x00\x00\x81\xa4\x00\x00\x03\xe8\x00\x00\x03\xe8\x00\x00\x07\xd6\xffj\r\xd7\xe9?/\x03\xab\t\xf3\xb2\x83#\xa9\xd7VUM3\x00\x18kernel/src/legacy_pic.rs\x00\x00e\x82\xce\xba*\x97L\xece\x82\xce\xba*\x97L\xec\x00\x00\x00M\x00\x01_\xb3\x00\x00\x81\xa4\x00\x00\x03\xe8\x00\x00\x03\xe8\x00\x00>\xf7K\x16\xa7\xf7\xfe\xb1\x93\xb4\x0e%0%Z\xe5\xa9L\x902|9\x00\x12kernel/src/main.rs\x00\x00\x00\x00\x00\x00\x00\x00e\x80\x1fi1\xa8\xf7$e\x80\x1fi1\xa8\xf7$\x00\x00\x00M\x00\tGj\x00\x00\x81\xa4\x00\x00\x03\xe8\x00\x00\x03\xe8\x00\x00\x0b\x9f;\xcc_aA\xb5\xb9\xb4:g;x\x99\x87Rv)\tq\x9d\x00\x14kernel/src/memory.rs\x00\x00\x00\x00\x00\x00ew,8(\xdb#tew,8(\xdb#t\x00\x00\x00M\x00\tGk\x00\x00\x81\xa4\x00\x00\x03\xe8\x00\x00\x03\xe8\x00\x00\x00\x00\xe6\x9d\xe2\x9b\xb2\xd1\xd6CK\x8b)\xaewZ\xd8\xc2\xe4\x8cS\x91\x00\x11kernel/src/mod.rs\x00e\x82\xce\xba-\xb0e}\xa5\xc97M>\xb0\x00\x00\x00M\x00\x00R*\x00\x00\x81\xa4\x00\x00\x03\xe8\x00\x00\x03\xe8\x00\x00\x00\x00\xe6\x9d\xe2\x9b\xb2\xd1\xd6CK\x8b)\xaewZ\xd8\xc2\xe4\x8cS\x91\x00\x14programs/GnuMakefile\x00\x00\x00\x00\x00\x00e}\xa5\xe3)\xe9\xd7te}\xa5\xe3)\xe9\xd7t\x00\x00\x00M\x00\x007?\x00\x00\x81\xa4\x00\x00\x03\xe8\x00\x00\x03\xe8\x00\x00\x00\x00\xe6\x9d\xe2\x9b\xb2\xd1\xd6CK\x8b)\xaewZ\xd8\xc2\xe4\x8cS\x91\x00\x11programs/build.py\x00e}\xa7;\x18&-\xe4e}\xa7;\x18&-\xe4\x00\x00\x00M\x00\x00R\xa2\x00\x00\x81\xa4\x00\x00\x03\xe8\x00\x00\x03\xe8\x00\x00\x00\x9f;\xcb\x98Z\x9eH\x16\xfa\xb0\xbd\xac\xb8-\t=\xff\x89\xb4Ob\x00\x1bprograms/example/Cargo.lock\x00\x00\x00\x00\x00\x00\x00e}\xa6\x1a\x177\xb8\xf8e}\xa6\x1a\x177\xb8\xf8\x00\x00\x00M\x00\x00R<\x00\x00\x81\xa4\x00\x00\x03\xe8\x00\x00\x03\xe8\x00\x00\x00\xb8\xaa\xe9\x89\x964\xe5D]\xfc\xb5\x85}\t\xabK\xd0\x1dd\xda\xde\x00\x1bprograms/example/Cargo.toml\x00\x00\x00\x00\x00\x00\x00e\x7fZ: go@e\x7fZ: go@\x00\x00\x00M\x00\x00RD\x00\x00\x81\xa4\x00\x00\x03\xe8\x00\x00\x03\xe8\x00\x00\x04\t\xe8_\x15w\xb5\x0e\x02\xbb\x83[(|\x92]\x19\xa0\x86\xb4\x00Yprograms/example/target/x86_64-unknown-none/debug/deps/example_program-90cda0d796f5b5ce.d\x00e}\xa9\xfd\x01.\xd2\xa8e}\xa9\xfc:\x91_\x84\x00\x00\x00M\x00\x00A\x17\x00\x00\x81\xa4\x00\x00\x03\xe8\x00\x00\x03\xe8\x00\x00\x1f\xd0\xa0\x88\xa7\xf1\xf5\xe2\xa3u~p\x9a\xaa)i\xab\x9b\x9f\xbc\x0cN\x00Wprograms/example/target/x86_64-unknown-none/debug/deps/example_program-b883f15776df51a0\x00\x00\x00e}\xa9\xfc1\xc8\x90\xfce}\xa9\xfc1\xc8\x90\xfc\x00\x00\x00M\x00\x00a\x9c\x00\x00\x81\xa4\x00\x00\x03\xe8\x00\x00\x03\xe8\x00\x00\x01\t\xaf9\xa6M\x08\xbdC\x90|\xc65\xa3q\x0b\x95\x7f\xe8\x97\xd3L\x00Yprograms/example/target/x86_64-unknown-none/debug/deps/example_program-b883f15776df51a0.d\x00e}\xa9\xfd\x01.\xd2\xa8e}\xa9\xfc:\x91_\x84\x00\x00\x00M\x00\x00A\x17\x00\x00\x81\xa4\x00\x00\x03\xe8\x00\x00\x03\xe8\x00\x00\x1f\xd0\xa0\x88\xa7\xf1\xf5\xe2\xa3u~p\x9a\xaa)i\xab\x9b\x9f\xbc\x0cN\x00Aprograms/example/target/x86_64-unknown-none/debug/example-program\x00e}\xa8\xef#7\xa8\xfce}\xa8\xef#7\xa8\xfc\x00\x00\x00M\x00\x00k\x9b\x00\x00\x81\xa4\x00\x00\x03\xe8\x00\x00\x03\xe8\x00\x00\x00\x8e?\x17o\xae\xcb`\x83?\xa1\xb7\xf5\xdf\x93g22xN\xc1\xd6\x00Cprograms/example/target/x86_64-unknown-none/debug/example-program.d\x00\x00\x00\x00\x00\x00\x00e}\xa9\xfc:\xf7Ghe}\xa9\xfc4\x9fr\xa0\x00\x00\x00M\x00\x00R\x04\x00\x00\x81\xa4\x00\x00\x03\xe8\x00\x00\x03\xe8\x00\x00,\x90\xc0\xf0_\xb4j\x1a\n\x87\xf2\xb8\tKg\x1d\x1a\xf5\xb7\x7fHH\x00\x9bprograms/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grkhcqfsoy-y9b5z6-c6mbj55ukyip8nfzu35p39ux4/1pf5l98mhuxb4c40.o\x00\x00\x00\x00\x00\x00\x00e}\xa9\xfc;\x17\x8b,e}\xa9\xfc4i\xb0\x84\x00\x00\x00M\x00\x00R\x06\x00\x00\x81\xa4\x00\x00\x03\xe8\x00\x00\x03\xe8\x00\x00\x0e \x96/\x06\xbe\xf2\x8e\xf4:common\x007 0\n\x05V\xf2D\xa5\xbd\x8bICe\xe7\xea\x1aJGi#\x95\xa3\xc0device\x005 0\n|*0\xf0\x96v\xad\x13\xfbh\xc4\x98\xa5\xfa.\xf5^\xef\xfc\x9bpaging\x004 0\n\xd2\xfc\x90)nb\xac\x07P\xd2_h\x93x`P\xe8\x99?\xfdgraphics\x003 0\n\x8d\xed\xeb{-\xab6O9\xccGW\x9e\xc0\xbdN\xfe\xcf\x16r.github\x002 1\n\xe2=\x99\xab\xbf\x1e\xc1\xe2\x92=\x8f\xb4Q\xc7\xd3\x18\xe5HyGworkflows\x002 0\n~.x\xcb\x00`7\x15\xd5\x1e\xf3Q\xd4]`\xae1n\x99c.vscode\x001 0\n/\x06\x82\xf0\x0fH\x1f\xb0\x16G\xb6\x87\xd7\xb2\x85\xd1\x14\xfe\xf4\xe4programs\x0029 1\n\x88\xde\x81\xae\xdc\x7f\x17q\x97\x8f\x9a\x1eU\xce\x1c\x89o\xda\xa3\x8dexample\x0027 2\n\x15\x9d\xdc\xffOfM43Q\xa4\x9a)\x03%\nDZ\x04\x1asrc\x001 0\n\x1c\x97\xa1\x0c\xbe#\x10%0\xed\xd4\t\xe0\x8d\xe1N\xe4\xf5\x89\xd9target\x0024 2\nJ.J\xfa\xa7\xa4\xa9a1\x18O\xf5\x166\xde\xa6;\\\xc2Sdebug\x001 0\n_\xc8\x1b\x9e\x90\x80$R\xe2v\xe2\x958B$%\xcc\x9a\xa0\x92x86_64-unknown-none\x0021 1\n\xb8\xf6\x08#M\xdd\xe3\xae\x8b3\x18\xc4\x13\xcf{.\xb9a\"\xc0debug\x0020 3\n6\x08gL\xf6\xad\xdb\x07\r8\xe1\xabD\xc4\xdd\x05\xba]V\xa9deps\x003 0\n\xf1\x07\xcee\xdd\x85j\x17\x1b\xb9l\x0b\xbe\x94*i4\xc8q\xb9incremental\x008 2\n\x93\x94\x1a\x1fw\xcd$\xb4_\\\xf0\x9ee\x9e\x85\x00\'i\xc8\xb5example_program-9ic89uw4p6xg\x006 1\n\x0c\t\xc5\xf8\xd3\xe9\x94\xa3!i\xddN\x9e\xcb\x00\xf15\xf5A\xb6s-grkhcqfsoy-y9b5z6-c6mbj55ukyip8nfzu35p39ux4\x005 0\n\x8e\'\xaf\xba\x11C4\xdf\x18bk\x96\xa2\x86\xae\xb8k\x14\x0c5example_program-jn9stlakvifm\x002 1\n\xcb\xc3\xcd\x86\n\xbd\x02ie\xc5g\x07\xd1L)x\xdc\tA\xf0s-grkh12jva9-17nr2z0-working\x001 0\nf\xe8R\x98u,<\xcc5#w/\x89\x1d\x13\xd9\xaf\xb4\xb7Z.fingerprint\x006 2\n!\x81X\xdd\x89\xe5N\x1e\x97\x91\xa4\x8e\xcb`I\xf0\xe0\xdag\xaeexample-program-90cda0d796f5b5ce\x002 0\n\xc3a\xde6\xdd|\'<\xcd\x00\xf0\xae\xd3\xa5\xb5\x045\xb1\x87Nexample-program-b883f15776df51a0\x004 0\nY%\xc3Sk\r-\x1cU)4\xfc\xff\\\xf9\x1f\xd4!Scy\xf6x\xc7\xd6\x04\xf0I-"; + "0f315e6-modified" + }); + crate::KERNEL_CONSOLE.write_str(" )"); + crate::KERNEL_CONSOLE.newline(); + }; + KERNEL_CONSOLE.newline(); + unsafe { + crate::KERNEL_CONSOLE.write_str("Console Successfully Initialized.\n"); + crate::KERNEL_CONSOLE.newline(); + }; + DEBUG_LINE.wait_for_connection(); + log::set_logger(&kernel_logger::KERNEL_LOGGER).unwrap(); + log::set_max_level(log::LevelFilter::Debug); + alloc_impl::KERNEL_ALLOCATOR + .initialize() + .expect("Failed to initialized Global Allocator."); + if let Some(kernel_addr) = KERNEL_ADDRESS_REQUEST.get_response().get() { + unsafe { + crate::KERNEL_CONSOLE.write_str("KERNEL BASE: ( virtual: 0x"); + crate::KERNEL_CONSOLE + .write_str( + VirtualAddress::new(kernel_addr.virtual_base as usize).as_str(), + ); + crate::KERNEL_CONSOLE.write_str(", physical: 0x"); + crate::KERNEL_CONSOLE + .write_str( + PhysicalAddress::new(kernel_addr.physical_base as usize).as_str(), + ); + crate::KERNEL_CONSOLE.write_str(" )"); + crate::KERNEL_CONSOLE.write_str("\n"); + crate::KERNEL_CONSOLE.newline(); + }; + } + SYSTEM_IDT[0x80 as usize] + .set_handler_fn(__irq_handler) + .set_present(true) + .set_privilege_level(x86_64::PrivilegeLevel::Ring0); + SYSTEM_IDT[0x20].set_handler_fn(handle_pit).set_present(true); + { + /// This constant is used to avoid spamming the same compilation error ~200 times + /// when the handler's signature is wrong. + /// If we just passed `$handler` to `set_general_handler_recursive_bits` + /// an error would be reported for every interrupt handler that tried to call it. + /// With `GENERAL_HANDLER` the error is only reported once for this constant. + const GENERAL_HANDLER: ::x86_64::structures::idt::GeneralHandlerFunc = __generic_error_irq_handler; + { + fn set_general_handler( + idt: &mut ::x86_64::structures::idt::InterruptDescriptorTable, + range: impl ::core::ops::RangeBounds, + ) { + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + error_code: u64, + ) -> ! { + GENERAL_HANDLER(frame, IDX.into(), Some(error_code)); + ::core::panicking::panic( + "General handler returned on double fault", + ); + } + idt.double_fault.set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + error_code: u64, + ) { + GENERAL_HANDLER(frame, IDX.into(), Some(error_code)); + } + idt.invalid_tss.set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + error_code: u64, + ) { + GENERAL_HANDLER(frame, IDX.into(), Some(error_code)); + } + idt.segment_not_present.set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + error_code: u64, + ) { + GENERAL_HANDLER(frame, IDX.into(), Some(error_code)); + } + idt.stack_segment_fault.set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + error_code: u64, + ) { + GENERAL_HANDLER(frame, IDX.into(), Some(error_code)); + } + idt.general_protection_fault.set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + error_code: ::x86_64::structures::idt::PageFaultErrorCode, + ) { + GENERAL_HANDLER(frame, IDX.into(), Some(error_code.bits())); + } + idt.page_fault.set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + error_code: u64, + ) { + GENERAL_HANDLER(frame, IDX.into(), Some(error_code)); + } + idt.alignment_check.set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) -> ! { + GENERAL_HANDLER(frame, IDX.into(), None); + ::core::panicking::panic( + "General handler returned on machine check exception", + ); + } + idt.machine_check.set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + error_code: u64, + ) { + GENERAL_HANDLER(frame, IDX.into(), Some(error_code)); + } + idt.cp_protection_exception.set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + error_code: u64, + ) { + GENERAL_HANDLER(frame, IDX.into(), Some(error_code)); + } + idt.vmm_communication_exception.set_handler_fn(handler); + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + error_code: u64, + ) { + GENERAL_HANDLER(frame, IDX.into(), Some(error_code)); + } + idt.security_exception.set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (0 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (0 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (0 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (0 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (1 << 3) | (0 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (0 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (0 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (0 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (0 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 0 | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; + { + const IDX: u8 = 1 | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4) + | (1 << 5) | (1 << 6) | (1 << 7); + #[allow(unreachable_code)] + if range.contains(&IDX) { + { + extern "x86-interrupt" fn handler( + frame: ::x86_64::structures::idt::InterruptStackFrame, + ) { + GENERAL_HANDLER(frame, IDX.into(), None); + } + idt[IDX as usize].set_handler_fn(handler); + }; + } + }; } - *(unsafe { - &mut PAGE_FRAME_ALLOCATOR - }) = core::mem::MaybeUninit::< - paging::frame_allocator::PageFrameAllocator, - >::new( - ({ - paging::frame_allocator::PageFrameAllocator::from_response( - memmap_response, - ) - }), - ); - } else { - DEBUG_LINE.unsafe_write_line("No Entries in Memory Map!") - } - } else { - DEBUG_LINE.unsafe_write_line("Failed to get Memory Map!"); - } - common::lgdt( - &DescriptorTablePointer { - limit: (gdt::INIT_GDT.len() * core::mem::size_of::() - 1) - as u16, - base: gdt::INIT_GDT.as_ptr() as u64, - }, - ); - let page_table_manager = PageTableManager::new().expect("Failed to crate PTM."); - if let Some(kernel_addr) = KERNEL_ADDRESS_REQUEST.get_response().get() { - unsafe { - crate::DEBUG_LINE.unsafe_write_string("KERNEL BASE: "); - crate::DEBUG_LINE - .unsafe_write_string(integer_to_string(kernel_addr.physical_base)); - }; - } - if let Some(kernel_file) = KERNEL_FILE_REQUEST.get_response().get() { - if let Some(file) = kernel_file.kernel_file.get() { - *(unsafe { - &mut KERNEL_CMDLINE - }) = core::mem::MaybeUninit::< - &'static str, - >::new( - (core::mem::transmute( - file - .cmdline - .to_str() - .expect("Failed to get kernel cmdline.") - .to_str() - .unwrap(), - )), - ); - *(unsafe { - &mut KERNEL_PATH - }) = core::mem::MaybeUninit::< - &'static str, - >::new( - (core::mem::transmute( - file - .path - .to_str() - .expect("Failed to get kernel path.") - .to_str() - .unwrap(), - )), - ); + set_general_handler(&mut SYSTEM_IDT, 0..28); } - unsafe { - crate::DEBUG_LINE.unsafe_write_string("\n\r"); - }; - unsafe { - crate::DEBUG_LINE.unsafe_write_string("CMDLINE: "); - crate::DEBUG_LINE.unsafe_write_string(KERNEL_CMDLINE.assume_init()); - crate::DEBUG_LINE.unsafe_write_string("\n\r"); - }; - unsafe { - crate::DEBUG_LINE.unsafe_write_string("PATH: "); - crate::DEBUG_LINE.unsafe_write_string(KERNEL_PATH.assume_init()); - crate::DEBUG_LINE.unsafe_write_string("\n\r"); - }; - } + }; + SYSTEM_IDT.load(); + legacy_pic::PRIMARY_PIC.enable(legacy_pic::Interrupt::PIT); + legacy_pic::PRIMARY_PIC.sync(); + unsafe { + crate::KERNEL_CONSOLE + .write_str("Successfully loaded Interrupt Descriptor Table."); + crate::KERNEL_CONSOLE.newline(); + }; if let Some(module_response) = MODULE_REQUEST.get_response().get() { unsafe { - crate::DEBUG_LINE.unsafe_write_string("MODULE COUNT: "); - crate::DEBUG_LINE - .unsafe_write_string(integer_to_string(module_response.module_count)); - crate::DEBUG_LINE.unsafe_write_string("\n\r"); + crate::KERNEL_CONSOLE.write_str("MODULE COUNT: "); + crate::KERNEL_CONSOLE + .write_str(integer_to_string(module_response.module_count)); + crate::KERNEL_CONSOLE.write_str("\n"); + crate::KERNEL_CONSOLE.newline(); }; for module in module_response.modules() { - unsafe { - crate::DEBUG_LINE.unsafe_write_string("Found Module "); - crate::DEBUG_LINE - .unsafe_write_string( - module - .path - .to_str() - .expect("Failed to get Module Path") - .to_str() - .unwrap(), - ); - crate::DEBUG_LINE.unsafe_write_string("!"); - crate::DEBUG_LINE.unsafe_write_string("\n\r"); - }; + let path = module + .path + .to_str() + .expect("Failed to get Module Path") + .to_str() + .unwrap(); + let cmdline = module + .cmdline + .to_str() + .expect("Failed to get Module Path") + .to_str() + .unwrap(); let addr = module.base.as_ptr().unwrap() as usize; - page_table_manager - .map_memory_internal( - VirtualAddress::new(addr), - PhysicalAddress::new(addr), - ); unsafe { - crate::DEBUG_LINE - .unsafe_write_string("Content(Null-Terminated String): "); - crate::DEBUG_LINE - .unsafe_write_string( - CStr::from_ptr( - module - .base - .as_ptr() - .map(|ptr| core::mem::transmute::<*mut _, *const _>(ptr)) - .expect("Failed to get Data of Module"), - ) - .to_str() - .unwrap(), - ); - crate::DEBUG_LINE.unsafe_write_string("\n\r"); + crate::KERNEL_CONSOLE.write_str("$BOOT$"); + crate::KERNEL_CONSOLE.write_str(path); + crate::KERNEL_CONSOLE + .write_str(": Successfully loaded... {\n parameters = [ "); + crate::KERNEL_CONSOLE.write_str(cmdline); + crate::KERNEL_CONSOLE.write_str(" ],\n base = 0x"); + crate::KERNEL_CONSOLE.write_str(VirtualAddress::new(addr).as_str()); + crate::KERNEL_CONSOLE.write_str("\n}"); + crate::KERNEL_CONSOLE.newline(); }; + 'module: { + if path.contains(".TTF") { + let face_result = ttf_parser::Face::parse( + core::slice::from_raw_parts( + module.base.as_ptr().unwrap(), + module.length as usize, + ), + 0, + ); + if let Ok(face) = face_result { + let id = face.glyph_index('A').unwrap(); + let mut builder = FontOutline::new(); + face.outline_glyph(id, &mut builder).unwrap(); + unsafe { + crate::KERNEL_CONSOLE.write_str("Font has "); + crate::KERNEL_CONSOLE + .write_str(integer_to_string(builder.segments().len())); + crate::KERNEL_CONSOLE.write_str(" Segments!"); + crate::KERNEL_CONSOLE.newline(); + }; + } + } else if path.contains(".SYS") { + let program_base = module.base.as_ptr().expect("No Module Base"); + let program = core::slice::from_raw_parts( + program_base, + module.length as usize, + ); + let bytes = match elf::ElfBytes::< + AnyEndian, + >::minimal_parse(program) { + Err(e) => { + { + let lvl = ::log::Level::Error; + if lvl <= ::log::STATIC_MAX_LEVEL + && lvl <= ::log::max_level() + { + ::log::__private_api::log( + format_args!("Error Parsing Program: {0:#?}", e), + lvl, + &( + "antos_kernel_minimal_generic", + "antos_kernel_minimal_generic", + "src/main.rs", + ), + 530u32, + ::log::__private_api::Option::None, + ); + } + }; + break 'module; + } + Ok(v) => v, + }; + KERNEL_PAGE_MAPPER + .lock() + .update_flags( + HugePage::from_start_address( + VirtAddr::new(program_base.addr().transmute()) + .align_down(HugePage::SIZE), + ) + .unwrap(), + PageTableFlags::PRESENT | !PageTableFlags::NO_EXECUTE, + ); + let start: *const unsafe extern "C" fn(KernelProgramMeta) = core::mem::transmute( + program_base.addr() as u64 + bytes.ehdr.e_entry, + ); + } + } } } + INTERRUPT_HANDLERS[0x1] = Some(example_interrupt_handler); + asm!("mov al, 0x1", options(preserves_flags, raw)); + { + asm!("int {0}", const 0x80, options(nomem, nostack)); + }; + let mut result: u16; + asm!("nop", out("rdx") result); + { + let lvl = ::log::Level::Info; + if lvl <= ::log::STATIC_MAX_LEVEL && lvl <= ::log::max_level() { + ::log::__private_api::log( + format_args!("Hello from the AntOS Kernel! ;)"), + lvl, + &( + "antos_kernel_minimal_generic", + "antos_kernel_minimal_generic", + "src/main.rs", + ), + 572u32, + ::log::__private_api::Option::None, + ); + } + }; DEBUG_LINE.unsafe_write_line("End of Runtime."); - hcf(); + loop { + asm!("hlt"); + } } pub fn boolean_to_str(value: bool) -> &'static str { match value { @@ -2993,6 +8380,7 @@ pub fn boolean_to_str(value: bool) -> &'static str { false => "false", } } +#[cfg(not(test))] #[panic_handler] fn rust_panic(_info: &core::panic::PanicInfo) -> ! { unsafe { @@ -3004,6 +8392,22 @@ fn rust_panic(_info: &core::panic::PanicInfo) -> ! { .unwrap_or(&"Panic!" as &&'_ str), ); } + { + let lvl = ::log::Level::Error; + if lvl <= ::log::STATIC_MAX_LEVEL && lvl <= ::log::max_level() { + ::log::__private_api::log( + format_args!("A Rust Panic has occurred: \n{0:#?}\n", _info), + lvl, + &( + "antos_kernel_minimal_generic", + "antos_kernel_minimal_generic", + "src/main.rs", + ), + 614u32, + ::log::__private_api::Option::None, + ); + } + }; hcf(); } fn hcf() -> ! { diff --git a/kernel/Cargo.lock b/kernel/Cargo.lock index e2b57f1..937149e 100644 --- a/kernel/Cargo.lock +++ b/kernel/Cargo.lock @@ -1,300 +1,321 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "ahash" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" -dependencies = [ - "cfg-if", - "once_cell", - "version_check", - "zerocopy", -] - -[[package]] -name = "antos-kernel-minimal-generic" -version = "0.1.0" -dependencies = [ - "bit", - "bitfield", - "bitflags", - "bitmap", - "elf", - "git-version", - "heapless", - "itoa", - "lazy_static", - "limine", - "lock_api", - "log", - "numtoa", - "psf-rs", - "spin", - "ttf-parser", - "x86_64", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "bit" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b645c5c09a7d4035949cfce1a915785aaad6f17800c35fda8a8c311c491f284" - -[[package]] -name = "bit_field" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61" - -[[package]] -name = "bitfield" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d7e60934ceec538daadb9d8432424ed043a904d8e0243f3c6446bce549a46ac" - -[[package]] -name = "bitflags" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" - -[[package]] -name = "bitmap" -version = "3.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e97e87564167fab42092c423e491e0fbb77b04ae02b5a78559a1396c052e01e9" - -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "elf" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4445909572dbd556c457c849c4ca58623d84b27c8fff1e74b0b4227d8b90d17b" - -[[package]] -name = "git-version" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad568aa3db0fcbc81f2f116137f263d7304f512a1209b35b85150d3ef88ad19" -dependencies = [ - "git-version-macro", -] - -[[package]] -name = "git-version-macro" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53010ccb100b96a67bc32c0175f0ed1426b31b655d562898e57325f81c023ac0" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "hash32" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" -dependencies = [ - "byteorder", -] - -[[package]] -name = "heapless" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" -dependencies = [ - "hash32", - "stable_deref_trait", -] - -[[package]] -name = "itoa" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -dependencies = [ - "spin", -] - -[[package]] -name = "limine" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f45c67c512034e8eb0064556e1db5da671b3ef50791cd6ac6376e7aefc0ef27e" - -[[package]] -name = "lock_api" -version = "0.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "log" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" - -[[package]] -name = "numtoa" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6aa2c4e539b869820a2b82e1aef6ff40aa85e65decdd5185e83fb4b1249cd00f" - -[[package]] -name = "once_cell" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - -[[package]] -name = "proc-macro2" -version = "1.0.70" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "psf-rs" -version = "2.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d8a4daa21926bedb8975fde0b9ac1d0b0d4d7212b04be1cfc0e6dd3f13034b8" -dependencies = [ - "ahash", - "hash32", - "heapless", -] - -[[package]] -name = "quote" -version = "1.0.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rustversion" -version = "1.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - -[[package]] -name = "stable_deref_trait" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" - -[[package]] -name = "syn" -version = "2.0.41" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c8b28c477cc3bf0e7966561e3460130e1255f7a1cf71931075f1c5e7a7e269" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "ttf-parser" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17f77d76d837a7830fe1d4f12b7b4ba4192c1888001c7164257e4bc6d21d96b4" - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "volatile" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "442887c63f2c839b346c192d047a7c87e73d0689c9157b00b53dcc27dd5ea793" - -[[package]] -name = "x86_64" -version = "0.14.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b835097a84e4457323331ec5d6eb23d096066cbfb215d54096dcb4b2e85f500" -dependencies = [ - "bit_field", - "bitflags", - "rustversion", - "volatile", -] - -[[package]] -name = "zerocopy" -version = "0.7.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c4061bedbb353041c12f413700357bec76df2c7e2ca8e4df8bac24c6bf68e3d" -dependencies = [ - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3c129550b3e6de3fd0ba67ba5c81818f9805e58b8d7fee80a3a59d2c9fc601a" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "antos-kernel-minimal-generic" +version = "0.1.0" +dependencies = [ + "antos-macros", + "bit", + "bitfield", + "bitflags", + "bitmap", + "elf", + "git-version", + "heapless", + "itoa", + "lazy_static", + "limine", + "lock_api", + "log", + "numtoa", + "psf-rs", + "spin", + "ttf-parser", + "x86_64", +] + +[[package]] +name = "antos-macros" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bit" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b645c5c09a7d4035949cfce1a915785aaad6f17800c35fda8a8c311c491f284" + +[[package]] +name = "bit_field" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61" + +[[package]] +name = "bitfield" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d7e60934ceec538daadb9d8432424ed043a904d8e0243f3c6446bce549a46ac" + +[[package]] +name = "bitflags" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" + +[[package]] +name = "bitmap" +version = "3.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e97e87564167fab42092c423e491e0fbb77b04ae02b5a78559a1396c052e01e9" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "elf" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4445909572dbd556c457c849c4ca58623d84b27c8fff1e74b0b4227d8b90d17b" + +[[package]] +name = "git-version" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ad568aa3db0fcbc81f2f116137f263d7304f512a1209b35b85150d3ef88ad19" +dependencies = [ + "git-version-macro", +] + +[[package]] +name = "git-version-macro" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53010ccb100b96a67bc32c0175f0ed1426b31b655d562898e57325f81c023ac0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.41", +] + +[[package]] +name = "hash32" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606" +dependencies = [ + "byteorder", +] + +[[package]] +name = "heapless" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" +dependencies = [ + "hash32", + "stable_deref_trait", +] + +[[package]] +name = "itoa" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +dependencies = [ + "spin", +] + +[[package]] +name = "limine" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f45c67c512034e8eb0064556e1db5da671b3ef50791cd6ac6376e7aefc0ef27e" + +[[package]] +name = "lock_api" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] +name = "numtoa" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6aa2c4e539b869820a2b82e1aef6ff40aa85e65decdd5185e83fb4b1249cd00f" + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "proc-macro2" +version = "1.0.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "psf-rs" +version = "2.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d8a4daa21926bedb8975fde0b9ac1d0b0d4d7212b04be1cfc0e6dd3f13034b8" +dependencies = [ + "ahash", + "hash32", + "heapless", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustversion" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c8b28c477cc3bf0e7966561e3460130e1255f7a1cf71931075f1c5e7a7e269" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "ttf-parser" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17f77d76d837a7830fe1d4f12b7b4ba4192c1888001c7164257e4bc6d21d96b4" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "volatile" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "442887c63f2c839b346c192d047a7c87e73d0689c9157b00b53dcc27dd5ea793" + +[[package]] +name = "x86_64" +version = "0.14.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b835097a84e4457323331ec5d6eb23d096066cbfb215d54096dcb4b2e85f500" +dependencies = [ + "bit_field", + "bitflags", + "rustversion", + "volatile", +] + +[[package]] +name = "zerocopy" +version = "0.7.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c4061bedbb353041c12f413700357bec76df2c7e2ca8e4df8bac24c6bf68e3d" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3c129550b3e6de3fd0ba67ba5c81818f9805e58b8d7fee80a3a59d2c9fc601a" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.41", +] diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index e269c82..e315cee 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -16,6 +16,7 @@ psf-rs = "2.1.4" ttf-parser = { version = "0.20.0", default-features = false } heapless = "*" git-version = "*" +antos-macros = { path = "../macros" } lock_api = "0.4.11" log = "0.4.20" elf = { version = "0.7.4", default-features = false, features = ["nightly"] } @@ -23,4 +24,6 @@ elf = { version = "0.7.4", default-features = false, features = ["nightly"] } # I really want to not do this.... but here we go... x86_64 = "0.14.11" -spin = "*" \ No newline at end of file +spin = "*" +# gdbstub = "0.7.0" +# gdbstub_arch = "*" \ No newline at end of file diff --git a/kernel/src/common/driver.rs b/kernel/src/common/driver.rs new file mode 100644 index 0000000..1920bea --- /dev/null +++ b/kernel/src/common/driver.rs @@ -0,0 +1,90 @@ +// Purpose: Common driver structures. + +use elf::endian::AnyEndian; + +pub type DriverStatus = u64; + +/// Driver structure +#[derive(Debug)] +#[repr(C)] +pub struct Driver { + pub name: &'static str, + pub signature: &'static str, + pub driver_entry: DriverEntry, +} + +/// Driver entry point +pub type DriverEntry = unsafe fn() -> DriverStatus; + +impl Driver { + /// Creates a new driver + pub const fn new(name: &'static str, signature: &'static str, driver_entry: DriverEntry) -> Self { + Self { + name, + signature, + driver_entry, + } + } + + /// Returns the driver name + pub const fn get_name(&self) -> &'static str { + self.name + } + + /// Returns the driver signature + pub const fn get_signature(&self) -> &'static str { + self.signature + } + + /// Returns the driver entry point + /// + /// # Safety + /// + /// This function is unsafe because it returns a function pointer. + pub unsafe fn get_driver_entry(&self) -> DriverEntry { + self.driver_entry + } + + /// Initializes the driver + /// + /// # Safety + /// + /// This function is unsafe because it calls the driver entry point. + /// + /// # Returns + /// + /// Returns the driver status. + /// + /// # Notes + /// + /// This function is unsafe because it calls the driver entry point. + /// + /// It is the responsibility of the caller to ensure that the driver entry point is valid. + pub unsafe fn init(&self) -> DriverStatus { + (self.driver_entry)() + } + + /// Creates a new driver from a raw ELF file + /// + /// # Parameters + /// + /// * `base` - The base address of the ELF file + /// * `elf` - The ELF file + /// * `identifier` - The driver identifier + /// + /// # Returns + /// + /// Returns a new driver. + /// + /// # Safety + /// + /// This function is unsafe because it transmutes the driver entry point. + pub unsafe fn from_raw_elf(base: u64, elf: &elf::ElfBytes<'_, AnyEndian>, identifier: &'static str) -> Self { + let name = identifier; + let signature = identifier; + + let driver_entry = unsafe { core::mem::transmute(base + elf.ehdr.e_entry)}; + + Self::new(name, signature, driver_entry) + } +} \ No newline at end of file diff --git a/kernel/src/common/mod.rs b/kernel/src/common/mod.rs index 9b33ca6..3d27ca5 100644 --- a/kernel/src/common/mod.rs +++ b/kernel/src/common/mod.rs @@ -1,6 +1,7 @@ pub mod consts; pub mod io; pub mod macros; +pub mod driver; use core::{simd::ptr::SimdConstPtr, ptr::NonNull, mem::{size_of_val, size_of}, sync::atomic::AtomicPtr, ops::Deref}; pub use limine::*; @@ -10,6 +11,9 @@ pub mod handler; pub type Unit = (); +pub use x86_64::structures::idt::ExceptionVector; +pub use x86_64::structures::idt::InterruptStackFrame; + #[doc = "A [AtomicPtr] wrapper that implements [Deref]."] #[repr(transparent)] struct AtomicRef{ @@ -58,6 +62,8 @@ unsafe impl TransmuteInto> for NonNull{ /* empty */ } unsafe impl TransmuteInto> for AtomicRef { /* empty */ } +unsafe impl TransmuteInto for u8 { /* empty */ } + #[cfg(target_pointer_width = "64")] unsafe impl TransmuteInto for usize{ /* empty */ } #[cfg(target_pointer_width = "32")] diff --git a/kernel/src/debug/gdb_impl.rs b/kernel/src/debug/gdb_impl.rs new file mode 100644 index 0000000..dbb1fbf --- /dev/null +++ b/kernel/src/debug/gdb_impl.rs @@ -0,0 +1,10 @@ +use super::protocol::{Protocol, ProtocolImpl}; +use alloc::boxed::Box; + +pub struct Gdb; + +impl ProtocolImpl for Gdb{ + fn handle_packet(packet: &[u8]) -> Box<[u8]>{ + + } +} \ No newline at end of file diff --git a/kernel/src/debug/mod.rs b/kernel/src/debug/mod.rs new file mode 100644 index 0000000..07f68ce --- /dev/null +++ b/kernel/src/debug/mod.rs @@ -0,0 +1,13 @@ +use core::{sync::atomic::{AtomicBool, Ordering::SeqCst}, arch}; + +use crate::{serial::Port, device::character::UnsafeCharacterDevice}; + +static DEBUG_ENABLED: AtomicBool = AtomicBool::new(false); + +pub fn toggle_debug(boolean: bool) { + DEBUG_ENABLED.store(boolean, SeqCst); +} + +pub fn is_debug_enabled() -> bool { + DEBUG_ENABLED.load(SeqCst) +} diff --git a/kernel/src/debug/protocol.rs b/kernel/src/debug/protocol.rs new file mode 100644 index 0000000..4ef480e --- /dev/null +++ b/kernel/src/debug/protocol.rs @@ -0,0 +1,144 @@ +//! GDB Serial Remote Protocol +//! ========================= +//! This module implements the GDB Serial Remote Protocol, which is used to +//! communicate with the kernel over a serial port. +//! https://sourceware.org/gdb/onlinedocs/gdb/Remote-Protocol.html + +use core::marker::PhantomData; + +use x86_64::structures::idt::{ExceptionVector, InterruptStackFrame}; + +use crate::{serial::Port as SerialPort, device::character::UnsafeCharacterDevice}; +use alloc::boxed::Box; + +const STATIC_PACKAGE_BUFFER_SIZE: usize = 4096; + +static mut PACKET_BUFFER: [u8; STATIC_PACKAGE_BUFFER_SIZE] = [0u8; STATIC_PACKAGE_BUFFER_SIZE]; + +/// GDB Serial Remote Protocol. +/// =========================== +/// This struct is thread-safe. +/// +/// It is safe to use this struct from multiple CPUs at the same time. +/// This is because the serial port is only accessed while handling a breakpoint exception. +/// The breakpoint exception handler is only called by one CPU at a time. +pub struct Protocol { + /// Serial port to use for communication. + serial_port: spin::RwLock, + /// Buffer for incoming packets. + /// This is a static buffer because we maybe be unable to allocate memory while handling + /// a breakpoint exception. + /// The buffer is only used while handling a breakpoint exception, so it's + /// fine to use a static buffer. + /// TODO: Make this more thread-safe? + packet_buffer: &'static mut [u8], + + /// Protocol implementation. + /// This is a phantom data field because we only need the type information. + _protocol_impl: PhantomData +} + +/// Protocol implementation. +/// Functions in this trait are called when the corresponding packet is received. +pub trait ProtocolImpl where Self: 'static { + /// Handle a packet. + /// The packet is guaranteed to be valid. + /// The response must be a valid packet. + fn handle_packet(packet: &[u8]) -> Box<[u8]>; +} + +// Mark the Protocol as being thread-safe. +// This is safe because the serial port is only accessed while handling a breakpoint exception. +// The breakpoint exception handler is only called by one CPU at a time. +unsafe impl Sync for Protocol { /* empty */ } +unsafe impl Send for Protocol { /* empty */ } + +impl Protocol{ + pub fn new(serial_port: SerialPort) -> Self{ + Self{ + serial_port: spin::RwLock::new(serial_port), + packet_buffer: unsafe { &mut PACKET_BUFFER }, + _protocol_impl: PhantomData + } + } + + pub fn handle_exception(&mut self, exception: ExceptionVector, stack_frame: InterruptStackFrame){ + if exception == ExceptionVector::Breakpoint{ + self.handle_packet(); + } + } + + pub fn handle_serial_interrupt(&mut self){ + todo!("Handle serial interrupt."); + } + + fn handle_packet(&mut self){ + // Read the packet from the serial port. + let packet = self.read_packet(); + + // Handle the packet. + let response = I::handle_packet(packet); + + // Send the response. + self.send_packet(response); + } + + pub fn update(&mut self){ + self.handle_packet(); + } + + fn read_packet(&mut self) -> &[u8]{ + let _start_byte = unsafe { self.serial_port.read().read_raw() }; + + // Read the packet until the end character. + let mut packet_length = 0; + loop{ + let byte = unsafe { self.serial_port.read().read_raw() }; + if byte == b'#'{ + break; + } + + if packet_length == self.packet_buffer.len(){ + unsafe { self.serial_port.read().write_raw('-' as u8) }; + return &[]; + } + + self.packet_buffer[packet_length] = byte; + packet_length += 1; + } + + let checksum = unsafe { self.serial_port.read().read_raw() }; + + let mut expected_checksum: u8 = 0; + for i in 0..packet_length{ + expected_checksum = expected_checksum.wrapping_add(self.packet_buffer[i] as u8); + } + expected_checksum &= 0xff; + + if checksum != expected_checksum{ + unsafe { self.serial_port.read().write_raw('-' as u8) }; + return &[]; + } + + // Send an acknowledgement. + unsafe { self.serial_port.read().write_raw('+' as u8) }; + + &self.packet_buffer[..packet_length] + } + + fn send_packet(&mut self, packet: Box<[u8]>) { + let mut checksum: u8 = 0; + for i in 0..packet.len() { + checksum = checksum.wrapping_add(packet[i] as u8); + } + checksum &= 0xff; + + unsafe { self.serial_port.read().write_raw('$' as u8) }; + + for i in 0..packet.len() { + unsafe { self.serial_port.read().write_raw(packet[i]) }; + } + + unsafe { self.serial_port.read().write_raw(checksum) }; + } +} diff --git a/kernel/src/main.rs b/kernel/src/main.rs index 4b16a7f..6e7439d 100644 --- a/kernel/src/main.rs +++ b/kernel/src/main.rs @@ -38,6 +38,7 @@ pub mod graphics; pub mod kernel_logger; pub mod legacy_pic; pub mod memory; +pub mod debug; pub mod paging; pub mod renderer; pub mod serial; @@ -48,11 +49,13 @@ use alloc_impl as _; use paging::frame_allocator::PageFrameAllocator; use spin::Mutex; use x86_64::structures::idt::InterruptStackFrame; +use x86_64::structures::paging::mapper::FlagUpdateError; use x86_64::structures::paging::page::PageRange; -use x86_64::structures::paging::{Mapper, PageTableFlags, PhysFrame, Size2MiB, Size4KiB}; +use x86_64::structures::paging::{Mapper, PageTableFlags, PhysFrame, Size2MiB, Size4KiB, Page}; use x86_64::{structures, PhysAddr, VirtAddr}; use crate::alloc_impl::KERNEL_ALLOCATOR; +use crate::common::driver::Driver; use crate::common::idt::{Idt, KERNEL_IDT}; use crate::common::io::outb; use crate::common::*; @@ -67,6 +70,7 @@ use crate::memory::{ use crate::paging::table_manager::PageTableManager; use core::arch::asm; use core::ffi::CStr; +use core::hint::unreachable_unchecked; use elf::endian::AnyEndian; use elf::segment::ProgramHeader; use memory::MemoryArea; @@ -84,6 +88,8 @@ extern crate bitfield; use numtoa::NumToA; use renderer::Renderer; +#[macro_use] extern crate antos_macros; + static FRAMEBUFFERS_REQUEST: limine::FramebufferRequest = limine::FramebufferRequest::new(0); static TERMINAL_REQUEST: limine::TerminalRequest = limine::TerminalRequest::new(0); static MEMMAP_REQUEST: limine::MemmapRequest = limine::MemmapRequest::new(0); @@ -148,6 +154,7 @@ lazy_static::lazy_static! { }; } + #[derive(Debug, Clone, Copy)] enum OutlineSegment { MoveTo(f32, f32), @@ -234,40 +241,273 @@ struct Person { name: &'static str, } -pub type InterruptParams = (usize, *mut ()); + + +#[repr(C)] +#[derive(Debug, Clone, Copy)] +pub struct RegisterCapture { + pub rax: u64, + #[deprecated(note = "This register is used by LLVM.")] + pub rbx: u64, + pub rcx: u64, + pub rdx: u64, + pub rsi: u64, + pub rdi: u64, + #[deprecated(note = "This register is used by LLVM.")] + pub rbp: u64, + #[deprecated(note = "This register is used by LLVM.")] + pub rsp: u64, + pub r8: u64, + pub r9: u64, + pub r10: u64, + pub r11: u64, + pub r12: u64, + pub r13: u64, + pub r14: u64, + pub r15: u64, +} + + +pub static mut INTERRUPT_HANDLERS: [Option; 255] = [None; 255]; + +static mut RAX: u64 = 0; +static mut RBX: u64 = 0; +static mut RCX: u64 = 0; +static mut RDX: u64 = 0; +static mut RSI: u64 = 0; +static mut RDI: u64 = 0; +static mut RBP: u64 = 0; +static mut RSP: u64 = 0; +static mut R8: u64 = 0; +static mut R9: u64 = 0; +static mut R10: u64 = 0; +static mut R11: u64 = 0; +static mut R12: u64 = 0; +static mut R13: u64 = 0; +static mut R14: u64 = 0; +static mut R15: u64 = 0; + +/// Captures the Registers of the CPU. +/// +/// ## Safety +/// +/// This macro is unsafe because it uses inline assembly. +/// +/// ## Returns +/// +/// The Captured Registers. +/// +/// ## Usage +/// +/// ```rust +/// let registers = unsafe { capture_registers!() }; +/// ``` +/// +/// ## Related +/// +/// See [`RegisterCapture`] for more info. +/// +/// [`RegisterCapture`]: kernel::RegisterCapture +pub macro capture_registers() { + { + ::core::arch::asm!("#CAPTURE_REGISTERS", out("rax") RAX, out("rcx") RCX, out("rdx") RDX, out("rsi") RSI, out("rdi") RDI, out("r8") R8, out("r9") R9, out("r10") R10, out("r11") R11, out("r12") R12, out("r13") R13, out("r14") R14, out("r15") R15, options(nostack, nomem, preserves_flags)); + + RegisterCapture { + rax: RAX, + rbx: RBX, + rcx: RCX, + rdx: RDX, + rsi: RSI, + rdi: RDI, + rbp: RBP, + rsp: RSP, + r8: R8, + r9: R9, + r10: R10, + r11: R11, + r12: R12, + r13: R13, + r14: R14, + r15: R15, + } + } +} + +/// Apply Registers and Return from Interrupt. +/// =========================================== +/// +/// ## Arguments +/// +/// * `registers` - The Registers to apply. +/// * `capture` - The Capture to apply the Registers from. +/// * `frame` - The Interrupt Stack Frame. +/// +/// ## Safety +/// This macro is unsafe because it uses inline assembly. +/// +/// See [`InterruptStackFrame::iretq`] for more info. +/// +/// See [`__capture_set_registers`] for more info. +/// +pub macro kernelcall_ret([$($reg:ident)*], $capture:expr, $frame:expr) { + ::antos_macros::__capture_set_registers!(($($reg),*), $capture); + $frame.iretq(); // Return from Interrupt. +} + +/// The Binding for the [`print`] Kernelcall. +/// +/// # Arguments +/// +/// * `buffer` - The Buffer to print. +/// * `len` - The Length of the Buffer. +/// +/// # Safety +/// +/// This function is unsafe because it uses inline assembly. +/// +/// # Returns +/// +/// The Status of the Kernelcall. +/// +/// # Usage +/// +/// To use this function, you have to call it with inline assembly or use AntOS's Kernel Bindings. +/// +/// ## Example +/// +/// ```asm +/// mov r9, A_POINTER_TO_THE_STRING +/// mov r10, THE_LENGTH_OF_THE_STRING +/// mov r8, 0x6 +/// int 0x80 +/// ``` +/// +/// This will call the [`print`] Kernelcall. +/// +/// [`print`]: kernelcall.print.html +#[inline(never)] +#[no_mangle] +pub unsafe extern "C" fn __kernelcall_print(buffer: *const u8, len: u64) -> u64 { + let mut status: u64; + asm!( + "mov r8, 0x6", + "int 0x80", + in("r9") buffer, + in("r10") len, + lateout("r8") status, + ); + status +} + +pub unsafe fn example_interrupt_handler(_frame: InterruptStackFrame, _capture: RegisterCapture) { + let mut response = _capture; + response.rdx = 0x1337; + + kernelcall_ret!([rdx], response, _frame); +} + +/// Kernelcall for printing to the Screen. +/// This is the Kernel's Implementation of the [`print`] Kernelcall. +/// +/// # Safety +/// +/// This function is unsafe, but anything that could go wrong is handled by the Kernel. +/// +/// # Related +/// See [`print`] for more info. +/// +/// [`print`]: kernelcall.print.html +pub unsafe fn kernelcall_print(_frame: InterruptStackFrame, _capture: RegisterCapture) { + let mut response = _capture; + let string_ptr = response.r9 as *const u8; + let string_len = response.r10 as usize; + + let string = core::slice::from_raw_parts(string_ptr, string_len); + + let string = core::str::from_utf8_unchecked(string); + + kprint!("{}", string); + + response.r8 = 0x0; // Return 0x0 ( Success ). + + kernelcall_ret!([r8], response, _frame); +} + + #[no_mangle] pub extern "x86-interrupt" fn __irq_handler(_frame: InterruptStackFrame) { - let (mut r8, mut r9, mut r10): (u64, u64, u64); + let mut capture = unsafe { capture_registers!() }; + + // The Index of the Interrupt Handler is stored in the AL Register. + let handler_index = (capture.r8) as u8; + + if handler_index == 0 { + return; + } + + if let Some(handler) = unsafe { INTERRUPT_HANDLERS[handler_index as usize] } { + unsafe { handler(_frame, capture) }; // Call the Interrupt Handler, it'll return from the Interrupt. + unreachable!("Interrupt Handler returned a value!") // The Interrupt Handler should never return. + } else { + panic!( + "Interrupt Handler for Index {} is not defined!", + handler_index + ); + } } static mut has_panicked: bool = false; -fn __generic_error_irq_handler( +/// The Interrupt Handler for all Exceptions. +/// This function is called when an Exception occurs. +/// +/// # Arguments +/// +/// * `stack_frame` - The Interrupt Stack Frame. +/// * `exception_number` - The Exception Number. +/// * `error_code` - The Error Code. +/// +/// # Usage +/// This function is called by the **CPU**. It's not meant to be called manually. +#[no_mangle] +#[inline(never)] +pub fn __generic_error_irq_handler( stack_frame: InterruptStackFrame, - index: u8, + exception_number: u8, error_code: Option, ) { - unsafe { - // Renderer::global_mut().clear(0xFF0000FF); - Renderer::global_mut().update_colors(Some(0xFF0000FF), Some(0xFF0000FF)); - KERNEL_CONSOLE.cursor_pos = (1, 1); - KERNEL_CONSOLE.print("=== PANIC ==="); - log::error!( - "A Exception has happend: ( error = {:?}, index = {:?}, frame = {:#?}", - error_code, - index, - stack_frame - ); - kdebug!( - "A Exception has happend: ( error = {:?}, index = {:?}, frame = {:#?}", - error_code, - index, - stack_frame - ); + let exception = unsafe { exception_number.transmute() }; + match exception{ + _ => { + unsafe { + if !has_panicked { + has_panicked = true; + panic!( + "Exception: {:?}\nError Code: {:?}\nStack Frame: {:#?}", + exception, error_code, stack_frame + ); + } + } + } + } +} - hcf(); +pub fn kernel_memmap(virt_addr: VirtAddr, phys_addr: PhysAddr, size: usize, flags: PageTableFlags) { + use x86_64::structures::paging::PageTableFlags as Flags; + + let allocator = unsafe { &mut *KERNEL_FRAME_ALLOCATOR.lock() }; + + let page = Page::::containing_address(virt_addr); + + let frame = PhysFrame::::containing_address(phys_addr); + let flags = flags; + + let map_to_result = unsafe { + // FIXME: this is not safe, we do it only for testing + KERNEL_PAGE_MAPPER.lock().map_to(page, frame, flags, allocator) }; + map_to_result.expect("map_to failed").flush(); } #[no_mangle] @@ -298,6 +538,7 @@ unsafe extern "C" fn _start<'kernel>() -> ! { KERNEL_CONSOLE.newline(); + kprint!("Console Successfully Initialized.\n"); DEBUG_LINE.wait_for_connection(); @@ -411,19 +652,38 @@ unsafe extern "C" fn _start<'kernel>() -> ! { Ok(v) => v, }; - KERNEL_PAGE_MAPPER.lock().update_flags( - HugePage::from_start_address( - VirtAddr::new(program_base.addr().transmute()) - .align_down(HugePage::SIZE), + + + for page_index in (program_base as u64 / HugePage::SIZE)..((program_base as u64 + module.length as u64) / HugePage::SIZE){ + let page = HugePage::containing_address(VirtAddr::new((page_index as u64).saturating_mul(HugePage::SIZE))); + + + + match KERNEL_PAGE_MAPPER.lock().update_flags( + page, + PageTableFlags::PRESENT | PageTableFlags::USER_ACCESSIBLE | PageTableFlags::WRITABLE | PageTableFlags::BIT_55, ) - .unwrap(), - PageTableFlags::PRESENT | !PageTableFlags::NO_EXECUTE, - ); + { + Ok(flusher) => flusher.flush(), + Err(FlagUpdateError::PageNotMapped) => { + KERNEL_PAGE_MAPPER.lock().identity_map( + PhysFrame::::containing_address(PhysAddr::new(page_index as u64 * HugePage::SIZE)), + PageTableFlags::PRESENT | PageTableFlags::USER_ACCESSIBLE | PageTableFlags::WRITABLE | PageTableFlags::BIT_55, + &mut *KERNEL_FRAME_ALLOCATOR.lock(), + ).unwrap().flush() + } + Err(e) => { + log::error!("Error Updating Page Flags: {:#?}", e); + break 'module; + } + } + } + + log::debug!("Loaded Driver."); - // kdebug!("Program ELF: {:#?}", &bytes); + let driver = Driver::from_raw_elf(program_base as u64, &bytes, "boot.driver.unknown"); - let start: *const unsafe extern "C" fn(KernelProgramMeta) = - core::mem::transmute(program_base.addr() as u64 + bytes.ehdr.e_entry); + // log::debug!("{}", driver.init()); } } @@ -436,22 +696,44 @@ unsafe extern "C" fn _start<'kernel>() -> ! { //let mut mapper = x86_64::structures::paging::RecursivePageTable::new(pml4_table) // .expect("Failed to create Recursive Page Table Mapper."); + INTERRUPT_HANDLERS[0x1] = Some(example_interrupt_handler); + INTERRUPT_HANDLERS[0x6] = Some(kernelcall_print); + asm!( - "mov r8w, 0x4", - "mov r9w, 0x6", + "mov r8, 0x1", options(raw, preserves_flags) ); x86_64::software_interrupt!(0x80); let mut result: u16; - asm!("nop", out("r10w") result); + asm!("nop", out("rdx") result); + + __kernelcall_print( + "Hello from the Kernel!\n\0".as_ptr(), + "Hello from the Kernel!\n\0".len() as u64, + ); + + for (i, e) in KERNEL_PAGE_MAPPER.lock().level_4_table().iter().enumerate() { + if !e.is_unused() { + kdebug!( + "Entry {}: {:#?}\n", + i, + e + ); + } + + } log::info!("Hello from the AntOS Kernel! ;)"); + // Breakpoint for GDB. + // x86_64::instructions::interrupts::int3(); + // log::debug!("MemArea: {:#?}", pf_allocator!().request_memory_area(2000)); DEBUG_LINE.unsafe_write_line("End of Runtime."); loop { + // GDB_PROTOCOL.lock().update(); asm!("hlt"); } } @@ -474,18 +756,14 @@ macro_rules! halt_while { #[cfg(not(test))] #[panic_handler] fn rust_panic(_info: &core::panic::PanicInfo) -> ! { + unsafe { - DEBUG_LINE.unsafe_write_line( - _info - .payload() - .downcast_ref::<&'_ str>() - .unwrap_or(&"Panic!" as &&'_ str), - ); + kdebug!("A Rust Panic has occurred: \n{:#?}\n", _info); + + log::error!("A Rust Panic has occurred: \n{:#?}\n", _info.clone()); + + hcf(); } - - log::error!("A Rust Panic has occurred: \n{:#?}\n", _info); - - hcf(); } fn hcf() -> ! { unsafe { diff --git a/kernel/src/serial.rs b/kernel/src/serial.rs index 8450a7c..a95725d 100644 --- a/kernel/src/serial.rs +++ b/kernel/src/serial.rs @@ -114,7 +114,7 @@ where unsafe { while self.test() {} - self.unsafe_write_string("(CONNECTED)\n\r"); + // self.unsafe_write_string("(CONNECTED)\n\r"); kprint!("Successfully connected to serial line.") } } diff --git a/macros/Cargo.toml b/macros/Cargo.toml new file mode 100644 index 0000000..56233f1 --- /dev/null +++ b/macros/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "antos-macros" +version = "0.1.0" +edition = "2021" + +[lib] +proc-macro = true +crate-type = ["proc-macro"] + + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +syn = "*" +quote = "*" +proc-macro2 = "1.0" \ No newline at end of file diff --git a/macros/src/lib.rs b/macros/src/lib.rs new file mode 100644 index 0000000..293f8d9 --- /dev/null +++ b/macros/src/lib.rs @@ -0,0 +1,90 @@ +use std::fmt::format; + +use proc_macro::{TokenStream}; +use quote::{quote, quote_spanned, ToTokens}; +use syn::{parse_macro_input, Ident, LitStr, Expr, parse::{ParseStream, Parse}, punctuated::Punctuated, parenthesized, token::Token}; + +/// This macro is used to set specific registers to specific values via a previously crated [RegisterCapture](crate::RegisterCapture). +/// +/// # Syntax +/// +/// ```ignore +/// __capture_set_registers!((, , , ...), , ); +/// ``` +/// +/// **This is a proc macro and must be used with the `#[macro_use]` attribute.** +#[proc_macro] +pub fn __capture_set_registers(input: TokenStream) -> TokenStream { + let input = parse_macro_input!(input as ApplyRegistersFromCaptureInput); + + let capture = input.capture.clone(); + + + let expanded =quote::quote! { + let __macro_capture = #capture; + ::core::arch::asm!( + "nop", + #input + options(nostack, nomem, preserves_flags) + ); + }; + + TokenStream::from(expanded) +} + +struct ApplyRegistersFromCaptureInput { + registers: Vec, + capture: Expr, +} + + +impl Parse for ApplyRegistersFromCaptureInput { + fn parse(input: ParseStream) -> syn::parse::Result { + let registers; + let capture; + + let content; + parenthesized!(content in input); + + + registers = Punctuated::::parse_terminated(&content)?; + + let _ = input.parse::()?; + + capture = input.parse()?; + + Ok(ApplyRegistersFromCaptureInput { + registers: registers.into_iter().collect(), + capture, + }) + } +} + +impl ToTokens for ApplyRegistersFromCaptureInput { + fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { + let registers = &self.registers; + let capture = &self.capture; + + for register in registers { + let name = ®ister.name; + let name_str = name.to_string(); + tokens.extend(quote! { + in(#name_str) #capture.#name, + }); + } + } +} + +struct Register { + name: Ident +} + +impl Parse for Register { + fn parse(input: ParseStream) -> syn::parse::Result { + let ident = input.parse()?; + + Ok(Register { + name: ident, + }) + } +} \ No newline at end of file diff --git a/programs/example/Cargo.toml b/programs/example/Cargo.toml index aae9899..5907716 100644 --- a/programs/example/Cargo.toml +++ b/programs/example/Cargo.toml @@ -2,7 +2,11 @@ name = "example-program" version = "0.1.0" edition = "2021" +panic = "abort" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] + +[target] +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/programs/example/src/main.rs b/programs/example/src/main.rs index e85f3c4..2dc15b6 100644 --- a/programs/example/src/main.rs +++ b/programs/example/src/main.rs @@ -3,44 +3,34 @@ #![no_std] #![no_main] - -pub macro __kernel_call($func:literal, $param_count:literal, $params:expr $return_storage:ident, $response_storage:ident){ +#[inline(never)] +#[no_mangle] +#[link_section = ".kernelcall"] +#[export_name = "__kernelcall_print"] +pub unsafe extern "C" fn print(buffer: *const u8, len: usize) -> u64 { + let mut status: u64; ::core::arch::asm!( + "mov r8, 0x6", "int 0x80", - in("eax") $func, - in("ecx") $param_count - in("edx") $params, - lateout("eax") $return_storage, - lateout("ecx") $response_storage + in("r9") buffer, + in("r10") len, + lateout("r8") status, ); + status } -use core::arch::asm; use core::panic::PanicInfo; -type DbgPrintFn = unsafe extern "C" fn (*const u8, usize); - -#[repr(C)] -pub struct KernelProgramMeta{ - _dbg_print: *const DbgPrintFn -} #[no_mangle] #[start] -pub unsafe fn _start(__meta: KernelProgramMeta){ +pub unsafe fn _start(){ let msg = "Hello from a Kernel Program!"; - (__meta._dbg_print)(msg.as_bytes().as_ptr(), msg.len()); - - terminate_kernel_program_internal(0); + print(msg.as_bytes().as_ptr(), msg.len()); } #[panic_handler] pub unsafe fn __panic_handler(__info: &'_ PanicInfo<'_>) -> !{ - asm!( - "mov ax, 0xA2", - "int 0xA2", - in("rdi") __info - ); - - loop {} + print("Kernel Panic!\0".as_ptr(), 14); + loop{} } \ No newline at end of file diff --git a/programs/example/target/.rustc_info.json b/programs/example/target/.rustc_info.json index 8cfe46f..6a4a74f 100644 --- a/programs/example/target/.rustc_info.json +++ b/programs/example/target/.rustc_info.json @@ -1 +1 @@ -{"rustc_fingerprint":8225995090261107881,"outputs":{"393722739454701655":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.a\n/home/joscha/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu\noff\n___\ndebug_assertions\noverflow_checks\npanic=\"abort\"\nproc_macro\nrelocation_model=\"pic\"\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"\"\ntarget_feature=\"fxsr\"\ntarget_has_atomic\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_has_atomic_equal_alignment=\"16\"\ntarget_has_atomic_equal_alignment=\"32\"\ntarget_has_atomic_equal_alignment=\"64\"\ntarget_has_atomic_equal_alignment=\"8\"\ntarget_has_atomic_equal_alignment=\"ptr\"\ntarget_has_atomic_load_store\ntarget_has_atomic_load_store=\"16\"\ntarget_has_atomic_load_store=\"32\"\ntarget_has_atomic_load_store=\"64\"\ntarget_has_atomic_load_store=\"8\"\ntarget_has_atomic_load_store=\"ptr\"\ntarget_os=\"none\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\n","stderr":"warning: dropping unsupported crate type `dylib` for target `x86_64-unknown-none`\n\nwarning: dropping unsupported crate type `cdylib` for target `x86_64-unknown-none`\n\nwarning: dropping unsupported crate type `proc-macro` for target `x86_64-unknown-none`\n\nwarning: 3 warnings emitted\n\n"},"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.76.0-nightly (d86d65bbc 2023-12-10)\nbinary: rustc\ncommit-hash: d86d65bbc19b928387f68427fcc3a0da498d8a19\ncommit-date: 2023-12-10\nhost: x86_64-unknown-linux-gnu\nrelease: 1.76.0-nightly\nLLVM version: 17.0.5\n","stderr":""},"225737801189894232":{"success":false,"status":"exit status: 1","code":1,"stdout":"","stderr":"error: Error loading target specification: Could not find specification for target \"x86_64-unknown-non\". Run `rustc --print target-list` for a list of built-in targets\n\n"},"15729799797837862367":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/joscha/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu\noff\npacked\nunpacked\n___\ndebug_assertions\noverflow_checks\npanic=\"unwind\"\nproc_macro\nrelocation_model=\"pic\"\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_has_atomic_equal_alignment=\"16\"\ntarget_has_atomic_equal_alignment=\"32\"\ntarget_has_atomic_equal_alignment=\"64\"\ntarget_has_atomic_equal_alignment=\"8\"\ntarget_has_atomic_equal_alignment=\"ptr\"\ntarget_has_atomic_load_store\ntarget_has_atomic_load_store=\"16\"\ntarget_has_atomic_load_store=\"32\"\ntarget_has_atomic_load_store=\"64\"\ntarget_has_atomic_load_store=\"8\"\ntarget_has_atomic_load_store=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_thread_local\ntarget_vendor=\"unknown\"\nunix\n","stderr":""}},"successes":{}} \ No newline at end of file +{"rustc_fingerprint":8225995090261107881,"outputs":{"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.76.0-nightly (d86d65bbc 2023-12-10)\nbinary: rustc\ncommit-hash: d86d65bbc19b928387f68427fcc3a0da498d8a19\ncommit-date: 2023-12-10\nhost: x86_64-unknown-linux-gnu\nrelease: 1.76.0-nightly\nLLVM version: 17.0.5\n","stderr":""},"15729799797837862367":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/joscha/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu\noff\npacked\nunpacked\n___\ndebug_assertions\noverflow_checks\npanic=\"unwind\"\nproc_macro\nrelocation_model=\"pic\"\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_has_atomic_equal_alignment=\"16\"\ntarget_has_atomic_equal_alignment=\"32\"\ntarget_has_atomic_equal_alignment=\"64\"\ntarget_has_atomic_equal_alignment=\"8\"\ntarget_has_atomic_equal_alignment=\"ptr\"\ntarget_has_atomic_load_store\ntarget_has_atomic_load_store=\"16\"\ntarget_has_atomic_load_store=\"32\"\ntarget_has_atomic_load_store=\"64\"\ntarget_has_atomic_load_store=\"8\"\ntarget_has_atomic_load_store=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_thread_local\ntarget_vendor=\"unknown\"\nunix\n","stderr":""},"393722739454701655":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.a\n/home/joscha/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu\noff\n___\ndebug_assertions\noverflow_checks\npanic=\"abort\"\nproc_macro\nrelocation_model=\"pic\"\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"\"\ntarget_feature=\"fxsr\"\ntarget_has_atomic\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_has_atomic_equal_alignment=\"16\"\ntarget_has_atomic_equal_alignment=\"32\"\ntarget_has_atomic_equal_alignment=\"64\"\ntarget_has_atomic_equal_alignment=\"8\"\ntarget_has_atomic_equal_alignment=\"ptr\"\ntarget_has_atomic_load_store\ntarget_has_atomic_load_store=\"16\"\ntarget_has_atomic_load_store=\"32\"\ntarget_has_atomic_load_store=\"64\"\ntarget_has_atomic_load_store=\"8\"\ntarget_has_atomic_load_store=\"ptr\"\ntarget_os=\"none\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\n","stderr":"warning: dropping unsupported crate type `dylib` for target `x86_64-unknown-none`\n\nwarning: dropping unsupported crate type `cdylib` for target `x86_64-unknown-none`\n\nwarning: dropping unsupported crate type `proc-macro` for target `x86_64-unknown-none`\n\nwarning: 3 warnings emitted\n\n"}},"successes":{}} \ No newline at end of file diff --git a/programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grkhcqfsoy-y9b5z6.lock b/programs/example/target/release/.cargo-lock similarity index 100% rename from programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grkhcqfsoy-y9b5z6.lock rename to programs/example/target/release/.cargo-lock diff --git a/programs/example/target/x86_64-unknown-none/debug/.fingerprint/example-program-90cda0d796f5b5ce/output-bin-example-program b/programs/example/target/x86_64-unknown-none/debug/.fingerprint/example-program-90cda0d796f5b5ce/output-bin-example-program deleted file mode 100644 index fcd93b5..0000000 --- a/programs/example/target/x86_64-unknown-none/debug/.fingerprint/example-program-90cda0d796f5b5ce/output-bin-example-program +++ /dev/null @@ -1,5 +0,0 @@ -{"message":"can't find crate for `core`","code":{"code":"E0463","explanation":"A plugin/crate was declared but cannot be found.\n\nErroneous code example:\n\n```compile_fail,E0463\n#![feature(plugin)]\n#![plugin(cookie_monster)] // error: can't find crate for `cookie_monster`\nextern crate cake_is_a_lie; // error: can't find crate for `cake_is_a_lie`\n```\n\nYou need to link your code to the relevant crate in order to be able to use it\n(through Cargo or the `-L` option of rustc example). Plugins are crates as\nwell, and you link to them the same way.\n\n## Common causes\n\n- The crate is not present at all. If using Cargo, add it to `[dependencies]`\n in Cargo.toml.\n- The crate is present, but under a different name. If using Cargo, look for\n `package = ` under `[dependencies]` in Cargo.toml.\n\n## Common causes for missing `std` or `core`\n\n- You are cross-compiling for a target which doesn't have `std` prepackaged.\n Consider one of the following:\n + Adding a pre-compiled version of std with `rustup target add`\n + Building std from source with `cargo build -Z build-std`\n + Using `#![no_std]` at the crate root, so you won't need `std` in the first\n place.\n- You are developing the compiler itself and haven't built libstd from source.\n You can usually build it with `x.py build library/std`. More information\n about x.py is available in the [rustc-dev-guide].\n\n[rustc-dev-guide]: https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html#building-the-compiler\n"},"level":"error","spans":[{"file_name":"src/main.rs","byte_start":0,"byte_end":0,"line_start":1,"line_end":1,"column_start":1,"column_end":1,"is_primary":true,"text":[],"label":"can't find crate","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"the `x86_64-unknown-none` target may not be installed","code":null,"level":"note","spans":[],"children":[],"rendered":null},{"message":"consider downloading the target with `rustup target add x86_64-unknown-none`","code":null,"level":"help","spans":[],"children":[],"rendered":null}],"rendered":"\u001b[0m\u001b[1m\u001b[38;5;9merror[E0463]\u001b[0m\u001b[0m\u001b[1m: can't find crate for `core`\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m= \u001b[0m\u001b[0m\u001b[1mnote\u001b[0m\u001b[0m: the `x86_64-unknown-none` target may not be installed\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m= \u001b[0m\u001b[0m\u001b[1mhelp\u001b[0m\u001b[0m: consider downloading the target with `rustup target add x86_64-unknown-none`\u001b[0m\n\n"} -{"message":"can't find crate for `compiler_builtins`","code":{"code":"E0463","explanation":"A plugin/crate was declared but cannot be found.\n\nErroneous code example:\n\n```compile_fail,E0463\n#![feature(plugin)]\n#![plugin(cookie_monster)] // error: can't find crate for `cookie_monster`\nextern crate cake_is_a_lie; // error: can't find crate for `cake_is_a_lie`\n```\n\nYou need to link your code to the relevant crate in order to be able to use it\n(through Cargo or the `-L` option of rustc example). Plugins are crates as\nwell, and you link to them the same way.\n\n## Common causes\n\n- The crate is not present at all. If using Cargo, add it to `[dependencies]`\n in Cargo.toml.\n- The crate is present, but under a different name. If using Cargo, look for\n `package = ` under `[dependencies]` in Cargo.toml.\n\n## Common causes for missing `std` or `core`\n\n- You are cross-compiling for a target which doesn't have `std` prepackaged.\n Consider one of the following:\n + Adding a pre-compiled version of std with `rustup target add`\n + Building std from source with `cargo build -Z build-std`\n + Using `#![no_std]` at the crate root, so you won't need `std` in the first\n place.\n- You are developing the compiler itself and haven't built libstd from source.\n You can usually build it with `x.py build library/std`. More information\n about x.py is available in the [rustc-dev-guide].\n\n[rustc-dev-guide]: https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html#building-the-compiler\n"},"level":"error","spans":[{"file_name":"src/main.rs","byte_start":0,"byte_end":0,"line_start":1,"line_end":1,"column_start":1,"column_end":1,"is_primary":true,"text":[],"label":"can't find crate","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":"\u001b[0m\u001b[1m\u001b[38;5;9merror[E0463]\u001b[0m\u001b[0m\u001b[1m: can't find crate for `compiler_builtins`\u001b[0m\n\n"} -{"message":"requires `sized` lang_item","code":null,"level":"error","spans":[],"children":[],"rendered":"\u001b[0m\u001b[1m\u001b[38;5;9merror\u001b[0m\u001b[0m\u001b[1m: requires `sized` lang_item\u001b[0m\n\n"} -{"message":"aborting due to 3 previous errors","code":null,"level":"error","spans":[],"children":[],"rendered":"\u001b[0m\u001b[1m\u001b[38;5;9merror\u001b[0m\u001b[0m\u001b[1m: aborting due to 3 previous errors\u001b[0m\n\n"} -{"message":"For more information about this error, try `rustc --explain E0463`.","code":null,"level":"failure-note","spans":[],"children":[],"rendered":"\u001b[0m\u001b[1mFor more information about this error, try `rustc --explain E0463`.\u001b[0m\n"} diff --git a/programs/example/target/x86_64-unknown-none/debug/deps/example_program-b883f15776df51a0 b/programs/example/target/x86_64-unknown-none/debug/deps/example_program-b883f15776df51a0 index a088a7f..67dbc72 100644 Binary files a/programs/example/target/x86_64-unknown-none/debug/deps/example_program-b883f15776df51a0 and b/programs/example/target/x86_64-unknown-none/debug/deps/example_program-b883f15776df51a0 differ diff --git a/programs/example/target/x86_64-unknown-none/debug/example-program b/programs/example/target/x86_64-unknown-none/debug/example-program index a088a7f..67dbc72 100644 Binary files a/programs/example/target/x86_64-unknown-none/debug/example-program and b/programs/example/target/x86_64-unknown-none/debug/example-program differ diff --git a/programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grkhcqfsoy-y9b5z6-c6mbj55ukyip8nfzu35p39ux4/1pf5l98mhuxb4c40.o b/programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grkhcqfsoy-y9b5z6-c6mbj55ukyip8nfzu35p39ux4/1pf5l98mhuxb4c40.o deleted file mode 100644 index c0f05fb..0000000 Binary files a/programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grkhcqfsoy-y9b5z6-c6mbj55ukyip8nfzu35p39ux4/1pf5l98mhuxb4c40.o and /dev/null differ diff --git a/programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grkhcqfsoy-y9b5z6-c6mbj55ukyip8nfzu35p39ux4/dep-graph.bin b/programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grkhcqfsoy-y9b5z6-c6mbj55ukyip8nfzu35p39ux4/dep-graph.bin deleted file mode 100644 index 154e316..0000000 Binary files a/programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grkhcqfsoy-y9b5z6-c6mbj55ukyip8nfzu35p39ux4/dep-graph.bin and /dev/null differ diff --git a/programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grkhcqfsoy-y9b5z6-c6mbj55ukyip8nfzu35p39ux4/query-cache.bin b/programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grkhcqfsoy-y9b5z6-c6mbj55ukyip8nfzu35p39ux4/query-cache.bin deleted file mode 100644 index 5881425..0000000 Binary files a/programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grkhcqfsoy-y9b5z6-c6mbj55ukyip8nfzu35p39ux4/query-cache.bin and /dev/null differ diff --git a/programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grp788mhu9-154e72b-cbypbzremwznh2hia585ezu7b/1pf5l98mhuxb4c40.o b/programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grp788mhu9-154e72b-cbypbzremwznh2hia585ezu7b/1pf5l98mhuxb4c40.o new file mode 100644 index 0000000..0c1ee45 Binary files /dev/null and b/programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grp788mhu9-154e72b-cbypbzremwznh2hia585ezu7b/1pf5l98mhuxb4c40.o differ diff --git a/programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grkhcqfsoy-y9b5z6-c6mbj55ukyip8nfzu35p39ux4/33fqgkfa8krixqrn.o b/programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grp788mhu9-154e72b-cbypbzremwznh2hia585ezu7b/33fqgkfa8krixqrn.o similarity index 100% rename from programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grkhcqfsoy-y9b5z6-c6mbj55ukyip8nfzu35p39ux4/33fqgkfa8krixqrn.o rename to programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grp788mhu9-154e72b-cbypbzremwznh2hia585ezu7b/33fqgkfa8krixqrn.o diff --git a/programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grp788mhu9-154e72b-cbypbzremwznh2hia585ezu7b/dep-graph.bin b/programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grp788mhu9-154e72b-cbypbzremwznh2hia585ezu7b/dep-graph.bin new file mode 100644 index 0000000..e40cf06 Binary files /dev/null and b/programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grp788mhu9-154e72b-cbypbzremwznh2hia585ezu7b/dep-graph.bin differ diff --git a/programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grp788mhu9-154e72b-cbypbzremwznh2hia585ezu7b/query-cache.bin b/programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grp788mhu9-154e72b-cbypbzremwznh2hia585ezu7b/query-cache.bin new file mode 100644 index 0000000..30fad7c Binary files /dev/null and b/programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grp788mhu9-154e72b-cbypbzremwznh2hia585ezu7b/query-cache.bin differ diff --git a/programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grkhcqfsoy-y9b5z6-c6mbj55ukyip8nfzu35p39ux4/work-products.bin b/programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grp788mhu9-154e72b-cbypbzremwznh2hia585ezu7b/work-products.bin similarity index 100% rename from programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grkhcqfsoy-y9b5z6-c6mbj55ukyip8nfzu35p39ux4/work-products.bin rename to programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grp788mhu9-154e72b-cbypbzremwznh2hia585ezu7b/work-products.bin diff --git a/programs/example/target/x86_64-unknown-none/debug/incremental/example_program-jn9stlakvifm/s-grkh12jva9-17nr2z0.lock b/programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grp788mhu9-154e72b.lock similarity index 100% rename from programs/example/target/x86_64-unknown-none/debug/incremental/example_program-jn9stlakvifm/s-grkh12jva9-17nr2z0.lock rename to programs/example/target/x86_64-unknown-none/debug/incremental/example_program-9ic89uw4p6xg/s-grp788mhu9-154e72b.lock diff --git a/programs/example/target/x86_64-unknown-none/debug/incremental/example_program-jn9stlakvifm/s-grkh12jva9-17nr2z0-working/dep-graph.part.bin b/programs/example/target/x86_64-unknown-none/debug/incremental/example_program-jn9stlakvifm/s-grkh12jva9-17nr2z0-working/dep-graph.part.bin deleted file mode 100644 index e517f18..0000000 Binary files a/programs/example/target/x86_64-unknown-none/debug/incremental/example_program-jn9stlakvifm/s-grkh12jva9-17nr2z0-working/dep-graph.part.bin and /dev/null differ diff --git a/programs/example/target/x86_64-unknown-none/release/.cargo-lock b/programs/example/target/x86_64-unknown-none/release/.cargo-lock new file mode 100644 index 0000000..e69de29 diff --git a/programs/example/target/x86_64-unknown-none/release/.fingerprint/example-program-d5a7f87a5feb9be5/bin-example-program b/programs/example/target/x86_64-unknown-none/release/.fingerprint/example-program-d5a7f87a5feb9be5/bin-example-program new file mode 100644 index 0000000..0e53f5e --- /dev/null +++ b/programs/example/target/x86_64-unknown-none/release/.fingerprint/example-program-d5a7f87a5feb9be5/bin-example-program @@ -0,0 +1 @@ +ebf4115fb6ad96fc \ No newline at end of file diff --git a/programs/example/target/x86_64-unknown-none/release/.fingerprint/example-program-d5a7f87a5feb9be5/bin-example-program.json b/programs/example/target/x86_64-unknown-none/release/.fingerprint/example-program-d5a7f87a5feb9be5/bin-example-program.json new file mode 100644 index 0000000..0a5a433 --- /dev/null +++ b/programs/example/target/x86_64-unknown-none/release/.fingerprint/example-program-d5a7f87a5feb9be5/bin-example-program.json @@ -0,0 +1 @@ +{"rustc":6975046092201686863,"features":"[]","declared_features":"","target":16925544410843377132,"profile":14094339167972473758,"path":1684066648322511884,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"x86_64-unknown-none/release/.fingerprint/example-program-d5a7f87a5feb9be5/dep-bin-example-program"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":12696962690237916270} \ No newline at end of file diff --git a/programs/example/target/x86_64-unknown-none/release/.fingerprint/example-program-d5a7f87a5feb9be5/dep-bin-example-program b/programs/example/target/x86_64-unknown-none/release/.fingerprint/example-program-d5a7f87a5feb9be5/dep-bin-example-program new file mode 100644 index 0000000..5fdf103 Binary files /dev/null and b/programs/example/target/x86_64-unknown-none/release/.fingerprint/example-program-d5a7f87a5feb9be5/dep-bin-example-program differ diff --git a/programs/example/target/x86_64-unknown-none/debug/.fingerprint/example-program-90cda0d796f5b5ce/invoked.timestamp b/programs/example/target/x86_64-unknown-none/release/.fingerprint/example-program-d5a7f87a5feb9be5/invoked.timestamp similarity index 100% rename from programs/example/target/x86_64-unknown-none/debug/.fingerprint/example-program-90cda0d796f5b5ce/invoked.timestamp rename to programs/example/target/x86_64-unknown-none/release/.fingerprint/example-program-d5a7f87a5feb9be5/invoked.timestamp diff --git a/programs/example/target/x86_64-unknown-none/release/deps/example_program-d5a7f87a5feb9be5 b/programs/example/target/x86_64-unknown-none/release/deps/example_program-d5a7f87a5feb9be5 new file mode 100644 index 0000000..12dc418 Binary files /dev/null and b/programs/example/target/x86_64-unknown-none/release/deps/example_program-d5a7f87a5feb9be5 differ diff --git a/programs/example/target/x86_64-unknown-none/debug/deps/example_program-90cda0d796f5b5ce.d b/programs/example/target/x86_64-unknown-none/release/deps/example_program-d5a7f87a5feb9be5.d similarity index 53% rename from programs/example/target/x86_64-unknown-none/debug/deps/example_program-90cda0d796f5b5ce.d rename to programs/example/target/x86_64-unknown-none/release/deps/example_program-d5a7f87a5feb9be5.d index 27c0f43..60dba8c 100644 --- a/programs/example/target/x86_64-unknown-none/debug/deps/example_program-90cda0d796f5b5ce.d +++ b/programs/example/target/x86_64-unknown-none/release/deps/example_program-d5a7f87a5feb9be5.d @@ -1,5 +1,5 @@ -/mnt/c/dev/rust-kernel/programs/example/target/x86_64-unknown-none/debug/deps/example_program-90cda0d796f5b5ce: src/main.rs +/mnt/c/dev/rust-kernel/programs/example/target/x86_64-unknown-none/release/deps/example_program-d5a7f87a5feb9be5: src/main.rs -/mnt/c/dev/rust-kernel/programs/example/target/x86_64-unknown-none/debug/deps/example_program-90cda0d796f5b5ce.d: src/main.rs +/mnt/c/dev/rust-kernel/programs/example/target/x86_64-unknown-none/release/deps/example_program-d5a7f87a5feb9be5.d: src/main.rs src/main.rs: diff --git a/programs/example/target/x86_64-unknown-none/release/example-program b/programs/example/target/x86_64-unknown-none/release/example-program new file mode 100644 index 0000000..12dc418 Binary files /dev/null and b/programs/example/target/x86_64-unknown-none/release/example-program differ diff --git a/programs/example/target/x86_64-unknown-none/release/example-program.d b/programs/example/target/x86_64-unknown-none/release/example-program.d new file mode 100644 index 0000000..7aca25a --- /dev/null +++ b/programs/example/target/x86_64-unknown-none/release/example-program.d @@ -0,0 +1 @@ +/mnt/c/dev/rust-kernel/programs/example/target/x86_64-unknown-none/release/example-program: /mnt/c/dev/rust-kernel/programs/example/src/main.rs