All of us have saved a file on our computers using a programming language. If I look down through the layers of abstraction, I usually get stuck at a kernel-level call or a C-call like fwrite();
But even at this already deep level things like filesystems and location of storage are hidden from us. For example, one cannot tell on which drive a file is stored when the partition uses more than one drive, nor do you need to care which file-system is used.
This leads me to an extensive set of questions:
Imagine you are a creator of an OS running on x86_64.
You have not yet created an abstraction for working with external devices. Somebody now plugs in a device using a USB - Port.
Does this interrupt the processor or does this change a flag the OS can read? How would you make sure a routine is set up which will start communicating with the device once plugged in?
After this routine is set up, which protocols are you using to communicate with the device? Does it matter that the device is plugged in via USB, or would other ports work the same? If it does matter, how does the program know? (x86: Which assembly instructions are achieving communication with any device?)
You have now figured out that the device is indeed a hard-drive. Is communicating with every hard-drive the same? You would now like to - only for the matter of further questions - do the following: If this device contains another OS (OS-signature in boot section), start the other OS (reading), if however, the disk does not contain another OS you would like to inject your data to the disk at byte
disk_size/2
. (Writing) How would you accomplish that? (Protocol?, Assembly - Instruction?) EDIT: In my mind, a UEFI is also a tiny little OS. The boot section - in my mind - correct me if I am wrong - is a part of a hard drive where Bios or UEFI is searching the actual OS. So any OS could start another OS...
Kind regards!
Disclaimer: I am not asking for assembly code, I am asking for the mechanism in general. However, examples given in x86_64 are welcomed.