Hello world boot loader for USB

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
User avatar
probe
Posts: 4
Joined: Wed Jan 05, 2011 12:14 am
Location: UAE

Hello world boot loader for USB

Post 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 ?
Last edited by JamesM on Wed Jan 05, 2011 7:59 am, edited 3 times in total.
Reason: Use code tags. Have you never used forum software before?
Kind regards,

Software Engineer
MSc Astrophysics
User avatar
probe
Posts: 4
Joined: Wed Jan 05, 2011 12:14 am
Location: UAE

Re: Hello world boot loader for USB

Post 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 ?
Last edited by probe on Wed Jan 05, 2011 11:33 am, edited 2 times in total.
Kind regards,

Software Engineer
MSc Astrophysics
User avatar
linuxfood
Member
Member
Posts: 38
Joined: Wed Dec 31, 2008 12:22 am

Re: Hello world boot loader for USB

Post 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.
User avatar
probe
Posts: 4
Joined: Wed Jan 05, 2011 12:14 am
Location: UAE

Re: Hello world boot loader for USB

Post by probe »

A
Last edited by probe on Wed Jan 05, 2011 3:07 am, edited 1 time in total.
Kind regards,

Software Engineer
MSc Astrophysics
User avatar
linuxfood
Member
Member
Posts: 38
Joined: Wed Dec 31, 2008 12:22 am

Re: Hello world boot loader for USB

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Hello world boot loader for USB

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: Hello world boot loader for USB

Post 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
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
M2004
Member
Member
Posts: 65
Joined: Sun Mar 07, 2010 2:12 am

Re: Hello world boot loader for USB

Post by M2004 »

Usb stick booting help can be found here:

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

Regards
Mac2004
User avatar
probe
Posts: 4
Joined: Wed Jan 05, 2011 12:14 am
Location: UAE

Re: Hello world boot loader for USB

Post 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.
Kind regards,

Software Engineer
MSc Astrophysics
User avatar
linuxfood
Member
Member
Posts: 38
Joined: Wed Dec 31, 2008 12:22 am

Re: Hello world boot loader for USB

Post by linuxfood »

Not a problem. Glad you are finding what you need.
Post Reply