Page 1 of 2

Assembly kernel does not work.

Posted: Thu Mar 06, 2025 5:30 pm
by core2extreme
Hello, I am having a problem where in my 32 bit assembly kernel, it stops at a black screen and a blinking cursor. And no I absolutely didnot use bios interrupts.

stage1.s: (bootloader)

Code: Select all

org 0x7c00
bits 16

cli
mov ax, 0x00
mov ds, ax
mov es, ax
mov ss, ax
mov bp, 0x7c00
mov sp, bp
sti

read:
        mov ah, 0x02
        mov al, 30
        mov ch, 0
        mov cl, 2
        mov dh, 0
        mov dl, 0x00
        mov bx, 0x8000
        int 13h
        jc err
        jmp 0x8000
print:
        lodsb
        cmp al, 0
        je done
        mov ah, 0eh
        int 10h
        jmp print
done:
        ret
err:
        mov si, errormsg
        call print
        mov ah, 0x00
        int 16h
        int 19h

errormsg: db "Error! Press any key to restart", 0
times 510-($-$$) db 0
dw 0xaa55
The bootloader definitely does work.

Kernel: (stage2.s)

Code: Select all

bits 16
org 0x8000

cli
mov ax, 0x00
mov ds, ax
mov es, ax
mov ss, ax
mov bp, 0x8000
mov sp, bp
sti
mov ah, 0x00
mov al, 0x03
int 10h

gdt_start:
        dd 0x0
        dd 0x0
gdt_code:
        dw 0xFFFF
        dw 0x0
        db 0x0
        db 0x00
        db 0x00
        db 0x00

        db 10011010b
        db 11001111b

        db 0x0
gdt_data:
        dw 0xFFFF
        dw 0x0
        db 0x0
        db 10010010b
        db 11001111b
        db 0x0

gdt_end:

gdt_descriptor:
        dw gdt_end - gdt_start - 1
        dd gdt_start

CODE_SEG equ gdt_code - gdt_start
DATA_SEG equ gdt_data - gdt_start

cli
lgdt [gdt_descriptor]
mov eax, cr0
or eax, 1
mov cr0, eax
jmp dword CODE_SEG:_pmode


[bits 32]
_pmode:
        mov ax, DATA_SEG
        mov ds, ax
        mov es, ax
        mov fs, ax
        mov gs, ax
        mov ss, ax                                                                                                                                                                       mov ebp, 0x100000
        mov esp, ebp
        in al, 0x92
        or al, 2
        out 0x92, al
        mov dword [0xB8000], 0x07690748


        jmp $


msg: db "Welcome to TastyCrepe!", 0
times 8192-($-$$) db 0
This according to my qemu logs DOES enter text mode and protected mode, but doesn't do anything in the _pmode function (or routine i have no idea what its called in assembly).

Any help would be appreciated. :D

Re: Assembly kernel does not work.

Posted: Thu Mar 06, 2025 6:31 pm
by Octocontrabass
core2extreme wrote: Thu Mar 06, 2025 5:30 pm

Code: Select all

mov ah, 0x00
mov al, 0x03
int 10h

gdt_start:
        dd 0x0
        dd 0x0
When you put data in the middle of your code, the CPU will try to execute that data. Either put the data elsewhere or tell the CPU to execute something else.

Re: Assembly kernel does not work.

Posted: Fri Mar 07, 2025 4:56 am
by core2extreme
Octocontrabass wrote: Thu Mar 06, 2025 6:31 pm
When you put data in the middle of your code, the CPU will try to execute that data. Either put the data elsewhere or tell the CPU to execute something else.
Thanks, now I have a triple faulting kernel. :)

Re: Assembly kernel does not work.

Posted: Fri Mar 07, 2025 11:19 am
by Octocontrabass
core2extreme wrote: Fri Mar 07, 2025 4:56 amThanks, now I have a triple faulting kernel. :)
I can't see your current code, but I notice the code you posted earlier has 11 bytes in the code segment descriptor instead of 8 bytes.

Re: Assembly kernel does not work.

Posted: Fri Mar 07, 2025 11:54 am
by core2extreme
Octocontrabass wrote: Fri Mar 07, 2025 11:19 am
core2extreme wrote: Fri Mar 07, 2025 4:56 amThanks, now I have a triple faulting kernel. :)
I can't see your current code, but I notice the code you posted earlier has 11 bytes in the code segment descriptor instead of 8 bytes.
Is that good or bad?

Re: Assembly kernel does not work.

