BootSector 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.
User avatar
iocoder
Member
Member
Posts: 208
Joined: Sun Oct 18, 2009 5:47 pm
Libera.chat IRC: iocoder
Location: Alexandria, Egypt | Ottawa, Canada
Contact:

Re: BootSector problem

Post by iocoder »

and the program wich is loaded is this i don't think the ORG directive is correct
Hey, you have already got the answer through your mind :)

Code: Select all

[ORG 0x0000]
I am making progress i succeded in loading the other program from the sector 2 and load it
Good work man! Go on :D
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: BootSector problem

Post by Chandra »

i don't think the ORG directive is correct but what should i put there if it's loaded at 0x1000:0x0000 ?
Seriously, you've no idea how 'Real Mode' addressing works. You really need to read docs on x86 architecture.

And yes, you're right. The ORG directive isn't correct. Now, what you should specify in the ORG directive depends upon how you setup the segment registers. Note that CS:IP must point to 0x10000 because that is the physical address the jump refers to. You can specify ORG 0x10000 and then setup the segment registers to 0 or, you can specify ORG 0 and setup the segment registers to 0x1000. I won't go further than this because you really need to refer to docs that explain about segmentation, memory addressing (real mode and protected mode) and some such.

Cheers.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
opc0de
Posts: 13
Joined: Wed Jun 08, 2011 1:53 am

Re: BootSector problem

Post by opc0de »

Ok i have solved all the problems and succesefully loaded windows mbr at correct address jumped to that adress but now i get an error.It says : couldn't open drive multi(0)disk(0)rdisk(0)partition(1) this error is from NTLDR what the heck is it and how i can bypass it?
opc0de
Posts: 13
Joined: Wed Jun 08, 2011 1:53 am

Re: BootSector problem

Post by opc0de »

berkus wrote:Probably need to call windows mbr exactly in a state it expects from BIOS (e.g. boot drive in DL)
Tried that doesn't work though maybe some other registers need to be initialized
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: BootSector problem

Post by neon »

If NTLDR is being loaded from the primary boot device successfully by Windows MBR I do not see your boot loader software being the cause. If your software calls the Windows MBR in the same state your MBR was called, your work is done.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
iocoder
Member
Member
Posts: 208
Joined: Sun Oct 18, 2009 5:47 pm
Libera.chat IRC: iocoder
Location: Alexandria, Egypt | Ottawa, Canada
Contact:

Re: BootSector problem

Post by iocoder »

Tried that doesn't work though maybe some other registers need to be initialized
maybe you need to:

Code: Select all

xor bx, bx
mov es, bx
mov ds, bx
mov dl, 0x80
jmp 0x0000:0x7C00
could u try it?
opc0de
Posts: 13
Joined: Wed Jun 08, 2011 1:53 am

Re: BootSector problem

Post by opc0de »

Nope it doesn't work :( if you give me your e-mail address i will provide you the source to try to fix it if you have time. Or maybe this error is caused by vmware ? I really don't have a clue...
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: BootSector problem

Post by Combuster »

opc0de wrote:if you give me your e-mail address i will provide you the source
Why not attach directly to this thread?
"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
iocoder
Member
Member
Posts: 208
Joined: Sun Oct 18, 2009 5:47 pm
Libera.chat IRC: iocoder
Location: Alexandria, Egypt | Ottawa, Canada
Contact:

Re: BootSector problem

Post by iocoder »

opc0de wrote:Nope it doesn't work :( if you give me your e-mail address i will provide you the source to try to fix it if you have time. Or maybe this error is caused by vmware ? I really don't have a clue...
I think it is better to post your source code here in this thread to allow all of us to help you :) at all it is up to you! if you want to send me the code you can send it in a message through your User Control Panel here in OSDev, my username is: mostafazizo.
sorry i am afraid i couldn't post my e-mail address because this is not allowed in the forums.

Regards,
Mostafa Abd El-Aziz
opc0de
Posts: 13
Joined: Wed Jun 08, 2011 1:53 am

Re: BootSector problem

Post by opc0de »

Here is the code :

The boot loader part :

