最簡單的操作系統


運行於虛擬機
彙編風格:NASM

org 0x7c00
jmp begin_real_mode

boot_msg:db "Load boot..."
pm_msg:db "go to protected mode..."
 
printmsg:
mov ax,0x1301; Service number
mov dx,0; Sursor position
mov bx,0xA; Green Color
int 0x10
ret
clrscr:
mov ax,0x0600
mov cx,0
mov dx,0x174f
mov bh,0
int 0x10
ret
getkey:
mov ah,0x00
int 0x16
ret

[BITS 16]
begin_real_mode:
mov ax,cs
mov ds,ax
mov ss,ax
mov es,ax
mov sp,0x100

call clrscr
mov bp,boot_msg
mov cx,12D
call printmsg
call getkey
call clrscr
mov bp,pm_msg
mov cx,23D
call printmsg
call getkey
call clrscr
 
cli
lgdt [ gdtr ]
mov eax,cr0
or al,0x01
mov cr0,eax
jmp codesel:begin_proected_mode
[BITS 32]
begin_proected_mode:
mov ax,datasel
mov ds,ax
mov es,ax
mov ax,videosel
mov gs,ax
mov word [gs:0],0x0A41 
mov word [gs:2],0x0A42 
mov word [gs:4],0x0A43 
mov word [gs:6],0x0A44
  
jmp $
[BITS 16]

gdtr
dw gdt_end - gdt - 1
dd gdt
gdt
nullselequ $-gdt
dd 0,0
codeselequ $-gdt
dw 0x0ffff; 4G
dw 0x0000
db 0x00
db 0x09a
db 0x0cf
db 0x00
dataselequ$-gdt
dw 0x0ffff; 4G 
dw 0x0000
db 0x00
db 0x092
db 0x0cf
db 0x00
videoselequ $-gdt
dw 3999; 80 cols * 25 * rows * 2bytes - 1
dw 0x8000
db 0x0b
db 0x92
db 0x00
db 0x00
gdt_end


times 510-($-$$) db 0
dw 0xAA55
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章