How can I use assembly to read from a U disk?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
XYS
Posts: 1
Joined: Thu Feb 04, 2016 9:01 am
Libera.chat IRC: Dev-XYS

How can I use assembly to read from a U disk?

Post by XYS »

(Please do not laugh at my poor English - I am not a native English speaker, but I will try my best to avoid grammar mistakes.)

I want to make a boot loader, and my boot loader is in a U disk. After choosing "booting from USB" when starting the computer, the first sector of the U disk will be loaded in memory automatically. But the rest of the boot loader is still in the U disk, so I have to write some code so that the content in the U disk will be read into memory. I have read this page: http://wiki.osdev.org/USB. But my English is not good, so I cannot read it at all. And I think it just contains some hardware-based information, without how to read from USB by using assembly.

So, would anyone like to tell me how to use assembly to read from a U disk?
I will really appreciate it if you can give me some code.

Thank you a lot!
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: How can I use assembly to read from a U disk?

Post by BrightLight »

Depending on the first sector of your USB flash, the BIOS will emulate a floppy disk or a hard disk. If you want to emulate a hard disk, the first sector will need to have a valid MBR partition table. The BIOS will then boot your USB flash with a BIOS boot drive number 0x80 in DL.
Then, reading the USB stick is done just like a hard disk, using INT 0x13 calls. In fact, your bootloader may not even know if it's booting from USB or hard disk.
These extended functions are the standard for reading hard disk in real mode.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
Post Reply