- updated to-dos
- removed unnecessary debugging code - moved x86_64-kernel.json to the project root
This commit is contained in:
+1
-1
@@ -18,5 +18,5 @@ spin = "0.9.8"
|
||||
futures-util = { version = "0.3.31", default-features = false, features = [
|
||||
"alloc",
|
||||
] }
|
||||
linked_list_allocator = "0.10.5"
|
||||
linked_list_allocator = { version = "0.10.5", features = ["use_spin"] }
|
||||
libm = { path = "../libm" }
|
||||
|
||||
@@ -1,15 +1,7 @@
|
||||
use linked_list_allocator::LockedHeap;
|
||||
use x86_64::{
|
||||
VirtAddr,
|
||||
structures::paging::{
|
||||
FrameAllocator, Mapper, Page, PageTableFlags, Size4KiB,
|
||||
mapper::{MapToError, MapperFlushAll},
|
||||
},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
drivers::memory::{FRAME_ALLOCATOR, OFFSET_PAGE_TABLE},
|
||||
serial_print, serial_println,
|
||||
use x86_64::structures::paging::{
|
||||
mapper::MapToError,
|
||||
Size4KiB,
|
||||
};
|
||||
|
||||
/// We are currently using a linked list heap allocator which uses our underlying page allocator.
|
||||
@@ -24,46 +16,7 @@ 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>> {
|
||||
// let mut frame_allocator = if let Some(f) = FRAME_ALLOCATOR.get() {
|
||||
// f.lock()
|
||||
// } else {
|
||||
// return Err(MapToError::FrameAllocationFailed);
|
||||
// };
|
||||
|
||||
// let mut mapper = if let Some(m) = OFFSET_PAGE_TABLE.get() {
|
||||
// m.lock()
|
||||
// } else {
|
||||
// return Err(MapToError::FrameAllocationFailed);
|
||||
// };
|
||||
|
||||
// let range = {
|
||||
// let heap_start = VirtAddr::new(HEAP_START as u64);
|
||||
// let heap_end = heap_start + HEAP_SIZE as u64 - 1u64;
|
||||
// let heap_start_page = Page::<Size4KiB>::containing_address(heap_start);
|
||||
// let heap_end_page = Page::<Size4KiB>::containing_address(heap_end);
|
||||
// Page::range_inclusive(heap_start_page, heap_end_page)
|
||||
// };
|
||||
|
||||
// let usable_frames = frame_allocator.count_usable_frames();
|
||||
// serial_println!("usable frames: {}", usable_frames);
|
||||
|
||||
// let mut i = 0;
|
||||
// for page in range {
|
||||
// i += 1;
|
||||
// if i % 128 == 0 {
|
||||
// serial_println!("allocated {} pages", i);
|
||||
// }
|
||||
// let frame = frame_allocator
|
||||
// .allocate_frame()
|
||||
// .ok_or(MapToError::FrameAllocationFailed)?;
|
||||
// let flags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE;
|
||||
// unsafe {
|
||||
// // IMPORTANT: make sure to flush the mapper!!!!
|
||||
// let _ = mapper.map_to(page, frame, flags, &mut *frame_allocator)?;
|
||||
// }
|
||||
// }
|
||||
|
||||
// MapperFlushAll::new().flush_all();
|
||||
// code to allocate frames is now done in the page fault interrupt handler!
|
||||
|
||||
unsafe {
|
||||
ALLOCATOR.lock().init(HEAP_START as *mut u8, HEAP_SIZE);
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
use limine::{memory_map::EntryType, response::MemoryMapResponse};
|
||||
use spin::{Mutex, Once};
|
||||
use x86_64::{
|
||||
PhysAddr, VirtAddr,
|
||||
registers::control::Cr3,
|
||||
structures::paging::{
|
||||
FrameAllocator, Mapper, OffsetPageTable, Page, PageTable, PhysFrame, Size4KiB,
|
||||
page_table::FrameError,
|
||||
registers::control::Cr3, structures::paging::{
|
||||
FrameAllocator, OffsetPageTable, PageTable, PhysFrame, Size4KiB
|
||||
,
|
||||
},
|
||||
PhysAddr,
|
||||
VirtAddr,
|
||||
};
|
||||
|
||||
pub static FRAME_ALLOCATOR: Once<Mutex<FoundryOSFrameAllocator>> = Once::new();
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use alloc::vec::Vec;
|
||||
|
||||
use crate::{drivers::io::framebuffer::colour::Colour, resources::font::Font};
|
||||
|
||||
use super::{
|
||||
|
||||
+76
-15
@@ -44,53 +44,110 @@ impl<'a> Editor {
|
||||
|
||||
let (width, height) = writer.font_size().into();
|
||||
|
||||
let mut col = Self::PADDING;
|
||||
let mut line = Self::PADDING;
|
||||
let mut col = 0;
|
||||
let mut line = 0;
|
||||
let mut scale = 1;
|
||||
|
||||
for ch in self.buffer.chars() {
|
||||
if ch == '\n' {
|
||||
line += scale * height;
|
||||
col = Self::PADDING;
|
||||
line += scale;
|
||||
col = 0;
|
||||
scale = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if width * scale + col > frame.dimensions().x() {
|
||||
line += scale * height;
|
||||
col = Self::PADDING;
|
||||
if width * (col + 1) > frame.dimensions().x() - 2 * Self::PADDING {
|
||||
line += scale;
|
||||
col = 0;
|
||||
}
|
||||
|
||||
writer.render_glyph(&mut frame, Vec2::new(col, line), ch as u8, scale)?;
|
||||
col += scale * width;
|
||||
writer.render_glyph(
|
||||
&mut frame,
|
||||
Vec2::new(col * width + Self::PADDING, line * height + Self::PADDING),
|
||||
ch as u8,
|
||||
scale,
|
||||
)?;
|
||||
col += scale;
|
||||
}
|
||||
|
||||
writer.render_glyph(
|
||||
&mut frame,
|
||||
Vec2::new(
|
||||
self.cursor_col * width + Self::PADDING,
|
||||
self.cursor_line * height + Self::PADDING,
|
||||
),
|
||||
b'_',
|
||||
scale,
|
||||
);
|
||||
|
||||
Ok(frame)
|
||||
}
|
||||
|
||||
#[allow(unused_variables, dead_code, clippy::needless_pass_by_ref_mut)]
|
||||
fn get_lines(&self) -> Vec<&str> {
|
||||
self.buffer.split('\n').collect::<Vec<&str>>();
|
||||
todo!()
|
||||
self.buffer.split('\n').collect::<Vec<&str>>()
|
||||
}
|
||||
|
||||
#[allow(unused_variables, dead_code, clippy::needless_pass_by_ref_mut)]
|
||||
fn move_cursor(&mut self, x: i32, y: i32) {
|
||||
todo!()
|
||||
self.cursor_line = self
|
||||
.cursor_line
|
||||
.checked_add_signed(y as isize)
|
||||
.unwrap_or(self.cursor_line);
|
||||
self.cursor_col = self
|
||||
.cursor_col
|
||||
.checked_add_signed(x as isize)
|
||||
.unwrap_or(self.cursor_col);
|
||||
}
|
||||
|
||||
#[allow(unused_variables, dead_code, clippy::needless_pass_by_ref_mut)]
|
||||
fn delete_char(&mut self) {
|
||||
todo!()
|
||||
let i = self.get_char_idx();
|
||||
self.buffer.remove(i);
|
||||
}
|
||||
|
||||
#[allow(unused_variables, dead_code, clippy::needless_pass_by_ref_mut)]
|
||||
fn insert_char(&mut self, c: char) {
|
||||
todo!()
|
||||
let i = self.get_char_idx();
|
||||
self.buffer.insert(i, c);
|
||||
}
|
||||
|
||||
#[allow(unused_variables, dead_code, clippy::needless_pass_by_ref_mut)]
|
||||
fn splitline(&mut self) {
|
||||
todo!()
|
||||
let i = self.get_char_idx();
|
||||
self.buffer.insert(i, '\n');
|
||||
}
|
||||
|
||||
fn get_char_idx(&self) -> usize {
|
||||
let frame = Frame::new(&self.window);
|
||||
let writer = Writer::new(Font::default());
|
||||
let (width, _height) = writer.font_size().into();
|
||||
|
||||
let mut col = 0;
|
||||
let mut line = 0;
|
||||
let mut scale = 1;
|
||||
|
||||
for (i, ch) in self.buffer.chars().enumerate() {
|
||||
if ch == '\n' {
|
||||
line += scale;
|
||||
col = 0;
|
||||
scale = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if width * (col + 1) > frame.dimensions().x() - 2 * Self::PADDING {
|
||||
line += scale;
|
||||
col = 0;
|
||||
}
|
||||
|
||||
if col == self.cursor_col && line == self.cursor_line {
|
||||
return i;
|
||||
}
|
||||
|
||||
col += scale;
|
||||
}
|
||||
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,15 +196,19 @@ impl Application for Editor {
|
||||
}
|
||||
}
|
||||
KeyStroke::Left => {
|
||||
serial_println!("Left\n");
|
||||
self.move_cursor(-1, 0);
|
||||
}
|
||||
KeyStroke::Right => {
|
||||
serial_println!("Right\n");
|
||||
self.move_cursor(1, 0);
|
||||
}
|
||||
KeyStroke::Up => {
|
||||
serial_println!("Up\n");
|
||||
self.move_cursor(0, -1);
|
||||
}
|
||||
KeyStroke::Down => {
|
||||
serial_println!("Down\n");
|
||||
self.move_cursor(0, 1);
|
||||
}
|
||||
KeyStroke::None => {}
|
||||
|
||||
Reference in New Issue
Block a user