Could anyone guide me to what goes wrong and why?
Code: Select all
[bits 16]
[org 0x7c00]
;- flush segments + set stack
cli
xor ax, ax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov sp, 0x9c00
jmp 0:start
start:
;- init video
mov ax, 0003h ; subroutine 00, mode 03
int 10h
;- quick enable a20
enable_a20_fv:
in al, 92h
or al, 2
out 92h, al
cli
lgdt [gdtr]
lidt [idtr]
mov eax, cr0
or al, 1 ; enable paging / PE-bit
mov cr0, eax
jmp gdt.code:main
[bits 32]
main:
mov eax, gdt.data
mov ds, ax
mov es, ax
call pic_remap
int 3h
jmp $
; FUNCTIONS
read_keyboard:
pusha
cli
in al,64h ; read status
test al,01h ;
jz read_keyboard
in al,60h ; read scancode
mov bx, ax
mov al, [bx+keymap]
;mov [key], al
mov [es:0xb8000], al
mov al,0x20 ; clear irq-buffer
out 0x20, al
sti
popa
iret
unhandled_int:
pusha
mov byte [es:0xb8000], '*'
popa
iret
pic_remap:
cli
mov al,0x11 ; put both 8259s in init mode
out 0x20,al
out 0xA0,al
mov al,0x20 ; remap pic irq0-irq7 -> int 0x20-27
out 0x21,al
mov al,0x28
out 0xA1,al ; remap pic irq8-irq15 -> int 0x28-30
mov al,4 ; icw3 pic1(master)
out 0x21,al ; bit 2=1: irq2 is the slave
mov al,2 ; icw3 pic2
out 0xA1,al ; bit 1=1: slave id is 2
mov al,1 ; icw4 to both controllers
out 0x21,al ; bit 0=1: 8086 mode
out 0xA1,al
cli
mov al,255 ; mask all irqs
out 0xa1,al
out 0x21,al
ret
; DATA SECTION
int_msg db 'unhandled interrrupt', 0
key db 0
keymap:
db 0, 0, '1','2','3','4','5','6','7','8','9','0','-','=',
db 0, 0, 'q','w','e','r','t','y','u','i','o','p','[',']',
db 0, 0, 'a','s','d','f','g','h','j','k','l',';',"'",'`',
db 0,'/','z','x','c','v','b','n','m','7','8','9',',','.',
db 0, '*'
; global descriptor tables
;--------------------------------------
gdt:
.null equ $-gdt ; 0x0
dq 0
.code equ $-gdt ; 0x8
dw 0ffffh ; limit 4 Gib
dw 0000h ; base 1-2
db 0 ; base 3
db 10011010b ; type
db 11001111b ; flags
db 0 ; base 4
.data equ $-gdt ; 0x10
dw 0ffffh ; limit 4 Gib
dw 0000h ; base 1-2
db 0 ; base 3
db 10010010b ; type
db 11001111b ; flags
db 0 ; base 4
gdt_end:
gdtr:
dw gdt_end - gdt ; size
dd gdt ; base address
idt:
; int 0 - divide error
dw unhandled_int
dw gdt.code
db 0
db 10001110b
dw 0
; int 1 - debug exception
dw unhandled_int
dw gdt.code
db 0
db 10001110b
dw 0
; int 2 - intel reserved
dw unhandled_int
dw gdt.code
db 0
db 10001110b
dw 0
; int 3 - breakpoint
dw unhandled_int
dw gdt.code
db 0
db 10001110b
dw 0
; int 4 - overflow
dw unhandled_int
dw gdt.code
db 0
db 10001110b
dw 0
; int 5 - bounds check
dw unhandled_int
dw gdt.code
db 0
db 10001110b
dw 0
; int 6 - invalid opcode
dw unhandled_int
dw gdt.code
db 0
db 10001110b
dw 0
; int 7 - coprocessor not available
dw unhandled_int
dw gdt.code
db 0
db 10001110b
dw 0
; int 8 - double fault
dw unhandled_int
dw gdt.code
db 0
db 10001110b
dw 0
; int 9 - coprocessor segment overrun
dw unhandled_int
dw gdt.code
db 0
db 10001110b
dw 0
; int A - invalid tss
dw unhandled_int
dw gdt.code
db 0
db 10001110b
dw 0
; int B - segment not present
dw unhandled_int
dw gdt.code
db 0
db 10001110b
dw 0
; int C - stack exception
dw unhandled_int
dw gdt.code
db 0
db 10001110b
dw 0
; int D - triple fault
dw unhandled_int
dw gdt.code
db 0
db 10001110b
dw 0
; int E - page fault
dw unhandled_int
dw gdt.code
db 0
db 10001110b
dw 0
; int F - intel reserved
dw unhandled_int
dw gdt.code
db 0
db 10001110b
dw 0
; int 10 - stack exception
dw unhandled_int
dw gdt.code
db 0
db 10001110b
dw 0
; int 11 - reserved
dw unhandled_int
dw gdt.code
db 0
db 10001110b
dw 0
; int 12 - reserved
dw unhandled_int
dw gdt.code
db 0
db 10001110b
dw 0
; int 13 - reserved
dw unhandled_int
dw gdt.code
db 0
db 10001110b
dw 0
; int 14 - reserved
dw unhandled_int
dw gdt.code
db 0
db 10001110b
dw 0
; int 15 - reserved
dw unhandled_int
dw gdt.code
db 0
db 10001110b
dw 0
; int 16 - reserved
dw unhandled_int
dw gdt.code
db 0
db 10001110b
dw 0
; int 17 - reserved
dw unhandled_int
dw gdt.code
db 0
db 10001110b
dw 0
; int 18 - reserved
dw unhandled_int
dw gdt.code
db 0
db 10001110b
dw 0
; int 19 - reserved
dw unhandled_int
dw gdt.code
db 0
db 10001110b
dw 0
; int 20 - reserved
dw unhandled_int
dw gdt.code
db 0
db 10001110b
dw 0
; int 21 - keyboard
dw read_keyboard
dw gdt.code
db 0
db 10001110b
dw 0
idt_end:
idtr:
dw idt_end - idt - 1
dd idt
times 510 - ($-$$) db 0
bios_signature:
db 55h
db 0AAh