Page 1 of 1
Bootloader doesn't get to halt instruction
Posted: Tue Mar 03, 2009 6:51 pm
by nekros
Ok, So I've been working on my bootloader lately. I tested it on qemu for the first time, and it did absolutely nothing.
I have this code at the beginning:
Code: Select all
begin:
mov sp,stackstart
push cs; THANKS TROY!
pop ds
push cs
pop es ;done setting segments
mov BYTE[drive],dl ; store the boot drive
;;;;;;;;;;;;;;;Load next 3 Sectors To complete stage1;;;;;;;;;;;;;;;;;;
mov ah,0x08
mov dl,BYTE [drive]
int 0x13 ; get drive parameters
jc FAIL ;did this faiL?
;else store info for LBA TO CHS
Really nothing here that should hold anything up. And FAIL is supposed to print a string and then hlt. (I haven't used my readsector code yet).
After that is this section of code:
Code: Select all
mov BYTE [HPC], dh ;//store heads per cylinder
mov ax,0 ;; start counter for all the bits
testandset: ; tests and sets all the sector bits in cl
bt cx,ax ; test bit
jc set ; is the bit set? if yes set it in SPT
inc ax ; if no go to next bit and test set
cmp ax,6
je continue ;if we are finished, continue with the rest of the code
jmp testandset
set:
bts WORD [SPT],ax
inc ax
cmp ax,6
je continue ;if done setting, continue
jmp testandset ;we are not done
Continue does the same thing as FAIL, I think their might be something wrong with the loop above and the loop never ends. Should I use test instead of cmp?
EDIT:
I tried using test, it doesn't change anything.
EDIT2:
I bet I'll be facepalming soon.
Re: Bootloader doesn't get to halt instruction
Posted: Tue Mar 03, 2009 7:11 pm
by Love4Boobies
Erm, why the heck don't you
instead of pushing CS twice?
And HEADS PER CYLINDER? ROFL! Dude, I'm not sure OSDev is the right thing for you
Re: Bootloader doesn't get to halt instruction
Posted: Tue Mar 03, 2009 7:17 pm
by Troy Martin
Heh, I was thinking quickly at the time (remembered the opcode, wasn't thinking "optimizations" xD)
Re: Bootloader doesn't get to halt instruction
Posted: Tue Mar 03, 2009 7:20 pm
by nekros
LBA to CHS formula I got from wikipedia. I'm going to bonafide to check if they are different...
Re: Bootloader doesn't get to halt instruction
Posted: Tue Mar 03, 2009 7:32 pm
by nekros
Wikipedia:
CYL = LBA / (HPC * SPT)
TEMP = LBA % (HPC * SPT)
HEAD = TEMP / SPT
SECT = TEMP % SPT + 1
Bonafide:
Sector = (LBA/SectorsPerTrack) Remainder value + 1
Cylinder = (LBA/SectorsPerTrack)/NumHeads (Take Remainder value)
Head = (LBA/SectorsPerTrack)/NumHeads (Take quotient value)
\
That still doesn't explain why I don't get to the print and then halt instructions.
Re: Bootloader doesn't get to halt instruction
Posted: Tue Mar 03, 2009 7:54 pm
by nekros
I'm starting to think that there is a problem with qemu. Since I switched the print string call to the start and it only prints one character.... The code for printing a string is from the babystep2 tutorial. I've used that little bit of code in the past and it worked so somethings not right here...
EDIT:
Wrong again, I tested it on real hardware...
Re: Bootloader doesn't get to halt instruction
Posted: Tue Mar 03, 2009 8:17 pm
by nekros
I now know that something is causing a halt. I tried executing the print string function twice and I only got one character. It's not the assembler (I tried nasm), what would cause a halt then?
Re: Bootloader doesn't get to halt instruction
Posted: Tue Mar 03, 2009 8:42 pm
by nekros
I found the bug, it was setting sp to stackstart. I changed it to (0x7c00-1) and it worked. I don't understand why though, so if anyone has an answer please tell me...
Re: Bootloader doesn't get to halt instruction
Posted: Tue Mar 03, 2009 8:47 pm
by JohnnyTheDon
You always need to set the stack pointer to the end of the stack, not the start.
Re: Bootloader doesn't get to halt instruction
Posted: Tue Mar 03, 2009 8:52 pm
by JohnnyTheDon
Love4Boobies wrote:Erm, why the heck don't you
instead of pushing CS twice?
And HEADS PER CYLINDER? ROFL! Dude, I'm not sure OSDev is the right thing for you
That code results in:
Code: Select all
[john@john-arch ~]$ yasm -f bin test.s
test.s:5: error: invalid combination of opcode and operands
So unless yasm sucks that bad, I don't think you get to tell him to stop doing os dev.
Re: Bootloader doesn't get to halt instruction
Posted: Tue Mar 03, 2009 8:53 pm
by nekros
I officially facepalm myself for missing that...
Oh well, back to happily coding until another facepalm...
Re: Bootloader doesn't get to halt instruction
Posted: Tue Mar 03, 2009 8:54 pm
by JohnnyTheDon
Don't worry, every time I start a bootloader I make that mistake
Re: Bootloader doesn't get to halt instruction
Posted: Tue Mar 03, 2009 9:06 pm
by Love4Boobies
I was referring to the thing with the heads per cylinder
Re: Bootloader doesn't get to halt instruction
Posted: Wed Mar 04, 2009 12:57 am
by xenos
Love4Boobies wrote:Erm, why the heck don't you
MOV ES, DS not a valid instruction. You can't move the content of one segment register into another. But this should work:
Re: Bootloader doesn't get to halt instruction
Posted: Wed Mar 04, 2009 5:50 am
by Love4Boobies
berkus wrote:Love4Boobies wrote:I was referring to the thing with the heads per cylinder
The number of heads is indeed counted per cylinder. Think for a minute what a cylinder is.
No, it's actually the other way around.