mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-18 15:27:50 +00:00
Merge branch 'post-11' into post-12-async-await
This commit is contained in:
@@ -21,7 +21,7 @@ static ALLOCATOR: Locked<FixedSizeBlockAllocator> = Locked::new(FixedSizeBlockAl
|
||||
pub fn init_heap(
|
||||
mapper: &mut impl Mapper<Size4KiB>,
|
||||
frame_allocator: &mut impl FrameAllocator<Size4KiB>,
|
||||
) -> Result<(), MapToError> {
|
||||
) -> Result<(), MapToError<Size4KiB>> {
|
||||
let page_range = {
|
||||
let heap_start = VirtAddr::new(HEAP_START as u64);
|
||||
let heap_end = heap_start + HEAP_SIZE - 1u64;
|
||||
|
||||
@@ -36,7 +36,10 @@ unsafe impl GlobalAlloc for Locked<BumpAllocator> {
|
||||
let mut bump = self.lock(); // get a mutable reference
|
||||
|
||||
let alloc_start = align_up(bump.next, layout.align());
|
||||
let alloc_end = alloc_start.checked_add(layout.size()).expect("overflow");
|
||||
let alloc_end = match alloc_start.checked_add(layout.size()) {
|
||||
Some(end) => end,
|
||||
None => return ptr::null_mut(),
|
||||
};
|
||||
|
||||
if alloc_end > bump.heap_end {
|
||||
ptr::null_mut() // out of memory
|
||||
|
||||
@@ -86,7 +86,7 @@ impl LinkedListAllocator {
|
||||
/// Returns the allocation start address on success.
|
||||
fn alloc_from_region(region: &ListNode, size: usize, align: usize) -> Result<usize, ()> {
|
||||
let alloc_start = align_up(region.start_addr(), align);
|
||||
let alloc_end = alloc_start.checked_add(size).expect("overflow");
|
||||
let alloc_end = alloc_start.checked_add(size).ok_or(())?;
|
||||
|
||||
if alloc_end > region.end_addr() {
|
||||
// region too small
|
||||
|
||||
@@ -4,7 +4,7 @@ use core::{
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
use pc_keyboard::{layouts, DecodedKey, Keyboard, ScancodeSet1};
|
||||
use pc_keyboard::{layouts, DecodedKey, HandleControl, Keyboard, ScancodeSet1};
|
||||
|
||||
fn next_scancode() -> impl Future<Output = u8> {
|
||||
NextScancode
|
||||
@@ -33,7 +33,7 @@ impl Future for NextScancode {
|
||||
}
|
||||
|
||||
pub async fn print_keypresses() {
|
||||
let mut keyboard = Keyboard::new(layouts::Us104Key, ScancodeSet1);
|
||||
let mut keyboard = Keyboard::new(layouts::Us104Key, ScancodeSet1, HandleControl::Ignore);
|
||||
|
||||
loop {
|
||||
if let Ok(Some(key_event)) = keyboard.add_byte(next_scancode().await) {
|
||||
|
||||
@@ -116,7 +116,6 @@ pub(crate) static KEYBOARD_INTERRUPT_WAKER: AtomicWaker = AtomicWaker::new();
|
||||
|
||||
extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: &mut InterruptStackFrame) {
|
||||
use x86_64::instructions::port::Port;
|
||||
|
||||
let mut port = Port::new(0x60);
|
||||
let scancode: u8 = unsafe { port.read() };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user