Code: Select all

[BITS 16]

[ORG 0x7C00] 


main:

	cli
	xor bx,bx
	mov es,bx
	mov fs,bx
	mov gs,bx
	mov ds,bx
	mov ss,bx
	mov sp,0x7C00
	sti

	MOV SI, Hello
	CALL PrintString

	MOV AH,0x03
	MOV BH,0x00
	INT 0x10
	ADD DH,2
	XOR DL,DL
	MOV AH,0x02
	XOR BH,BH
	INT 0x10 

	XOR BX,BX
ReadPass:
	MOV AH,0x00
	INT 0x16
	CMP AL,13
	JE Verify
	MOV [read+BX],AL
	PUSH BX
	CALL PrintChar
	POP BX
	INC BX
	CMP BX,6
	JE Verify
	JMP ReadPass
Verify:	
	MOV SI,read
	MOV DI,pass
	MOV CX,6
	REP CMPSB
	JNE the_end

Done:
	MOV SI,succ
	call PrintString
	MOV AH,0x02
	MOV AL,1
	MOV CH,0
	MOV CL,2
	MOV DX,0x0080 	
	MOV BX,1000h
	MOV ES, BX
	XOR BX,BX
	INT 13h
	CMP AH,0
	JNE Done
	jmp   0x1000:0x0000

the_end:
	INT 0x19

PrintChar:
	MOV AH,0x0E
	MOV BH,0x04
	MOV BL,0x10
	INT 0x10
	RET

PrintString:
        MOV AL,[SI]
	CMP AL,0
	JE theret
	INC SI
	CALL PrintChar
	JMP PrintString

theret:
	ret
	pass  db 'MUKMIK',0
	read times 7 db 0
	succ db 'Success booting...',0
	Hello db 'Enter password',0


times 510 - ($ - $$) DB 0
   dw 0xAA55
The part wich loads the original MBR at 7C00h and jumps to it

Code: Select all

[BITS 16]

[ORG 0x0000]

Start:
	
	MOV AH,0x02
	MOV AL,1
	MOV CH,0
	MOV CL,4
	MOV DX,0x0080
	MOV BX,0x0000
	MOV ES,BX
	MOV BX,0x7C00
	INT 13h
	CMP AH,0
	JNE Fail
	cli
	xor bx,bx
	mov es,bx
	mov fs,bx
	mov gs,bx
	mov dl,0x80
	mov ds,bx
	mov ss,bx
	mov sp,0x7C00
	sti
	JMP 0x0000:0x7C00

Fail:
	INT 0x19
	
times 512 - ($ - $$) DB 0
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: BootSector problem

Post by bluemoon »

I'm not familiar with NTFS but are you sure you not overwriting important data at sector 2, 3, 4, which you used to store your application?
opc0de
Posts: 13
Joined: Wed Jun 08, 2011 1:53 am

Re: BootSector problem

Post by opc0de »

I thought so at first ... but then i just overwritten sectors 2 and 4 but not the mbr and windows booted up normally... so that's not the problem
opc0de
Posts: 13
Joined: Wed Jun 08, 2011 1:53 am

Re: BootSector problem

Post by opc0de »

berkus wrote:No, usually entire first track is reserved (partitions start on track boundary).
You are way offtopic read something about MBR to refresh your memory...
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: BootSector problem

Post by Chandra »

opc0de wrote:
berkus wrote:No, usually entire first track is reserved (partitions start on track boundary).
You are way offtopic read something about MBR to refresh your memory...
I didn't find anything off-topic.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
opc0de
Posts: 13
Joined: Wed Jun 08, 2011 1:53 am

Re: BootSector problem

Post by opc0de »

Chandra wrote:
opc0de wrote:
berkus wrote:No, usually entire first track is reserved (partitions start on track boundary).
You are way offtopic read something about MBR to refresh your memory...
I didn't find anything off-topic.
It has been implemented before and should work if i use the original mbr what it has to do with the first track...anyway maybe i don't get it but if others used the same method and worked it should work for me but it's a mistake in the code.if you find it i owe you a pack of beer.cheers
Post Reply