32 Commits

Author SHA1 Message Date
zxq5 b80b400c19 fixed interrupts (temporary, we need to do a real fix for this) 2025-03-10 15:40:38 +00:00
nullndvoid 31f14e8aec Get rid of warning 2025-03-10 13:35:27 +00:00
nullndvoid 91e5602e82 Don't enable APIC yet 2025-03-10 13:29:07 +00:00
nullndvoid a83108a08e Clean up dead code 2025-03-08 18:43:43 +00:00
nullndvoid da6690fd8b Save failed stack trace code for future reference. 2025-03-08 18:40:05 +00:00
nullndvoid 4b8388c66d Update boot prints to be a little less noisy.
TODO:

* Debugging, tracing support.
* Logging infra so we can may pass a loglevel like on Linux.
2025-03-06 20:32:46 +00:00
nullndvoid 1d192adde0 Removed messy debug logging, added print_oneshot!() 2025-03-06 20:11:54 +00:00
zxq5 4bf31e653b Merge remote-tracking branch 'refs/remotes/origin/unified' into unified 2025-03-06 01:22:53 +00:00
nullndvoid 5aad3e6096 Fixed stack unwind bugs (works!) 2025-03-06 01:22:17 +00:00
zxq5 c06425949a Merge remote-tracking branch 'refs/remotes/origin/unified' into unified 2025-03-06 01:21:02 +00:00
zxq5 ecdc76b068 Merge remote-tracking branch 'origin' into unified 2025-03-06 01:18:43 +00:00
nullndvoid f197149d80 Forced unwind tables - still bugged 2025-03-06 01:01:04 +00:00
nullndvoid bc51f3ec43 Force rustc to generate unwind-tables - infinite loop :( 2025-03-05 22:37:19 +00:00
nullndvoid b26dc6de01 Wrote stack unwinder. NEEDTO: fix NoUnwindInfo
Probably incorrect PC was set.
2025-03-05 22:21:38 +00:00
zxq5 8ee4af1a48 someone broke a mod.rs so i fixed it. 2025-03-05 21:10:36 +00:00
zxq5 03c07cb5c4 Merging with origin/unified 2025-03-05 21:04:58 +00:00
zxq5 ef70bcf51e - heap allocator now makes sure virtual memory pages are mapped before using them. this means we no longer have to use page faults to allocate frames, it is done automatically.
- fixed the apic code that caused a page fault. it now writes the correct values at the correct physical address
- improved startup logging including displaying how much RAM is installed.
2025-03-05 20:49:21 +00:00
nullndvoid 2fb1741100 Begin setting up stack unwinding/tracing.
This actually worked so I am chuffed, but it doesn't read the necessary
DWARF structures just yet. Still a good step forwards.
2025-03-05 20:44:09 +00:00
nullndvoid af995d1d76 Tried and failed to use unwinding crate: shall do it myself tomorrow. 2025-03-05 03:24:26 +00:00
nullndvoid 014ec5310c Some more clippy fixes, warnings are noisy 2025-03-05 00:57:06 +00:00
nullndvoid d53661b9a0 Ran cargo fmt, clippy fixes, suppressed some warns
I will start working on stack traces tonight and tomorrow.

We need to be able to 'unwind' by finding calling functions.
2025-03-04 23:06:47 +00:00
zxq5 8704b5d249 FIXED THE APIC HELL YEAH 2025-03-04 12:44:42 +00:00
zxq5 2186b829aa - made improvements to memory code (refactored)
- started on improvements to the page frame allocator. it should be able to provide a usable page for any given virtual memory address requested.
2025-03-04 01:28:39 +00:00
zxq5 f502104a6e changes 2025-03-04 00:53:38 +00:00
zxq5 48dcde0c02 minor changes & work on threading 2025-03-04 00:53:06 +00:00
nullndvoid 6e913b15d7 Update macro to use relative working dirs, Spans 2025-03-03 15:57:16 +00:00
nullndvoid 0a5269eeb0 Fix clippy errors 2025-03-03 15:51:39 +00:00
zxq5 a0f5ce8797 reorganised memory. starting on threads 2025-03-03 15:50:58 +00:00
nullndvoid 2d3bc56962 Fix some clippy errors 2025-03-03 14:53:30 +00:00
nullndvoid 5703032f87 Fix module inception 2025-03-03 14:47:24 +00:00
zxq5 3966e697da refactor mega-commit.
- reorganised the entire project so that the entire kernel is a single codebase rather than a kernel and a libk.
2025-03-03 02:49:56 +00:00
aha480 e8237f4610 run_debug.sh now checks if it running on wsl and disables boot_flags if it is since it was causing issues with qemu 2025-03-01 12:49:42 +00:00
78 changed files with 1566 additions and 1475 deletions
-3
View File
@@ -17,8 +17,5 @@ runner = "scripts/run_debug.sh"
[target.'cfg(all(target_arch = "x86_64", target_os = "none", not(debug_assertions)))']
runner = "scripts/run_release.sh"
# [registry]
# default = "gitea"
[registries.gitea]
index = "sparse+https://git.zxq5.dev/api/packages/OsDev/cargo/" # Sparse index
+1
View File
@@ -6,6 +6,7 @@
<sourceFolder url="file://$MODULE_DIR$/lib_example/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/libk/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/libm/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/kernel_fonts/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
+5
View File
@@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>
+1
View File
@@ -6,4 +6,5 @@
"editor.formatOnSave": true
},
"rust-analyzer.check.command": "clippy",
"rust-analyzer.cargo.buildScripts.enable": true
}
Generated
+4 -15
View File
@@ -110,8 +110,11 @@ name = "foundry_os"
version = "0.1.0"
dependencies = [
"cc",
"libk",
"crossbeam",
"futures-util",
"libm",
"limine",
"linked_list_allocator",
"pc-keyboard",
"pic8259",
"spin",
@@ -148,20 +151,6 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]]
name = "libk"
version = "0.1.0"
dependencies = [
"crossbeam",
"futures-util",
"libm",
"limine",
"linked_list_allocator",
"pc-keyboard",
"spin",
"x86_64",
]
[[package]]
name = "libm"
version = "0.1.0"
+1 -1
View File
@@ -1,5 +1,5 @@
[workspace]
members = ["kernel", "libk", "libm"]
members = ["kernel", "libm"]
resolver = "2"
[workspace.package]
+10 -5
View File
@@ -7,12 +7,17 @@
> - [ ] write a script to run tests
> - [ ] a release should only be published if all tests pass
> [!todo] Memory
> - [ ] make sure page tables are correct. we're still getting the annoying page fault errors for the APIC
> - [ ] page allocator
> - [ ] e
> [!todo] Allocator
> - [ ] learn about several allocator designs and decide on the optimal one
> - [ ] implementation
> - [ ] implement an allocate method
> - [ ] implement a deallocate method
> - [ ] set the global allocator
> - [x] learn about several allocator designs and decide on the optimal one
> - [x] implementation
> - [x] implement an allocate method
> - [x] implement a deallocate method
> - [x] set the global allocator
> - [ ] testing
> - [ ] write unit tests
> - [ ] many allocations
+14 -1
View File
@@ -6,11 +6,24 @@ authors.workspace = true
[dependencies]
limine = "0.3.1"
libk = { path = "../libk" }
x86_64 = "0.15.2"
spin = "0.9.8"
pic8259 = "0.11.0"
pc-keyboard = "0.8.0"
libm = { path = "../libm" }
crossbeam = { version = "0.8.4", default-features = false, features = [
"alloc",
"crossbeam-queue",
] }
futures-util = { version = "0.3.31", default-features = false, features = [
"alloc",
] }
linked_list_allocator = { version = "0.10.5", features = ["use_spin"] }
# gimli = { version = "0.31.1", default-features = false, features = ["read"] }
# elf = { version = "0.7.4", default-features = false, features = ["nightly"] }
# fallible-iterator = "0.3.0"
# framehop = { version = "0.13.2", default-features = false }
# object = { version = "0.36.7", default-features = false, features = ["read"] }
[build-dependencies]
cc = "1.2.14"
+1 -2
View File
@@ -62,9 +62,8 @@ SECTIONS
*(COMMON)
} :data
/* Discard .note.* and .eh_frame* since they may cause issues on some hosts. */
/* Discard .note.* and ~~.eh_frame*~~ since they may cause issues on some hosts. */
/DISCARD/ : {
*(.eh_frame*)
*(.note .note.*)
}
}
-106
View File
@@ -1,106 +0,0 @@
use core::arch::x86_64::__cpuid;
use libk::drivers::memory::{FoundryOSFrameAllocator, FRAME_ALLOCATOR, OFFSET_PAGE_TABLE};
use spin::Lazy;
use x86_64::{
PhysAddr, VirtAddr,
instructions::port::Port,
registers::model_specific::Msr,
structures::paging::{
FrameAllocator, Mapper, Page, PageTableFlags, PhysFrame, Size4KiB, Translate,
},
};
use crate::serial_print;
use super::{cpu::model_specific_registers::*, memmap::PHYSICAL_MEMORY_OFFSET};
const IA32_APIC_BASE_MSR: u32 = 0x1b;
const IA32_APIC_BASE_MSR_BSP: u64 = 0x100;
const IA32_APIC_BASE_MSR_ENABLE: u64 = 0x800;
const IA32_APIC_BASE_MSR_DISABLE: u64 = !IA32_APIC_BASE_MSR_ENABLE;
const CPUID_FEAT_EDX_APIC: u64 = 1 << 9; // the cpuid instruction will return this flag if it supports APIC
// const APIC_VIRTUAL_ADDRESS: Lazy<VirtAddr> = Lazy::new(|| {
// let apic_base = get_apic_base();
// let virt_addr = unsafe { phys_to_virt(apic_base) };
// virt_addr
// });
fn set_apic_base_enable(apic: PhysAddr) {
let rax = (apic.as_u64() & 0xfffff0000) | IA32_APIC_BASE_MSR_ENABLE;
cpu_set_msr(IA32_APIC_BASE_MSR, rax);
}
fn set_apic_base_disable(apic: PhysAddr) {
let rax = (apic.as_u64() & 0xfffff0000) & IA32_APIC_BASE_MSR_DISABLE;
cpu_set_msr(IA32_APIC_BASE_MSR, rax);
}
fn get_apic_base() -> PhysAddr {
let mut value: u64 = 0;
cpu_get_msr(IA32_APIC_BASE_MSR, &mut value);
PhysAddr::new(value & 0xfffff0000)
}
fn write_apic_register(apic_base: &VirtAddr, reg: u8, value: u32) {
let apic_base = apic_base.as_u64();
let reg_addr = (apic_base & 0xFFFFF0000) + reg as u64;
unsafe { *(reg_addr as *mut u32) = value };
}
fn read_apic_register(apic_base: &VirtAddr, reg: u8) -> u32 {
let apic_base = apic_base.as_u64();
serial_print!("got apic base");
let reg_addr = (apic_base & 0xFFFFF0000) + reg as u64;
unsafe { *(reg_addr as *const u32) }
}
pub fn check_apic() -> bool {
let res = unsafe { __cpuid(1) };
res.edx as u64 & CPUID_FEAT_EDX_APIC != 0
}
#[inline(always)]
unsafe fn phys_to_virt(phys: PhysAddr) -> VirtAddr {
let phys = phys.as_u64();
phys.checked_add(*PHYSICAL_MEMORY_OFFSET).map_or_else(|| panic!(" overflow"), VirtAddr::new)
}
pub fn enable_apic() {
let mut mapper = OFFSET_PAGE_TABLE.get().unwrap().lock();
let mut frame_allocator = FRAME_ALLOCATOR.get().unwrap().lock();
let apic_phys_addr = get_apic_base();
set_apic_base_enable(apic_phys_addr);
// map virt address of apic
let apic_virt = unsafe { phys_to_virt(apic_phys_addr) };
let page: Page<Size4KiB> = Page::containing_address(apic_virt);
let frame: PhysFrame<Size4KiB> = PhysFrame::containing_address(apic_phys_addr);
let flags: PageTableFlags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE;
unsafe {
match mapper.map_to(page, frame, flags, &mut *frame_allocator) {
Ok(_) => {}
Err(why) => panic!("failed to map apic: {:?}", why),
}
}
// // FIXME: this causes a page fault
// // TODO: map to virtual memor
let reg = read_apic_register(&apic_virt, 0xF0);
serial_print!("ok2");
write_apic_register(&apic_virt, 0xF0, reg | 0x100);
}
pub struct Apic {}
pub enum ApicVector {}
-26
View File
@@ -1,26 +0,0 @@
pub mod model_specific_registers {
use core::arch::x86_64::__cpuid;
use spin::Lazy;
use x86_64::registers::model_specific::Msr;
const CPUID_FLAG_MSR: u32 = 1 << 5;
static EDX: Lazy<u32> = Lazy::new(|| unsafe { __cpuid(1).edx });
pub fn cpu_has_msr() -> bool {
*EDX & CPUID_FLAG_MSR != 0
}
pub fn cpu_get_msr(msr: u32, value: &mut u64) {
let msr = Msr::new(msr);
unsafe {
*value = msr.read();
}
}
pub fn cpu_set_msr(msr: u32, value: u64) {
let mut msr = Msr::new(msr);
unsafe {
msr.write(value);
}
}
}
+98
View File
@@ -0,0 +1,98 @@
#![expect(unused)]
use core::arch::x86_64::__cpuid;
use crate::arch::x86_64::{
cpu::msr::*,
memory::{
FRAME_ALLOCATOR, OFFSET_PAGE_TABLE, mapping::PHYSICAL_MEMORY_OFFSET,
},
};
use x86_64::structures::paging::Translate;
use x86_64::{
PhysAddr, VirtAddr,
structures::paging::{Mapper, Page, PageTableFlags, PhysFrame, Size4KiB},
};
const IA32_APIC_BASE_MSR: u32 = 0x1b;
const IA32_APIC_BASE_MSR_BSP: u64 = 0x100;
const IA32_APIC_BASE_MSR_ENABLE: u64 = 0x800;
const IA32_APIC_BASE_MSR_DISABLE: u64 = !IA32_APIC_BASE_MSR_ENABLE;
const CPUID_FEAT_EDX_APIC: u64 = 1 << 9; // the cpuid instruction will return this flag if it supports APIC
// const APIC_VIRTUAL_ADDRESS: Lazy<VirtAddr> = Lazy::new(|| {
// let apic_base = get_apic_base();
// let virt_addr = unsafe { phys_to_virt(apic_base) };
// virt_addr
// });
fn set_apic_base_enable(apic: PhysAddr) {
let rax = (apic.as_u64() & 0xfffff0000) | IA32_APIC_BASE_MSR_ENABLE;
cpu_set_msr(IA32_APIC_BASE_MSR, rax);
}
#[allow(dead_code)]
fn set_apic_base_disable(apic: PhysAddr) {
let rax = (apic.as_u64() & 0xfffff0000) & IA32_APIC_BASE_MSR_DISABLE;
cpu_set_msr(IA32_APIC_BASE_MSR, rax);
}
fn get_apic_base() -> PhysAddr {
let mut value: u64 = 0;
cpu_get_msr(IA32_APIC_BASE_MSR, &mut value);
PhysAddr::new(value & 0xfffff0000)
}
fn write_apic_register(apic_base: &PhysAddr, reg: u64, value: u32) {
let apic_base = apic_base.as_u64();
let reg_addr = (apic_base & 0xFFFFF0000) + reg;
let virt_addr = unsafe { phys_to_virt(PhysAddr::new(reg_addr)) };
let phys_check =
OFFSET_PAGE_TABLE.get().unwrap().lock().translate(virt_addr);
unsafe { *(virt_addr.as_u64() as *mut u32) = value };
}
fn read_apic_register(apic_base: &PhysAddr, reg: u64) -> u32 {
let apic_base = apic_base.as_u64();
let reg_addr = (apic_base & 0xFFFFF0000) + reg;
let virt_addr = unsafe { phys_to_virt(PhysAddr::new(reg_addr)) };
unsafe { *(virt_addr.as_u64() as *const u32) }
}
pub fn check_apic() -> bool {
let res = unsafe { __cpuid(1) };
res.edx as u64 & CPUID_FEAT_EDX_APIC != 0
}
#[inline(always)]
unsafe fn phys_to_virt(phys: PhysAddr) -> VirtAddr {
let phys = phys.as_u64();
phys.checked_add(*PHYSICAL_MEMORY_OFFSET)
.map_or_else(|| panic!("Overflow"), VirtAddr::new)
}
pub fn enable_apic() {
let apic_base_physical_addr = get_apic_base();
set_apic_base_enable(apic_base_physical_addr);
enable_timer();
write_apic_register(
&apic_base_physical_addr,
0xF0,
read_apic_register(&apic_base_physical_addr, 0xF0) | 0x1FF,
);
}
pub fn enable_timer() {
let apic_base = get_apic_base();
let current = read_apic_register(&apic_base, 0x320);
write_apic_register(&get_apic_base(), 0x320, (current & 0xFFFFFF00) | 0x20);
}
+3
View File
@@ -0,0 +1,3 @@
pub mod apic;
mod msr;
pub mod pic;
+25
View File
@@ -0,0 +1,25 @@
#![expect(unused)]
use core::arch::x86_64::__cpuid;
use spin::Lazy;
use x86_64::registers::model_specific::Msr;
const CPUID_FLAG_MSR: u32 = 1 << 5;
static EDX: Lazy<u32> = Lazy::new(|| unsafe { __cpuid(1).edx });
pub fn cpu_has_msr() -> bool {
*EDX & CPUID_FLAG_MSR != 0
}
pub fn cpu_get_msr(msr: u32, value: &mut u64) {
let msr = Msr::new(msr);
unsafe {
*value = msr.read();
}
}
pub fn cpu_set_msr(msr: u32, value: u64) {
let mut msr = Msr::new(msr);
unsafe {
msr.write(value);
}
}
@@ -1,3 +1,5 @@
#![allow(clippy::missing_safety_doc)]
use x86_64::instructions::port::Port;
const CMD_INIT: u8 = 0x11;
@@ -40,8 +42,16 @@ pub struct ChainedPics {
}
impl ChainedPics {
/// Construct a new `ChainedPics` given the base offsets of the two PICs.
///
/// # Safety
///
/// This function is unsafe because it requires you to pass valid offsets.
/// If you pass offsets that are out of range, or if you pass offsets that
/// conflict with one another, the resulting object will be useless and
/// will likely cause problems for your system.
pub const unsafe fn new(offset1: u8, offset2: u8) -> Self {
ChainedPics {
Self {
pics: [
Pic {
offset: offset1,
@@ -66,11 +76,11 @@ impl ChainedPics {
unsafe { Self::new(primary_offset, primary_offset + 8) }
}
/// Returns the initialize of this [`ChainedPics`].
/// Returns a new instance of [`ChainedPics`].
///
/// # Safety
///
/// .
/// this is unsafe because it required writing to CPU I/O ports.
pub unsafe fn initialize(&mut self) {
unsafe {
let mut wait_port: Port<u8> = Port::new(0x80);
@@ -1,15 +1,19 @@
use core::fmt;
use core::fmt::{self, Write};
use spin::{Lazy, Mutex};
use x86_64::instructions::interrupts;
use super::framebuffer::{colour::Colour, display::FRAMEBUFFER_WRITER};
use crate::arch::x86_64::drivers::framebuffer::{
colour::Colour, display::FRAMEBUFFER_WRITER,
};
use crate::resources::font::{FONT_SPLEEN_8X16, Font};
use crate::std::maths::geometry::Vec2;
static FONT_WIDTH: u32 = 8;
static FONT_HEIGHT: u32 = 16;
pub static WRITER: Lazy<Mutex<Writer>> = Lazy::new(|| Mutex::new(Writer::new()));
pub static WRITER: Lazy<Mutex<Writer>> =
Lazy::new(|| Mutex::new(Writer::new()));
pub fn screensize_chars() -> (u32, u32) {
let writer = WRITER.lock();
@@ -22,11 +26,8 @@ pub struct Writer {
screen_width: u32,
/// Measured in chars not pixels.
screen_height: u32,
/// 16 pixels tall.
text_line: u32,
/// 8 pixels wide.
text_col: u32,
fg_color: Colour,
bg_color: Colour,
}
@@ -59,6 +60,15 @@ impl Writer {
self.font = font;
}
pub const fn set_pos(&mut self, coords: Vec2<u32>) {
self.text_col = coords.x();
self.text_line = coords.y();
}
pub const fn pos(&self) -> Vec2<u32> {
Vec2::new(self.text_col, self.text_line)
}
/// This is sent when the user types a backspace.
const BACKSPACE: u8 = 8;
@@ -71,21 +81,31 @@ impl Writer {
return;
}
// Get the character data from the font array. -- each byte is a row of pixels
// Get the character data from the font array. -- each byte is a row of
// pixels
let data: &[u8] = self.font.glyph_for(c as u16);
if let Some(writer) = FRAMEBUFFER_WRITER.lock().as_mut() {
for (row, line) in data.iter().enumerate().take(16) {
for col in 0..8 {
let pixel_x: u32 = self.text_col * FONT_WIDTH + col;
let pixel_y: u32 = self.text_line * FONT_HEIGHT + row as u32;
let pixel_y: u32 =
self.text_line * FONT_HEIGHT + row as u32;
if line & (0x80 >> col) != 0 {
// Write the foreground color
writer.write_pixel(pixel_x as usize, pixel_y as usize, self.fg_color);
writer.write_pixel(
pixel_x as usize,
pixel_y as usize,
self.fg_color,
);
} else {
// Write the background color
writer.write_pixel(pixel_x as usize, pixel_y as usize, self.bg_color);
writer.write_pixel(
pixel_x as usize,
pixel_y as usize,
self.bg_color,
);
}
}
}
@@ -117,8 +137,8 @@ impl Writer {
}
}
/// Handles the backspace character. TODO: Implement VT-100 style terminal control
/// codes alongside a shell. Not simple.
/// Handles the backspace character. TODO: Implement VT-100 style terminal
/// control codes alongside a shell. Not simple.
pub fn backspace(&mut self) {
if self.text_col > 0 {
self.text_col -= 1;
@@ -145,7 +165,7 @@ impl Writer {
}
}
impl core::fmt::Write for Writer {
impl fmt::Write for Writer {
fn write_str(&mut self, s: &str) -> core::fmt::Result {
self.write_string(s);
Ok(())
@@ -164,19 +184,19 @@ fn write(args: fmt::Arguments, fg: Colour, bg: Colour) {
}
pub fn _print(args: fmt::Arguments) {
x86_64::instructions::interrupts::without_interrupts(|| {
interrupts::without_interrupts(|| {
write(args, Colour::White, Colour::Black);
})
}
pub fn _print_err(args: fmt::Arguments) {
x86_64::instructions::interrupts::without_interrupts(|| {
interrupts::without_interrupts(|| {
write(args, Colour::Red, Colour::Black);
})
}
pub fn _print_log(args: fmt::Arguments) {
x86_64::instructions::interrupts::without_interrupts(|| {
interrupts::without_interrupts(|| {
write(args, Colour::Yellow, Colour::Black);
})
}
@@ -193,6 +213,34 @@ pub fn clear_screen() {
});
}
/// Prints a string at a given `coords` before returning to original position.
///
/// These are 0 based indices and refer to character position, not pixel
/// positions.
pub fn _print_oneshot(
fg: Colour,
bg: Colour,
coords: Vec2<u32>,
args: fmt::Arguments,
) {
interrupts::without_interrupts(|| {
let mut writer = WRITER.lock();
// Save the old positions of `text_col` and `text_line`.
let old_pos = writer.pos();
// Also save the colors.
let old_fg_color = writer.fg_color;
let old_bg_color = writer.bg_color;
writer.set_pos(coords);
writer.set_colour(fg, bg);
writer.write_fmt(args).unwrap();
writer.set_colour(old_fg_color, old_bg_color);
writer.set_pos(old_pos);
});
}
pub fn reset_cursor() {
interrupts::without_interrupts(|| {
let mut writer = WRITER.lock();
@@ -201,6 +249,15 @@ pub fn reset_cursor() {
});
}
#[macro_export]
/// Prints a coloured string at a position before restoring previous position
/// and colour.
macro_rules! print_oneshot {
($position:expr, $fg:expr, $bg:expr, $($arg:tt)*) => {
$crate::arch::x86_64::drivers::ascii::_print_oneshot($fg, $bg, $position, format_args!($($arg)*));
};
}
#[macro_export]
macro_rules! println_log {
() => ($crate::print_log!("\n"));
@@ -209,7 +266,7 @@ macro_rules! println_log {
#[macro_export]
macro_rules! print_log {
($($arg:tt)*) => ($crate::_print_log(format_args!($($arg)*)));
($($arg:tt)*) => ($crate::prelude::_print_log(format_args!($($arg)*)));
}
#[macro_export]
@@ -220,16 +277,16 @@ macro_rules! println {
#[macro_export]
macro_rules! print {
($($arg:tt)*) => ($crate::_print(format_args!($($arg)*)));
($($arg:tt)*) => ($crate::prelude::_print(format_args!($($arg)*)));
}
#[macro_export]
macro_rules! printlnerr {
macro_rules! eprintln {
() => ($crate::printerr!("\n"));
($($arg:tt)*) => ($crate::printerr!("{}\n", format_args!($($arg)*)));
($($arg:tt)*) => ($crate::eprint!("{}\n", format_args!($($arg)*)));
}
#[macro_export]
macro_rules! printerr {
($($arg:tt)*) => ($crate::_print_err(format_args!($($arg)*)));
macro_rules! eprint {
($($arg:tt)*) => ($crate::prelude::_print_err(format_args!($($arg)*)));
}
@@ -19,9 +19,14 @@ impl From<Colour> for u32 {
fn from(val: Colour) -> Self {
match val {
Colour::ARGB(a, r, g, b) => {
(a as u32) << 24 | (r as u32) << 16 | (g as u32) << 8 | (b as u32)
(a as u32) << 24
| (r as u32) << 16
| (g as u32) << 8
| (b as u32)
}
Colour::RGB(r, g, b) => {
((r as u32) << 16) | (g as u32) << 8 | (b as u32)
}
Colour::RGB(r, g, b) => ((r as u32) << 16) | (g as u32) << 8 | (b as u32),
Colour::HexARGB(hex) => hex,
Colour::Black => 0xFF000000,
Colour::Blue => 0xFF0000FF,
@@ -38,7 +43,9 @@ impl From<Colour> for u32 {
impl core::fmt::Display for Colour {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::ARGB(r, g, b, a) => write!(f, "RGBA(#{:x}{:x}{:x}{:x})", r, g, b, a),
Self::ARGB(r, g, b, a) => {
write!(f, "RGBA(#{:x}{:x}{:x}{:x})", r, g, b, a)
}
Self::RGB(r, g, b) => write!(f, "RGB(#{:x}{:x}{:x})", r, g, b),
Self::HexARGB(hex) => write!(f, "Hex(#{:x})", hex),
Self::Black => write!(f, "Black"),
@@ -10,13 +10,15 @@ use core::panic;
use limine::framebuffer::Framebuffer;
use spin::{Lazy, Mutex};
pub static FRAMEBUFFER_WRITER: Lazy<Mutex<Option<FramebufferWriter>>> = Lazy::new(|| {
pub static FRAMEBUFFER_WRITER: Lazy<Mutex<Option<FramebufferWriter>>> =
Lazy::new(|| {
Mutex::new(FRAMEBUFFER_REQUEST.get_response().map_or_else(
|| {
panic!("Framebuffer request failed");
},
|framebuffer_response| {
let framebuffer = framebuffer_response.framebuffers().next().unwrap();
let framebuffer =
framebuffer_response.framebuffers().next().unwrap();
Some(FramebufferWriter::new(framebuffer))
},
))
@@ -28,7 +30,8 @@ pub static FRAMEBUFFER_WRITER: Lazy<Mutex<Option<FramebufferWriter>>> = Lazy::ne
///
/// It also avoids the requirement for lifetimes.
///
/// Note this does not implement Writer as these functions only handle drawing pixels.
/// Note this does not implement Writer as these functions only handle drawing
/// pixels.
pub struct FramebufferWriter {
pitch: u64,
bpp: u16,
@@ -3,24 +3,24 @@ use core::{
task::{Context, Poll},
};
use crate::println;
use crossbeam::queue::ArrayQueue;
use futures_util::{Stream, StreamExt, task::AtomicWaker};
use pc_keyboard::{
DecodedKey, HandleControl, KeyCode, Keyboard, ScancodeSet1,
layouts::{self, Uk105Key},
layouts::Uk105Key,
};
use spin::{Lazy, Mutex, Once};
use crate::prelude::*;
static KBD_QUEUE: Once<ArrayQueue<u8>> = Once::new();
static WAKER: AtomicWaker = AtomicWaker::new();
pub static KEYBOARD: Lazy<Mutex<Keyboard<Uk105Key, ScancodeSet1>>> = Lazy::new(|| {
pub static KEYBOARD: Lazy<Mutex<Keyboard<Uk105Key, ScancodeSet1>>> =
Lazy::new(|| {
Mutex::new(Keyboard::new(
ScancodeSet1::new(),
// TODO: Expose an API to change the default KB layout.
layouts::Uk105Key,
Uk105Key,
HandleControl::Ignore,
))
});
@@ -63,7 +63,10 @@ impl Default for ScancodeStream {
impl Stream for ScancodeStream {
type Item = u8;
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
fn poll_next(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Self::Item>> {
let queue = KBD_QUEUE.get().unwrap();
if let Some(scancode) = queue.pop() {
+5
View File
@@ -0,0 +1,5 @@
pub mod ascii;
pub mod framebuffer;
pub mod keyboard;
pub mod port;
pub mod serial;
@@ -15,7 +15,7 @@ macro_rules! serial_println {
($($arg:tt)*) => (serial_print!("{}\n", format_args!($($arg)*)));
}
use super::port::{inb, outb};
use crate::arch::x86_64::drivers::port::{inb, outb};
use x86_64::instructions::interrupts;
+2 -2
View File
@@ -1,11 +1,11 @@
use x86_64::{
VirtAddr,
instructions::tables::load_tss,
registers::segmentation::{Segment, CS, DS, ES, SS},
registers::segmentation::{CS, DS, ES, SS, Segment},
structures::{
gdt::{Descriptor, GlobalDescriptorTable, SegmentSelector},
tss::TaskStateSegment,
},
VirtAddr,
};
use spin::Lazy;
+29 -17
View File
@@ -1,14 +1,18 @@
use libk::drivers::memory::{FRAME_ALLOCATOR, OFFSET_PAGE_TABLE};
use libk::prelude::*;
use crate::{debug, serial_print};
use pic8259::ChainedPics;
use x86_64::registers::control::Cr2;
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame, PageFaultErrorCode};
use x86_64::structures::idt::{
InterruptDescriptorTable, InterruptStackFrame, PageFaultErrorCode,
};
use x86_64::structures::paging::mapper::MapperFlushAll;
use x86_64::structures::paging::{FrameAllocator, Mapper, Page, PageTableFlags, Size4KiB};
use spin::{Lazy, Mutex};
use x86_64::structures::paging::{
FrameAllocator, Mapper, Page, PageTableFlags, Size4KiB,
};
use super::gdt;
use crate::arch::x86_64::memory::{FRAME_ALLOCATOR, OFFSET_PAGE_TABLE};
use crate::{println_log, serial_println};
use spin::{Lazy, Mutex};
static IDT: Lazy<InterruptDescriptorTable> = Lazy::new(|| {
let mut idt = InterruptDescriptorTable::new();
@@ -25,7 +29,8 @@ static IDT: Lazy<InterruptDescriptorTable> = Lazy::new(|| {
idt.page_fault.set_handler_fn(page_fault_handler);
idt[InterruptIndex::Timer.as_u8()].set_handler_fn(timer_interrupt_handler);
idt[InterruptIndex::Keyboard.as_u8()].set_handler_fn(keyboard_interrupt_handler);
idt[InterruptIndex::Keyboard.as_u8()]
.set_handler_fn(keyboard_interrupt_handler);
idt
});
@@ -90,13 +95,16 @@ extern "x86-interrupt" fn double_fault_handler(
panic!("Exception: Double Fault\n{:#?}", stack_frame);
}
extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStackFrame) {
use pc_keyboard::{layouts, HandleControl, Keyboard, ScancodeSet1};
extern "x86-interrupt" fn keyboard_interrupt_handler(
_stack_frame: InterruptStackFrame,
) {
use pc_keyboard::{HandleControl, Keyboard, ScancodeSet1, layouts};
// use pc_keyboard::DecodedKey;
use spin::Mutex;
use x86_64::instructions::port::Port;
static KEYBOARD: Lazy<Mutex<Keyboard<layouts::Uk105Key, ScancodeSet1>>> = Lazy::new(|| {
static KEYBOARD: Lazy<Mutex<Keyboard<layouts::Uk105Key, ScancodeSet1>>> =
Lazy::new(|| {
Mutex::new(Keyboard::new(
ScancodeSet1::new(),
layouts::Uk105Key,
@@ -108,7 +116,7 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac
let mut port = Port::new(0x60);
let scancode: u8 = unsafe { port.read() };
libk::drivers::io::keyboard::add_scancode(scancode);
crate::arch::x86_64::drivers::keyboard::add_scancode(scancode);
unsafe {
PICS.lock()
@@ -116,7 +124,10 @@ extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStac
}
}
extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: InterruptStackFrame) {
extern "x86-interrupt" fn timer_interrupt_handler(
_stack_frame: InterruptStackFrame,
) {
// debug!("Timer Interrupt");
unsafe {
PICS.lock()
.notify_end_of_interrupt(InterruptIndex::Timer.as_u8());
@@ -127,17 +138,18 @@ extern "x86-interrupt" fn page_fault_handler(
_stack_frame: InterruptStackFrame,
_error_code: PageFaultErrorCode,
) {
serial_println!("Exception: Page Fault");
serial_println!("Accessed Address: {:?}", Cr2::read());
serial_println!("Error Code: {:?}", _error_code);
serial_println!("{:#?}", _stack_frame);
// serial_println!("Exception: Page Fault");
// serial_println!("Accessed Address: {:?}", Cr2::read());
// serial_println!("Error Code: {:?}", _error_code);
// serial_println!("{:#?}", _stack_frame);
if let Some(frame_allocator) = FRAME_ALLOCATOR.get() {
let mut f = frame_allocator.lock();
let frame = f.allocate_frame().unwrap();
let flags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE;
let page: Page<Size4KiB> = Page::containing_address(Cr2::read().unwrap());
let page: Page<Size4KiB> =
Page::containing_address(Cr2::read().unwrap());
unsafe {
let mut mapper = OFFSET_PAGE_TABLE.get().unwrap().lock();
@@ -1,9 +1,72 @@
use alloc::collections::LinkedList;
use crate::arch::x86_64::memory::allocation::page_alloc::FoundryOSFrameAllocator;
use crate::arch::x86_64::memory::units::MemoryUnits;
use crate::arch::x86_64::memory::{
FRAME_ALLOCATOR, HEAP_SIZE, HEAP_VIRTUAL_SPACE,
};
use crate::debugln;
use core::alloc::{GlobalAlloc, Layout};
use core::{mem, ptr};
use core::ptr::NonNull;
use crate::drivers::kalloc::allocator::Locked;
const BLOCK_SIZES: &[usize] = &[8, 16, 32, 64, 128, 256, 512, 1024, 2048];
use core::ptr;
use spin::{Mutex, MutexGuard};
use x86_64::VirtAddr;
use x86_64::structures::paging::{
PageTableFlags, Size4KiB, mapper::MapToError,
};
/// We are currently using a linked list heap allocator which uses our
/// underlying page allocator.
#[global_allocator]
/// This is now Rust's global allocator, so we can use stuff requiring heap
/// allocations.
static ALLOCATOR: Locked<FoundryAllocator> =
Locked::new(FoundryAllocator::new());
/// Initializes the heap.
///
/// This function must be called once, before any functions that
/// require a heap are called. It sets up the heap by allocating
/// the necessary frames from the page allocator. The heap is
/// then ready for use.
///
/// # Safety
///
/// This function must be called only once, and must be called before any types
/// are constructed that require dynamic memory allocation.
///
/// # Parameters
///
/// None
///
/// # Returns
///
/// Returns a `Result` containing a `MapToError` if the heap
/// could not be initialized, or `Ok` if the heap was
/// initialized successfully.
pub unsafe fn init_heap() -> Result<(), MapToError<Size4KiB>> {
unsafe {
// code to allocate frames is now done in the page fault interrupt
// handler!
ALLOCATOR.lock().init(HEAP_VIRTUAL_SPACE, HEAP_SIZE);
Ok(())
}
}
pub struct Locked<T> {
inner: Mutex<T>,
}
impl<T> Locked<T> {
pub const fn new(inner: T) -> Self {
Self {
inner: Mutex::new(inner),
}
}
pub fn lock(&self) -> MutexGuard<T> {
self.inner.lock()
}
}
const BLOCK_SIZES: &[usize] = &[8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096];
struct ListNode {
next: Option<&'static mut ListNode>,
@@ -28,13 +91,25 @@ impl FoundryAllocator {
fallback: Locked::new(FoundryFallbackAllocator::new()),
}
}
pub unsafe fn init(&mut self, heap_start: usize, heap_size: usize) { unsafe {
self.fallback.lock().init(heap_start, heap_size);
}}
/// Initializes the fallback allocator with the given heap start address and
/// size.
///
/// # Safety
///
/// This function is unsafe because it does not check whether the given heap
/// start address and size are valid.
pub unsafe fn init(&mut self, heap_start: usize, heap_size: usize) {
debugln!(" => Start: {:?}", VirtAddr::new(heap_start as u64));
debugln!(" => Size: {}", MemoryUnits::from_bytes(heap_size));
unsafe fn fallback_alloc(&mut self, layout: Layout) -> *mut u8 { unsafe {
self.fallback.alloc(layout)
}}
unsafe {
self.fallback.lock().init(heap_start, heap_size);
}
}
unsafe fn fallback_alloc(&mut self, layout: Layout) -> *mut u8 {
unsafe { self.fallback.alloc(layout) }
}
fn block_size(&self, layout: &Layout) -> Option<usize> {
let required_block_size = layout.size().max(layout.align());
@@ -51,14 +126,17 @@ unsafe impl GlobalAlloc for Locked<FoundryAllocator> {
match allocator.list_heads[index].take() {
Some(node) => {
allocator.list_heads[index] = node.next.take();
node as *mut ListNode as *mut u8
let ptr = node as *mut ListNode as *mut u8;
ensure_mapped(VirtAddr::new(ptr as u64));
ptr
}
None => {
// no block exists in list => allocate new block
let block_size = BLOCK_SIZES[index];
// only works if all block sizes are a power of 2
let block_align = block_size;
let layout = Layout::from_size_align(block_size, block_align)
let layout =
Layout::from_size_align(block_size, block_align)
.unwrap();
unsafe { allocator.fallback_alloc(layout) }
}
@@ -68,7 +146,6 @@ unsafe impl GlobalAlloc for Locked<FoundryAllocator> {
}
}
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
let mut allocator = self.lock();
match allocator.block_size(&layout) {
@@ -81,7 +158,7 @@ unsafe impl GlobalAlloc for Locked<FoundryAllocator> {
unsafe { new_ptr.write(new_node) };
allocator.list_heads[idx] = Some(unsafe { &mut *new_ptr });
}
None => {;
None => {
unsafe { allocator.fallback.dealloc(ptr, layout) };
}
}
@@ -95,10 +172,7 @@ struct FallbackListNode {
impl FallbackListNode {
const fn new(size: usize) -> Self {
Self {
size,
next: None,
}
Self { size, next: None }
}
fn start_addr(&self) -> usize {
@@ -114,6 +188,12 @@ pub struct FoundryFallbackAllocator {
head: FallbackListNode,
}
impl Default for FoundryFallbackAllocator {
fn default() -> Self {
Self::new()
}
}
impl FoundryFallbackAllocator {
pub const fn new() -> Self {
Self {
@@ -121,23 +201,41 @@ impl FoundryFallbackAllocator {
}
}
/// Initializes the allocator with a given heap start address and size.
///
/// # Safety
///
/// This function is unsafe because it does not check whether the given heap
/// start address and size are valid.
pub unsafe fn init(&mut self, heap_start: usize, heap_size: usize) {
unsafe { self.add_region(heap_start, heap_size) };
}
unsafe fn add_region(&mut self, addr: usize, size: usize) { unsafe {
unsafe fn add_region(&mut self, addr: usize, size: usize) {
unsafe {
let mut node = FallbackListNode::new(size);
node.next = self.head.next.take();
let virt_addr = VirtAddr::new(addr as u64);
ensure_mapped(virt_addr);
let node_ptr = addr as *mut FallbackListNode;
node_ptr.write(node);
self.head.next = Some(&mut *node_ptr);
}}
}
}
fn find_region(&mut self, size: usize, align: usize) -> Option<(&'static mut FallbackListNode, usize)> {
fn find_region(
&mut self,
size: usize,
align: usize,
) -> Option<(&'static mut FallbackListNode, usize)> {
let mut current = &mut self.head;
// look for a large enough memory region in linked list
while let Some(ref mut region) = current.next {
if let Ok(alloc_start) = Self::alloc_from_region(&region, size, align) {
if let Ok(alloc_start) =
Self::alloc_from_region(region, size, align)
{
// region suitable for allocation -> remove node from list
let next = region.next.take();
let ret = Some((current.next.take().unwrap(), alloc_start));
@@ -163,8 +261,11 @@ impl FoundryFallbackAllocator {
(size, layout.align())
}
fn alloc_from_region(region: &FallbackListNode, size: usize, align: usize) -> Result<usize, ()>
{
fn alloc_from_region(
region: &FallbackListNode,
size: usize,
align: usize,
) -> Result<usize, ()> {
let alloc_start = Self::align_up(region.start_addr(), align);
let alloc_end = alloc_start.checked_add(size).ok_or(())?;
@@ -187,13 +288,16 @@ unsafe impl GlobalAlloc for Locked<FoundryFallbackAllocator> {
// perform layout adjustments
let (size, align) = FoundryFallbackAllocator::size_align(layout);
if let Some((region, alloc_start)) = allocator.find_region(size, align) {
if let Some((region, alloc_start)) = allocator.find_region(size, align)
{
let alloc_end = alloc_start.checked_add(size).expect("overflow");
let excess_size = region.end_addr() - alloc_end;
if excess_size > 0 {
unsafe { allocator.add_region(alloc_end, excess_size) };
}
alloc_start as *mut u8
let ptr = alloc_start as *mut u8;
ensure_mapped(VirtAddr::new(ptr as u64));
ptr
} else {
ptr::null_mut()
}
@@ -204,28 +308,18 @@ unsafe impl GlobalAlloc for Locked<FoundryFallbackAllocator> {
// perform layout adjustments
let (size, _) = FoundryFallbackAllocator::size_align(layout);
unsafe {
allocator.add_region(ptr as usize, size)
unsafe { allocator.add_region(ptr as usize, size) }
}
}
fn ensure_mapped(virt_addr: VirtAddr) {
if !FoundryOSFrameAllocator::is_mapped(virt_addr) {
let mut foundry_alloc = FRAME_ALLOCATOR.get().unwrap().lock();
foundry_alloc
.allocate_page(
virt_addr,
PageTableFlags::PRESENT | PageTableFlags::WRITABLE,
)
.unwrap();
}
}
@@ -0,0 +1,3 @@
pub mod heap_alloc;
pub(crate) mod page_alloc;
pub mod stack_alloc;
@@ -0,0 +1,102 @@
use crate::arch::x86_64::memory::{FRAME_ALLOCATOR, OFFSET_PAGE_TABLE};
use limine::memory_map::EntryType;
use limine::response::MemoryMapResponse;
use spin::Mutex;
use x86_64::structures::paging::mapper::{MapToError, TranslateResult};
use x86_64::structures::paging::{
FrameAllocator, Mapper, Page, PageTableFlags, PhysFrame, Size4KiB,
Translate,
};
use x86_64::{PhysAddr, VirtAddr};
pub struct FoundryOSFrameAllocator {
memory_map: &'static MemoryMapResponse,
next: usize,
}
impl FoundryOSFrameAllocator {
/// Creates a new `FoundryOSFrameAllocator` from a memory map.
///
/// This function takes a reference to a `MemoryMapResponse` and initializes
/// a `FoundryOSFrameAllocator` with it. The `next` field is set to 0,
/// indicating that the first frame to be allocated is the first frame
/// in the memory map.
pub fn init(memory_map: &'static MemoryMapResponse) {
FRAME_ALLOCATOR.call_once(|| {
Mutex::new(Self {
memory_map,
next: 0,
})
});
}
pub fn count_usable_frames(&self) -> u64 {
self.usable_frames().count() as u64
}
pub fn available_memory(&self) -> u64 {
self.memory_map
.entries()
.iter()
.map(|region| region.base..region.base + region.length)
.flat_map(|r| r.step_by(4096))
.count() as u64
* 4096
}
/// An iterator over all usable frames in the memory map.
///
/// Yields one `PhysFrame` for each available 4KiB frame in the memory map.
///
/// This function is used to allocate frames for the page map.
fn usable_frames(&self) -> impl Iterator<Item = PhysFrame> + use<> {
let regions = self.memory_map.entries().iter();
let usable_regions =
regions.filter(|region| region.entry_type == EntryType::USABLE);
let addr_ranges = usable_regions
.map(|region| region.base..region.base + region.length);
let frame_addresses = addr_ranges.flat_map(|r| r.step_by(4096));
frame_addresses.map(|addr| {
PhysFrame::from_start_address(PhysAddr::new(addr)).unwrap()
})
}
pub(crate) fn is_mapped(virt_addr: VirtAddr) -> bool {
let mapper = OFFSET_PAGE_TABLE.get().unwrap().lock();
matches!(mapper.translate(virt_addr), TranslateResult::Mapped { .. })
}
pub(crate) fn allocate_page(
&mut self,
start_addr: VirtAddr,
flags: PageTableFlags,
) -> Result<(), MapToError<Size4KiB>> {
let page = Page::containing_address(start_addr);
let frame = self
.allocate_frame()
.ok_or(MapToError::<Size4KiB>::FrameAllocationFailed)?;
let mut mapper = OFFSET_PAGE_TABLE.get().unwrap().lock();
unsafe { mapper.map_to(page, frame, flags, self)? }.flush();
Ok(())
}
}
unsafe impl FrameAllocator<Size4KiB> for FoundryOSFrameAllocator {
/// Allocates a frame from the list of usable frames.
///
/// This function returns the next available `PhysFrame` from the memory
/// map, if one exists. Once a frame is allocated, the internal counter
/// is incremented to point to the next frame for future allocations.
///
/// # Returns
///
/// - `Some(PhysFrame)`: If a usable frame is available.
/// - `None`: If there are no more usable frames to allocate.
fn allocate_frame(&mut self) -> Option<PhysFrame> {
let frame = self.usable_frames().nth(self.next);
self.next += 1;
frame
}
}
@@ -0,0 +1,86 @@
use crate::arch::x86_64::memory::STACK_VIRTUAL_SPACE;
use x86_64::VirtAddr;
use x86_64::structures::paging::{
FrameAllocator, Mapper, Page, Size4KiB, mapper,
};
fn reserve_stack_memory(size_in_pages: u64) -> Page {
use core::sync::atomic::{AtomicU64, Ordering};
static STACK_ALLOC_NEXT: AtomicU64 =
AtomicU64::new(STACK_VIRTUAL_SPACE as u64);
let start_addr =
VirtAddr::new(STACK_ALLOC_NEXT.fetch_add(
size_in_pages * Page::<Size4KiB>::SIZE,
Ordering::Relaxed,
));
Page::from_start_address(start_addr)
.expect("`STACK_ALLOC_NEXT` not page aligned")
}
/// Allocates a stack in the virtual address space, mapped to physical pages.
///
/// This function allocates a stack in the virtual address space, mapped to
/// physical pages. The stack is allocated as a sequence of pages, with the
/// first page allocated as a guard page. The stack is then mapped to the
/// allocated physical frame.
///
/// The function takes the size of the stack in pages, a mutable reference to a
/// mapper, and a mutable reference to a frame allocator. It returns a `Result`
/// containing a `StackBounds` struct, which contains the start and end virtual
/// addresses of the allocated stack.
///
/// # Safety
///
/// This function is unsafe because it maps physical frames to virtual addresses
/// without any protection. This can lead to bugs if the physical frames are not
/// correctly allocated, or if the virtual addresses are not correctly aligned.
///
/// # Panics
///
/// This function will panic if the allocation of the physical frame fails.
pub unsafe fn alloc_stack(
size_in_pages: u64,
mapper: &mut impl Mapper<Size4KiB>,
frame_allocator: &mut impl FrameAllocator<Size4KiB>,
) -> Result<StackBounds, mapper::MapToError<Size4KiB>> {
unsafe {
use x86_64::structures::paging::PageTableFlags as Flags;
let guard_page = reserve_stack_memory(size_in_pages + 1);
let stack_start = guard_page + 1;
let stack_end = stack_start + size_in_pages;
for page in Page::range(stack_start, stack_end) {
let frame = frame_allocator
.allocate_frame()
.ok_or(mapper::MapToError::FrameAllocationFailed)?;
let flags = Flags::PRESENT | Flags::WRITABLE;
mapper.map_to(page, frame, flags, frame_allocator)?.flush();
}
Ok(StackBounds {
start: stack_start.start_address(),
end: stack_end.start_address(),
})
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct StackBounds {
start: VirtAddr,
end: VirtAddr,
}
impl StackBounds {
pub const fn new(start: VirtAddr, end: VirtAddr) -> Self {
Self { start, end }
}
pub const fn start(&self) -> VirtAddr {
self.start
}
pub const fn end(&self) -> VirtAddr {
self.end
}
}
@@ -16,7 +16,8 @@ static HIGHER_HALF_DIRECT_MAP_REQUEST: HhdmRequest = HhdmRequest::new();
#[used]
#[unsafe(link_section = ".requests")]
static KERNEL_ADDRESS_REQUEST: KernelAddressRequest = KernelAddressRequest::new();
pub static KERNEL_ADDRESS_REQUEST: KernelAddressRequest =
KernelAddressRequest::new();
/// ```rs
/// let virt_addr = phys_addr + offset;
+65
View File
@@ -0,0 +1,65 @@
pub mod allocation;
pub mod mapping;
pub mod units;
use allocation::page_alloc::FoundryOSFrameAllocator;
use spin::{Mutex, Once};
use units::MemoryUnits::*;
use x86_64::{
VirtAddr,
registers::control::Cr3,
structures::paging::{OffsetPageTable, PageTable},
};
/// Start address of the memory space where we store allocated stacks.
pub const STACK_VIRTUAL_SPACE: usize = 0x5555_5555_0000;
/// Start address of heap allocated memory.
pub const HEAP_VIRTUAL_SPACE: usize = 0x4444_4444_0000;
pub const HEAP_SIZE: usize = MiB(1).to_bytes();
pub static FRAME_ALLOCATOR: Once<Mutex<FoundryOSFrameAllocator>> = Once::new();
pub static OFFSET_PAGE_TABLE: Once<Mutex<OffsetPageTable>> = Once::new();
/// Returns a mutable reference to the current level 4 page table.
///
/// # Safety
///
/// The caller must ensure that the level 4 page table is not modified
/// simultaneously. The caller must also ensure that the physical memory offset
/// is correct, to ensure that the correct virtual address is constructed.
unsafe fn active_l4_table(
physical_memory_offset: VirtAddr,
) -> &'static mut PageTable {
let (level_4_frame, _) = Cr3::read();
let phys_addr = level_4_frame.start_address();
let virt = phys_addr.as_u64() + physical_memory_offset.as_u64();
unsafe { &mut *(virt as *mut PageTable) }
}
/// Initializes the `OffsetPageTable` for the current CPU architecture.
///
/// # Safety
///
/// This function must be called only once and should be called before any
/// memory operations are performed that rely on virtual memory management.
/// The provided `physical_memory_offset` must be accurate to ensure correct
/// translation of physical addresses.
///
/// # Parameters
///
/// - `physical_memory_offset`: The offset to convert physical addresses to
/// virtual addresses in the higher-half direct map.
///
/// # Returns
///
/// Returns an `OffsetPageTable` that allows for manipulation of the page
/// tables for the current CPU architecture.
pub fn init_page_table(physical_memory_offset: VirtAddr) {
unsafe {
let l4_table = active_l4_table(physical_memory_offset);
let offset_table =
OffsetPageTable::new(l4_table, physical_memory_offset);
OFFSET_PAGE_TABLE.call_once(|| Mutex::new(offset_table));
}
}
+49
View File
@@ -0,0 +1,49 @@
pub enum MemoryUnits {
B(usize),
KiB(usize),
MiB(usize),
GiB(usize),
}
impl MemoryUnits {
pub const fn to_bytes(&self) -> usize {
match self {
Self::B(b) => *b,
Self::KiB(kib) => *kib * 1024,
Self::MiB(mib) => *mib * 1024 * 1024,
Self::GiB(gib) => *gib * 1024 * 1024 * 1024,
}
}
pub const fn from_bytes(bytes: usize) -> Self {
if bytes < 1024 {
Self::B(bytes)
} else if bytes < 1024 * 1024 {
Self::KiB(bytes / 1024)
} else if bytes < 1024 * 1024 * 1024 {
Self::MiB(bytes / (1024 * 1024))
} else {
Self::GiB(bytes / (1024 * 1024 * 1024))
}
}
pub const fn convert(&mut self) {
match self {
Self::B(b) if *b > 1024 => *self = Self::KiB(*b / 1024),
Self::KiB(kib) if *kib > 1024 => *self = Self::MiB(*kib / 1024),
Self::MiB(mib) if *mib > 1024 => *self = Self::GiB(*mib / 1024),
_ => (),
}
}
}
impl core::fmt::Display for MemoryUnits {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::B(b) => write!(f, "{} B", b),
Self::KiB(kib) => write!(f, "{} KiB", kib),
Self::MiB(mib) => write!(f, "{} MiB", mib),
Self::GiB(gib) => write!(f, "{} GiB", gib),
}
}
}
+5 -8
View File
@@ -1,9 +1,6 @@
pub mod gdt;
pub mod interrupts;
pub mod memmap;
pub mod apic;
pub mod cpu;
pub mod drivers;
pub mod gdt;
pub mod interrupts;
pub mod memory;
pub mod processing;
@@ -2,8 +2,8 @@
//!
//! Written by @zxq5 for the most part with code from
//! [here](https://github.com/phil-opp/blog_os/).
//!
use crate::prelude::*;
use alloc::boxed::Box;
use alloc::collections::BTreeMap;
use alloc::sync::Arc;
use alloc::task::Wake;
@@ -80,9 +80,9 @@ impl Executor {
Some(task) => task,
None => continue, // task no longer exists
};
let waker = waker_cache
.entry(task_id)
.or_insert_with(|| TaskWaker::new_waker(task_id, task_queue.clone()));
let waker = waker_cache.entry(task_id).or_insert_with(|| {
TaskWaker::new_waker(task_id, task_queue.clone())
});
let mut context = Context::from_waker(waker);
match task.poll(&mut context) {
Poll::Ready(()) => {
@@ -128,7 +128,10 @@ impl TaskWaker {
self.task_queue.push(self.task_id).expect("task_queue full");
}
fn new_waker(task_id: TaskId, task_queue: Arc<ArrayQueue<TaskId>>) -> Waker {
fn new_waker(
task_id: TaskId,
task_queue: Arc<ArrayQueue<TaskId>>,
) -> Waker {
Waker::from(Arc::new(Self {
task_id,
task_queue,
+4
View File
@@ -0,0 +1,4 @@
#![expect(unused)]
pub mod async_io;
mod taskrunner;
pub mod threading;
@@ -0,0 +1,12 @@
use alloc::boxed::Box;
pub struct Task {
pid: usize,
task: Box<dyn Fn() + Send + 'static>,
}
impl Task {
// pub const fn new() {}
pub const fn run() {}
}
@@ -1,3 +1,6 @@
mod switch;
mod deprecated;
use core::arch::asm;
#[repr(C)]
@@ -0,0 +1,26 @@
use crate::arch::x86_64::memory::allocation::stack_alloc::StackBounds;
use x86_64::VirtAddr;
mod switch;
#[derive(Debug)]
pub struct Thread {
id: ThreadId,
stack_ptr: Option<VirtAddr>,
stack_bounds: Option<StackBounds>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct ThreadId(u64);
impl ThreadId {
pub const fn as_u64(&self) -> u64 {
self.0
}
fn new() -> Self {
use core::sync::atomic::{AtomicU64, Ordering};
static NEXT_THREAD_ID: AtomicU64 = AtomicU64::new(1);
Self(NEXT_THREAD_ID.fetch_add(1, Ordering::Relaxed))
}
}
@@ -0,0 +1,13 @@
.intel_syntax noprefix
switch_thread:
pushfq
mov rax, rsp
mov rsp, rdi
mov rdi, rax
call add_paused_thread
popfq
ret
@@ -0,0 +1 @@
+101 -52
View File
@@ -1,5 +1,5 @@
#![no_std]
#![feature(abi_x86_interrupt)]
#![feature(abi_x86_interrupt, breakpoint)]
#![warn(
clippy::correctness,
clippy::nursery,
@@ -13,100 +13,149 @@
extern crate alloc;
use arch::x86_64::apic::enable_apic;
use crate::{
arch::x86_64::{
// cpu::apic::enable_apic,
drivers::{
ascii::screensize_chars, framebuffer::display::screensize_px,
},
gdt,
interrupts,
memory::{
FRAME_ALLOCATOR,
allocation::{
heap_alloc::init_heap, page_alloc::FoundryOSFrameAllocator,
},
init_page_table, mapping,
units::MemoryUnits,
},
},
prelude::*,
};
use alloc::{boxed::Box, format};
use core::arch::asm;
use libk::drivers::memory;
use limine::BaseRevision;
use libk::drivers::kalloc::allocator::init_heap;
use libk::prelude::*;
use x86_64::VirtAddr;
mod arch;
pub mod arch;
/// Commonly used re-exports.
pub mod prelude;
pub mod resources;
// We aren't using much of this right now.
#[allow(unused)]
pub mod std;
mod step;
pub mod util;
/// Sets the base revision to the latest revision supported by the crate.
/// See specification for further info.
/// Be sure to mark all limine requests with #[used], otherwise they may be removed by the compiler.
/// Be sure to mark all limine requests with #[used], otherwise they may be
/// removed by the compiler.
#[used]
// The .requests section allows limine to find the requests faster and more safely.
// The .requests section allows limine to find the requests faster and more
// safely.
#[unsafe(link_section = ".requests")]
static BASE_REVISION: BaseRevision = BaseRevision::new();
#[panic_handler]
fn rust_panic(_info: &core::panic::PanicInfo) -> ! {
println!("Kernel panic: {}", _info);
serial_println!("Kernel panic: {}", _info);
hcf();
}
pub fn hcf() -> ! {
loop {
unsafe {
#[cfg(target_arch = "x86_64")]
asm!("hlt");
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
asm!("wfi");
#[cfg(target_arch = "loongarch64")]
asm!("idle 0");
}
}
}
pub fn boot() -> Result<(), &'static str> {
#[derive(Debug)]
pub struct NoError {}
impl core::fmt::Display for NoError {
fn fmt(&self, _f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
Ok(())
}
}
pub struct NoTags;
impl core::error::Error for NoError {}
/// Panicking before this is initialised is unwise. We should probably extract
/// very early init into it's own function because Stack Traces may require
/// allocations etc.
#[inline(never)]
pub fn boot() -> Result<(), Box<dyn core::error::Error>> {
if !BASE_REVISION.is_supported() {
return Err("base revision not supported");
return Err("Base revision not supported.".into());
}
use arch::x86_64::{gdt, interrupts, memmap};
let memory_map = memmap::get_memory_map();
let memory_map = mapping::get_memory_map();
print_log!(" Initialising Serial... ");
if libk::drivers::io::serial::init().is_err() {
println_log!("[Not Detected]")
let res = arch::x86_64::drivers::serial::init();
serial_print!(" Initialising Serial... ");
if res.is_err() {
debugln!("[Not Detected]")
} else {
println_log!("[Success]");
debugln!("[Success]");
}
print_log!(" Setting Up Global Descriptor Table... ");
debugln!(
"Display is {:?} chars, {:?} px.",
screensize_chars(),
screensize_px()
);
debug!(" Setting Up Global Descriptor Table... ");
gdt::init();
println_log!("[Success]");
debugln!("[Success]");
print_log!(" Setting Up Interrupt Descriptor Table... ");
debug!(" Setting Up Interrupt Descriptor Table... ");
interrupts::init_idt();
println_log!("[Success]");
debugln!("[Success]");
print_log!(" Initialising Memory Subsystem... ");
let physical_memory_offset = VirtAddr::new(*memmap::PHYSICAL_MEMORY_OFFSET);
memory::init_page_table(physical_memory_offset);
println_log!("[Success]");
debugln!(" Initialising Memory Subsystem... ");
let physical_memory_offset =
VirtAddr::new(*mapping::PHYSICAL_MEMORY_OFFSET);
init_page_table(physical_memory_offset);
FoundryOSFrameAllocator::init(memory_map);
let available_bytes =
FRAME_ALLOCATOR.get().unwrap().lock().available_memory();
print_log!(" Setting Up Page Table... ");
memory::init_frame_allocator(memory_map);
println_log!("[Success]");
debugln!(
" => Available Memory: {}",
MemoryUnits::from_bytes(available_bytes as usize)
);
print_log!(" Initialising Heap... ");
if init_heap().is_err() {
return Err("Failed to initialise heap: error");
// Allocations should be all fine past this point.
debugln!(" Initialising Heap... ");
match unsafe { init_heap() } {
Ok(_) => debugln!(" [Success]"),
Err(why) => return Err(format!("{:?}", why).into()),
}
println_log!("[Success]");
print_log!(" Enabling PICs... ");
debug!(" Enabling PICs... ");
interrupts::enable_pic();
println_log!("[Success]");
debugln!("[Success]");
// print_log!(" Disabling PICs... ");
// debug!(" Disabling PICs... ");
// interrupts::disable_pic();
// println_log!("[Success]");
// debugln!("[Success]");
// print_log!(" Initialising APIC");
// debug!(" Initialising APIC... ");
// enable_apic();
// println_log!("[Success]");
// debugln!("[Success]");
print_log!(" Enabling Interrupts... ");
debug!(" Enabling Interrupts... ");
x86_64::instructions::interrupts::enable();
println_log!("[Success]");
debugln!("[Success]");
Ok(())
}
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo<'_>) -> ! {
debugln!("{:?}", _info);
hcf()
}
+4 -16
View File
@@ -3,12 +3,8 @@
extern crate alloc;
use alloc::vec;
use libk::{
drivers::{
async_io::task::{Executor, Task},
io::{self, framebuffer::colour::Colour},
},
use foundry_os::{
arch::x86_64::processing::async_io::task::{Executor, Task},
prelude::*,
util::shell::shell,
};
@@ -19,25 +15,17 @@ extern "C" fn kmain() -> ! {
if let Err(err) = foundry_os::boot() {
panic!("{}", err);
}
println_log!(" [ Kernel Initialised Successfully ] ");
let dimensions = io::ascii::screensize_chars();
let dimensions2 = io::framebuffer::display::screensize_px();
println!("Dimensions: {}x{} (px)", dimensions2.0, dimensions2.1);
println!("Dimensions: {}x{} (chars)", dimensions.0, dimensions.1);
// println!("TESTING :: Allocation");
// let somevec = vec![0; 1_000_000];
// println!("{:?}", somevec);
// println!("{}", somevec.len());
// println!("PASSED!");
// test1();
let mut executor = Executor::new();
executor.spawn(Task::new(shell()));
executor.run();
loop {}
executor.run()
}
+7
View File
@@ -0,0 +1,7 @@
pub use crate::{
arch::x86_64::drivers::framebuffer::colour::Colour,
debug, debugln, eprint, eprintln, hcf, print, print_log, print_oneshot,
println, println_log, serial_print, serial_println,
std::debug::_debug,
std::io::{_print, _print_err, _print_log, _serial_write},
};
@@ -1,11 +1,9 @@
use libm::include_font;
pub const FONT_SPLEEN_8X16: Font =
Font::new(include_font!("../../../resources/font/spleen-8x16.psf"));
pub mod ibm_vga_8x16;
pub static FONT_SPLEEN_8X16: Font =
Font::new(include_font!("./libk/resources/font/spleen-8x16.psf"));
pub static FONT_CP850_8X16: Font = Font::new(include_font!("./libk/resources/font/cp850-8x16.psf"));
pub const FONT_CP850_8X16: Font =
Font::new(include_font!("../../../resources/font/cp850-8x16.psf"));
// pub struct Font(pub [[u8; 16]; 512]);
@@ -17,8 +15,8 @@ pub struct Font {
}
impl Font {
pub const fn new(data: [[u8; 16]; 512]) -> Font {
Font {
pub const fn new(data: [[u8; 16]; 512]) -> Self {
Self {
width: 8,
height: 16,
length: data.len() as u16,
@@ -41,8 +39,10 @@ impl Font {
pub const fn height(&self) -> usize {
self.height
}
}
pub const fn default() -> &'static Font {
&FONT_CP850_8X16
impl Default for Font {
fn default() -> Self {
FONT_CP850_8X16
}
}
@@ -1,4 +1,5 @@
use crate::prelude::*;
use alloc::string::String;
use alloc::vec::Vec;
pub mod frame;
pub mod render;
@@ -10,7 +11,7 @@ pub trait Application {
fn run(
&mut self,
args: Vec<String>,
) -> impl core::future::Future<Output = Result<Self::Output, Error>> + Send;
) -> impl Future<Output = Result<Self::Output, Error>> + Send;
}
#[derive(Debug)]
+48
View File
@@ -0,0 +1,48 @@
use super::{render::RenderError, window::Window};
use crate::arch::x86_64::drivers::framebuffer::colour::Colour;
use crate::std::maths::geometry::Vec2;
use alloc::{vec, vec::Vec};
pub struct Frame<'f> {
data: Vec<Vec<Colour>>,
window: &'f Window,
}
impl<'a> Frame<'a> {
pub fn new(window: &'a Window) -> Self {
Self {
data: vec![
vec![Colour::Black; window.dimensions().x()];
window.dimensions().y()
],
window,
}
}
pub fn render(&self) -> Result<(), RenderError> {
let data: Vec<&[Colour]> =
self.data.iter().map(|v| v.as_slice()).collect::<Vec<_>>();
self.window
.render(data.as_slice())
.map_err(|_| RenderError::Generic)
}
pub fn write_pixel(
&mut self,
x: usize,
y: usize,
color: Colour,
) -> Result<(), RenderError> {
if x >= self.window.dimensions().x()
|| y >= self.window.dimensions().y()
{
return Err(RenderError::Generic);
}
self.data[y][x] = color;
Ok(())
}
pub const fn dimensions(&self) -> Vec2<usize> {
self.window.dimensions()
}
}
@@ -1,7 +1,6 @@
use crate::arch::x86_64::drivers::framebuffer::colour::Colour;
use core::fmt::Display;
use crate::drivers::io::framebuffer::colour::Colour;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum RenderError {
Generic,
@@ -1,12 +1,8 @@
use limine::framebuffer;
use crate::{
drivers::io::framebuffer::{colour::Colour, display::FRAMEBUFFER_WRITER},
prelude::*,
std::maths::geometry::Vec2,
};
use super::render::RenderError;
use crate::arch::x86_64::drivers::framebuffer::colour::Colour;
use crate::arch::x86_64::drivers::framebuffer::display::FRAMEBUFFER_WRITER;
use crate::std::maths::geometry::Vec2;
use alloc::string::String;
pub struct Window {
dimensions: Vec2<usize>,
@@ -28,7 +24,8 @@ impl Window {
}
pub fn render(&self, _data: &[&[Colour]]) -> Result<(), RenderError> {
// TODO: error handling!! the kernel should return an error in some cases
// TODO: error handling!! the kernel should return an error in some
// cases
if let Some(fb) = FRAMEBUFFER_WRITER.lock().as_mut() {
fb.render_frame(_data);
}
@@ -1,9 +1,9 @@
use crate::{drivers::io::framebuffer::colour::Colour, resources::font::Font};
use super::{
application::{frame::Frame, render::RenderError},
maths::geometry::Vec2,
};
use crate::arch::x86_64::drivers::framebuffer::colour::Colour;
use crate::resources::font::Font;
pub struct Writer<'a> {
font: &'a Font,
@@ -46,7 +46,11 @@ impl<'a> Writer<'a> {
if line & (0x80 >> col) != 0 {
for i in 0..scale {
for j in 0..scale {
frame.write_pixel(pixel_x + i, pixel_y + j, Colour::White)?;
frame.write_pixel(
pixel_x + i,
pixel_y + j,
Colour::White,
)?;
}
}
}
+21
View File
@@ -0,0 +1,21 @@
use crate::prelude::{_print_log, _serial_write};
use core::fmt;
use x86_64::instructions::interrupts;
#[macro_export]
macro_rules! debugln {
() => ($crate::print_log!("\n"));
($($arg:tt)*) => ($crate::debug!("{}\n", format_args!($($arg)*)));
}
#[macro_export]
macro_rules! debug {
($($arg:tt)*) => ($crate::prelude::_debug(format_args!($($arg)*)));
}
pub fn _debug(args: fmt::Arguments) {
interrupts::without_interrupts(|| {
_print_log(args);
_serial_write(args);
});
}
+168
View File
@@ -0,0 +1,168 @@
//! Basic ELF parsing functionality using the `elf` crate.
//!
//! This may be extended in the future to support loading programs, however we
//! currently use this for getting the sizes of sections in our kernel ELF at
//! runtime.
//!
//! This is used for implementing stacktraces in std::unwind.
//!
//! # TODO
//!
//! * Add support for loading binary programs (this should probably be written
//! in a different module)
use alloc::{format, vec::Vec};
use elf::{
ElfBytes, ParseError,
endian::LittleEndian,
parse::{ParseAt, ParsingTable},
section::{SectionHeader, SectionHeaderTable},
string_table::StringTable,
symbol::{Symbol, SymbolTable},
};
use limine::request::KernelFileRequest;
use crate::prelude::*;
#[cfg(target_arch = "x86_64")]
/// The length of the ELF header in bytes.
pub const ELF_HEADER_LEN: usize = 64;
/// Information about our own ELF file to make ELF parsing easier, such as the
/// length of the file and a pointer to the contents.
#[used]
pub static KERNEL_FILE_REQUEST: KernelFileRequest = KernelFileRequest::new();
/// A list of errors that may occur when parsing ELF files.
#[derive(Debug)]
pub enum ElfError {
/// Returned if a section did not exist in [ElfReader::get_section_size].
SectionNotExists,
/// Returned if we failed to fetch the symbol table.
Symtab,
/// Parse errors returned by the `elf` crate.
OtherParseError(elf::ParseError),
}
impl From<elf::ParseError> for ElfError {
fn from(err: elf::ParseError) -> Self {
Self::OtherParseError(err)
}
}
pub struct ElfReader {
/// The underlying bytes for the ELF file.
pub bytes: &'static [u8],
/// Structure returned by the `elf` crate having parsed the ELF header.
pub elf: ElfBytes<'static, LittleEndian>,
/// A sorted list of symbols to binary search.
pub sorted_syms: Vec<Symbol>,
/// The string table for looking up symbol names.
pub symbol_strtab: StringTable<'static>,
}
impl ElfReader {
/// Parses the ELF file for the kernel, this uses data from Limine's Kernel
/// File Request to get a slice over the whole executable file.
///
/// # Safety
///
/// Assumes a properly formed ELF file, and that Limine returns a correct
/// pointer to the start of the file as well as a valid length in bytes.
///
/// Both of these should be satisfied, but this function is marked unsafe
/// just in case, because we are derefererencing arbitrary pointers.
pub unsafe fn new() -> Result<Self, ElfError> {
// Store this for use with other libraries.
let bytes = get_elf_slice();
let elf: ElfBytes<'static, LittleEndian> =
elf::ElfBytes::minimal_parse(bytes)?;
let Some((symtab, strtab)) = elf.symbol_table()? else {
return Err(ElfError::Symtab);
};
// Sort the symtab for later use and store the strtab.
let mut symbols = symtab.into_iter().collect::<Vec<Symbol>>();
symbols.sort_by_key(|sym| sym.st_value);
Ok(Self {
elf,
sorted_syms: symbols,
symbol_strtab: strtab,
bytes,
})
}
pub fn get_symbol_table(
&self,
) -> Result<
Option<(SymbolTable<'static, LittleEndian>, StringTable<'static>)>,
ElfError,
> {
Ok(self.elf.symbol_table()?)
}
/// Gets the section size of `section_name` in bytes.
pub fn get_section_size(
&self,
section_name: &'static str,
) -> Result<u64, ElfError> {
Ok(self.get_section_header(section_name)?.sh_size)
}
/// Gets the start address of the section `section_name` in memory.
pub fn get_section_addr(
&self,
section_name: &'static str,
) -> Result<*const u8, ElfError> {
Ok(self.get_section_header(section_name)?.sh_addr as *const u8)
}
/// Gets the section header of `section_name`.
pub fn get_section_header(
&self,
section_name: &str,
) -> Result<SectionHeader, ElfError> {
let section_hdr = self
.elf
.section_header_by_name(section_name)
.map_err(|_e| ElfError::SectionNotExists)?;
section_hdr.ok_or(ElfError::SectionNotExists)
}
pub fn search_symbol(&self, address: u64) -> Option<elf::symbol::Symbol> {
let entries = self.sorted_syms.iter().collect::<Vec<_>>();
let idx = entries
.as_slice()
.binary_search_by_key(&address, |sym| sym.st_value)
.ok()?;
Some(entries[idx].clone())
}
pub fn get_symbol_name(
&self,
sym: elf::symbol::Symbol,
) -> Option<&'static str> {
self.symbol_strtab.get(sym.st_name as usize).ok()
}
}
/// Gets a slice of the bytes of the kernel ELF file.
pub fn get_elf_slice() -> &'static [u8] {
let response = KERNEL_FILE_REQUEST
.get_response()
.expect("Didn't get the kernel file from Limine. That's odd.");
// We fetch these from Limine and use them to parse our own ELF file.
let file = response.file();
let file_start_ptr = file.addr();
let file_size = file.size() as usize;
// Safety: This slice should contain the whole bytes of the ELF file.
(unsafe { core::slice::from_raw_parts(file_start_ptr, file_size) }) as _
}
+6
View File
@@ -0,0 +1,6 @@
pub use crate::arch::x86_64::drivers::{
ascii::{_print, _print_err, _print_log},
serial::_serial_write,
};
pub mod stdin;
+75
View File
@@ -0,0 +1,75 @@
use crate::arch::x86_64::drivers::{
ascii::WRITER,
keyboard::{KeyStroke, get_keystroke_async, get_keystroke_optional},
};
use alloc::string::String;
/// Reads a line of input from standard input asynchronously, returning a
/// `String` containing the input line. Does not include the newline
/// character at the end of the line.
///
/// If the user presses the abort key (usually Ctrl+C), the returned string
/// will be empty.
pub async fn read_line() -> String {
let mut writer = WRITER.lock();
let mut buff = String::new();
loop {
match get_keystroke_async().await {
KeyStroke::Char(c) => match c {
'\n' => {
writer.write_glyph(c as u8);
return buff;
}
'\r' => {
writer.write_glyph(c as u8);
return buff;
}
'\x08' => {
if !buff.is_empty() {
buff.pop();
writer.backspace();
}
}
c => {
writer.write_glyph(c as u8);
buff.push(c)
}
},
KeyStroke::Enter => {
writer.write_glyph(b'\n');
return buff;
}
KeyStroke::Backspace => {
if !buff.is_empty() {
buff.pop();
writer.backspace();
}
}
_ => continue,
}
}
}
/// Reads a character from standard input and blocks the current task until
/// a character is available.
///
/// # Note
///
/// This function is not yet implemented.
pub async fn async_keystroke() -> KeyStroke {
get_keystroke_async().await
}
/// Attempt to read a character from standard input without blocking the
/// current task.
///
/// If no character is available, returns `None`.
///
/// # Note
///
/// This function is not yet implemented.
pub fn keystroke() -> Option<KeyStroke> {
get_keystroke_optional()
}
@@ -42,6 +42,14 @@ impl<T: Coordinate> Vec2<T> {
pub const fn y(&self) -> T {
self.y
}
pub const fn set_x(&mut self, x: T) {
self.x = x;
}
pub const fn set_y(&mut self, y: T) {
self.y = y;
}
}
impl<T: Coordinate> AddAssign for Vec2<T> {
@@ -1,4 +1,5 @@
pub mod application;
pub mod ascii;
pub mod debug;
pub mod io;
pub mod maths;
+104
View File
@@ -0,0 +1,104 @@
/* //! Defines the [Step] struct which may be used when initialising the system.
//!
//! # Warning
//!
//! Use of alloc is currently required, so early initialisation will need a
//! different method. We should possibly abstract some functionality so that
//! consumers don't need to worry or care about the difference.
use alloc::{borrow::ToOwned, boxed::Box, string::String, vec::Vec};
use crate::{arch::x86_64::drivers::ascii::WRITER, prelude::*};
/// Represents a [Step] when initialising the system.
///
/// Handles printing various information to the framebuffer using steps.
///
/// # Example
///
/// ```rs
/// // Setup a Step for Foo.
/// let foo_step: Step<Foo, FooError> = Step::new("foo", Foo::init()).register_tag(|foo| { foo.bar().to_string() });
/// // This returns a Result<T, E>
/// let foo = foo_step.run()?;
/// ```
///
/// # TODOs
///
/// * If T = Option<T> and None is returned, we print `"[Not found]"`, otherwise
/// `"[Success]`".
pub struct Step<T: Clone + ToOwned> {
/// The initialisation function for the Step, usually this is a closure.
init_fn: fn() -> T,
/// A list of tag generator functions to display under the Step on success.
/// They are displayed like:
/// ```
/// Initialising module... [Success]
/// => Some information here.
/// ```
///
/// # TODOs
///
/// * Support tags without alloc being initialised.
tags: Vec<Box<dyn Fn(T) -> String>>,
/// The name of the module being initialised.
task: &'static str,
}
// This impl block might be so horrible it needs its own file.
impl<T: ToOwned + Clone> Step<T> {
pub fn new(
task: &'static str,
init_fn: fn() -> T,
tags: Vec<Box<dyn Fn(T) -> String>>,
) -> Self {
Self {
init_fn,
tags,
task,
}
}
/// Runs the initialisation function and logs where required.
///
/// This function is a little messy but it just handles pretty printing the
/// [Step] to the terminal for us.
pub fn run(self) -> T {
print_log!(" {}", self.task);
let mut success_position = WRITER.lock().pos();
success_position.set_x(success_position.x() + 1);
let ret = (self.init_fn)();
println!();
for tag in &self.tags[..] {
// Calls the closure on the return value.
println_log!(" => {}", (tag)(ret.clone()));
}
// Print whether or not the step succeeded.
print_oneshot!(
success_position,
Colour::Green,
Colour::Black,
"[Success]"
);
ret
}
/// Registers a 'tag' or note to display under the line which says
/// `Initialising module... [Success]`.
///
/// # Notes
///
/// The tag is a closure taking in a reference to T and returning a
/// presumably formatted String.
#[allow(unused)]
pub fn register_tag(&mut self, tag: Box<dyn Fn(T) -> String>) -> &Self {
self.tags.push(tag);
self
}
}
*/
@@ -1,13 +1,14 @@
use crate::drivers::io::keyboard::{KeyStroke, get_keystroke_async};
use crate::prelude::*;
use crate::resources::font::{FONT_CP850_8X16, FONT_SPLEEN_8X16, Font};
use crate::std::application::frame::Frame;
use crate::std::application::render::RenderError;
use crate::std::application::window::Window;
use crate::std::application::{Application, Error};
use crate::arch::x86_64::drivers::keyboard::{KeyStroke, get_keystroke_async};
use crate::resources::font::Font;
use crate::serial_print;
use crate::serial_println;
use crate::std::application::{
Application, Error, frame::Frame, render::RenderError, window::Window,
};
use crate::std::ascii::Writer;
use crate::std::maths::geometry::Vec2;
use alloc::string::ToString;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
pub struct Editor {
cursor_line: usize,
@@ -40,7 +41,8 @@ impl<'a> Editor {
fn render(&'a self) -> Result<Frame<'a>, RenderError> {
let mut frame = Frame::new(&self.window);
let writer = Writer::new(Font::default());
let font = Font::default();
let writer = Writer::new(&font);
let (width, height) = writer.font_size().into();
@@ -63,14 +65,18 @@ impl<'a> Editor {
writer.render_glyph(
&mut frame,
Vec2::new(col * width + Self::PADDING, line * height + Self::PADDING),
Vec2::new(
col * width + Self::PADDING,
line * height + Self::PADDING,
),
ch as u8,
scale,
)?;
col += scale;
}
writer.render_glyph(
writer
.render_glyph(
&mut frame,
Vec2::new(
self.cursor_col * width + Self::PADDING,
@@ -78,7 +84,8 @@ impl<'a> Editor {
),
b'_',
scale,
);
)
.expect("TODO: panic message");
Ok(frame)
}
@@ -120,7 +127,8 @@ impl<'a> Editor {
fn get_char_idx(&self) -> usize {
let frame = Frame::new(&self.window);
let writer = Writer::new(Font::default());
let font = Font::default();
let writer = Writer::new(&font);
let (width, _height) = writer.font_size().into();
let mut col = 0;
@@ -153,7 +161,10 @@ impl<'a> Editor {
impl Application for Editor {
type Output = ();
async fn run(&mut self, _args: Vec<alloc::string::String>) -> Result<Self::Output, Error> {
async fn run(
&mut self,
_args: Vec<alloc::string::String>,
) -> Result<Self::Output, Error> {
self.window.set_dimensions(Vec2::new(1280, 800));
self.window.set_position(Vec2::new(0, 0));
self.window.open();
@@ -163,7 +174,9 @@ impl Application for Editor {
loop {
if let Err(_err) = self.render().and_then(|frame| frame.render()) {
// TODO: Handle error
return Err(Error::ApplicationFailed("Rendering failed".to_string()));
return Err(Error::ApplicationFailed(
"Rendering failed".to_string(),
));
}
let keystroke = get_keystroke_async().await;
@@ -1,12 +1,12 @@
// use x86_64::registers::rflags::read;
use crate::arch::x86_64::drivers::ascii::clear_screen;
use crate::prelude::*;
use crate::std::application::Application;
use crate::std::io::stdin::read_line;
use crate::util::editor::Editor;
use alloc::vec::Vec;
use crate::{
drivers::io::ascii::clear_screen, prelude::stdin::read_line, print, println,
std::application::Application, util::editor::Editor,
};
static FETCH: &str = "
$$$$$$$$\\ $$\\
$$ _____| $$ |
-22
View File
@@ -1,22 +0,0 @@
[package]
name = "libk"
publish = ["gitea"]
version.workspace = true
edition.workspace = true
authors.workspace = true
description = "A library crate used to write the kernel for Foundry OS."
[dependencies]
limine = "0.3.1"
x86_64 = "0.15.2"
crossbeam = { version = "0.8.4", default-features = false, features = [
"alloc",
"crossbeam-queue",
] }
pc-keyboard = "0.8.0"
spin = "0.9.8"
futures-util = { version = "0.3.31", default-features = false, features = [
"alloc",
] }
linked_list_allocator = { version = "0.10.5", features = ["use_spin"] }
libm = { path = "../libm" }
-24
View File
@@ -1,24 +0,0 @@
# libk is for the code that did not make the kernel*
\*crate, lol.
libk is an attempt to move away from the godforsaken git submodules that plagued our forefathers. Now we have a crate containing a bunch of code that didn't quite make the core kernel crate, which should be:
* simpler to maintain
* has a catchier name
* less fighting with Cargo.toml manifests
## TODO:
A lot of things must be improved and worked on, feel free to add extra TODOs below.
- [] Create a kernel logging abstraction similar to Linux. (this should probably just use the serial drivers)
The rationale behind this is that we want some sort of debug log/tracing support so we aren't just printf debugging forever.
## Authors
Again, write your name below if you like:
* @zxq5 (wrote most of the libraries as of 23/02/25)
* @nullndvoid (made this lushious library crate)
-17
View File
@@ -1,17 +0,0 @@
pub mod ascii;
pub mod framebuffer;
pub mod keyboard;
pub mod port;
pub mod serial;
// Re-exported macro definitions.
pub use crate::print;
pub use crate::print_log;
pub use crate::printerr;
pub use crate::println;
pub use crate::println_log;
pub use crate::printlnerr;
pub use crate::serial_print;
pub use crate::serial_println;
-42
View File
@@ -1,42 +0,0 @@
use linked_list_allocator::LockedHeap;
use spin::{Mutex, MutexGuard};
use x86_64::structures::paging::{
mapper::MapToError,
Size4KiB,
};
use crate::drivers::kalloc::foundry_kalloc::FoundryAllocator;
/// We are currently using a linked list heap allocator which uses our underlying page allocator.
#[global_allocator]
/// This is now Rust's global allocator, so we can use stuff requiring heap allocations.
static ALLOCATOR: Locked<FoundryAllocator> = Locked::new(FoundryAllocator::new());
pub const HEAP_START: usize = 0x4444_4444_0000;
pub const HEAP_SIZE: usize = 1024 * 1024 * 1024;
/// Sets up the heap using the backing page frame allocator.
pub fn init_heap() -> Result<(), MapToError<Size4KiB>> {
// code to allocate frames is now done in the page fault interrupt handler!
unsafe {
ALLOCATOR.lock().init(HEAP_START, HEAP_SIZE);
}
Ok(())
}
pub struct Locked<T> {
inner: Mutex<T>,
}
impl<T> Locked<T> {
pub const fn new(inner: T) -> Self {
Locked {
inner: Mutex::new(inner)
}
}
pub fn lock(&self) -> MutexGuard<T> {
self.inner.lock()
}
}
-2
View File
@@ -1,2 +0,0 @@
pub mod allocator;
mod foundry_kalloc;
-149
View File
@@ -1,149 +0,0 @@
// use lib_alloc::allocator::FoundryAllocator;
use limine::{memory_map::EntryType, response::MemoryMapResponse};
use spin::{Mutex, Once};
use x86_64::{
registers::control::Cr3, structures::paging::{
FrameAllocator, OffsetPageTable, PageTable, PhysFrame, Size4KiB
,
},
PhysAddr,
VirtAddr,
};
pub static FRAME_ALLOCATOR: Once<Mutex<FoundryOSFrameAllocator>> = Once::new();
pub static OFFSET_PAGE_TABLE: Once<Mutex<OffsetPageTable>> = Once::new();
/// Returns a mutable reference to the current level 4 page table.
///
/// # Safety
///
/// The caller must ensure that the level 4 page table is not modified
/// simultaneously. The caller must also ensure that the physical memory offset
/// is correct, to ensure that the correct virtual address is constructed.
unsafe fn active_l4_table(physical_memory_offset: VirtAddr) -> &'static mut PageTable {
let (level_4_frame, _) = Cr3::read();
let phys_addr = level_4_frame.start_address();
let virt = phys_addr.as_u64() + physical_memory_offset.as_u64();
unsafe { &mut *(virt as *mut PageTable) }
}
/// Initializes the `OffsetPageTable` for the current CPU architecture.
///
/// # Safety
///
/// This function must be called only once and should be called before any
/// memory operations are performed that rely on virtual memory management.
/// The provided `physical_memory_offset` must be accurate to ensure correct
/// translation of physical addresses.
///
/// # Parameters
///
/// - `physical_memory_offset`: The offset to convert physical addresses to
/// virtual addresses in the higher-half direct map.
///
/// # Returns
///
/// Returns an `OffsetPageTable` that allows for manipulation of the page
/// tables for the current CPU architecture.
pub fn init_page_table(physical_memory_offset: VirtAddr) {
unsafe {
let l4_table = active_l4_table(physical_memory_offset);
let offset_table = OffsetPageTable::new(l4_table, physical_memory_offset);
OFFSET_PAGE_TABLE.call_once(|| Mutex::new(offset_table));
}
}
pub struct FoundryOSFrameAllocator {
memory_map: &'static MemoryMapResponse,
next: usize,
}
pub fn init_frame_allocator(memory_map: &'static MemoryMapResponse) {
unsafe {
FRAME_ALLOCATOR.call_once(|| Mutex::new(FoundryOSFrameAllocator::init(memory_map)));
}
}
impl FoundryOSFrameAllocator {
/// Creates a new `FoundryOSFrameAllocator` from a memory map.
///
/// This function takes a reference to a `MemoryMapResponse` and initializes a
/// `FoundryOSFrameAllocator` with it. The `next` field is set to 0, indicating that
/// the first frame to be allocated is the first frame in the memory map.
pub const unsafe fn init(memory_map: &'static MemoryMapResponse) -> Self {
Self {
memory_map,
next: 0,
}
}
pub fn count_usable_frames(&self) -> u32 {
self.usable_frames().count() as u32
}
/// An iterator over all usable frames in the memory map.
///
/// Yields one `PhysFrame` for each available 4KiB frame in the memory map.
///
/// This function is used to allocate frames for the pagemap.
fn usable_frames(&self) -> impl Iterator<Item = PhysFrame> + use<> {
let regions = self.memory_map.entries().iter();
let usable_regions = regions.filter(|region| region.entry_type == EntryType::USABLE);
let addr_ranges = usable_regions.map(|region| region.base..region.base + region.length);
let frame_addresses = addr_ranges.flat_map(|r| r.step_by(4096));
frame_addresses.map(|addr| PhysFrame::from_start_address(PhysAddr::new(addr)).unwrap())
}
}
unsafe impl FrameAllocator<Size4KiB> for FoundryOSFrameAllocator {
/// Allocates a frame from the list of usable frames.
///
/// This function returns the next available `PhysFrame` from the memory map,
/// if one exists. Once a frame is allocated, the internal counter is incremented
/// to point to the next frame for future allocations.
///
/// # Returns
///
/// - `Some(PhysFrame)`: If a usable frame is available.
/// - `None`: If there are no more usable frames to allocate.
fn allocate_frame(&mut self) -> Option<PhysFrame> {
let frame = self.usable_frames().nth(self.next);
self.next += 1;
frame
}
}
// pub unsafe fn translate_addr(addr: VirtAddr, physical_memory_offset: VirtAddr) -> Option<PhysAddr> {
// translate_addr_inner(addr, physical_memory_offset)
// }
// fn translate_addr_inner(addr: VirtAddr, physical_memory_offset: VirtAddr) -> Option<PhysAddr> {
// let (l4_table_frame, _) = Cr3::read();
// let table_indexes = [
// addr.p4_index(),
// addr.p3_index(),
// addr.p2_index(),
// addr.p1_index(),
// ];
// let mut frame = l4_table_frame;
// for &i in &table_indexes {
// let virt = physical_memory_offset + frame.start_address().as_u64();
// let table_ptr: *const PageTable = virt.as_ptr();
// let table = unsafe { &*table_ptr };
// let entry = &table[i];
// frame = match entry.frame() {
// Ok(frame) => frame,
// Err(FrameError::FrameNotPresent) => return None,
// Err(FrameError::HugeFrame) => panic!("huge frames are not supported!"),
// };
// }
// Some(frame.start_address() + u64::from(addr.page_offset()))
// }
-6
View File
@@ -1,6 +0,0 @@
pub mod io;
pub mod kalloc;
pub mod async_io;
pub mod memory;
pub mod pic;
-38
View File
@@ -1,38 +0,0 @@
#![no_std]
#![warn(
clippy::correctness,
clippy::nursery,
clippy::unnecessary_cast,
clippy::all,
clippy::suspicious,
clippy::perf,
rustdoc::missing_errors_doc,
rustdoc::missing_panics_doc,
tail_expr_drop_order
)]
extern crate alloc;
pub mod drivers;
pub mod resources;
pub mod threads;
pub mod util;
#[allow(unused)] // We aren't using much of this right now.
pub mod std;
/// Re-exports most of the IO macros as well as standard allocation stuff
#[allow(unused)]
pub mod prelude {
pub use crate::std::io::*;
pub use alloc::{
boxed::Box,
string::{String, ToString},
vec::Vec,
};
}
pub use crate::drivers::io::{
ascii::{_print, _print_log},
serial::_serial_write,
};
-578
View File
@@ -1,578 +0,0 @@
pub static FONT: [u8; 288 * 16] = [
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 0
0x00, 0x00, 0x3f, 0x33, 0x3f, 0x30, 0x30, 0x30, 0x30, 0x70, 0xf0, 0xe0, 0x00, 0x00, 0x00,
0x00, // 1
0x00, 0x00, 0x7e, 0x81, 0xa5, 0x81, 0x81, 0xbd, 0x99, 0x81, 0x81, 0x7e, 0x00, 0x00, 0x00,
0x00, // 2
0x00, 0x00, 0x7e, 0xff, 0xdb, 0xff, 0xff, 0xc3, 0xe7, 0xff, 0xff, 0x7e, 0x00, 0x00, 0x00,
0x00, // 3
0x00, 0x00, 0x00, 0x00, 0x6c, 0xfe, 0xfe, 0xfe, 0xfe, 0x7c, 0x38, 0x10, 0x00, 0x00, 0x00,
0x00, // 4
0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x7c, 0xfe, 0x7c, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00,
0x00, // 5
0x00, 0x00, 0x00, 0x18, 0x3c, 0x3c, 0xe7, 0xe7, 0xe7, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00,
0x00, // 6
0x00, 0x00, 0x00, 0x18, 0x3c, 0x7e, 0xff, 0xff, 0x7e, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00,
0x00, // 7
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 8
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe7, 0xc3, 0xc3, 0xe7, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, // 9
0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, 0x42, 0x42, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x00,
0x00, // 10
0xff, 0xff, 0xff, 0xff, 0xff, 0xc3, 0x99, 0xbd, 0xbd, 0x99, 0xc3, 0xff, 0xff, 0xff, 0xff,
0xff, // 11
0x00, 0x00, 0x1e, 0x0e, 0x1a, 0x32, 0x78, 0xcc, 0xcc, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0x00,
0x00, // 12
0x00, 0x00, 0x3c, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x7e, 0x18, 0x18, 0x00, 0x00, 0x00,
0x00, // 13
0x00, 0x00, 0x7f, 0x63, 0x7f, 0x63, 0x63, 0x63, 0x63, 0x67, 0xe7, 0xe6, 0xc0, 0x00, 0x00,
0x00, // 14
0x00, 0x00, 0x00, 0x18, 0x18, 0xdb, 0x3c, 0xe7, 0x3c, 0xdb, 0x18, 0x18, 0x00, 0x00, 0x00,
0x00, // 15
0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfe, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00, 0x00, 0x00,
0x00, // 16
0x00, 0x02, 0x06, 0x0e, 0x1e, 0x3e, 0xfe, 0x3e, 0x1e, 0x0e, 0x06, 0x02, 0x00, 0x00, 0x00,
0x00, // 17
0x00, 0x00, 0x18, 0x3c, 0x7e, 0x18, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00,
0x00, // 18
0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x66, 0x00, 0x00, 0x00,
0x00, // 19
0x00, 0x00, 0x7f, 0xdb, 0xdb, 0xdb, 0x7b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x00, 0x00, 0x00,
0x00, // 20
0x00, 0x7c, 0xc6, 0x60, 0x38, 0x6c, 0xc6, 0xc6, 0x6c, 0x38, 0x0c, 0xc6, 0x7c, 0x00, 0x00,
0x00, // 21
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xfe, 0xfe, 0xfe, 0x00, 0x00, 0x00,
0x00, // 22
0x00, 0x00, 0x18, 0x3c, 0x7e, 0x18, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x7e, 0x00, 0x00, 0x00,
0x00, // 23
0x00, 0x00, 0x18, 0x3c, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00,
0x00, // 24
0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x00, 0x00, 0x00,
0x00, // 25
0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x0c, 0xfe, 0x0c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 26
0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x60, 0xfe, 0x60, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 27
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 28
0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x6c, 0xfe, 0x6c, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 29
0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x38, 0x7c, 0x7c, 0xfe, 0xfe, 0x00, 0x00, 0x00, 0x00,
0x00, // 30
0x00, 0x00, 0x00, 0x00, 0xfe, 0xfe, 0x7c, 0x7c, 0x38, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00,
0x00, // 31
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 32
0x00, 0x00, 0x18, 0x3c, 0x3c, 0x3c, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00,
0x00, // 33
0x00, 0x66, 0x66, 0x66, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 34
0x00, 0x00, 0x00, 0x6c, 0x6c, 0xfe, 0x6c, 0x6c, 0x6c, 0xfe, 0x6c, 0x6c, 0x00, 0x00, 0x00,
0x00, // 35
0x18, 0x18, 0x7c, 0xc6, 0xc2, 0xc0, 0x7c, 0x06, 0x06, 0x86, 0xc6, 0x7c, 0x18, 0x18, 0x00,
0x00, // 36
0x00, 0x00, 0x00, 0x00, 0xc2, 0xc6, 0x0c, 0x18, 0x30, 0x60, 0xc6, 0x86, 0x00, 0x00, 0x00,
0x00, // 37
0x00, 0x00, 0x38, 0x6c, 0x6c, 0x38, 0x76, 0xdc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00,
0x00, // 38
0x00, 0x30, 0x30, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 39
0x00, 0x00, 0x0c, 0x18, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x18, 0x0c, 0x00, 0x00, 0x00,
0x00, // 40
0x00, 0x00, 0x30, 0x18, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x18, 0x30, 0x00, 0x00, 0x00,
0x00, // 41
0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x3c, 0xff, 0x3c, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 42
0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 43
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x30, 0x00, 0x00,
0x00, // 44
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 45
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00,
0x00, // 46
0x00, 0x00, 0x00, 0x00, 0x02, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0x80, 0x00, 0x00, 0x00,
0x00, // 47
0x00, 0x00, 0x38, 0x6c, 0xc6, 0xc6, 0xd6, 0xd6, 0xc6, 0xc6, 0x6c, 0x38, 0x00, 0x00, 0x00,
0x00, // 48
0x00, 0x00, 0x18, 0x38, 0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x00, 0x00, 0x00,
0x00, // 49
0x00, 0x00, 0x7c, 0xc6, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0xc6, 0xfe, 0x00, 0x00, 0x00,
0x00, // 50
0x00, 0x00, 0x7c, 0xc6, 0x06, 0x06, 0x3c, 0x06, 0x06, 0x06, 0xc6, 0x7c, 0x00, 0x00, 0x00,
0x00, // 51
0x00, 0x00, 0x0c, 0x1c, 0x3c, 0x6c, 0xcc, 0xfe, 0x0c, 0x0c, 0x0c, 0x1e, 0x00, 0x00, 0x00,
0x00, // 52
0x00, 0x00, 0xfe, 0xc0, 0xc0, 0xc0, 0xfc, 0x06, 0x06, 0x06, 0xc6, 0x7c, 0x00, 0x00, 0x00,
0x00, // 53
0x00, 0x00, 0x38, 0x60, 0xc0, 0xc0, 0xfc, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00,
0x00, // 54
0x00, 0x00, 0xfe, 0xc6, 0x06, 0x06, 0x0c, 0x18, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00,
0x00, // 55
0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00,
0x00, // 56
0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0x7e, 0x06, 0x06, 0x06, 0x0c, 0x78, 0x00, 0x00, 0x00,
0x00, // 57
0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00,
0x00, // 58
0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00,
0x00, // 59
0x00, 0x00, 0x00, 0x06, 0x0c, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x00, 0x00, 0x00,
0x00, // 60
0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 61
0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x0c, 0x18, 0x30, 0x60, 0x00, 0x00, 0x00,
0x00, // 62
0x00, 0x00, 0x7c, 0xc6, 0xc6, 0x0c, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00,
0x00, // 63
0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xde, 0xde, 0xde, 0xdc, 0xc0, 0x7c, 0x00, 0x00, 0x00,
0x00, // 64
0x00, 0x00, 0x10, 0x38, 0x6c, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00,
0x00, // 65
0x00, 0x00, 0xfc, 0x66, 0x66, 0x66, 0x7c, 0x66, 0x66, 0x66, 0x66, 0xfc, 0x00, 0x00, 0x00,
0x00, // 66
0x00, 0x00, 0x3c, 0x66, 0xc2, 0xc0, 0xc0, 0xc0, 0xc0, 0xc2, 0x66, 0x3c, 0x00, 0x00, 0x00,
0x00, // 67
0x00, 0x00, 0xf8, 0x6c, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x6c, 0xf8, 0x00, 0x00, 0x00,
0x00, // 68
0x00, 0x00, 0xfe, 0x66, 0x62, 0x68, 0x78, 0x68, 0x60, 0x62, 0x66, 0xfe, 0x00, 0x00, 0x00,
0x00, // 69
0x00, 0x00, 0xfe, 0x66, 0x62, 0x68, 0x78, 0x68, 0x60, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00,
0x00, // 70
0x00, 0x00, 0x3c, 0x66, 0xc2, 0xc0, 0xc0, 0xde, 0xc6, 0xc6, 0x66, 0x3a, 0x00, 0x00, 0x00,
0x00, // 71
0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00,
0x00, // 72
0x00, 0x00, 0x3c, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00,
0x00, // 73
0x00, 0x00, 0x1e, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0xcc, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0x00,
0x00, // 74
0x00, 0x00, 0xe6, 0x66, 0x66, 0x6c, 0x78, 0x78, 0x6c, 0x66, 0x66, 0xe6, 0x00, 0x00, 0x00,
0x00, // 75
0x00, 0x00, 0xf0, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x62, 0x66, 0xfe, 0x00, 0x00, 0x00,
0x00, // 76
0x00, 0x00, 0xc6, 0xee, 0xfe, 0xfe, 0xd6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00,
0x00, // 77
0x00, 0x00, 0xc6, 0xe6, 0xf6, 0xfe, 0xde, 0xce, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00,
0x00, // 78
0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00,
0x00, // 79
0x00, 0x00, 0xfc, 0x66, 0x66, 0x66, 0x7c, 0x60, 0x60, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00,
0x00, // 80
0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xd6, 0xde, 0x7c, 0x0c, 0x0e, 0x00,
0x00, // 81
0x00, 0x00, 0xfc, 0x66, 0x66, 0x66, 0x7c, 0x6c, 0x66, 0x66, 0x66, 0xe6, 0x00, 0x00, 0x00,
0x00, // 82
0x00, 0x00, 0x7c, 0xc6, 0xc6, 0x60, 0x38, 0x0c, 0x06, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00,
0x00, // 83
0x00, 0x00, 0x7e, 0x7e, 0x5a, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00,
0x00, // 84
0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00,
0x00, // 85
0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x6c, 0x38, 0x10, 0x00, 0x00, 0x00,
0x00, // 86
0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xd6, 0xd6, 0xd6, 0xfe, 0xee, 0x6c, 0x00, 0x00, 0x00,
0x00, // 87
0x00, 0x00, 0xc6, 0xc6, 0x6c, 0x7c, 0x38, 0x38, 0x7c, 0x6c, 0xc6, 0xc6, 0x00, 0x00, 0x00,
0x00, // 88
0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00,
0x00, // 89
0x00, 0x00, 0xfe, 0xc6, 0x86, 0x0c, 0x18, 0x30, 0x60, 0xc2, 0xc6, 0xfe, 0x00, 0x00, 0x00,
0x00, // 90
0x00, 0x00, 0x3c, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3c, 0x00, 0x00, 0x00,
0x00, // 91
0x00, 0x00, 0x00, 0x80, 0xc0, 0xe0, 0x70, 0x38, 0x1c, 0x0e, 0x06, 0x02, 0x00, 0x00, 0x00,
0x00, // 92
0x00, 0x00, 0x3c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x3c, 0x00, 0x00, 0x00,
0x00, // 93
0x10, 0x38, 0x6c, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 94
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00,
0x00, // 95
0x30, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 96
0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00,
0x00, // 97
0x00, 0x00, 0xe0, 0x60, 0x60, 0x78, 0x6c, 0x66, 0x66, 0x66, 0x66, 0x7c, 0x00, 0x00, 0x00,
0x00, // 98
0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc0, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00,
0x00, // 99
0x00, 0x00, 0x1c, 0x0c, 0x0c, 0x3c, 0x6c, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00,
0x00, // 100
0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00,
0x00, // 101
0x00, 0x00, 0x38, 0x6c, 0x64, 0x60, 0xf0, 0x60, 0x60, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00,
0x00, // 102
0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x7c, 0x0c, 0xcc, 0x78,
0x00, // 103
0x00, 0x00, 0xe0, 0x60, 0x60, 0x6c, 0x76, 0x66, 0x66, 0x66, 0x66, 0xe6, 0x00, 0x00, 0x00,
0x00, // 104
0x00, 0x00, 0x18, 0x18, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00,
0x00, // 105
0x00, 0x00, 0x06, 0x06, 0x00, 0x0e, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x66, 0x66, 0x3c,
0x00, // 106
0x00, 0x00, 0xe0, 0x60, 0x60, 0x66, 0x6c, 0x78, 0x78, 0x6c, 0x66, 0xe6, 0x00, 0x00, 0x00,
0x00, // 107
0x00, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00,
0x00, // 108
0x00, 0x00, 0x00, 0x00, 0x00, 0xec, 0xfe, 0xd6, 0xd6, 0xd6, 0xd6, 0xc6, 0x00, 0x00, 0x00,
0x00, // 109
0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00,
0x00, // 110
0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00,
0x00, // 111
0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7c, 0x60, 0x60, 0xf0,
0x00, // 112
0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x7c, 0x0c, 0x0c, 0x1e,
0x00, // 113
0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x76, 0x66, 0x60, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00,
0x00, // 114
0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0x60, 0x38, 0x0c, 0xc6, 0x7c, 0x00, 0x00, 0x00,
0x00, // 115
0x00, 0x00, 0x10, 0x30, 0x30, 0xfc, 0x30, 0x30, 0x30, 0x30, 0x36, 0x1c, 0x00, 0x00, 0x00,
0x00, // 116
0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00,
0x00, // 117
0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x00, 0x00, 0x00,
0x00, // 118
0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xd6, 0xd6, 0xd6, 0xfe, 0x6c, 0x00, 0x00, 0x00,
0x00, // 119
0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x6c, 0x38, 0x38, 0x38, 0x6c, 0xc6, 0x00, 0x00, 0x00,
0x00, // 120
0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7e, 0x06, 0x0c, 0xf8,
0x00, // 121
0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xcc, 0x18, 0x30, 0x60, 0xc6, 0xfe, 0x00, 0x00, 0x00,
0x00, // 122
0x00, 0x00, 0x0e, 0x18, 0x18, 0x18, 0x70, 0x18, 0x18, 0x18, 0x18, 0x0e, 0x00, 0x00, 0x00,
0x00, // 123
0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00,
0x00, // 124
0x00, 0x00, 0x70, 0x18, 0x18, 0x18, 0x0e, 0x18, 0x18, 0x18, 0x18, 0x70, 0x00, 0x00, 0x00,
0x00, // 125
0x00, 0x00, 0x76, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 126
0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c, 0xc6, 0xc6, 0xc6, 0xfe, 0x00, 0x00, 0x00, 0x00,
0x00, // 127
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 128
0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x3c, 0x3c, 0x3c, 0x18, 0x00, 0x00, 0x00,
0x00, // 129
0x00, 0x18, 0x18, 0x3c, 0x66, 0x60, 0x60, 0x60, 0x66, 0x3c, 0x18, 0x18, 0x00, 0x00, 0x00,
0x00, // 130
0x00, 0x38, 0x6c, 0x64, 0x60, 0xf0, 0x60, 0x60, 0x60, 0x60, 0xe6, 0xfc, 0x00, 0x00, 0x00,
0x00, // 131
0x00, 0x00, 0x66, 0x66, 0x3c, 0x18, 0x7e, 0x18, 0x7e, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00,
0x00, // 132
0x00, 0x7c, 0xc6, 0x60, 0x38, 0x6c, 0xc6, 0xc6, 0x6c, 0x38, 0x0c, 0xc6, 0x7c, 0x00, 0x00,
0x00, // 133
0x00, 0x3c, 0x6c, 0x6c, 0x3e, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 134
0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x6c, 0xd8, 0x6c, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 135
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x06, 0x06, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00,
0x00, // 136
0x00, 0x38, 0x6c, 0x6c, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 137
0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00,
0x00, // 138
0x00, 0x70, 0xd8, 0x30, 0x60, 0xc8, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 139
0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7c, 0x60, 0x60, 0xc0, 0x00, 0x00,
0x00, // 140
0x00, 0x00, 0x7f, 0xdb, 0xdb, 0xdb, 0x7b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x00, 0x00, 0x00,
0x00, // 141
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 142
0x00, 0x38, 0x6c, 0x6c, 0x38, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 143
0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x6c, 0x36, 0x6c, 0xd8, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 144
0x00, 0xc0, 0xc0, 0xc2, 0xc6, 0xcc, 0x18, 0x30, 0x66, 0xce, 0x9e, 0x3e, 0x06, 0x06, 0x00,
0x00, // 145
0x00, 0xc0, 0xc0, 0xc2, 0xc6, 0xcc, 0x18, 0x30, 0x60, 0xdc, 0x86, 0x0c, 0x18, 0x3e, 0x00,
0x00, // 146
0x00, 0x00, 0x30, 0x30, 0x00, 0x30, 0x30, 0x60, 0xc0, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00,
0x00, // 147
0x00, 0xc6, 0x00, 0x10, 0x38, 0x6c, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00,
0x00, // 148
0x38, 0x6c, 0x38, 0x00, 0x38, 0x6c, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00,
0x00, // 149
0x00, 0x00, 0x3e, 0x6c, 0xcc, 0xcc, 0xfe, 0xcc, 0xcc, 0xcc, 0xcc, 0xce, 0x00, 0x00, 0x00,
0x00, // 150
0x00, 0x00, 0x3c, 0x66, 0xc2, 0xc0, 0xc0, 0xc0, 0xc2, 0x66, 0x3c, 0x0c, 0x06, 0x7c, 0x00,
0x00, // 151
0x18, 0x30, 0x60, 0x00, 0xfe, 0x66, 0x60, 0x7c, 0x60, 0x60, 0x66, 0xfe, 0x00, 0x00, 0x00,
0x00, // 152
0x76, 0xdc, 0x00, 0xc6, 0xe6, 0xf6, 0xfe, 0xde, 0xce, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00,
0x00, // 153
0x00, 0xc6, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00,
0x00, // 154
0x00, 0xc6, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00,
0x00, // 155
0x00, 0x00, 0x78, 0xcc, 0xcc, 0xcc, 0xd8, 0xcc, 0xc6, 0xc6, 0xc6, 0xcc, 0x00, 0x00, 0x00,
0x00, // 156
0x00, 0x60, 0x30, 0x18, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00,
0x00, // 157
0x00, 0x18, 0x30, 0x60, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00,
0x00, // 158
0x00, 0x10, 0x38, 0x6c, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00,
0x00, // 159
0x00, 0x00, 0xcc, 0x00, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00,
0x00, // 160
0x00, 0x38, 0x6c, 0x38, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00,
0x00, // 161
0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0x76, 0x36, 0x7e, 0xd8, 0xd8, 0x6e, 0x00, 0x00, 0x00,
0x00, // 162
0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, 0x60, 0x60, 0x66, 0x3c, 0x0c, 0x06, 0x3c, 0x00, 0x00,
0x00, // 163
0x00, 0x60, 0x30, 0x18, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00,
0x00, // 164
0x00, 0x0c, 0x18, 0x30, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00,
0x00, // 165
0x00, 0x10, 0x38, 0x6c, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00,
0x00, // 166
0x00, 0x00, 0xc6, 0x00, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00,
0x00, // 167
0x00, 0x60, 0x30, 0x18, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00,
0x00, // 168
0x00, 0x0c, 0x18, 0x30, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00,
0x00, // 169
0x00, 0x18, 0x3c, 0x66, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00,
0x00, // 170
0x00, 0x00, 0x66, 0x00, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00,
0x00, // 171
0x00, 0x00, 0x76, 0xdc, 0x00, 0xdc, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00,
0x00, // 172
0x00, 0x60, 0x30, 0x18, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00,
0x00, // 173
0x00, 0x18, 0x30, 0x60, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00,
0x00, // 174
0x00, 0x10, 0x38, 0x6c, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00,
0x00, // 175
0x00, 0x00, 0xc6, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00,
0x00, // 176
0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x7e, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00,
0x00, // 177
0x00, 0x60, 0x30, 0x18, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00,
0x00, // 178
0x00, 0x18, 0x30, 0x60, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00,
0x00, // 179
0x00, 0x30, 0x78, 0xcc, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00,
0x00, // 180
0x00, 0x00, 0xcc, 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00,
0x00, // 181
0x00, 0x00, 0xc6, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7e, 0x06, 0x0c, 0x78,
0x00, // 182
0x00, 0x0e, 0x1b, 0x18, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0xd8, 0x70, 0x00,
0x00, // 183
0x00, 0x00, 0xfe, 0xc6, 0xc6, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00,
0x00, // 184
0x00, 0x00, 0x00, 0x38, 0x6c, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0x6c, 0x38, 0x00, 0x00, 0x00,
0x00, // 185
0x00, 0x00, 0x00, 0xfe, 0xc6, 0x60, 0x30, 0x18, 0x30, 0x60, 0xc6, 0xfe, 0x00, 0x00, 0x00,
0x00, // 186
0x00, 0x00, 0x00, 0x7e, 0x18, 0x3c, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x7e, 0x00, 0x00, 0x00,
0x00, // 187
0x00, 0x00, 0x38, 0x6c, 0xc6, 0xc6, 0xc6, 0x6c, 0x6c, 0x6c, 0x6c, 0xee, 0x00, 0x00, 0x00,
0x00, // 188
0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0xd8, 0xd8, 0xd8, 0xdc, 0x76, 0x00, 0x00, 0x00,
0x00, // 189
0x00, 0x00, 0x1e, 0x30, 0x18, 0x0c, 0x3e, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x00, 0x00, 0x00,
0x00, // 190
0x00, 0x00, 0x1c, 0x30, 0x60, 0x60, 0x7c, 0x60, 0x60, 0x60, 0x30, 0x1c, 0x00, 0x00, 0x00,
0x00, // 191
0x00, 0x00, 0x00, 0x00, 0xfe, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x00,
0x00, // 192
0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0xd8, 0xd8, 0xd8, 0xd8, 0xd8, 0x70, 0x00, 0x00, 0x00,
0x00, // 193
0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00,
0x00, // 194
0x00, 0x00, 0x00, 0x03, 0x06, 0x7e, 0xdb, 0xdb, 0xf3, 0x7e, 0x60, 0xc0, 0x00, 0x00, 0x00,
0x00, // 195
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 196
0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x66, 0x00, 0x00, 0x00,
0x00, // 197
0x00, 0xd8, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 198
0x00, 0xf8, 0xcc, 0xcc, 0xf8, 0xc4, 0xcc, 0xde, 0xcc, 0xcc, 0xcc, 0xc6, 0x00, 0x00, 0x00,
0x00, // 199
0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x60, 0xfe, 0x60, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 200
0x00, 0x00, 0x18, 0x3c, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00,
0x00, // 201
0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x0c, 0xfe, 0x0c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 202
0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x00, 0x00, 0x00,
0x00, // 203
0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x6c, 0xfe, 0x6c, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 204
0x00, 0x00, 0x18, 0x3c, 0x7e, 0x18, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00,
0x00, // 205
0x00, 0x00, 0x18, 0x3c, 0x7e, 0x18, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x7e, 0x00, 0x00, 0x00,
0x00, // 206
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 207
0x00, 0x0f, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0xec, 0x6c, 0x6c, 0x3c, 0x1c, 0x00, 0x00, 0x00,
0x00, // 208
0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0xdb, 0xdb, 0xdb, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 209
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 210
0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00,
0x00, // 211
0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0x00, 0x76, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 212
0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0xfe, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00,
0x00, // 213
0x00, 0x00, 0x00, 0x0c, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0c, 0x00, 0x7e, 0x00, 0x00, 0x00,
0x00, // 214
0x00, 0x00, 0x00, 0x30, 0x18, 0x0c, 0x06, 0x0c, 0x18, 0x30, 0x00, 0x7e, 0x00, 0x00, 0x00,
0x00, // 215
0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c, 0xc6, 0xc6, 0xc6, 0xfe, 0x00, 0x00, 0x00, 0x00,
0x00, // 216
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, // 217
0x00, 0x00, 0x0e, 0x1b, 0x1b, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, // 218
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xd8, 0xd8, 0xd8, 0x70, 0x00, 0x00, 0x00,
0x00, // 219
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 220
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, // 221
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, // 222
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, // 223
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 224
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 225
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, // 226
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, // 227
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, // 228
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 229
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, // 230
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 231
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, // 232
0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, // 233
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, // 234
0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x30, 0x37, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, // 235
0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, // 236
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, // 237
0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x06, 0xf6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, // 238
0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 239
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 240
0x36, 0x36, 0x36, 0x36, 0x36, 0x37, 0x30, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 241
0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 242
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 243
0x36, 0x36, 0x36, 0x36, 0x36, 0xf6, 0x06, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 244
0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, // 245
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x37, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, // 246
0x36, 0x36, 0x36, 0x36, 0x36, 0x37, 0x30, 0x37, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, // 247
0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, // 248
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xf6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, // 249
0x36, 0x36, 0x36, 0x36, 0x36, 0xf6, 0x06, 0xf6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, // 250
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, // 251
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, // 252
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xf7, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, // 253
0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 254
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 255
0x36, 0x36, 0x36, 0x36, 0x36, 0xf7, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 256
0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0x18, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, // 257
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xff, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, // 258
0x36, 0x36, 0x36, 0x36, 0x36, 0xf7, 0x00, 0xf7, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, // 259
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // 260
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, // 261
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, // 262
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
0xf0, // 263
0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
0x0f, // 264
0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11,
0x44, // 265
0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55,
0xaa, // 266
0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd,
0x77, // 267
0x00, 0x00, 0x00, 0x00, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x00, 0x00, 0x00, 0x00,
0x00, // 268
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xfe, 0xfe, 0xfe, 0x00, 0x00, 0x00,
0x00, // 269
0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x38, 0x7c, 0x7c, 0xfe, 0xfe, 0x00, 0x00, 0x00, 0x00,
0x00, // 270
0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfe, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00, 0x00, 0x00,
0x00, // 271
0x00, 0x00, 0x00, 0x00, 0xfe, 0xfe, 0x7c, 0x7c, 0x38, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00,
0x00, // 272
0x00, 0x02, 0x06, 0x0e, 0x1e, 0x3e, 0xfe, 0x3e, 0x1e, 0x0e, 0x06, 0x02, 0x00, 0x00, 0x00,
0x00, // 273
0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, 0x42, 0x42, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x00,
0x00, // 274
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe7, 0xc3, 0xc3, 0xe7, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, // 275
0xff, 0xff, 0xff, 0xff, 0xff, 0xc3, 0x99, 0xbd, 0xbd, 0x99, 0xc3, 0xff, 0xff, 0xff, 0xff,
0xff, // 276
0x00, 0x00, 0x7e, 0x81, 0xa5, 0x81, 0x81, 0xbd, 0x99, 0x81, 0x81, 0x7e, 0x00, 0x00, 0x00,
0x00, // 277
0x00, 0x00, 0x7e, 0xff, 0xdb, 0xff, 0xff, 0xc3, 0xe7, 0xff, 0xff, 0x7e, 0x00, 0x00, 0x00,
0x00, // 278
0x00, 0x00, 0x00, 0x18, 0x18, 0xdb, 0x3c, 0xe7, 0x3c, 0xdb, 0x18, 0x18, 0x00, 0x00, 0x00,
0x00, // 279
0x00, 0x00, 0x3c, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x7e, 0x18, 0x18, 0x00, 0x00, 0x00,
0x00, // 280
0x00, 0x00, 0x1e, 0x0e, 0x1a, 0x32, 0x78, 0xcc, 0xcc, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0x00,
0x00, // 281
0x00, 0x00, 0x00, 0x18, 0x3c, 0x7e, 0xff, 0xff, 0x7e, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00,
0x00, // 282
0x00, 0x00, 0x00, 0x18, 0x3c, 0x3c, 0xe7, 0xe7, 0xe7, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00,
0x00, // 283
0x00, 0x00, 0x00, 0x00, 0x6c, 0xfe, 0xfe, 0xfe, 0xfe, 0x7c, 0x38, 0x10, 0x00, 0x00, 0x00,
0x00, // 284
0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x7c, 0xfe, 0x7c, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00,
0x00, // 285
0x00, 0x00, 0x3f, 0x33, 0x3f, 0x30, 0x30, 0x30, 0x30, 0x70, 0xf0, 0xe0, 0x00, 0x00, 0x00,
0x00, // 286
0x00, 0x00, 0x7f, 0x63, 0x7f, 0x63, 0x63, 0x63, 0x63, 0x67, 0xe7, 0xe6, 0xc0, 0x00, 0x00,
0x00, // 287
];
-40
View File
@@ -1,40 +0,0 @@
use crate::{drivers::io::framebuffer::colour::Colour, std::maths::geometry::Vec2};
use super::{
render::{ColouredChar, RenderError},
window::{self, Window},
};
use alloc::{vec, vec::Vec};
pub struct Frame<'f> {
data: Vec<Vec<Colour>>,
window: &'f Window,
}
impl<'a> Frame<'a> {
pub fn new(window: &'a Window) -> Self {
Self {
data: vec![vec![Colour::Black; window.dimensions().x()]; window.dimensions().y()],
window,
}
}
pub fn render(&self) -> Result<(), RenderError> {
let data: Vec<&[Colour]> = self.data.iter().map(|v| v.as_slice()).collect::<Vec<_>>();
self.window
.render(data.as_slice())
.map_err(|_| RenderError::Generic)
}
pub fn write_pixel(&mut self, x: usize, y: usize, color: Colour) -> Result<(), RenderError> {
if x >= self.window.dimensions().x() || y >= self.window.dimensions().y() {
return Err(RenderError::Generic);
}
self.data[y][x] = color;
Ok(())
}
pub const fn dimensions(&self) -> Vec2<usize> {
self.window.dimensions()
}
}
-84
View File
@@ -1,84 +0,0 @@
pub use crate::drivers::io::{
ascii::{_print, _print_err, _print_log},
print, print_log, printerr, println, println_log, printlnerr,
serial::_serial_write,
serial_print, serial_println,
};
pub mod stdin {
use alloc::string::String;
use crate::drivers::io::{
ascii::WRITER,
keyboard::{KeyStroke, get_keystroke_async, get_keystroke_optional},
};
/// Reads a line of input from standard input asynchronously, returning a `String` containing
/// the input line. Does not include the newline character at the end of the line.
///
/// If the user presses the abort key (usually Ctrl+C), the returned string will be empty.
///
/// This function is currently unimplemented.
pub async fn read_line() -> String {
let mut writer = WRITER.lock();
let mut buff = String::new();
loop {
match get_keystroke_async().await {
KeyStroke::Char(c) => match c {
'\n' => {
writer.write_glyph(c as u8);
return buff;
}
'\r' => {
writer.write_glyph(c as u8);
return buff;
}
'\x08' => {
if !buff.is_empty() {
buff.pop();
writer.backspace();
}
}
c => {
writer.write_glyph(c as u8);
buff.push(c)
}
},
KeyStroke::Enter => {
writer.write_glyph(b'\n');
return buff;
}
KeyStroke::Backspace => {
if !buff.is_empty() {
buff.pop();
writer.backspace();
}
}
_ => continue,
}
}
}
/// Reads a character from standard input and blocks the current task until a character is
/// available.
///
/// # Note
///
/// This function is not yet implemented.
pub async fn async_keystroke() -> KeyStroke {
get_keystroke_async().await
}
/// Attempt to read a character from standard input without blocking the current task.
///
/// If no character is available, returns `None`.
///
/// # Note
///
/// This function is not yet implemented.
pub fn keystroke() -> Option<KeyStroke> {
get_keystroke_optional()
}
}
+71 -41
View File
@@ -1,3 +1,5 @@
#![allow(dead_code)]
#![feature(proc_macro_span)]
#![warn(
clippy::correctness,
clippy::nursery,
@@ -9,29 +11,41 @@
rustdoc::missing_panics_doc
)]
use std::fs::File;
use std::io::{Read, Seek, SeekFrom};
use proc_macro::TokenStream;
use proc_macro::{Span, TokenStream};
use quote::quote;
use std::path::PathBuf;
use syn::{LitStr, parse_macro_input};
extern crate proc_macro;
#[proc_macro]
/// Expects the file path to be relative to the current file so this works
/// similarly to the standard Rust include! macros.
pub fn include_font(item: TokenStream) -> TokenStream {
let span = Span::call_site();
let source_file = span.source_file();
if !source_file.is_real() {
panic!(
"We can't handle finding files if the source file does not exist. TODO: Can we?"
)
}
let filename = parse_macro_input!(item as LitStr);
let file_path = filename.value();
let source_filepath: PathBuf = source_file.path();
let file_path = format!(
"{}/{}",
source_filepath.parent()
.unwrap_or_else(|| panic!("Expected to find the calling source file in a folder like src! Got: {}", source_filepath.display())).display(),
filename.value()
);
println!("Loading font: [{}]", file_path);
let font_bytes = match load_file(file_path) {
let font_bytes = match std::fs::read(file_path) {
Ok(bytes) => bytes,
Err(why) => panic!("{}", why),
};
let font_data = match Font::new(font_bytes) {
Ok(font) => font.0,
let font_data = match FontBuilder::load(font_bytes) {
Ok(font) => font.data,
Err(why) => panic!("{}", why),
};
@@ -47,18 +61,48 @@ pub fn include_font(item: TokenStream) -> TokenStream {
struct Font([[u8; 16]; 512]);
impl Font {
const MAGIC: u16 = 0x3604;
struct FontData {
width: u8,
height: u8,
length: u16,
pub data: [[u8; 16]; 512],
}
enum FontBuilder {
Psf1(FontData),
Psf2(FontData),
}
pub fn new(data: [u8; (32 + 2) * 512 + 4]) -> Result<Self, &'static str> {
let magic: u16 = (data[0] as u16) << 8 | data[1] as u16;
impl FontBuilder {
const PSF1_MAGIC: u16 = 0x3604;
const PSF2_MAGIC: u32 = 0x72b54a86;
fn revision(data: &[u8]) -> u8 {
if (data[0] as u16) << 8 | data[1] as u16 == Self::PSF1_MAGIC {
1
} else if (data[0] as u32) << 24
| (data[1] as u32) << 16
| (data[2] as u32) << 8
| data[3] as u32
== Self::PSF2_MAGIC
{
2
} else {
0
}
}
pub fn load(data: Vec<u8>) -> Result<FontData, &'static str> {
match Self::revision(&data[0..4]) {
1 => Self::parse_psf1(&data),
2 => Self::parse_psf2(&data),
_ => panic!("invalid font revision result"),
}
}
fn parse_psf1(data: &[u8]) -> Result<FontData, &'static str> {
let mode = data[2];
let size = data[3];
if magic != Self::MAGIC {
return Err("Magic value is invalid!");
}
let has_512_glyphs = (mode & 0x01) != 0;
let mut glyphs = [[0; 16]; 512];
let glyph_count = if has_512_glyphs { 512 } else { 256 };
@@ -71,29 +115,15 @@ impl Font {
glyphs[i] = buff;
}
Ok(Self(glyphs))
}
Ok(FontData {
width: 8,
height: size,
length: glyph_count,
data: glyphs,
})
}
type FileContents = [u8; (32 + 2) * 512 + 4];
fn load_file(filename: String) -> Result<FileContents, std::io::Error> {
let mut buf = [0; (32 + 2) * 512 + 4];
let mut f = File::open(filename).unwrap();
f.seek(SeekFrom::Start(0)).unwrap();
loop {
match f.read(&mut buf) {
Ok(read) => {
if read == 0 {
break;
const fn parse_psf2(_data: &[u8]) -> Result<FontData, &'static str> {
Err("PSF2 support is not implemented yet!")
}
}
Err(why) => {
eprintln!("Failed to read PS1 font file: {}", why);
return Err(why);
}
}
}
Ok(buf)
}
+5
View File
@@ -0,0 +1,5 @@
wrap_comments = true
max_width = 80
comment_width = 80
format_code_in_doc_comments = true
doc_comment_code_block_width = 80
+10 -1
View File
@@ -32,7 +32,7 @@ else
fi
# Set up test-specific flags
if [ $is_test -eq 1 ]; then
if [$is_test]; then
test_flags="-device isa-debug-exit,iobase=0xf4,iosize=0x04 -display none"
serial_flags="-serial stdio"
else
@@ -94,6 +94,15 @@ check_test_res() {
trap 'check_test_res "tests completed"' ERR
# NOTE(ali): For some reason the values in `boot_flags` were causing issues
# on WSL, so they've been eradicated.
systemInfo=$(uname -r)
if [[ $systemInfo == *"WSL"* ]]; then
echo "Running on WSL2"
boot_flags=""
fi
cd "$project_root"
qemu-system-x86_64 -M q35 \
-cdrom "$build_dir/image.iso" \