BootLoader 3

If you are new to OS Development, plan on spending some time here first before going into the other forums.

Moderator:Moderators

Post Reply
Zig
Posts:10
Joined:Fri Feb 20, 2009 11:58 pm
BootLoader 3

Post by Zig » Wed Mar 04, 2009 8:48 am

hi guys,

It seems I'm making a habit of posting a topic for every tutorial I read 8).

I have some questions for bootloader 3, could you guys help out?

1. I am trying out the demo for bootloader 3. I typed the code and try to compile to NASM, but I got an error because there are 2 [ORG] directive in the same ASM file. How else I can specify the second sector to be loaded at 0x1000 without the org directive?

2.

Code: Select all

   mov  ah, 0x02 ; read floppy sector function
   mov	al, 1	; read 1 sector
   mov	ch, 1	; we are reading the second sector past us, so its still on track 1
   mov	cl, 2	; sector to read (The second sector)
   mov	dh, 0	; head number
   mov	dl, 0	; drive number. Remember Drive 0 is floppy drive.
   int	0x13	; call BIOS - Read the sector
Are we trying to read the second sector of the floppy disc, which supposes to be the second stage boot loader right? The first sector is the first bootloader, and the second sector contains the second stage boot sector. Is it where the second stage boot loader usually stays?

Thanks

Andyhhp
Moderator
Posts:387
Joined:Tue Oct 23, 2007 10:05 am
Location:127.0.0.1
Contact:

Post by Andyhhp » Wed Mar 04, 2009 6:10 pm

I have some answers about bootloader 3 - they might help :P

1) You can only have a singe org declaration per asm file.

Therefore, you need a seporate file for the 2nd stage loader, assemble them separatly and copy them separatly to the disk.

2)Yes and No. In this case, the 2nd stage is written to the 2nd sector of the disk. However, in general, Floppy disks should use the FAT12 filesystem and the 1st stage booloader should be able to use the filesystem to load the 2nd stage. The next tutorials explain how to do this.

~Andrew
Image

Zig
Posts:10
Joined:Fri Feb 20, 2009 11:58 pm

Post by Zig » Wed Mar 04, 2009 9:08 pm

thanks again :)

ggeorgak
Posts:2
Joined:Thu May 28, 2009 1:15 am

Re: BootLoader 3

Post by ggeorgak » Thu May 28, 2009 1:18 am

Actually there is an error too on using int 0x13. Cylinders are numbered starting from 0 whereas sectors are numbered starting 1. This must be changed in the bootloaders tutorial too.

Andyhhp
Moderator
Posts:387
Joined:Tue Oct 23, 2007 10:05 am
Location:127.0.0.1
Contact:

Re: BootLoader 3

Post by Andyhhp » Thu May 28, 2009 12:28 pm

What do you mean
Cylinders are numbered starting from 0 whereas sectors are numbered starting 1
.

The CHS address scheme is defined with Heads starting from 0 while Cylinders (Tracks) and Sectors start from 1.

Are you saying that the tutorial has a mistake?

~Andrew
Image

ggeorgak
Posts:2
Joined:Thu May 28, 2009 1:15 am

Re: BootLoader 3

Post by ggeorgak » Thu May 28, 2009 11:33 pm

Actually in CHS addressing cylinders start from 0 (http://en.wikipedia.org/wiki/Cylinder-head-sector), and Heads start from 0. Just tracks start from 1.

In tutorial BootLoader 3, the code to read sector 2 from floppy is:

Code: Select all

.Read:
	mov		ah, 0x02				; function 2
	mov		al, 1					; read 1 sector
	mov		ch, 1					; we are reading the second sector past us, so its still on track 1
	mov		cl, 2					; sector to read (The second sector)
	mov		dh, 0					; head number
	mov		dl, 0					; drive number. Remember Drive 0 is floppy drive.
	int		0x13					; call BIOS - Read the sector
	jc		.Read					; Error, so try again	
The higher byte of CX, CH must be set to 0 (it is set wrongfully to 1) in order to read the first cylinder (having track 1)

You can see that this is the case also at: http://en.wikipedia.org/wiki/INT_13

Andyhhp
Moderator
Posts:387
Joined:Tue Oct 23, 2007 10:05 am
Location:127.0.0.1
Contact:

Re: BootLoader 3

Post by Andyhhp » Fri May 29, 2009 12:22 pm

Hmm

I stand corrected - you make a very good point.

Furthermore, this is a bug that appears to exists in all of the bootloader tutorials, including the algorithms for reading clusters from FAT12 sources.

Mike: any comments?

~Andrew
Image

User avatar
Mike
Site Admin
Posts:465
Joined:Sat Oct 20, 2007 7:58 pm
Contact:

Re: BootLoader 3

Post by Mike » Sat May 30, 2009 1:28 am

Hello,

It will exist in all later tutorials/demos do to the way the later tutorials build off the code from the previous demos. However this might be a bug in the initial code that has not been detected and thus still existent in the later tutorials. It will be looked at.
Lead Programmer for BrokenThorn Entertainment, Co.
Website: http://www.brokenthorn.com
Email: webmaster@brokenthorn.com

Post Reply