Switching to (un)real mode, reading disk and switc

2019-08-16 03:02发布

问题:

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.