asteroids game rewrite
This commit is contained in:
@@ -5,7 +5,7 @@ use x86_64::{
|
||||
PhysAddr
|
||||
};
|
||||
use bootloader::bootinfo::{MemoryMap, MemoryRegionType};
|
||||
use x86_64::structures::paging::OffsetPageTable;
|
||||
use x86_64::structures::paging::{mapper, OffsetPageTable};
|
||||
|
||||
unsafe fn active_level_4_table(physical_memory_offset: VirtAddr) -> &'static mut PageTable {
|
||||
|
||||
@@ -72,7 +72,7 @@ unsafe impl FrameAllocator<Size4KiB> for BootInfoFrameAllocator {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct StackBounds {
|
||||
@@ -119,7 +119,7 @@ fn reserve_stack_memory(size_in_pages: u64) -> Page {
|
||||
pub fn alloc_stack(
|
||||
size_in_pages: u64, mapper: &mut impl Mapper<Size4KiB>,
|
||||
frame_allocator: &mut impl FrameAllocator<Size4KiB>
|
||||
) -> Result<StackBounds, mapper::MapToError> {
|
||||
) -> Result<StackBounds, mapper::MapToError<Size4KiB>> {
|
||||
use x86_64::structures::paging::PageTableFlags as Flags;
|
||||
|
||||
let guard_page = reserve_stack_memory(size_in_pages + 1);
|
||||
@@ -127,9 +127,10 @@ pub fn alloc_stack(
|
||||
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::FrameAllocatorFailed)?;
|
||||
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();
|
||||
|
||||
unsafe { mapper.map_to(page, frame, flags, frame_allocator)?.flush() };
|
||||
}
|
||||
|
||||
Ok(StackBounds {
|
||||
@@ -137,4 +138,4 @@ pub fn alloc_stack(
|
||||
end: stack_end.start_address(),
|
||||
})
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
@@ -6,4 +6,5 @@ pub mod serial;
|
||||
pub mod tasks;
|
||||
pub mod sysinit;
|
||||
pub mod authenticator;
|
||||
pub mod render;
|
||||
pub mod render;
|
||||
pub mod multitasking;
|
||||
@@ -0,0 +1,2 @@
|
||||
pub mod thread;
|
||||
mod thread_switch;
|
||||
@@ -0,0 +1,9 @@
|
||||
use x86_64::VirtAddr;
|
||||
use crate::system::kernel::memory::{StackBounds, ThreadId};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Thread {
|
||||
id: ThreadId,
|
||||
stack_ptr: Option<VirtAddr>,
|
||||
stack_bounds: Option<StackBounds>,
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
.intel_syntax noprefix
|
||||
pushfq
|
||||
|
||||
mov rax, rsp
|
||||
mov rsp, rdi
|
||||
|
||||
mov rdi, rax
|
||||
call add_paused_thread
|
||||
|
||||
popfq
|
||||
ret
|
||||
@@ -0,0 +1,2 @@
|
||||
use core::arch::global_asm;
|
||||
global_asm!(include_str!("thread_switch.asm"));
|
||||
@@ -1,15 +0,0 @@
|
||||
|
||||
|
||||
pub mod thread_switch;
|
||||
|
||||
use x86_64::VirtAddr;
|
||||
use crate::memory::{ThreadId, StackBounds};
|
||||
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Thread {
|
||||
id: ThreadId,
|
||||
stack_pointer: Option<VirtAddr>,
|
||||
stack_bounds: Option<StackBounds>,
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
use core::arch::global_asm;
|
||||
|
||||
global_asm!(include_str!("thread_switch.s"));
|
||||
@@ -1,13 +0,0 @@
|
||||
|
||||
|
||||
asm_thread_switch:
|
||||
pushfq
|
||||
|
||||
mov rax, rsp
|
||||
mov rsp, rdi
|
||||
|
||||
mov rdi, rax
|
||||
call add_paused_thread
|
||||
|
||||
popfq
|
||||
ret
|
||||
Reference in New Issue
Block a user