Page 1 of 1
load volume boot sector
Posted: Wed Mar 28, 2012 10:57 am
by hojjatrakhshani
hi
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
Re: load volume boot sector
Posted: Wed Mar 28, 2012 11:08 am
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.
Re: load volume boot sector
Posted: Wed Mar 28, 2012 12:21 pm
by Combuster
Code: Select all
int 0x0D ; Do not call disk functions
Re: load volume boot sector
Posted: Wed Mar 28, 2012 6:54 pm
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.
Re: load volume boot sector
Posted: Thu Mar 29, 2012 1:08 am
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
Re: load volume boot sector
Posted: Thu Mar 29, 2012 1:37 am
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?
Re: load volume boot sector
Posted: Thu Mar 29, 2012 2:21 am
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.
Re: load volume boot sector
Posted: Thu Mar 29, 2012 2:51 am
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.)
Re: load volume boot sector
Posted: Thu Mar 29, 2012 5:37 am
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.
Re: load volume boot sector
Posted: Thu Mar 29, 2012 6:57 am
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.
Re: load volume boot sector
Posted: Thu Mar 29, 2012 9:56 am
by bubach
You code still says "INT 13", which is decimal.
It should be "INT 0x13" or "INT 13h" for hexadecimal.
Re: load volume boot sector
Posted: Thu Mar 29, 2012 2:13 pm
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.
Re: load volume boot sector
Posted: Fri Mar 30, 2012 12:25 am
by hojjatrakhshani
hi guy!i finally load windows xp with my code.thank for your helps
you can download it and load more than one.