Page 1 of 1

Hello world boot loader for USB

Posted: Wed Jan 05, 2011 12:19 am
by probe
Hello friends,

I have read many posts on internet to write basic boot loader, like this one for example:

http://viralpatel.net/taj/tutorial/hell ... loader.php

Here is for example code that boots and display char on screen:

Code: Select all

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[BITS 16]	;Tells the assembler that its a 16 bit code
[ORG 0x7C00]	;Origin, tell the assembler that where the code will
	                ;be in memory after it is been loaded

MOV AL, 65
CALL PrintCharacter
JMP $ 		;Infinite loop, hang it here.

PrintCharacter:	;Procedure to print character on screen
;Assume that ASCII value is in register AL
MOV AH, 0x0E	;Tell BIOS that we need to print one charater on screen.
MOV BH, 0x00	;Page no.
MOV BL, 0x07	;Text attribute 0x07 is lightgrey font on black background

INT 0x10	;Call video interrupt
RET		;Return to calling procedure

TIMES 510 - ($ - $$) db 0	;Fill the rest of sector with 0
DW 0xAA55			;Add boot signature at the end of bootloader
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
The problem is that all these examples are written for booting from floppy drive,
and my intention is to write basic boot loader for USB drive, so this is probably
reason why this code does not work for USB.

Does anybody have idea or experience with this ?

Re: Hello world boot loader for USB

Posted: Wed Jan 05, 2011 12:36 am
by probe
I just found one previous post that has similar subject and the code is also provided.
This code boot from CD and without FDD emulation, anyway code begin like this:

Code: Select all

/***************************************************************/
/*
 * Features:
 *	- supports ISO-9660 filesystem ("El Torito")
 *	- supports multiples burning session
 *	- no floppy emulation
 *
 * Limitations:
 *	- supports only Joliet format
 */
	.text
	.code16

	.org 0

/*
 * This is the main function of the boot sector, which loads the OS image
 * into memory at 1000:0000.
 *
 * Parameters:
 *	DL = boot disk number.
 */
	.global	_start
_start:
	cli

	/* The BIOS has loaded our boot sector at 0000:7C00. We move the code
	   of this boot sector at 9000:0000. */
	xorw	%ax, %ax
	movw	%ax, %ds
	movw	$0x7C00, %si				/* DS:SI = 0000:7C00. */
	movw	$0x9000, %ax
	movw	%ax, %es
	xorw	%di, %di				/* ES:DI = 9000:0000. */
	movw	$0x0800, %cx				/* 2048 bytes. */
	rep
	movsb						/* do the relocation. */

	/* Jump to the new address. */
	ljmp	$0x9000, $1f
/***************************************************************/
So it seems that jump address for floppy is 7000:0000 and for CD is 9000:0000

Does anybody know what is address for USB drive ?

Re: Hello world boot loader for USB

Posted: Wed Jan 05, 2011 2:05 am
by linuxfood
Please use code tags. On first read I couldn't tell if you were even asking a question or just dumping code for no reason.

As per your question, booting from USB is done by asking the BIOS to fake/emulate it as a floppy or hard drive. Different BIOSes require different things to be present. There's a number of threads floating around here detailing quirks people have encountered. I'll trust you can use forum search or google to find them.

There is also general information on the boot process in the wiki, and someone may have transcribed the USB booting quirks there. I haven't looked, though.

Re: Hello world boot loader for USB

Posted: Wed Jan 05, 2011 2:12 am
by probe
A

Re: Hello world boot loader for USB

Posted: Wed Jan 05, 2011 2:51 am
by linuxfood
probe wrote:Why did you post here at all ?
This what you write is total zero.

Please write only if you have something connected to technical subject,
not things like "search on google" and "I can not read".
That was unnecessarily rude and confrontational. I asked you to conform to the rules of the community, and even pointed you in the right direction for your problem. What I posted was completely on topic.

Since you couldn't search the first time, I'll link you this time.

http://forum.osdev.org/viewtopic.php?f=1&t=16944 - Forum rules.

http://forum.osdev.org/viewtopic.php?t= ... hlight=usb - One of several threads discussing USB booting.

Re: Hello world boot loader for USB

Posted: Wed Jan 05, 2011 2:58 am
by Combuster
Linuxfood beat me to most of my point - it is very rude to complain to someone if you break three rules yourself (legibility, smart questions, search first)

The answer to your original question is "dl" by the way. I doubt if it's going to help you though. Ask a better question (as per above) for practice.

Re: Hello world boot loader for USB

Posted: Wed Jan 05, 2011 5:10 am
by Chandra
Hi, I am glad that you edited your post. Please cooperate. If you neglect the one who is trying to help you, it is likely that you will be neglected as well.

Regards,
Chandra

Re: Hello world boot loader for USB

Posted: Wed Jan 05, 2011 11:11 am
by M2004
Usb stick booting help can be found here:

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

Regards
Mac2004

Re: Hello world boot loader for USB

Posted: Wed Jan 05, 2011 11:32 am
by probe
Thank you mac2004 and linuxfood for very usefull links.
I am sure I will learn more from it.

Linuxfood please accept my apologise for my very uncultured post and thinking.

Re: Hello world boot loader for USB

Posted: Wed Jan 05, 2011 12:21 pm
by linuxfood
Not a problem. Glad you are finding what you need.