-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor the kernel's mm module #145
Conversation
In doing so, we were overating over one page too many. Instead iterate over an exlusive range.
We have to assume PAGE_SIZE from the HAL to be a baked in constant at compile-time. Similar to a PAGE_SIZE define in a C project. Don't pass it because it won't (read *must not*) change at run-time.
5632e1a
to
2835844
Compare
Hum, looks like I did not fix riscv alongside aarch64... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work
I wonder if we should take the time to add a interrupt handler for catching bad memory access since we should be able to catch them now.
@@ -97,12 +97,14 @@ fn test_timer_interrupt() -> TestResult { | |||
fn test_pagetable_remap() -> TestResult { | |||
info!("Testing the remapping capabilities of our pagetable..."); | |||
|
|||
let page_src = alloc_pages(1).unwrap(); | |||
let page_src = globals::PHYSICAL_MEMORY_MANAGER.alloc(1).unwrap(); | |||
let page_src = unsafe { slice::from_raw_parts_mut(page_src as *mut u8, PAGE_SIZE) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should add a wrapper for that because we do this casting in a lot of different places
})?; | ||
let pt = hal_core::mm::prefill_pagetable::<PageTable>(r, rw, rwx, pre_allocated, allocator)?; | ||
|
||
// TODO: put into into the hal_core::Error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do the todo now or later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oneday 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note that using &impl PageAllocator
is similar to using <P: PageAllocator>
and &P
. the function will be monomorphized and "templated" for each allocator it is used with. If this becomes a problem it might be worth switching to &dyn PageAllocator
instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
woops meant to approve this
Had to change a few interfaces to get around ownership issues. But now that all DRAM is not mapped as r/w, hopefully we will catch bugs earlier later on.
PageAllocFn was not very wieldy, the alloc_pages_* (alloc_pages_for_hal etc...) functions were a mess and it was hard to know what to use when etc... Use a trait instead, that way we can still pass an allocator that does not allocate in cases when we don't want to allocate, and pass the whole allocator when allocations actually are needed. That way it is easier to add functionality for when the HALs need more info from the allocator. Also it is much much easier to manage ownership&lifetimes this way.
Thanks to the previous patch, it was fairly easy to just make the PMM thread-safe. It also makes interfaces a bit nicer imo. Lastly I did it because it was easy and I felt like it.
2835844
to
e63a319
Compare
e63a319
to
7e73956
Compare
9b8b759
to
ce3d57e
Compare
ce3d57e
to
72db5f4
Compare
I was feeling like the
mm
module was a hot mess ready to blow our legs off.Now that we only map the memory we need as r/w, I hope we will catch bugs earlier (if we create some).
I also prefer those interfaces, and having the PMM thread-safe is a nice step forward.
I should have cleaned up all the weird debug stuff I had left laying around.