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
memory model 64bit
Re: memory model 64bit
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 didntos64dev 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.
simple answer: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.
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
that depends... i dont, i have never found any reason to do so, though a lot of people disagreeFurther 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?
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...)
... 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...I can map this using 2MiB pages so mapping 512 GiB will take only 16 KiB of memory.
You are completely right, my bad. i used multiplication instead of addition.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...
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.
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 ...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
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
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)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.
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 timeThe 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 ...