OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 2:20 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Simple CD/USB boot-loader
PostPosted: Sun Jul 19, 2009 10:38 pm 
Offline

Joined: Fri Jul 17, 2009 11:16 pm
Posts: 6
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.


Top
 Profile  
 
 Post subject: Re: Simple CD/USB boot-loader
PostPosted: Sun Jul 19, 2009 11:28 pm 
Offline
Member
Member
User avatar

Joined: Thu Jun 04, 2009 5:01 pm
Posts: 168
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).

_________________
Valix is an experiment in an interpreted userspace with object-oriented and functional design patterns. Developers needed! Join #valix on irc.freenode.net


Top
 Profile  
 
 Post subject: Re: Simple CD/USB boot-loader
PostPosted: Sun Jul 19, 2009 11:36 pm 
Offline
Member
Member
User avatar

Joined: Mon Jul 06, 2009 12:55 am
Posts: 51
Location: Kamloops, BC, Canada
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.

_________________
Vancouver Canucks fan for life


Top
 Profile  
 
 Post subject: Re: Simple CD/USB boot-loader
PostPosted: Mon Jul 20, 2009 12:29 am 
Offline

Joined: Fri Jul 17, 2009 11:16 pm
Posts: 6
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:)


Top
 Profile  
 
 Post subject: Re: Simple CD/USB boot-loader
PostPosted: Mon Jul 20, 2009 1:06 am 
Offline
Member
Member
User avatar

Joined: Fri May 15, 2009 2:58 am
Posts: 120
Quote:
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"


Top
 Profile  
 
 Post subject: Re: Simple CD/USB boot-loader
PostPosted: Mon Jul 20, 2009 1:18 am 
Offline
Member
Member
User avatar

Joined: Mon Jun 15, 2009 10:01 am
Posts: 311
Location: France
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.


Attachments:
File comment: ISO-9660 boot sector.
cdfs.S [8.94 KiB]
Downloaded 879 times

_________________
"Open source seems to embrace the dark side of human nature." - Ville Turjanmaa
Top
 Profile  
 
 Post subject: Re: Simple CD/USB boot-loader
PostPosted: Mon Jul 20, 2009 3:00 am 
Offline

Joined: Fri Jul 17, 2009 11:16 pm
Posts: 6
Thank you very much all:)
Quote:
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?


Top
 Profile  
 
 Post subject: Re: Simple CD/USB boot-loader
PostPosted: Mon Jul 20, 2009 3:05 am 
Offline
Member
Member
User avatar

Joined: Fri May 15, 2009 2:58 am
Posts: 120
Quote:
real mode doesn't support operations with 32-bit registers/memory_blocks?


No, it support!


Top
 Profile  
 
 Post subject: Re: Simple CD/USB boot-loader
PostPosted: Tue Jul 21, 2009 10:18 am 
Offline
Member
Member
User avatar

Joined: Thu Jun 04, 2009 5:01 pm
Posts: 168
Quote:
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.

_________________
Valix is an experiment in an interpreted userspace with object-oriented and functional design patterns. Developers needed! Join #valix on irc.freenode.net


Top
 Profile  
 
 Post subject: Re: Simple CD/USB boot-loader
PostPosted: Tue Jul 21, 2009 10:41 am 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

xvedejas wrote:
Quote:
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

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
 Post subject: Re: Simple CD/USB boot-loader
PostPosted: Wed May 04, 2011 9:43 am 
Offline
Member
Member
User avatar

Joined: Tue Apr 20, 2010 1:11 am
Posts: 49
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#INT_13h_AH.3D42h:_Extended_Read_Sectors_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.


Top
 Profile  
 
 Post subject: Re: Simple CD/USB boot-loader
PostPosted: Wed May 04, 2011 11:17 am 
Offline
Member
Member

Joined: Sun Mar 07, 2010 2:12 am
Posts: 65
Here's an example which may be of a help.

http://board.flatassembler.net/topic.php?t=12389

Regards
Mac2004


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], JAAman, MichaelPetch and 160 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group