Assembly errors in my boot loader code

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.
Post Reply
chris

Assembly errors in my boot loader code

Post by chris »

Hi,

In the process of creating my boot loader I've come upon a few Assembly errors that I don't know how to fix. Any help would be appreciated.

[font=Courier]
pmode.s:7: error: invalid combination of opcode and operands
[/font]

Code: Select all

        mov     ss, 08000h
This one is weird. It tells me that a symbol isn't defined when I do define it. It is called before it's defined though, but I though this was OK?

[font=Courier]
pmode.s:38: error: symbol `.empty_8024_end_loop' undefined
[/font]

No idea for this one. I'm assuming the line of code it points to has nothing to do with the error.

[font=Courier]
pmode.s:180: error: phase error detected at end of assembly.
[/font]

Code: Select all

        dw 0AA55h
----

I'm also wondering what I need to do after setting the bit in cr0 for protected mode. Currently I just make a "jmp main32".

Code: Select all

BITS 32

main32:
        jmp main32
bakery2k

Re:Assembly errors in my boot loader code

Post by bakery2k »

Which assembler are you using?
Dreamsmith

Re:Assembly errors in my boot loader code

Post by Dreamsmith »

First of all, there is no such instruction on Intel processors as "move an immediate value into the SS register", thus that error. Do something like this instead:

Code: Select all

    mov ax,0x8000
    mov ss,ax
As far as your undefined reference and your phase error, you didn't list the code where you define the reference, so we can't possibly say for sure what the problem is. However, although labels can be forward referenced, equates cannot, IIRC. Is it possible that's your problem?
chris

Re:Assembly errors in my boot loader code

Post by chris »

bakery2k wrote: Which assembler are you using?
NASM. Sorry, should have mentioned that in my OP.

I fixed the first problem with Dreamsmith's solution. As for the other two, I still don't know what's going on. Here is the code:

Code: Select all

.empty_8042_loop:
        dec     cx
        jz      .empty_8024_end_loop ***

        mov     dx, 064h
        in      al, dx
        test    al, 01h
        jz      .no_output

        mov     dx, 064h
        in      al, dx
        jmp     .empty_8042_loop

.no_output:
        test    al, 02h
        jnz     .empty_8042_loop

.empty_8042_end_loop:
        pop     cx
        ret
And I don't know what to give you for the phase thing? It just points me to the last line in the boot loader, which I gave in my OP.
Dreamsmith

Re:Assembly errors in my boot loader code

Post by Dreamsmith »

chris wrote:

Code: Select all

        jz      .empty_8024_end_loop
        ...
.empty_8042_end_loop:
And I don't know what to give you for the phase thing? It just points me to the last line in the boot loader, which I gave in my OP.
Fixing the undefined reference should fix the phase error. As for the undefined reference, do you see it now? 8024 vs. 8042?
bakery2k

Re:Assembly errors in my boot loader code

Post by bakery2k »

chris wrote: I'm also wondering what I need to do after setting the bit in cr0 for protected mode. Currently I just make a "jmp main32".

Code: Select all

BITS 32

main32:
        jmp main32
You need to make a far jump, setting CS to the value for your code segment. Since you want a 32-bit jump offset from 16-bit code, you need a "jmp dword". You then need to load all of the other segment registers. Eg

Code: Select all

BITS 16

mov eax, cr0
or eax, 1
mov cr0, eax

jmp dword 0x08:main32

BITS 32

main32:

mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
chris

Re:Assembly errors in my boot loader code

Post by chris »

Dreamsmith wrote:
chris wrote:

Code: Select all

        jz      .empty_8024_end_loop
        ...
.empty_8042_end_loop:
And I don't know what to give you for the phase thing? It just points me to the last line in the boot loader, which I gave in my OP.
Fixing the undefined reference should fix the phase error. As for the undefined reference, do you see it now? 8024 vs. 8042?
Oh man, I can't beleive I missed that. I looked at those two labels hard too! Thank you Dreamsmith.

And thanks to bakery2k for the others :)
Post Reply