bits 16 org 0x00 jmp start_os ;these lines are the messages to be printed by our OS switching_msg db "Currently placing processor in 32-bit Protected mode...",0 done_msg db "Done with placing processor in 32-bit Protected mode. I can't believe I finally made it!!!",0 cur_char dw 0x0 ;these functions print messages on the screen in 16-bit and 32-bit mode, respectively print_ln_16: mov ah,0x0e mov bx,0x0007 .print_loop lodsb or al,al jz .done int 0x10 jmp .print_loop .done retn bits 32 print_ln_32: mov ax,video_selector mov gs,ax .print_loop: lodsb or al,al jz .done mov ah,0x07 mov word [gs:cur_char],ax inc word [cur_char] inc word [cur_char] jmp .print_loop .done: retn bits 16 start_os: mov ax,0x0050 mov ds,ax mov es,ax mov si,switching_msg call print_ln_16 cli lgdt [global_descriptor] mov eax,cr0 or al,0x01 mov cr0,eax jmp code_selector:pmode_jmp bits 32 pmode_jmp: jmp pmode_jmp mov ax,data_selector mov ds,ax mov es,ax mov ax,video_selector mov gs,ax mov word [gs:0],0x741 hang: jmp hang bits 16 global_descriptor: dw gdt_end - gdt_begin -1 ;total length of global descriptor table dd gdt_begin ;beginning of global descriptor table gdt_begin: empty_selector equ $-gdt_begin ;empty selector located at 0x0 in the table gdt_0 ;first entry is to be a null descriptor dd 0x0 ;make all the entries in dd 0x0 ;this descriptor null code_selector equ $-gdt_begin ;code selector located at 0x08 in the table gdt_code ;this entry is our code selector dw 0xFFFF ;4 Gb limit dw 0x0000 ;base is at 0x0 db 0x00 ;no actual idea what this field does db 0x9A ;this field sets the status of the segment to be executable db 0xCF ;this sets some more of those status bits db 0x00 ;no idea about this one either data_selector equ $-gdt_begin ;data selector located at 0x10 gdt_data ;this entry is the data selector dw 0xFFFF ;4 Gb limit dw 0x0000 ;base is at 0x0 db 0x00 ;still no clue about this field db 0x92 ;sets the status of the segment to be data db 0xCF ;this does God only knows what db 0x00 ;this sprinkles magic pixie dust over the whole shabang video_selector equ $-gdt_begin ;video selector at 0x18 gdt_video ;video selector dw 3999 ;this selector should have a limit of ((80*25)*2)-1 or 3999 decimal dw 0xb800 ;and should start at 0xB800, video memory db 0x00 ;no idea db 0x92 ;no idea db 0x00 ;still no idea db 0x00 ;no freakin clue gdt_end
alot of this came from the tutorial "Write your own toy os" as well. I am loading this program at 0050:0000 and I am using Microsoft Virtual PC to test it. I am assembling it using NASM. Whenever I run this code, the VM says that an unrecoverable processor error has occurred. It happens right at the switch to protected mode at the jump to clear the prefetch buffer. anyone have an idea what's wrong?


Sign In
Create Account

Back to top









