Page 1 of 1
Simple CD/USB boot-loader
Posted: Sun Jul 19, 2009 10:38 pm
by 0xIvan32
I never seen any CD or USB boot-loader without FDD emulation. I dont even found any documentation about how BIOS loads such devices. Can somebody show me example of this code. Im just a beginner of system programming and i just need the simpleest code that could be I most forget. Can someone explain how to interract with USB in real mode? If there is no way to boot from USB without emulation, i guess i would be at least able to read my kernel(by the way i still didnt even proected - just want to have at least a valid boot-loader) from it. As i heard, FDD makes a lot of error while reading - so procedure of load would be very paintfull for boot-loader. I cant write a fully functional boot-loader what would excepting this kind of troubles because i just studing.
PS: I have already tryed to write a FDD boot-loader - so i understand how it works, but i used only Int in it - no ports.. Can anybody recommend me a book for study a port-based device programming?
PSS: Sorry for my english, have no time yet to improve it=(
PSSS: I use FASM.
Re: Simple CD/USB boot-loader
Posted: Sun Jul 19, 2009 11:28 pm
by xvedejas
You pretty much depend on your BIOS to boot from various mediums, so you're stuck with floppy emulation. The BIOS contains a floppy driver that you call with interrupts to load a kernel or stage2 of your bootloader. Since it (probably) is impossible to write your own drivers in a bootsector to load something off a USB drive without this emulation, just forget about it. If you're writing your own bootloader, you need to use BIOS interrupts.
Now, if you're talking about USB drivers AFTER your kernel has been loaded (ie not in the bootloader) then that's a whole different story, where I recommend you start with the wiki.
Also, you mean PPS, not PSS (also PPPS, not PSSS). PS stands for "Post Scriptum" (After Writing), and PPS stands for "Post post scriptum" (after after writing).
Re: Simple CD/USB boot-loader
Posted: Sun Jul 19, 2009 11:36 pm
by Thor
xvedejas wrote:Since it (probably) is impossible to write your own drivers in a bootsector to load something off a USB drive without this emulation, just forget about it. If you're writing your own bootloader, you need to use BIOS interrupts.
I don't see any reason you can't boot from CD without emulation. It would be quite possible if all you did was load a stage 2. You wouldn't need an entire device driver either. Just one routine to load the necessary sectors into memory and you would be set.
Re: Simple CD/USB boot-loader
Posted: Mon Jul 20, 2009 12:29 am
by 0xIvan32
Thor, can you explain with more details? Maybe some articles are exist about this topic? I need a quite simple sample of that kind of boot-loader, it would be innaf to understand:) Thank you.
PS: PSS and more S - it's some kind of habit in russian segment of intrenet. We talk so only because we like this form of it:)
Re: Simple CD/USB boot-loader
Posted: Mon Jul 20, 2009 1:06 am
by kop99
Can anybody recommend me a book for study a port-based device programming?
here is related wiki.
http://wiki.osdev.org/Floppy_Disk_Controller
And related books.
"The Indispensable PC Hardware Book"
Re: Simple CD/USB boot-loader
Posted: Mon Jul 20, 2009 1:18 am
by f2
0xIvan32 wrote:Thor, can you explain with more details? Maybe some articles are exist about this topic? I need a quite simple sample of that kind of boot-loader, it would be innaf to understand:) Thank you.
PS: PSS and more S - it's some kind of habit in russian segment of intrenet. We talk so only because we like this form of it:)
Hi 0xIvan32,
You may be happy, I wrote a boot sector for CD-ROM to one of my old OS project. As the boot sector does not serve me in my current project, I will give the source of this boot sector to all those who need them.
Features:
- supports ISO-9660 filesystem ("El Torito");
- no floppy emulation;
- supports multiples burning session.
Limitations:
- supports only Joliet format.
The boot sector is written with the GAS assembler. Those who use NASM or FASM will have to translate it.
Re: Simple CD/USB boot-loader
Posted: Mon Jul 20, 2009 3:00 am
by 0xIvan32
Thank you very much all:)
movl $16, %eax
I've seen before code like this but never understand how it works? I may mistake, but if i right - real mode doesn't support operations with 32-bit registers/memory_blocks?
Re: Simple CD/USB boot-loader
Posted: Mon Jul 20, 2009 3:05 am
by kop99
real mode doesn't support operations with 32-bit registers/memory_blocks?
No, it support!
Re: Simple CD/USB boot-loader
Posted: Tue Jul 21, 2009 10:18 am
by xvedejas
I don't see any reason you can't boot from CD without emulation. It would be quite possible if all you did was load a stage 2.
Yeah, exactly; it takes emulation to load the stage 2 in the first place.
Re: Simple CD/USB boot-loader
Posted: Tue Jul 21, 2009 10:41 am
by Brendan
Hi,
xvedejas wrote:I don't see any reason you can't boot from CD without emulation. It would be quite possible if all you did was load a stage 2.
Yeah, exactly; it takes emulation to load the stage 2 in the first place.
For bootable CDs (El Torito), there's 3 different methods:
- The BIOS uses a floppy image on the CD and emulates a floppy disk for you
- The BIOS uses a hard disk image on the CD and emulates a hard disk for you
- The BIOS lets you access the CD directly (without any emulation); where you use extended disk services to read (any number of) 2048 byte sectors from a starting LBA address
I would assume that Xvedejas was talking about the third option (no emulation). In this case the boot loader can be several (2048-byte) sectors and the BIOS will load all the sectors into RAM for you - e.g. the boot loader can be up to about 512 KiB, which is more than enough for a generic ATA/ATAPI driver.
However, you'd have problems to support all CD drives: a generic ATA/ATAPI driver, plus three separate USB controller drivers (AHCI, OHCI and EHCI) and a generic mass storage device driver, plus about 30 different drivers for each type of SCSI controller, plus code to scan PCI configuration space (to figure out which drivers you *might* need to use). It adds up to far too much for a boot loader...
Cheers,
Brendan
Re: Simple CD/USB boot-loader
Posted: Wed May 04, 2011 9:43 am
by smwikipedia
f2 wrote:0xIvan32 wrote:Thor, can you explain with more details? Maybe some articles are exist about this topic? I need a quite simple sample of that kind of boot-loader, it would be innaf to understand:) Thank you.
PS: PSS and more S - it's some kind of habit in russian segment of intrenet. We talk so only because we like this form of it:)
Hi 0xIvan32,
You may be happy, I wrote a boot sector for CD-ROM to one of my old OS project. As the boot sector does not serve me in my current project, I will give the source of this boot sector to all those who need them.
Features:
- supports ISO-9660 filesystem ("El Torito");
- no floppy emulation;
- supports multiples burning session.
Limitations:
- supports only Joliet format.
The boot sector is written with the GAS assembler. Those who use NASM or FASM will have to translate it.
I roughly go through the code, it is neatly written. Basically it relies on INT 13h AH=42h: Extended Read Sectors From Drive
http://en.wikipedia.org/wiki/INT_13H#IN ... From_Drive to load data from CD.
I think we can also implement our own CD Drive driver. Anyway, if we want to use CD-ROM, we have to implement the CD Drive driver, sooner or later once we entered the Protected Mode.
However, I am not quite sure how BIOS treat the floppy boot sector and CD boot sector differently. Could anyone elabrate the details about it? Thanks.
Re: Simple CD/USB boot-loader
Posted: Wed May 04, 2011 11:17 am
by M2004
Here's an example which may be of a help.
http://board.flatassembler.net/topic.php?t=12389
Regards
Mac2004