load volume boot sector

Programming, for all ages and all languages.
Post Reply
hojjatrakhshani
Posts: 21
Joined: Sun Feb 19, 2012 7:25 am

load volume boot sector

Post by hojjatrakhshani »

hi :D
i want to read first volume boot sector from master boot record and i write below code,test it in virtual pc but it dosent work.why? :(
load at 0000:0x7C00
thank for your help

Code: Select all

READACTIVE:
MOV DI,0x9
RETRY:
XOR     AX,AX
INT 13
XOR      AX,AX
MOV     ES,AX
MOV     SI,07BEh
LODSB
MOV     DL,AL
LODSB
MOV DH,AL
LODSB
MOV     CL,AL
LODSB
MOV     CH,AL
MOV     BX,0x7c00	
MOV     AH,02h 
MOV     AL,01h 
INT     13
DEC DI
JNZ RETRY
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: load volume boot sector

Post by bluemoon »

1. Your DS is not initialized and you do LODSB, are you sure?
2. You tell BIOS to read into 7c00, the BIOS will happily overwrite your code.
3. BIOS call's result is not checked but you just re-read it 9 times.
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: load volume boot sector

Post by Combuster »

Code: Select all

int 0x0D ; Do not call disk functions 
"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 ]
Rudster816
Member
Member
Posts: 141
Joined: Thu Jun 17, 2010 2:36 am

Re: load volume boot sector

Post by Rudster816 »

Combuster wrote:

Code: Select all

int 0x0D ; Do not call disk functions 
To be slightly less cryptic, the INT 13's need to be INT 0x13's.
hojjatrakhshani
Posts: 21
Joined: Sun Feb 19, 2012 7:25 am

Re: load volume boot sector

Post by hojjatrakhshani »

thank for your comment?
You tell BIOS to read into 7c00, the BIOS will happily overwrite your code
i reallocate my boot loader
this is complete sorce code
To be slightly less cryptic, the INT 13's need to be INT 0x13's.
i use INT 0x13 and result have been changed.now it is read diffrent content but it is false

Code: Select all

bits	16						
org	0x7c00						
start:	jmp	main					
;print something
Print:
			lodsb				
			or	al, al			
			jz	PrintDone		
			mov	ah, 0eh			
			int	10h
			jmp	Print			
	PrintDone:
			ret				
;this is program entry			
main:
;adjust our segments
    cli						
    xor ax,ax			
    mov     ds, ax
    mov     es, ax
    mov     fs, ax
    mov     gs, ax
    sti
;display message	
mov AH,06H 
mov AL,00H 
mov BH,1FH 
mov CX,0000 
mov DX,184FH 
INT 10H 
mov si,msgLoading
call Print
;move our programe to new entry
mov si,0x7c00
xor ax,ax
push ax
pop es
mov di,0x0600
MOV CX,0100h
REPNZ
MOVSW
;far jmp to new location
JMP     0000:0x0642
nop
nop
;adjust our segment
    cli						
    xor ax,ax			
    mov     ds, ax
    mov     es, ax
    mov     fs, ax
    mov     gs, ax
;set our stack
    mov     ax, 0x0000				
    mov     ss, ax
    mov     sp, 0xFFFF
;try to load active partiotion
READACTIVE:
MOV DI,0x9
RETRY:
XOR     AX,AX
INT 13
XOR     AX,AX
MOV     ES,AX
MOV     SI,07BEh
LODSB
MOV     DL,AL
LODSB
MOV DH,AL
LODSB
MOV     CL,AL
LODSB
MOV     CH,AL
MOV     BX,0x7c00	
MOV     AH,02h 
MOV     AL,01h 
INT     13
DEC DI
JNZ RETRY
MOV DI,0x200
MOV SI,0x7c00
CALL PRIM
jmp done
;for test our memory content
PRIM:
PUSHA
MOV CX,DI
MOV AX,SI
.LOOPM:
lodsb
mov dl,al
mov BX,table 
SHR AL, 4    
XLAT         
MOV AH, 0Eh  
INT 10h
MOV AL, DL
AND AL, 0Fh  
XLAT             
MOV AH, 0Eh  
INT 10h
dec cx
jnz .LOOPM
POPA 
RET
;for test our register content
PRIR:
PUSHA
MOV DL,AL
mov BX,table 
SHR AL, 4    
XLAT         
MOV AH, 0Eh  
INT 10h
MOV AL,DL
AND AL, 0Fh  
XLAT             
MOV AH, 0Eh  
INT 10h
POPA 
RET
done:
hlt
jmp done
;************************************
table DB '0123456789ABCDEF'
msgLoadin  db 0x0D, 0x0A, "ok thats right!", 0x0D, 0x0A, 0x00 
msgLoading  db 0x0D, 0x0A, "Boot Loader Start Please Choose One Active Parttiotion", 0x0D,0x0A,0x00  
          TIMES 446-($-$$) DB 0
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: load volume boot sector

Post by Solar »

I don't understand much ASM, but...
hojjatrakhshani wrote:JMP 0000:0x0642
...that's the point where I lost any trust in the code.

Jumping to a hardcoded address? Really?
Every good solution is obvious once you've found it.
User avatar
Yoda
Member
Member
Posts: 255
Joined: Tue Mar 09, 2010 8:57 am
Location: Moscow, Russia

Re: load volume boot sector

Post by Yoda »

Solar is right in a neighbour topic: newcomers shouldn't even try to do something with MBR code, since it is not a part of any particular OS. Use any other ready MBR.

hojjatrakhshani,
If you plan to develop your own OS you don't need to start from booting. Try ready-to-use tools, for example this and start directly developing kernel.
Yet Other Developer of Architecture.
OS Boot Tools.
Russian national OSDev forum.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: load volume boot sector

Post by Solar »

Just start at the Wiki (link at top of the page), and read the first couple of articles (up to and including "Bare Bones") in order of appearance.

Thoroughly.

Including the discouraging parts. (This is important.)
Every good solution is obvious once you've found it.
hojjatrakhshani
Posts: 21
Joined: Sun Feb 19, 2012 7:25 am

Re: load volume boot sector

Post by hojjatrakhshani »

i found it in this http://www.nondot.org/sabre/os/articles/TheBootProcess/
but it is very simple and not work when you have partition entry.
you can also it is picture.
Attachments
when go to crazy
when go to crazy
when it is true
when it is true
User avatar
turdus
Member
Member
Posts: 496
Joined: Tue Feb 08, 2011 1:58 pm

Re: load volume boot sector

Post by turdus »

Read this site. It has details on many MBR variants, this is for the standard (MSDOS3.3-7.0) MBR:
http://thestarman.narod.ru/asm/mbr/STDMBR.htm
Shows how to relocate and how to parse partition table to find active partition, and load it's VBR.
If you're only writing MBR to test your VBR, it's easier to use an existing MBR code (I would recommend to use it instead of writing your own).
If you plan to create a VBR code that can be used on partitionless layout as well, read the wiki, there's a tutorial on that with example code.
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re: load volume boot sector

Post by bubach »

You code still says "INT 13", which is decimal.
It should be "INT 0x13" or "INT 13h" for hexadecimal.
:roll:
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
hojjatrakhshani
Posts: 21
Joined: Sun Feb 19, 2012 7:25 am

Re: load volume boot sector

Post by hojjatrakhshani »

i use INT 13H also,it work but not in true way.i read all link it is very simple i see lot of code but dont work ?we just must load dx,cx register just it. all bootloader work in this way?but it dont work for my code. :shock:
hojjatrakhshani
Posts: 21
Joined: Sun Feb 19, 2012 7:25 am

Re: load volume boot sector

Post by hojjatrakhshani »

hi guy!i finally load windows xp with my code.thank for your helps [-o<
you can download it and load more than one.
Attachments
boo.asm
(1.57 KiB) Downloaded 50 times
Post Reply