Hi,
salil_bhagurkar wrote:Hello.. I currently have my os in pmode. I need to also make it work in long mode. Is it possible that without changing much code other than paging, i can port it to long mode? Where can i get good examples for long mode?
You would need to change the paging code because long mode uses 4 levels of paging structures - PML4 (page-map level 4), PDP (page directory pointer table), PD (page directory) and PT (page table). Each of these tables is 4 KB and contains 512 entries that are 8 bytes each.
The task switch code needs to change (more registers to save/restore). There's also a few differences with interrupt handling. The code that starts processes may also need changing.
The rest of your code will mostly depend on what language it is. For high level languages you should be able to recompile the code and get it running if it was written as portable code to begin with.
For most assembly code you must change some things to suit (make any addressing 64-bit, remove "PUSHAD", "POPAD", "INC reg" and "DEC reg" instructions, etc) and you will probably want to rewrite everything to use the extra registers.
For the OS design, you may want to change some things depending how they're done now. For example, if you originally made some design decisions based on the amount of linear address space you had to work with, then you might want to redesign those parts now that the there's a huge amount of linear address space.
Also, if you've already got a 32-bit OS then you might want to add support for running 32-bit processes. This should be relatively easy (if applications never have direct access to kernel data structures and don't work with 32-bit physical addresses), but will mean having 2 different kernel APIs. The best way is to make the kernel APIs as similar as possible, so that the 32-bit kernel API is just a small layer over the 64-bit kernel functions.
@Dex: That's not the shortest "switch from real mode to long mode" code possible - you can switch directly from real mode to long mode without any intermediate 32-bit protected mode.
Cheers,
Brendan