Raspberry Pi 4

Programming, for all ages and all languages.
Octocontrabass
Member
Member
Posts: 5524
Joined: Mon Mar 25, 2013 7:01 pm

Re: Raspberry Pi 4

Post by Octocontrabass »

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.
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: Raspberry Pi 4

Post by zap8600 »

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?
Octocontrabass
Member
Member
Posts: 5524
Joined: Mon Mar 25, 2013 7:01 pm

Re: Raspberry Pi 4

Post by Octocontrabass »

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.
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: Raspberry Pi 4

Post by zap8600 »

All right. I'm a little confused, but I think I can understand. So for bitmapping, give me an example.
Octocontrabass
Member
Member
Posts: 5524
Joined: Mon Mar 25, 2013 7:01 pm

Re: Raspberry Pi 4

Post by Octocontrabass »

Here's an example. This person calls it a "bitset" instead of a "bitmap" but it's the same thing.
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: Raspberry Pi 4

Post by zap8600 »

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?
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: Raspberry Pi 4

Post by zap8600 »

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.
Octocontrabass
Member
Member
Posts: 5524
Joined: Mon Mar 25, 2013 7:01 pm

Re: Raspberry Pi 4

Post by Octocontrabass »

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.
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: Raspberry Pi 4

Post by zap8600 »

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.
Octocontrabass
Member
Member
Posts: 5524
Joined: Mon Mar 25, 2013 7:01 pm

Re: Raspberry Pi 4

Post by Octocontrabass »

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.
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: Raspberry Pi 4

Post by zap8600 »

So, how do I setup an ARM Page Table? How do I free a page? Stuff like that.
Octocontrabass
Member
Member
Posts: 5524
Joined: Mon Mar 25, 2013 7:01 pm

Re: Raspberry Pi 4

Post by Octocontrabass »

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.)
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: Raspberry Pi 4

Post by zap8600 »

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?
Octocontrabass
Member
Member
Posts: 5524
Joined: Mon Mar 25, 2013 7:01 pm

Re: Raspberry Pi 4

Post by Octocontrabass »

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.
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: Raspberry Pi 4

Post by zap8600 »

Hi. I'm considering using Aarch64 instead of Aarch32. Would everything that has been talked about here still work?
Post Reply