OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 1:06 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 37 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject: Re: Raspberry Pi 4
PostPosted: Tue Feb 08, 2022 2:24 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
zap8600 wrote:
Like, how do I make a block header?

Look at different malloc() implementations and see how they did it. You'll probably find some that don't use block headers at all.

zap8600 wrote:
Or, how do I set up a basic bitmap system?

Look at different bitmap allocators and see how they did it.

zap8600 wrote:
What is an ideal page size?

It depends on the workload. If you're worried about the ideal page size, you'll need to benchmark your target workload with different page sizes.

zap8600 wrote:
How would I reserve some space in a .bss?

Perhaps using assembly or some linker trickery.

zap8600 wrote:
How do I even read these values from RAM?

Which values?

zap8600 wrote:
How could I setup this?

You already did. Modify it to call your VMM whenever it needs more memory, and fix the alignment bug.


Top
 Profile  
 
 Post subject: Re: Raspberry Pi 4
PostPosted: Tue Feb 08, 2022 4:01 pm 
Offline
Member
Member

Joined: Tue Nov 02, 2021 11:26 am
Posts: 195
All right. I know what I want to do.
I want to remake my memory manager.
It'll be a Water Mark Memory Manager.

First, the MM will go to the start of memory.
Then, it'll go through memory until it finds start of the free memory.
It'll mark that address in it's reserved area (which will probably be a variable because I have no idea about how to do this kind of stuff with a linker) as freebase, and mark the start of RAM as kernelstart.
Then, from freebase, it'll continue until it reaches a limit I put in (which will be about 1GB to start).
It'll mark that as freetop.

What would be a good variable to store these points in?
How will I move from point to point in RAM?
How will I check if the RAM is free?


Top
 Profile  
 
 Post subject: Re: Raspberry Pi 4
PostPosted: Tue Feb 08, 2022 4:24 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
zap8600 wrote:
All right. I know what I want to do.
I want to remake my memory manager.
It'll be a Water Mark Memory Manager.

That's a heap allocator. Don't you need a PMM and a VMM before you worry about a heap allocator?

zap8600 wrote:
What would be a good variable to store these points in?

They're pointers, right? Probably a pointer type, or an integer the same size as a pointer.

zap8600 wrote:
How will I move from point to point in RAM?

Arithmetic.

zap8600 wrote:
How will I check if the RAM is free?

Your heap allocator doesn't need to check, because your VMM always provides free memory. Your VMM doesn't need to check, because your PMM always provides free memory. Your PMM uses the memory map provided by firmware (or hardcoded) along with symbols defined in your linker script.


Top
 Profile  
 
 Post subject: Re: Raspberry Pi 4
PostPosted: Tue Feb 08, 2022 6:15 pm 
Offline
Member
Member

Joined: Tue Nov 02, 2021 11:26 am
Posts: 195
All right. I'm a little confused, but I think I can understand. So for bitmapping, give me an example.


Top
 Profile  
 
 Post subject: Re: Raspberry Pi 4
PostPosted: Tue Feb 08, 2022 7:27 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
Here's an example. This person calls it a "bitset" instead of a "bitmap" but it's the same thing.


Top
 Profile  
 
 Post subject: Re: Raspberry Pi 4
PostPosted: Wed Feb 09, 2022 12:17 pm 
Offline
Member
Member

Joined: Tue Nov 02, 2021 11:26 am
Posts: 195
So, I have a plan. But I need to know how to get the memory mapping. I also need to know how to make a page. Can I use an MMU?


Top
 Profile  
 
 Post subject: Re: Raspberry Pi 4
PostPosted: Wed Feb 09, 2022 12:31 pm 
Offline
Member
Member

Joined: Tue Nov 02, 2021 11:26 am
Posts: 195
I would also like to know if the following steps would make a new page:
1. Copy freebase into another variable.
2. Increment freebase by 0x1000.
I'm making my page size 4KB for now.


Top
 Profile  
 
 Post subject: Re: Raspberry Pi 4
PostPosted: Wed Feb 09, 2022 12:49 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
zap8600 wrote:
But I need to know how to get the memory mapping.

I believe this is handled by a mailbox call. Possibly two, since I think that first call can only report up to 1GB.

zap8600 wrote:
I also need to know how to make a page. Can I use an MMU?

Yes. It's all explained in the ARM Architecture Reference Manual, but there's also some information about the ARMv7-A MMU on the wiki.

zap8600 wrote:
I would also like to know if the following steps would make a new page:
1. Copy freebase into another variable.
2. Increment freebase by 0x1000.

