memory model 64bit

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
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

memory model 64bit

Post by os64dev »

Hi All,

I finally got preliminary elf64 support working and the boot loader now loads the kernel (core.elf) and starts the main function. In the screen shot posted all the blue stuff is the boot loader and the black lines are the kernel. The code is rather dodgy but i will change that later.

Now i have several question:
Because i am building a pure 64bit kernel, so no BIOS and pmode, i want the kernel to reside at physical memory address zero, currently 2 MiB, and onwards and the virtual memory address in the higher half the upper MiB in this case, though this is determined by the elf file.

Question 1) What is the best way to implement the loading of the core.elf file at physical address 0 without overwriting the boot loader. Considering the boot loader generally resides at 0x7C00 onwards and the kernel will be not more then 256 KiB including data structures. and i don't want to use the memory above 1 MiB.

Further more i get the concept and benefits of each user thread/process to have the kernel space mapped, so that is what i will implement but..

Question 2) Do you make the whole physical memory space available to the kernel?

I can map this using 2MiB pages so mapping 512 GiB will take only 16 KiB of memory.

Looking forward to hear from you all,

os64dev
Attachments
cobos64.png
cobos64.png (31.44 KiB) Viewed 749 times
Author of COBOS
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Re: memory model 64bit

Post by JAAman »

os64dev wrote: i want the kernel to reside at physical memory address zero, currently 2 MiB, and onwards and the virtual memory address in the higher half the upper MiB in this case, though this is determined by the elf file.
any particular reason you need it at 0 physical? because once you are in LMode, all addresses are virtual, and are handled through paging, so... it would certainly make things easier if you didnt
Question 1) What is the best way to implement the loading of the core.elf file at physical address 0 without overwriting the boot loader. Considering the boot loader generally resides at 0x7C00 onwards and the kernel will be not more then 256 KiB including data structures. and i don't want to use the memory above 1 MiB.
simple answer:
you cant...
complicated answer:
you can...
but... its very complicated -- you would need to load the first portion (remember this cannot be done while you are in RMode -- so you must already be in PMode or LMode before loading this file), from 0-7C00, then skip 512 bytes, and load the remainder at 7E00->

but im not sure why you want to do this -- just be sure you have finished your setup before doing this -- preferably, also have finished any hardware detection
Further more i get the concept and benefits of each user thread/process to have the kernel space mapped, so that is what i will implement but..

Question 2) Do you make the whole physical memory space available to the kernel?
that depends... i dont, i have never found any reason to do so, though a lot of people disagree

many (if not most) OSes reserve a portion of the virtual address space for mapping all physical memory (assuming all physical memory will fit in the window... with systems having 2GB+ memory common... or even 4GB or more... 32bit virtual address space...)
I can map this using 2MiB pages so mapping 512 GiB will take only 16 KiB of memory.
... how?? 512GB/2MB is 256KB of pages how do you map 262,144 pages in only 65536 bytes of memory? -- that means your somehow mapping 2 pages in each bit? -- i dont see any discription of how to do that in the manuals...
User avatar
binutils
Member
Member
Posts: 214
Joined: Thu Apr 05, 2007 6:07 am

Post by binutils »

what is your hardware platform?

PS: ah nevermind, seems amd64.
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post by os64dev »

Quote:

I can map this using 2MiB pages so mapping 512 GiB will take only 16 KiB of memory.

... how?? 512GB/2MB is 256KB of pages how do you map 262,144 pages in only 65536 bytes of memory? -- that means your somehow mapping 2 pages in each bit? -- i dont see any discription of how to do that in the manuals...
You are completely right, my bad. i used multiplication instead of addition.
so i would need (3 + 4) * 4 KiB = 28 KiB of memory to address 4 GiB of pages. Newer processors of AMD support 1 GiB pages thus require even less memory.
simple answer:
you cant...
complicated answer:
you can...
but... its very complicated -- you would need to load the first portion (remember this cannot be done while you are in RMode -- so you must already be in PMode or LMode before loading this file), from 0-7C00, then skip 512 bytes, and load the remainder at 7E00->

but im not sure why you want to do this -- just be sure you have finished your setup before doing this -- preferably, also have finished any hardware detection
The reason is that i want to boot the kernel with as little memory as possible. If one day the OS goes embedded i don't want to have memory issues. I know it is rather silly but still if it is possible ...

I was thinking more in the lines of: a boot sector or 2 load a boot loader (possibly elf) at 512 KiB, which loads the kernel at physical memory zero. Giving a requirement that the whole kernel code + data cannot be more then 512 KiB, heap excluded, which seems a fair requirement.
Author of COBOS
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Post by JAAman »

I was thinking more in the lines of: a boot sector or 2 load a boot loader (possibly elf) at 512 KiB, which loads the kernel at physical memory zero. Giving a requirement that the whole kernel code + data cannot be more then 512 KiB, heap excluded, which seems a fair requirement.
this could be done, however... you must be in LMode (or at least PMode) already before loading this (therefore it would be much more complicated than a normal boot sector)
The reason is that i want to boot the kernel with as little memory as possible. If one day the OS goes embedded i don't want to have memory issues. I know it is rather silly but still if it is possible ...
the physical address of the kernel is of little (or no) consequence -- it is quite possible to load it to any physical address, since it itself uses only virtual addresses, and therefore doesnt even know what address its loaded at (of course the exception is in your memory manager -- but thats easy enough to account for, if you wish) in fact, windows doesnt even know the virtual address at boot -- both the physical address and (as of windows vista) the virtual address of the kernel are determined at boot time
Post Reply