assembly - Trying to return from Protected Mode to Real -
i'm trying go real mode, after protected, , processor got stuck right after changing cr0 register. i'm using nasm, , compile program binary .img run under virtualbox bootloader. i'm missing long jump realmain proc.
[org 0x7c00] ; bios boot origin [bits 16] ; 16-bit real mode jmp start ;jump start() entry-point %include "routines16.asm" [bits 16] start: mov si, welcomemsg call print call getkey call clear realmain: cli mov ax, cs mov ds, ax mov es, ax ; mov ax, stack16 ; mov ss, ax sti mov si, inrealmsg call print mov si, anykeymsg call print call getkey call toprotected toprotected: mov si, toprotectedmsg call print call clear; ;move cli lgdt [gdt32_descriptor] ; load gdt mov eax, cr0 or eax, 0x1 mov cr0, eax jmp dword code_seg_32:protectedmain ;;;;;;;;;;;;;; welcomemsg db "ipr1-degtyarev. press key start", 0x0 inrealmsg db "in real", 0x0 toprotectedmsg db "switching protected", 0x0 anykeymsg db "press key switch cpu mode...", 0x0 ;;;;;;;;;;;;;; %include "gdt32.asm" %include "routines32.asm" [bits 32] protectedmain: mov eax, data_seg_32 mov ds, eax mov es, eax mov eax, 0x0000; 0 line mov ebx, inprotectedmsg call print32 add eax, 0x00a0; moving next line call toreal toreal: mov edx, eax mov ebx, torealmsg call print32 ;move cli mov eax, cr0 dec al mov cr0, eax jmp 0x7c00:realmain end: jmp end ;;;;;;;;;;;;;; inprotectedmsg db "in protected", 0x0 torealmsg db "switching real", 0x0 ;;;;;;;;;;;;;; times 510 - ($-$$) db 0 ;fill rest of bootloader zeros dw 0xaa55 ;boot signature
attached gdt32
; descriptor config gdt32_start: gdt32_null: ; initialization null dq 0x0 gdt32_cs: dw 0xffff ; limit dw 0x0000 ; base db 0x0000 ; base 23:16 db 10011011b ; [p][dpl][][s][type][][][a] db 11011111b ; [g][x][0][avl][lim][][][] db 0x0000 gdt32_ds: dw 0xffff ; limit dw 0x0000 ; base db 0x0000 ; base 23:16 db 10010011b db 11011111b db 0x0000 gdt32_end: ; pour avoir la taille du gdt gdt32_descriptor: dw gdt32_end - gdt32_start - 1 ; gdt size dd gdt32_start ; constants address of gdt32 code_seg_32 equ gdt32_cs - gdt32_start data_seg_32 equ gdt32_ds - gdt32_start
Comments
Post a Comment