Page 2 of 2

Re:Boot loader code

Posted: Wed May 21, 2003 3:20 am
by Pype.Clicker
np. btw, i would apologize if my rant was misunderstood. As a moderator, i don't want to scare or make anybody feel uncomfortable ... the rant was not to be taken personnally -- that's just a general feeling. I just wanted you to see what OS dev was.

Re:Boot loader code

Posted: Fri May 23, 2003 11:02 am
by manchev
beyond infinity lazy, you may be don't get it. i know that i researched the problem with the mbr and i'm sure that there is no ready solution for it so i think that i have the right to ask. if you don't like to read my questions the go for a hot d***. pype, thank you, but i want to know if you can help me with a concrete code on the procedure that moves the code. thank you again!



:manchev

Re:Boot loader code

Posted: Sat May 24, 2003 7:39 am
by tommie
Manchev....there's no need for this obscenity...I'm not a moderator, but I have seen discussions that got out of hand....learn from me...it's just aint worth it ok! I've seen postings in some newsgroups and everyone got hurt by the words....nothing is to be taken personally...yes you have the right to ask after all you're learning, but not the right to hurl abuse at others if they don't understand you or how you ask questions!!! change your approach next time and please do not throw sh*t into other people's faces just cos you couldn't handle it - not worth it! Take it from me, and learn, I'm learning about os development myself...and yes I go off and research why this/that doesn't work, and dismantle it until my brain says "Ah-haa"!
Regards,
Tommie/newbie_os_dsgnr
manchev wrote: beyond infinity lazy, you may be don't get it. i know that i researched the problem with the mbr and i'm sure that there is no ready solution for it so i think that i have the right to ask. if you don't like to read my questions the go for a hot d***. pype, thank you, but i want to know if you can help me with a concrete code on the procedure that moves the code. thank you again!



:manchev

Re:Boot loader code

Posted: Sat May 24, 2003 9:15 am
by manchev
thanks tommie. i generally agree with you but i don't like the way others talk to me. i just want information that i can't get anywhere else. thanks again!


:manchev

Re:Boot loader code

Posted: Sun May 25, 2003 3:04 am
by Pype.Clicker
okay. i'll try to make myself more clear ...

your floppy bootsector has been loaded at 0x7C00 by the BIOS and is 512 bytes wide. Unfortunately, this is precisely where you want your hard disk's MBR to be loaded ...

So you can't just load the MBR at 0x7C00, or it will overwrite the current code.

As you know (or should know) memory from 0:0x7C00 to 9000:FFFF is free for your use when booting, let's just move 512 bytes of bios bootsector to another location (say, just after it at 0x7E00)

Code: Select all

mov cx, 256
mov si,0x7C00
mov di, 0x7E00
l:
  mov ax,[si]
  mov [di],ax
  loop l
The loop may be replaced by a single rep movsb, as you could guess :D

Once this has been done, you just jmp to the new copy.

Code: Select all

jmp next+0x200
next:
And now, you're ready to load the MBR as if you were the BIOS. As i might have said earlier, you can either jmp 0x0000:0x7C00 once this is done and run the bootsector of the MBR, or start scanning the partition table entries yourself (for more information, look at the MBR description in OSRC from .:QuickLinkz:.), and find out which one is the Windows partition (comparing the type byte of the entries).

Re:Boot loader code

Posted: Sun May 25, 2003 8:56 pm
by manchev
ooooh, i'm in a full mess. i wrote it like this:

[bits 16]
[org 0]

begin:
;;;;;;;;;;;;;;;;;;;;;;;
cli
mov ax,0x9000
mov ss,ax
mov sp,0xffff
sti

mov cx, 256
mov si,0x7C00
mov di, 0x7E00
copyloop:
mov ax,[si]
mov [di],ax
loop copyloop

;;;;;;;;;;;;;;;;;;;;;;;;
mov ah,02h
mov al,01h
mov ch,00h
mov cl,01h
mov dh,00h
mov dl,80h
mov bx,0x0000
mov es,bx
mov bx,0x7C00
int 13h

jmp 0x0000:0x7C00

times 512-($-$$)-2 db 0
dw 0AA55h

but the code still doesn't work - it just hangs my computer. i guess i gone wrong again... what should i do now? thanks for your help and backup, Pype.Clicker!



:manchev

Re:Boot loader code

Posted: Mon May 26, 2003 1:09 am
by Beyond Infinity Lazy
oy, manchev, i have of course read your question. I always read the question. As for your ... hm, I don't know, heavy use of STARS, ... I take it with a grain of salt for I know I am no kind guy.

As for your code: your copy loop lacks adress increment.
you should increment both si and di by one, then move stuff, then check whether work is done. All right? Check this out. Or try out rep movsb: this automagically increments both si and di after moving stuff. REP makes movsb move stuff and increment pointers as long as a given counter(in cx) is above zero.(roughly said) and Maybe I am wring with this, then you may tell me my mistake.

Re:Boot loader code

Posted: Mon May 26, 2003 1:27 am
by Pype.Clicker
ooops again ::) seems i forgot the inc si and inc di ... this is why everyone should use movsb whenever possible :p

but as manchev forgot to jmp to the code copy, we're even :D

manchev, lemme give you an advice. If you're new to ASM programming, you should start by something you can debug. It's pretty hard to debug a bootsector because you can hardly force it to be located at 0x7C00 and have the good testing environment with classic DOS debug tools (not even talking about linux one which completely ignore 16bits programming)

now, for sure, i should've give correct copy loop, but the fact you didn't notice there was missing something in it makes me really fear you damage your system by some silly mistake. If you have a "test machine" you can crash as much as you want, this is not a problem, but if you're testing your bootsector on your main machine, please get a ASM tutorial, and study the code you want to execute carefully until you're 100% sure of what it is going to do and how and why ...

this is no threatening from me, and i'm not trying to fool you with bad code ... i may just make mistake, as everyone ... and in your situation, trusting my mistakes could be fatal.

Re:Boot loader code

Posted: Mon May 26, 2003 4:04 am
by df
i'd give up on him pype, the guy does not know what he is doing, despite all his protesting. there is only so much you can do without doing it all for him.

Re:Boot loader code

Posted: Tue May 27, 2003 11:46 am
by manchev
here's the code that works:

-----------------------------------

[bits 16]
[org 0x7C00]

cli
mov ax,0x9000
mov ss,ax
mov sp,0xffff
sti

mov ax,0x07c0
mov ds,ax
mov es,ax
cld

mov si,0
mov di,0200h
mov cx,0200h
repz movsb
jmp read + 200h

read:
mov ah,02h
mov al,01h
mov ch,00h
mov cl,01h
mov dh,00h
mov dl,80h
mov bx,0x0000
mov es,bx
mov bx,0x7C00
int 13h

jmp 0x0000:0x7C00

times 510-($-$$) db 0
dw 0AA55h

-----------------------------------

thanks for all! best regards,

:manchev