How Physical Memory Mapping / Allocation works

Thread Starter

Ab Abrams

Joined Apr 27, 2017
25
Hi guys,

I am new on software programming and I am trying to understand some basic/ important things. I am interested in Bare-metal software programming, so please give me answers related on this. My question is: who is responsible and manage the physical memory mapping / allocation? Meaning, If I have 1GB physical memory on my system, the 1) CPU or 2) the Bootloader (like GRUB, U-boot) is responsible for the memory addresses that I can use for my program?
Is hardware specific architecture? Each platform manufacture has their own memory address mapping scheme and layout?
Furthermore, is there any standart way that you have to partition the physical memory? meaning, give some memory for I/Oports and so on?

Sorry for the mess, but I dont understand when you create/ build your software, how you know what range of physical addresses you can use for start/entry point, stack
and so on.

Please help me to clear all this in my mind. If you can give me examples will help me more
P.S. Programming in C

Thanks
 

MrChips

Joined Oct 2, 2009
22,869
It depends on the scale of the computer system. Are we talking about desktop/laptop personal computers, servers, or single chip systems?

On a single chip system (microcontroller), it is up to the manufacturer to layout the addressing space and allocation for internal/external memory, peripherals, etc.

For larger systems, address allocation is done by the system designer. For legacy systems, the designer is usually constrained by previous and current systems in order to maintain backward compatibility.

For the programmer, the allocation will be found in the linker configuration files usually setup by the toolset supplier with input from the system designer or manufacturer.
 

MrChips

Joined Oct 2, 2009
22,869
If you are interested in bare-metal C programming on an ARM platform, my recommendation would be to get an STM32 DISCO board.
Something like a STM32F407G-DISC1 will do nicely and will get you started.
The Atollic software is free from ST.
 

Thread Starter

Ab Abrams

Joined Apr 27, 2017
25
These are the routines that the kernel uses to allocate memory to itself:

http://minirighi.sourceforge.net/html/kmalloc_8c.html

You can click on the constants and other definitions to see how it maps the memory.

Or not. Your choice.
Ok, @joeyd999 sorry about my offensive reply to you, my bad but lots of times people just give an answer like "google it" and its not helpfull at all. But, maybe you did not understand what I need or I am not sure If I can do that I want to do.
I dont want to boot or load any kernel, I just want to run my application up to the hardware and maybe boot it and load it through U-boot bootloader that, as a bonus, it even boots from a .img file or .bin file
Based on your answer I understand that I have to install and load the kernel and then run my application?
Let me show you what order I want :
hardware -> U-boot -> run / boot my application and maybe then a kernel like linux
Just I want to know where I can save my variables, which amount of physical address space I can use and so on.
 
Last edited:

joeyd999

Joined Jun 6, 2011
4,477
Ok, @joeyd999 sorry about my offensive reply to you, my bad but lots of times people just give an answer like "google it" and its not helpfull at all. But, maybe you did not understand what I need or I am not sure If I can do that I want to do.
I dont want to boot or load any kernel, I just want to run my application up to the hardware and maybe boot it and load it through U-boot bootloader that gives you the chance to load an .img or .bin file
Based on your answer I understand that I have to install and load the kernel and then run my application?
Let me show you what order I want :
hardware -> U-boot -> run / boot my application and maybe then a kernel like linux
Just I want to know where I can save my variables, which amount of physical address space I can use and so on.
My point was that a kernel is just a program. And it runs on bare metal. That it is an OS is irrelevant. The reason I chose to use Linux as an example is that a) the code is available to examine and b) it does a fine job managing its own memory (in addition to the memory required by managed processes) on multiple platforms*.

As part of your question, you asked for examples of memory allocation on bare metal. My service to you was to offer you one.

Aside from this, I have no other knowledge to give -- unless you are asking about much smaller systems (like microcontrollers).

*edit: and, as a bonus, it even boots from a .img file!
 

WBahn

Joined Mar 31, 2012
26,398
Ok, @joeyd999 sorry about my offensive reply to you, my bad but lots of times people just give an answer like "google it" and its not helpfull at all. But, maybe you did not understand what I need or I am not sure If I can do that I want to do.
I dont want to boot or load any kernel, I just want to run my application up to the hardware and maybe boot it and load it through U-boot bootloader that gives you the chance to load an .img or .bin file
Based on your answer I understand that I have to install and load the kernel and then run my application?
Let me show you what order I want :
hardware -> U-boot -> run / boot my application and maybe then a kernel like linux
Just I want to know where I can save my variables, which amount of physical address space I can use and so on.
I could be way off target here, but it seems like there are two somewhat different aspects of this.

The first is how does your program GET whatever chunk of physical memory it will have access to. If your program is running without hosting (no O/S), then it probably has access to all of the memory that can physically be reached.

The second is how does your program USE whatever memory it can access. That is often performed by a memory manager that the compiler inserts into your program. Some memory (static memory) is effectively allocated at compile time. Some memory automatically allocated and deallocates as a consequence of the a stack-based virtual machine that your compiler constructs (or that the intermediate code runs on). Some memory is dynamically allocated by the built-in memory manager that has to keep track of what memory is available, where it is, how to mark it as unavailable, and how to recover it when your program is done with it.

Which of these two are you mostly interested in?
 

miniwinwm

Joined Feb 2, 2018
67
If you are interested in bare-metal C programming on an ARM platform, my recommendation would be to get an STM32 DISCO board.
Something like a STM32F407G-DISC1 will do nicely and will get you started.
The Atollic software is free from ST.
Yep, I'd agree with that. Although the STM32F4xx (as on a couple of ST's Discovery boards) are fearsome beasts with lots of capabilities and can be complicated to program, getting going on them is really easy - get Atollic TrueStudio, start a new project, select your board, click create - and there you are. All the pre-main set up and clock configuration is done, the required libraries linked in, it even creates a main file and function, and you just start adding your code. This kind of device will be excellent for figuring out what memory is where because there's no memory manager or memory protection getting in the way.
 
Last edited:

MrChips

Joined Oct 2, 2009
22,869
If you wish to get into more exciting and complex ARM systems development, get the STM32F746G-DISCO that comes with 4.3" color LCD and touch screen. C libraries and example programs are readily available. You can easily turn it into a hand-held scope as a starter project exercise. (Maybe I will create a blog on this.)
 

miniwinwm

Joined Feb 2, 2018
67
If you wish to get into more exciting and complex ARM systems development, get the STM32F746G-DISCO that comes with 4.3" color LCD and touch screen. C libraries and example programs are readily available. You can easily turn it into a hand-held scope as a starter project exercise. (Maybe I will create a blog on this.)
For anyone attempting to use this board with Atollic TrueStudio - ST have removed project files for this IDE from their Cube download of examples, which seems strange considering that they have now taken over Atollic (I guess support will be going back in soonish). Anyway, to get sample projects for this board that build in Atollic TrueStudio download them from within the TrueStudio IDE. These are a bit older than the versions in the Cube download, but build straight out of the box.

The STM32F429-DISC1 also comes with a touchscreen LCD and drivers, and is cheaper than the 746 based one. It's the main dev board I am now using for my freebie window manager here (no adverts, non-commercial, all free)...

https://miniwinwm.wixsite.com/miniwinwm
 
Top