Physical memory management.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
cacao
Posts: 8
Joined: Tue Dec 12, 2006 5:32 pm

Physical memory management.

Post by cacao »

Hello,

For physical memory management I'd like to know if mostly physical pages are reserved to prevent it for data erasing.
I know the pages of my kernel and I can protect it to allocate this
pages.

Regards
User avatar
gaf
Member
Member
Posts: 349
Joined: Thu Oct 21, 2004 11:00 pm
Location: Munich, Germany

Post by gaf »

Hello cacao,
If you want to know which memory areas mustn't be overwritten you should ask the BIOS for a memory map. In case that you're using GRUB this can also be done by interpreting the multiboot structures.

I'm not quite sure if I got you correctly. Just ask again if there are still question..

regards,
gaf
cacao
Posts: 8
Joined: Tue Dec 12, 2006 5:32 pm

Post by cacao »

I read the GRUB specification and I saw :

Code: Select all

[...]
`type' is the variety of address range represented, where a value of 1 indicates available ram, and all other values currently indicated a reserved area.
That's it !!! But what is the functionnality of reserved page ? (BIOS, Hardware mapping, ...)
User avatar
gaf
Member
Member
Posts: 349
Joined: Thu Oct 21, 2004 11:00 pm
Location: Munich, Germany

Post by gaf »

As far as I know GRUB tries to use Int15/0xE820 to get the memory map. For this function the BIOS specifies a few more types to describe in more detail why an area is reserved. To avoid problems your memory manager should only use blocks defined as type1 for allocation:
1 - memory, available to OS
2 - reserved, not available (e.g. system ROM, memory-mapped device)
3 - ACPI Reclaim Memory (usable by OS after reading ACPI tables)
4 - ACPI NVS Memory (OS is required to save this memory between NVS sessions)

other: not defined yet -- treat as reserved
cheers,
gaf
INF1n1t
Member
Member
Posts: 60
Joined: Fri Dec 22, 2006 5:32 pm
Location: Somewhere Down...

Post by INF1n1t »

I think I can give you the exact BIOS memory map:

Code: Select all

 0x0000:0x0000 -> 0x0000:0x03FF = IVT (Interrupt Vector Table)
0x0000:0x0400 -> 0x0000:0x04FF = BDA (BIOS Data Area)

0x0000:0x0500 -> 0x0000:0x7BFF = Free Useable Memory!

0x0000:0x7C00 -> 0x0000:0x7DFF = Operating System BootSector - This is where the BIOS
Loads your Operating System's BootSector at Boot Time (You can use this Memory, as long as
your BootSector isn't executing and you don't need your BootSector anymore!)

0x0000:0x7E00 -> 0x9000:0xFFFF = Free Useable Memory!

0xA000:0x0000 -> 0xB000:0xFFFF = VGA Video RAM
0xC000:0x0000 -> 0xF000:0xFFFF = BIOS ROM Memory Area

0xFFFF:0x0010 -> 0xFFFF:0xFFFF = Free Useable Memory (If the A20 Gate is Enabled) - This
Memory is Above the 1mb Mark, 0xFFFF:0x0010 = 0x00100000(1mb)
If this is the answer to the question....
I think, I have problems with Bochs. The biggest one: Bochs hates me!
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

I think I can give you the exact BIOS memory map:
I'm missing the EBDA in there... the area just below A000:0000 might be in use by the bios as well.
Also, its officially incorrect to assume 640k of conventional memory... (although everybody seems to do it)
Pretty much everything past 9000:0000 is chipset-dependent (With the exception of video memory)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
INF1n1t
Member
Member
Posts: 60
Joined: Fri Dec 22, 2006 5:32 pm
Location: Somewhere Down...

Post by INF1n1t »

So, you're telling we should load at least at the 1 MB mark and I think you're right, because...different BIOS, different memory map :)

But I've loaded my second boot loader (it is 200 bytes for now) at the 0100:0000 and it doesn't do a problem. May be if I try on another computer it would do a problem?
I think, I have problems with Bochs. The biggest one: Bochs hates me!
smbogan
Member
Member
Posts: 29
Joined: Tue Nov 21, 2006 3:17 pm

Post by smbogan »

Ask the bios system or Grub for the memory map, don't assume that every memory map is the same. Getting the information from Grub is not very hard. If you can't figure it out, send me a PM and I will show you a code example.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Post by Brendan »

Hi,
INF1n1t wrote:So, you're telling we should load at least at the 1 MB mark and I think you're right, because...different BIOS, different memory map :)

But I've loaded my second boot loader (it is 200 bytes for now) at the 0100:0000 and it doesn't do a problem. May be if I try on another computer it would do a problem?
Before you know which areas are what, the area from 0x00000000 to 0x00008000 *should* be entirely safe for all 80286 or later computers (except for the area below 0x00000500 while you're in real mode).

It's also possible to tell users that your OS requires N MB of RAM at 0x00100000, which shouldn't be a problem if N is less than 14 MB and is chosen to suit the rest of the OS's requirements. If it is a problem, then the user has a computer that isn't supported by the OS. :)

For an example, if the OS requires an 80486 or later CPU, then saying it requires 3 MB of RAM at 0x00100000 shouldn't cause any problem because almost all 80486 or later computers have 8 MB or more (an 80486 or later computer that doesn't meet this requirement would be extremely rare).

@smbogan: People should write code that uses the BIOS services (or GRUB's memory map), but the code to use BIOS services (or GRUB's memory map) needs to be stored in memory somewhere before it's executed... ;)


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply