Skip to content
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

Riscv64 mmu #35

Closed
wants to merge 15 commits into from
Closed

Riscv64 mmu #35

wants to merge 15 commits into from

Conversation

Skallwar
Copy link
Collaborator

No description provided.

// TODO: Find real value
const PAGE_NUMBER: usize = 50;

static mut PageUsage: [UsageFlags; PAGE_NUMBER] = [UsageFlags::Free; PAGE_NUMBER];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static mut PageUsage: [UsageFlags; PAGE_NUMBER] = [UsageFlags::Free; PAGE_NUMBER];
static mut PAGE_USAGE: [UsageFlags; PAGE_NUMBER] = [UsageFlags::Free; PAGE_NUMBER];

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will sed this

let mut index = 0;

// FIXME: Iterator
while index < 50 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 50?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had problems with .bss and .data section. I've removed most of the statics and const to test if it will work. This will be fixed before going out of draft state

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry I hadn't even noticed it was a draft :D My bad!


// FIXME: Iterator
while index < 50 {
unsafe {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put the unsafe block just around the "pointer arithmetics"? Or does rustc disagree

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PageUsage[index] is unsafe (static mut), line 26 is also unsafe. So I made a big unsafe block. But you're right it's better to see exactly where is the unsafe code in the most fine grained manner as possible. I will change this

Comment on lines 40 to 48
mod test {
use super::*;
use crate::utest::uassert_eq;
#[test_case]
fn page_alloc_test() {
let test = page_alloc();
kassert_eq!(test.is_some(), true, "Page alloc test");
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a test for .is_none(), when all pages are allocated, just so we're sure we don't introduce regressions on future updates of the MMU

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a test for .is_none(), when all pages are allocated

Yup makes sense.

future updates of the MMU

This is independent of the MMU, we are just managing the heap here, nothing more

src/main.rs Show resolved Hide resolved
@@ -45,7 +45,7 @@ pub fn runner(tests: &[&dyn Fn()]) {
end_utests();
}

fn uassert_eq<T: PartialEq + core::fmt::Debug>(lhs: T, rhs: T, test_name: &str) {
pub fn uassert_eq<T: PartialEq + core::fmt::Debug>(lhs: T, rhs: T, test_name: &str) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to expose the function? There are macros available IIRC

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason macros doesn't work in I can't get access to this in src/allocator/mod.rs (see line 42). I will try to figure this out, but I just wanted to make something work x)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to use the macros at the beginning of the file

use crate::kassert_eq;
use crate::kassert;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get this error:

error[E0425]: cannot find function `uassert_eq` in this scope
  --> src/utest/mod.rs:34:9
   |
34 |         uassert_eq($stmt, true, $name)
   |         ^^^^^^^^^^ not found in this scope
   |
  ::: src/spin_lock/mod.rs:58:13
   |
58 |             kassert!(*data, 1);
   |             ------------------- in this macro invocation
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this function
   |
44 |     use crate::utest::uassert_eq;
   |

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmmh that's odd. I'm gonna take a look at it on your branch

@Skallwar
Copy link
Collaborator Author

I found the bug which blocked iterators and range. The stack was misaligned and rust was calling abort. And OpensSBI rebooted our kernel. We should override rust abort() to print something in the future

@Skallwar Skallwar mentioned this pull request Oct 29, 2020
@Skallwar Skallwar closed this Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants