My question is quite a bit theoretical, but I want to implement disk r/w to my Operating system, while I know how to do it in protected mode, it would take too long to implement ATAPI+ATA+FDC drivers (to make my OS boot on any device). I took two ideas to consider: Make my OS bootable only from pendrive (so I can handle only pendrive for disk r/w and it wouldn't take as much time), and jump to real mode, read sector, and jump back to protected mode. But AFAIK i have to be in conventional memory (IP can be max 65k) so CPU would crash as my kernel resides near 1MB mark. I use GRUB as bootloader and test my code in VMWare VirtualBox. My question is, should I implement USB mass memory driver or do it like DOS extenders do? If so, could you show me some code in C that for example goes back to real mode and waits for keypress, then goes back to protected mode? I can't pack data to kernel. My OS supports at the moment keyboard, advanced terminal functions and some utilities from C standard library.
Asked
Active
Viewed 584 times
0
-
2Switching to real mode to do disk IO can be done, but is problematic and if you have remapped the PIC you may have to put the original mappings back for Hard drive IRQs to be directed to the right place. You also have to change the IDT and point it back to the real mode interrupt vector table at the bottom of memory. (0x0000 to 0x03ff) Yes you can flip back to unreal mode if you set up 16-bit segment descriptors in your GDT that have a limit of 4gb rather than 64kb. Using a VM8086 task is preferable to real mode but not by much (still bad) but you can't do unreal mode in a VM8086 task. – Michael Petch Nov 25 '17 at 19:00
-
The best way is to do 32-bit protected mode drivers (and yes they take time). Win95 used VM8086 tasks to do hard drive access this way accessing the real mode BIOS. That was also responsible for the poor disk performance, the crashes, and Win95 often being unresponsive during disk reads and writes. – Michael Petch Nov 25 '17 at 19:02
-
With a VM8086 task, although you can't do unreal mode you can read data into a buffer in the first megabyte of memory and then when you switch back to protected mode you copy that buffer to its final destination which can be anywhere in addressable memory. – Michael Petch Nov 25 '17 at 19:03
-
The OSDev wiki has some information to switch back to real mode. The description of the process is good but the source code provided is only a part of the process. This isn't for the faint of heart: http://wiki.osdev.org/Real_Mode#Switching_from_Protected_Mode_to_Real_Mode – Michael Petch Nov 25 '17 at 19:05