3

I'm learning to write my own Operating System from this wonderful text (https://www.cs.bham.ac.uk/~exr/lectures/opsys/10_11/lectures/os-dev.pdf). I'm facing a weird problem upon entering 32 bit protected mode from 16 bit real mode. The code i've written is supposed to output a sentence while in 16 bit mode (using interrupts) and output a sentence again after entering 32 bit mode (by initializing the VGA memory). However, only the first sentence gets printed in qemu for some reason. Here is the relevant segments of the code:

The main boot sector code

[org 0x7c00]

    mov bp, 0x9000
    mov sp, bp

    mov bx, MSG_REAL_MODE
    call print_string
    call print_newline

    call switch_to_pm

    jmp $

    %include "print_string.asm"
    %include "gdt.asm"
    %include "print_string_pm.asm"
    %include "switch_to_pm.asm"

[bits 32]

    BEGIN_PM:

        mov ebx, MSG_PROT_MODE
        call print_string_pm

        jmp $

    MSG_REAL_MODE db "Started in 16-bit Real Mode", 0
    MSG_PROT_MODE db "Loaded 32-bit Protected Mode", 0

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

The 32 bit print function

[bits 32]

VIDEO_MEMORY equ 0xb8000
WHITE_ON_BLACK equ 0x0f

print_string_pm:
    pusha
    mov edx, VIDEO_MEMORY

print_string_pm_loop:
    mov al, [ebx]
    mov ah, WHITE_ON_BLACK

    cmp al, 0
    je print_string_pm_done

    mov [edx], ax

    add ebx, 1
    add edx, 2

    jmp print_string_pm_loop

print_string_pm_done:
    popa
    ret

The text to be printed in 32 bit mode has been stored in the register ebx.

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
  • 3
    Are you sure it isn't printed? I am guessing it is at the very top of the screen on the first line but you have missed it. This tutorial has some issues with it as they don't load the DS register so DS isn't guaranteed to be a specific value (it just happens to work in the emulators). I happen to have an SO answer with [some bootloader tips](https://stackoverflow.com/questions/32701854/boot-loader-doesnt-jump-to-kernel-code/32705076#32705076) – Michael Petch Jun 28 '20 at 17:52
  • 2
    Yes that was it actually. It was a very stupid mistake by me, the code had overwritten the qemu header text and I missed it. – P. Sai Prasanth Jun 28 '20 at 21:24
  • 2
    No worries, you aren't the first person who has made that mistake. – Michael Petch Jun 28 '20 at 21:26

0 Answers0