Switching to GDT/Protected Mode - Things not printing

59 Views Asked by At

I'm trying to switch my code over to use GDT and protected mode, however I'm having an issue to where the new print.asm file isn't printing anything anymore, any help would be appreciated

I've tried debugging this for about 30 minutes and I can't really figure it out

My code: boot.asm -

[ORG 0x7C00]

jmp start

%include "boot/disk.asm"
%include "boot/print.asm"
%include "boot/gdt.asm"
%include "boot/switch.asm"

hang:
    jmp hang

start:
    xor ecx, ecx

    mov bp, 0x9000
    mov sp, bp
    mov ecx, realmsg
    call print

    xor ecx, ecx

    mov ecx, loadmsg
    call print

    xor ecx, ecx

    mov ecx, protmsg
    call print

    call switchPM

    xor ecx, ecx

    mov ecx, diskmsg
    call print

    call diskLoad
    jc diskErr

    jmp hang

done:
    ret

    realmsg db "Loading real mode...", 0x0D, 0x0A, 0
    loadmsg db "Loading OS...", 0x0D, 0x0A, 0
    diskmsg db "Loading disk sectors...", 0x0D, 0x0A, 0
    diskmsgdone db "Disk sectors loaded", 0x0D, 0x0A, 0
    diskerr db "Error loading disk sectors", 0x0D, 0x0A, 0
    protmsg db "Loading protected mode...", 0x0D, 0x0A, 0
    protmsgdone db "Protected mode loaded", 0x0D, 0x0A, 0

    times 510-($-$$) db 0
    db 0x55
    db 0xAA

[bits 32]
beginPM:
    xor ecx, ecx

    mov ecx, protmsgdone
    call print

gdt.asm -

gdtStart:
    dd 0x0
    dd 0x0

gdtCode:
    dw 0xFFFF
    dw 0x0
    db 0x0
    db 10011010b
    db 11001111b
    db 0x0

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

gdtEnd:

gdtDescriptor:
    dw gdtEnd - gdtStart - 1
    dd gdtStart

codeSeg equ gdtCode - gdtStart
dataSeg equ gdtData - gdtStart

switch.asm -

[bits 16]
switchPM:
    cli
    lgdt [gdtDescriptor]
    mov eax, cr0
    or eax, 0x1
    mov cr0, eax
    jmp codeSeg:initPM

[bits 32]
initPM:
    mov ax, dataSeg
    mov ds, ax
    mov ss, ax
    mov es, ax
    mov fs, ax
    mov gs, ax

    mov ebp, 0x90000
    mov esp, ebp

    call beginPM

print.asm -

[bits 32]

videoMemory equ 0xb8000
whiteOnBlack equ 0x0f

print:
    pusha
    mov edx, videoMemory
    mov ecx, 0
    mov ebx, whiteOnBlack

    call printString
    popa
    ret

printString:
    pusha
    mov ah, 0x0e

    .loop:
        lodsb
        cmp al, 0
        je .done
        mov [edx], ax
        add edx, 2
        jmp .loop

    .done:
        popa
        ret

disk.asm -

diskLoad:
    mov bx, 0x8000
    mov dh, 0x00
    mov dl, 0x80
    mov ch, 0x00
    mov cl, 0x02
    mov al, 0x01
    mov ah, 0x01
    int 0x13
    jc diskLoad
    ret
    
diskErr:
    xor si, si

    mov si, diskerr
    call print
    jmp hang
0

There are 0 best solutions below