Hi everyone!
I feel like I've come a long way in my "quest" of creating a 16-bit toy os, since I last posted in these forums.
Currently, the problem is that my CPU encounters an error, trying to switch to protected mode, and therefore shuts down the computer.
This is my full Assembly source:

[bits 16]
[org 0x7c00]
booter:
    mov ax, 0x0000
    mov ds, ax
    mov si, bootingSystem
    call clearScreen
    call output
    mov si, switching
    call output
    call switch
clearScreen:
    mov ax, 0x0600
    mov cx, 0x0000
    mov dx, 0x174f
    mov bh, 0
    int 0x10
    ret booter
output:
    mov ah, 0x0e
    mov al, [si]
    mov bh, 0x0000
    mov bl, 0x0007
    mov dx, 0x0000
    cmp al, 0
    jz hang
    int 0x10
    inc si
    jmp output
hang:
    ret booter
switch:
    cli
    call enableA20
    lgdt[gdtr]
    mov eax, cr0
    or eax, 1
    mov cr0, eax
    jmp codeSel:protectedMode
enableA20:
    in al, 0x92
    or al, 2
    out 0x92, al
    ret
[bits 32]
protectedMode:
    mov ax, dataSel
    mov ds, ax
    mov es, ax
    mov ax, videoSel
    mov gs, ax
    mov word [gs:0], 0x741
[bits 16]
gdtr:
    dw gdtEnd-gdt-1
    dd gdt
gdt
nullSel equ $-gdt
gdt0
    dd 0
    dd 0
codeSel equ $-gdt
codeGdt
    dw 0x0ffff
    dw 0x0000
    db 0x00
    db 0x09a
    db 0x0cf
    db 0x00
dataSel equ $-gdt
dataGdt
    dw 0x0ffff
    dw 0x0000
    db 0x00
    db 0x092
    db 0x0cf
    db 0x00
videoSel equ $-gdt
    dw 3999
    dw 0x8000
    db 0x0b
    db 0x92
    db 0x00
    db 0x00
gdtEnd
bootingSystem db "Booting process started..", 0dh, 0ah, 0
switching db "Switching to protected mode..", 0dh, 0ah, 0
times 510 - ($ - $$) db 0
dw 0xaa55

By running a lot of tests, I found out that this line causes the processor error:

mov cr0, eax

In my "switch" function.
I've checked my BIOS configurations and according to them my A20 Gate is set to Fast, so I don't really understand why it won't work.

Best regards,
- Benjamin.

It doesn't matter. I found out myself.

It doesn't matter. I found out myself.

Emh... so... can u help me?
im trying to write a toy os but i cant switch to pmode!
I am booting it on a VMWare virtual machine.
What is happening is that after "mov cr0, eax" if i try to set the values in segment register the VM restarts, as a triple fault happens. My code folloew the same steps as yours, but i dont enable A20.

HELP! Please.....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.