Loading USB SecondStage Loader Problem

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
Muneer
Member
Member
Posts: 104
Joined: Tue Nov 02, 2010 2:05 am
Location: India

Loading USB SecondStage Loader Problem

Post by Muneer »

Hi,


I know this has been discussed before and I have searched through almost all the topics related to this but the problem is that i still cant get it to work.
My Pc supports USB booting ( I can load my MBR and get it to work).
But When I load the second sector and jump to it , it triple faults in real hardware ( and not in virtual box or virtual pc or Bochs).
Also my Pc boots Usb as HDD

Code: Select all

               
Load_Second_Sector:

			Mov	Ax , 0x1000		; 	Segment Address To Copy Sector
			Mov	Es , Ax	
			Xor	Bx , Bx		;	Offset Address To Copy Sector

			Mov	Ah , 2			;	Copy Sector Function
			Mov	Al , 1		         	;	Number Of Sectors to Copy
			Mov	Ch , 0			;	Track Number
			Mov	Cl , 2			        ; 	Sector Number 
			Mov	Dh , 0			;	Head Number
			mov	Dl , [BootDiskNumber]   ; Drive Number With Which Bios Was Booted
			Int 	0x13
			Ret

BootDiskNumber: db 0
Thanks In Advance
Even the smallest person could change the course of the future - Lord Of The Rings.

In the end all that matters is what you have done - Alexander.

Even after a decade oh god those still gives me the shivers.
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: Loading USB SecondStage Loader Problem

Post by Combuster »

What's with the lack of error checking?
"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
Muneer
Member
Member
Posts: 104
Joined: Tue Nov 02, 2010 2:05 am
Location: India

Re: Loading USB SecondStage Loader Problem

Post by Muneer »

This is supposed to be a basic bios call procedure . So I thought I could do without it. Does it make any difference?......
Even the smallest person could change the course of the future - Lord Of The Rings.

In the end all that matters is what you have done - Alexander.

Even after a decade oh god those still gives me the shivers.
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: Loading USB SecondStage Loader Problem

Post by Combuster »

Yes. It's called basic debugging skills.
How else do you think you can find out if the bios call is the problem? It even gives a description of the error if it has one.

(and on real hardware, you can have random read errors although for USB they should be rather unlikely)
"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
Muneer
Member
Member
Posts: 104
Joined: Tue Nov 02, 2010 2:05 am
Location: India

Re: Loading USB SecondStage Loader Problem

Post by Muneer »

Thanks . I will check and post the result
Even the smallest person could change the course of the future - Lord Of The Rings.

In the end all that matters is what you have done - Alexander.

Even after a decade oh god those still gives me the shivers.
User avatar
Muneer
Member
Member
Posts: 104
Joined: Tue Nov 02, 2010 2:05 am
Location: India

Re: Loading USB SecondStage Loader Problem

Post by Muneer »

I still cant get it to work. No Error after reading the drive.
Here is the code with Extended Functions (unlike earlier with 02 funtion)


Code: Select all

DriveRead:

Mov	Ax , 0
Mov	Ds , Ax
Mov	Si , Packet

Mov	Ah , 0x42         ;  Extended Bios Drive Read Function
Mov	Dl , [BootDiskNumber] 	; Drive Number With Which Bios Was Booted
Int	0x13
Jnc	Continue
             Call Display_Error      ;   Procedure that prints "There is Error" to screen
Continue:


			
Packet:

db 16	;	Size Of packet
db  0	;	Should Be 0
db  1 ;	Number Of Sectors To Be  Read
db  0	;	Should Be 0
dw 0	;	Offset (1000:0000)
dw 1000	;	Segment
dd  1 , 0	;	Start Of Sector To Be Read (First sector of drive has number 0)


BootDiskNumber: db 0


Can Someone post code to read the second sector from a Usb-HDD . ....
Even the smallest person could change the course of the future - Lord Of The Rings.

In the end all that matters is what you have done - Alexander.

Even after a decade oh god those still gives me the shivers.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Loading USB SecondStage Loader Problem

Post by gerryg400 »

Code: Select all

dw 1000   ;   Segment
Is that supposed to be 0x1000 ?
If a trainstation is where trains stop, what is a workstation ?
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: Loading USB SecondStage Loader Problem

Post by Combuster »

Code: Select all

Jnc	Continue
             Call Display_Error      ;   Procedure that prints "There is Error" to screen
Continue: ; continue anyway
Doesn't this qualify as "print a message then crash anyway" (especially, crash before you can see the printout)
"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
Muneer
Member
Member
Posts: 104
Joined: Tue Nov 02, 2010 2:05 am
Location: India

Re: Loading USB SecondStage Loader Problem

Post by Muneer »

Hi gerryg400,

Well you are right. That was supposed to be 0x1000. But anyways i had detected it just after posting that and the result is still the same.

Hi Combuster ,

It has a Cli and Hlt just after the code so that I can check whether the crash will print to the screen. But then It does not, So I have to take it as no error. Both the codes ( supposed to function similarly does not work out and both gives back "no error" result)

First Method:

Code: Select all

Load_Second_Sector:

         Mov   Ax , 0x1000      ;    Segment Address To Copy Sector
         Mov   Es , Ax   
         Xor   Bx , Bx      ;   Offset Address To Copy Sector

         Mov   Ah , 2         ;   Copy Sector Function
         Mov   Al , 1                  ;   Number Of Sectors to Copy
         Mov   Ch , 0         ;   Track Number
         Mov   Cl , 2                 ;    Sector Number
         Mov   Dh , 0         ;   Head Number
         mov   Dl , [BootDiskNumber]   ; Drive Number With Which Bios Was Booted
         Int    0x13
         Ret

BootDiskNumber: db 0
Second Method:

Code: Select all

DriveRead:

Mov   Ax , 0
Mov   Ds , Ax
Mov   Si , Packet

Mov   Ah , 0x42         ;  Extended Bios Drive Read Function
Mov   Dl , [BootDiskNumber]    ; Drive Number With Which Bios Was Booted
Int   0x13
Jnc   Continue
             Call Display_Error      ;   Procedure that prints "There is Error" to screen
Continue:


         
Packet:

db 16   ;   Size Of packet
db  0   ;   Should Be 0
db  1 ;   Number Of Sectors To Be  Read
db  0   ;   Should Be 0
dw 0   ;   Offset (1000:0000)
dw 0x1000   ;   Segment
dd  1 , 0   ;   Start Of Sector To Be Read (First sector of drive has number 0)


BootDiskNumber: db 0

VirtualBox when booting with Usb works all right with the first method ( I suppose it is because It emulates Usb FDD ), whereas with the second method it displays "There is Error" message as expected with my code ( May be because it doesn't emulate Usb HDD ). But in the real hardware neither causes a error ( My Pc supports only Usb HDD ) but looks as if the area to which the load was made doesn't have the value as expected.
I really cant understand what is going on.. Thabks
Even the smallest person could change the course of the future - Lord Of The Rings.

In the end all that matters is what you have done - Alexander.

Even after a decade oh god those still gives me the shivers.
Post Reply