Posted: Fri Mar 07, 2025 12:45 pm
by Octocontrabass
core2extreme wrote: Fri Mar 07, 2025 11:54 amIs that good or bad?
That depends. Why did you put 11 bytes in your code segment descriptor?

Re: Assembly kernel does not work.

Posted: Fri Mar 07, 2025 1:39 pm
by core2extreme
Octocontrabass wrote: Fri Mar 07, 2025 12:45 pm
core2extreme wrote: Fri Mar 07, 2025 11:54 amIs that good or bad?
That depends. Why did you put 11 bytes in your code segment descriptor?
Because its what the guy on YouTube did 8)

Re: Assembly kernel does not work.

Posted: Fri Mar 07, 2025 4:12 pm
by Octocontrabass
core2extreme wrote: Fri Mar 07, 2025 1:39 pmBecause its what the guy on YouTube did 8)
Did the guy on YouTube explain why he did that? Did you understand his explanation? Was his explanation correct?

Re: Assembly kernel does not work.

Posted: Fri Mar 07, 2025 4:48 pm
by core2extreme
Octocontrabass wrote: Fri Mar 07, 2025 4:12 pm
core2extreme wrote: Fri Mar 07, 2025 1:39 pmBecause its what the guy on YouTube did 8)
Did the guy on YouTube explain why he did that? Did you understand his explanation? Was his explanation correct?
No, and no, but it worked for him why not for me?

Re: Assembly kernel does not work.

Posted: Fri Mar 07, 2025 4:55 pm
by MichaelPetch
Are you the one who is also posting on r/osdev here: https://www.reddit.com/r/osdev/comments ... _faulting/ . If so that code you claim has a triple fault is not the same code you are asking about here. The code on /rosdev (that I can't get to fail with the fix I suggested there) doesn't have extra bytes in the descriptors which will screw things up and this code display something to the screen and the code on r/osdev doesn't. Can you post a link to the video/tutorial that claims the extra bytes in the GDT should be there? I think you misunderstood because it is just plain wrong.

The code on r/osdev with the one fix I suggested there works for me. The code simply gets in protected mode and does nothing (but it doesn't triple fault).

Re: Assembly kernel does not work.

Posted: Fri Mar 07, 2025 5:05 pm
by Octocontrabass
core2extreme wrote: Fri Mar 07, 2025 4:48 pmNo, and no,
You shouldn't copy code if you don't understand it.
core2extreme wrote: Fri Mar 07, 2025 4:48 pmbut it worked for him why not for me?
It's probably because your code is different from his code.

Re: Assembly kernel does not work.

Posted: Fri Mar 07, 2025 5:29 pm
by core2extreme
Octocontrabass wrote: Fri Mar 07, 2025 5:05 pm
core2extreme wrote: Fri Mar 07, 2025 4:48 pmNo, and no,
You shouldn't copy code if you don't understand it.
core2extreme wrote: Fri Mar 07, 2025 4:48 pmbut it worked for him why not for me?
It's probably because your code is different from his code.
Uhh.. alright. I'll make sure to bring able to understand 0s and 1s next time.

Also, I have concluded that the GDT is NOT faulty, the far jump is. I'm gonna try jmp dword now,
and resort to.. unorthodox ways to solve this.

Re: Assembly kernel does not work.

Posted: Fri Mar 07, 2025 5:39 pm
by core2extreme
Octocontrabass wrote: Fri Mar 07, 2025 5:05 pm
core2extreme wrote: Fri Mar 07, 2025 4:48 pmNo, and no,
You shouldn't copy code if you don't understand it.
core2extreme wrote: Fri Mar 07, 2025 4:48 pmbut it worked for him why not for me?
It's probably because your code is different from his code.
Oh yeah. Just realised the problem is with my bootloader. Sorry for wasting yalls time :) :)

Re: Assembly kernel does not work.

Posted: Fri Mar 07, 2025 5:41 pm
by Octocontrabass
core2extreme wrote: Fri Mar 07, 2025 5:29 pmAlso, I have concluded that the GDT is NOT faulty, the far jump is.
How do you know the problem with the far jump isn't a faulty GDT?

Re: Assembly kernel does not work.

Posted: Fri Mar 07, 2025 5:57 pm
by core2extreme
Octocontrabass wrote: Fri Mar 07, 2025 5:41 pm
core2extreme wrote: Fri Mar 07, 2025 5:29 pmAlso, I have concluded that the GDT is NOT faulty, the far jump is.
How do you know the problem with the far jump isn't a faulty GDT?
Because the GDT loads fine and the PE bit is set fine.