Only if it's aligned by 0x1000, and if you do this you won't be able to free the pages when you're done with them.


Top
 Profile  
 
 Post subject: Re: Raspberry Pi 4
PostPosted: Wed Feb 09, 2022 2:52 pm 
Offline
Member
Member

Joined: Tue Nov 02, 2021 11:26 am
Posts: 195
So, how can I make pages without some crazy setup? I want it to be simple at first, and then advance over time. What about just making the pages myself? They would need to be able to be freed.


Top
 Profile  
 
 Post subject: Re: Raspberry Pi 4
PostPosted: Wed Feb 09, 2022 3:18 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
zap8600 wrote:
So, how can I make pages without some crazy setup?

What do you mean? ARM paging is not that different from x86 paging, but there are more choices in how you can set it up. Maybe it will make more sense if you do some x86 paging and come back to ARM later.

zap8600 wrote:
What about just making the pages myself?

You can't make pages without a MMU.


Top
 Profile  
 
 Post subject: Re: Raspberry Pi 4
PostPosted: Wed Feb 09, 2022 4:06 pm 
Offline
Member
Member

Joined: Tue Nov 02, 2021 11:26 am
Posts: 195
So, how do I setup an ARM Page Table? How do I free a page? Stuff like that.


Top
 Profile  
 
 Post subject: Re: Raspberry Pi 4
PostPosted: Wed Feb 09, 2022 7:02 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
zap8600 wrote:
So, how do I setup an ARM Page Table?

It depends on which mode you choose, and there are a few different options since the different tables are usually not the same size as a page. If you're just going for a single set of two-level page tables, you'll use your PMM to allocate an aligned 16kB block of memory (made of four pages), then fill that 16kB with the first level entries. Each entry in the first level table describes 1MB of virtual address space. Then, for each 1MB of virtual address space where you want to map something, you'll use your PMM to allocate one 4kB page of physical memory, and fill 1kB of that page with your second level table. Each entry in the second level table describes 4kB of virtual address space.

The ARM MMU is very flexible, so you have a lot of different options available to you, but this is enough to make a working VMM.

zap8600 wrote:
How do I free a page?

Mark it as free in whichever data structure your PMM uses. (Before you do that, you also need to stop using the page: remove it from the page tables and perform any necessary TLB or cache flushes.)


Top
 Profile  
 
 Post subject: Re: Raspberry Pi 4
PostPosted: Wed Feb 09, 2022 10:55 pm 
Offline
Member
Member

Joined: Tue Nov 02, 2021 11:26 am
Posts: 195
Octocontrabass wrote:
zap8600 wrote:
So, how do I setup an ARM Page Table?

It depends on which mode you choose, and there are a few different options since the different tables are usually not the same size as a page. If you're just going for a single set of two-level page tables, you'll use your PMM to allocate an aligned 16kB block of memory (made of four pages), then fill that 16kB with the first level entries. Each entry in the first level table describes 1MB of virtual address space. Then, for each 1MB of virtual address space where you want to map something, you'll use your PMM to allocate one 4kB page of physical memory, and fill 1kB of that page with your second level table. Each entry in the second level table describes 4kB of virtual address space.

The ARM MMU is very flexible, so you have a lot of different options available to you, but this is enough to make a working VMM.
So, in the first block, I make 4 4kB pages. Then, each one describes 1MB of virtual memory space. Then, I make a 4kB page, and use 1kB of it to describe 4kB of virtual address space.
Now I will ask questions.
First, how do I make a block? Second, what kind of data do I need to put into these pages? Third, would I use some code from here to add the data?


Top
 Profile  
 
 Post subject: Re: Raspberry Pi 4
PostPosted: Wed Feb 09, 2022 11:57 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
zap8600 wrote:
First, how do I make a block?

It's just four physically contiguous 4kB pages at a 16kB-aligned physical address.

zap8600 wrote:
Second, what kind of data do I need to put into these pages?

Page tables. For the simplest case, using only two levels, you would use the short-descriptor format. The short-descriptor format is explained in great detail in the ARM Architecture Reference Manual. I've been using this ARMv7-A manual.

zap8600 wrote:
Third, would I use some code from here to add the data?

No.


Top
 Profile  
 
 Post subject: Re: Raspberry Pi 4
PostPosted: Thu Feb 10, 2022 4:01 pm 
Offline
Member
Member

Joined: Tue Nov 02, 2021 11:26 am
Posts: 195
Hi. I'm considering using Aarch64 instead of Aarch32. Would everything that has been talked about here still work?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 37 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 40 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group