testing
This commit is contained in:
parent
ccf3ae1dd1
commit
9cb9033a25
6 changed files with 220 additions and 358 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -9,6 +9,5 @@ build.sh
|
||||||
run.bat
|
run.bat
|
||||||
.gdbinit
|
.gdbinit
|
||||||
.gdb_history
|
.gdb_history
|
||||||
link.ld
|
|
||||||
.gitignore
|
.gitignore
|
||||||
|
*.ld
|
||||||
|
|
|
||||||
24
src/bda.asm
24
src/bda.asm
|
|
@ -75,15 +75,35 @@
|
||||||
; -----------------------------------------------------------------------------------
|
; -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
; controleur clavier/souris i8042 (AT-PS/2)
|
; controleur clavier/souris i8042 (AT-PS/2)
|
||||||
%define PS2_PORT_BUFFER 0x60
|
%define i8042_PS2_DATA 0x60
|
||||||
%define PS2_PORT_CTRL 0x64
|
%define i8042_PS2_CTRL 0x64
|
||||||
|
|
||||||
; PIC 8259 ports (Programmable Interrupt Controller)
|
; PIC 8259 ports (Programmable Interrupt Controller)
|
||||||
|
; PIC 1 : Master
|
||||||
%define i8259_MASTER_CMD 0x20
|
%define i8259_MASTER_CMD 0x20
|
||||||
%define i8259_MASTER_DATA 0x21
|
%define i8259_MASTER_DATA 0x21
|
||||||
|
; PIC 2 : Slave
|
||||||
%define i8259_SLAVE_CMD 0xA0
|
%define i8259_SLAVE_CMD 0xA0
|
||||||
%define i8259_SLAVE_DATA 0xA1
|
%define i8259_SLAVE_DATA 0xA1
|
||||||
|
|
||||||
|
; i8259 Commands
|
||||||
|
%define ICW1_ICW4 0x01 ; Indicates that ICW4 will be present
|
||||||
|
%define ICW1_SINGLE 0x02 ; Single (cascade) mode
|
||||||
|
%define ICW1_INTERVAL4 0x04 ; Call address interval 4 (8)
|
||||||
|
%define ICW1_LEVEL 0x08 ; Level triggered (edge) mode
|
||||||
|
%define ICW1_INIT 0x10 ; Initialization - required!
|
||||||
|
|
||||||
|
%define ICW4_8086 0x01 ; 8086/88 (MCS-80/85) mode
|
||||||
|
%define ICW4_AUTO 0x02 ; Auto (normal) EOI
|
||||||
|
%define ICW4_BUF_SLAVE 0x08 ; Buffered mode/slave
|
||||||
|
%define ICW4_BUF_MASTER 0x0C ; Buffered mode/master
|
||||||
|
%define ICW4_SFNM 0x10 ; Special fully nested (not)
|
||||||
|
%define PIC_EOI 0x20
|
||||||
|
|
||||||
|
; Remap : IRQ0..7 -> 0x08..0x0F, IRQ8..15 -> 0x70..0x77
|
||||||
|
%define i8259_MASTER_INT 0x08
|
||||||
|
%define i8259_SLAVE_INT 0x70
|
||||||
|
|
||||||
; -----------------------------------------------------------------------------------
|
; -----------------------------------------------------------------------------------
|
||||||
; bda_setup
|
; bda_setup
|
||||||
; Initialise la BDA à zéro
|
; Initialise la BDA à zéro
|
||||||
|
|
|
||||||
81
src/boot.asm
81
src/boot.asm
|
|
@ -47,8 +47,8 @@ bits 16
|
||||||
%include "./services/macros.asm"
|
%include "./services/macros.asm"
|
||||||
%include "./drivers/debug.asm"
|
%include "./drivers/debug.asm"
|
||||||
%include "./drivers/gfx_cgam.asm"
|
%include "./drivers/gfx_cgam.asm"
|
||||||
%include "./drivers/mouse_ps2.asm"
|
;%include "./drivers/mouse_ps2.asm"
|
||||||
%include "./drivers/keyboard_ps2.asm"
|
;%include "./drivers/keyboard_ps2.asm"
|
||||||
%include "./services/generic.asm"
|
%include "./services/generic.asm"
|
||||||
|
|
||||||
err_vganok db 'VGA Not Initialized',0
|
err_vganok db 'VGA Not Initialized',0
|
||||||
|
|
@ -63,6 +63,8 @@ reset:
|
||||||
|
|
||||||
; detection de la mémoire totale
|
; detection de la mémoire totale
|
||||||
call ram_setup
|
call ram_setup
|
||||||
|
sti
|
||||||
|
|
||||||
; modification du stack en "haut" de la RAM
|
; modification du stack en "haut" de la RAM
|
||||||
mov ax, dx
|
mov ax, dx
|
||||||
sub ax, 0x0400 ; réserver les 16 dernier KB
|
sub ax, 0x0400 ; réserver les 16 dernier KB
|
||||||
|
|
@ -75,41 +77,60 @@ reset:
|
||||||
; installé une table d'interruption "dummy"
|
; installé une table d'interruption "dummy"
|
||||||
call ivt_setup
|
call ivt_setup
|
||||||
|
|
||||||
; initialisation des PIC 8259A
|
|
||||||
call pic_init
|
|
||||||
sti
|
|
||||||
|
|
||||||
; load Roms
|
; load Roms
|
||||||
call setup_load_rom
|
call setup_load_rom
|
||||||
|
|
||||||
; on vérifie que le BIOS VGA a installé une INT 10h
|
; on vérifie que le BIOS VGA a installé une INT 10h
|
||||||
call setup_check_vga
|
call setup_check_vga
|
||||||
|
|
||||||
; on active le mode graphique
|
|
||||||
; call gfx_init
|
|
||||||
|
|
||||||
call kbd_init
|
|
||||||
|
|
||||||
call mouse_reset
|
|
||||||
call mouse_init
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; on initialise le mode texte 80x25 par défaut DEBUG
|
; on initialise le mode texte 80x25 par défaut DEBUG
|
||||||
mov ax, 0x0003
|
mov ax, 0x0003
|
||||||
int 10h
|
int 10h
|
||||||
|
|
||||||
|
cli
|
||||||
|
; initialisation des PIC 8259A
|
||||||
|
call pic_init
|
||||||
|
; call kbd_init
|
||||||
|
|
||||||
|
; test IRQ 0
|
||||||
|
mov ax,cs
|
||||||
|
mov dx,ax
|
||||||
|
mov bx,test_isr
|
||||||
|
mov ax,i8259_MASTER_INT
|
||||||
|
|
||||||
|
call ivt_setvector
|
||||||
|
|
||||||
|
sti
|
||||||
|
|
||||||
|
; on active le mode graphique
|
||||||
|
; call gfx_init
|
||||||
|
|
||||||
|
;call mouse_reset
|
||||||
|
;call mouse_init
|
||||||
endless:
|
endless:
|
||||||
|
mov ax,0x0050
|
||||||
|
mov ds,ax
|
||||||
|
|
||||||
|
; in al, 0x64
|
||||||
|
; test al, 1 ; OBF
|
||||||
|
; jz .no
|
||||||
|
; in al, 0x60 ; scancode dans AL
|
||||||
|
; mov byte [0x0001],al
|
||||||
|
;.no:
|
||||||
|
|
||||||
mov dx,0
|
mov dx,0
|
||||||
call scr_gotoxy
|
call scr_gotoxy
|
||||||
|
|
||||||
mov ax,BDA_MOUSE_SEG
|
|
||||||
mov ds,ax
|
|
||||||
|
|
||||||
mov ax,0 ; adresse début dump
|
mov ax,0 ; adresse début dump
|
||||||
mov si,ax
|
mov si,ax
|
||||||
mov cx, 0x10
|
mov cx, 0x20
|
||||||
.dump:
|
.dump:
|
||||||
|
test cx,0x000F
|
||||||
|
jnz .sameline
|
||||||
|
inc dh
|
||||||
|
xor dl,dl
|
||||||
|
call scr_gotoxy
|
||||||
|
.sameline:
|
||||||
mov al,[ds:si]
|
mov al,[ds:si]
|
||||||
inc si
|
inc si
|
||||||
|
|
||||||
|
|
@ -127,6 +148,26 @@ endless:
|
||||||
|
|
||||||
jmp endless
|
jmp endless
|
||||||
|
|
||||||
|
|
||||||
|
; -----------------------------------------------------------
|
||||||
|
; Keyboard ISR (IRQ -> INT)
|
||||||
|
; -----------------------------------------------------------
|
||||||
|
test_isr:
|
||||||
|
pusha
|
||||||
|
push ds
|
||||||
|
|
||||||
|
mov ax,0x0050
|
||||||
|
mov ds,ax
|
||||||
|
inc byte [0x0005]
|
||||||
|
|
||||||
|
mov al, PIC_EOI ; EOI master
|
||||||
|
out i8259_MASTER_CMD, al
|
||||||
|
|
||||||
|
pop ds
|
||||||
|
popa
|
||||||
|
iret
|
||||||
|
|
||||||
|
|
||||||
; ------------------------------------------------------------------
|
; ------------------------------------------------------------------
|
||||||
; Padding jusqu'au reset vector
|
; Padding jusqu'au reset vector
|
||||||
; ------------------------------------------------------------------
|
; ------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -21,335 +21,127 @@
|
||||||
;
|
;
|
||||||
; =============================================================================
|
; =============================================================================
|
||||||
|
|
||||||
; -------------------------------
|
kbc_wait_in_empty:
|
||||||
; scancode set 1 -> ASCII
|
in al, i8042_PS2_CTRL
|
||||||
; index = scancode (0..0x7F)
|
test al, 0x02 ; IBF
|
||||||
; 0 = non imprimable
|
jnz kbc_wait_in_empty
|
||||||
; -------------------------------
|
|
||||||
kbd_map_nomod:
|
|
||||||
db 0,
|
|
||||||
db 27 ; 01 ESC
|
|
||||||
db '1','2','3','4','5','6','7','8','9','0','-','='
|
|
||||||
db 8 ; 0E Backspace
|
|
||||||
db 9 ; 0F Tab
|
|
||||||
db 'q','w','e','r','t','y','u','i','o','p','[',']'
|
|
||||||
db 13 ; 1C Enter
|
|
||||||
db 0 ; 1D Ctrl
|
|
||||||
db 'a','s','d','f','g','h','j','k','l',';',0x27, 0x60
|
|
||||||
db 0 ; 2A LShift
|
|
||||||
db 0x5c,'z','x','c','v','b','n','m',',','.','/'
|
|
||||||
db 0 ; 36 RShift
|
|
||||||
db '*' ; 37 keypad *
|
|
||||||
db 0 ; 38 Alt
|
|
||||||
db ' ' ; 39 Space
|
|
||||||
times (0x80-($-kbd_map_nomod)) db 0
|
|
||||||
|
|
||||||
kbd_map_shift:
|
|
||||||
db 0
|
|
||||||
db 27
|
|
||||||
db '!','@','#','$','%','^','&','*','(',')','_','+'
|
|
||||||
db 8
|
|
||||||
db 9
|
|
||||||
db 'Q','W','E','R','T','Y','U','I','O','P','{','}'
|
|
||||||
db 13
|
|
||||||
db 0
|
|
||||||
db 'A','S','D','F','G','H','J','K','L',':','"','~'
|
|
||||||
db 0
|
|
||||||
db '|','Z','X','C','V','B','N','M','<','>','?'
|
|
||||||
db 0
|
|
||||||
db '*'
|
|
||||||
db 0
|
|
||||||
db ' '
|
|
||||||
times (0x80-($-kbd_map_shift)) db 0
|
|
||||||
|
|
||||||
; -----------------------------------------------------------
|
|
||||||
; Vérifie si une touche est disponible dans le buffer clavier
|
|
||||||
; Retour: CF=0 si une touche est dispo, CF=1 sinon
|
|
||||||
; -----------------------------------------------------------
|
|
||||||
kbd_kbhit:
|
|
||||||
push ds
|
|
||||||
mov ax, BDA_SEGMENT
|
|
||||||
mov ds, ax
|
|
||||||
mov al, [BDA_KBD_HEAD]
|
|
||||||
cmp al, [BDA_KBD_TAIL]
|
|
||||||
pop ds
|
|
||||||
je .empty
|
|
||||||
clc
|
|
||||||
ret
|
|
||||||
.empty:
|
|
||||||
stc
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; -----------------------------------------------------------
|
kbc_wait_out_full:
|
||||||
; Lit un caractère du buffer clavier (make+ascii)
|
in al, i8042_PS2_CTRL
|
||||||
; Retour: CF=0 si une touche est dispo, AX=word (scancode<<8 | ascii)
|
test al, 0x01 ; OBF
|
||||||
; CF=1 si aucune touche disponible
|
jz kbc_wait_out_full
|
||||||
; -----------------------------------------------------------
|
|
||||||
kbd_poll:
|
|
||||||
push ds
|
|
||||||
mov ax, BDA_SEGMENT
|
|
||||||
mov ds, ax
|
|
||||||
call kbd_buf_pop
|
|
||||||
pop ds
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; -----------------------------------------------------------
|
kbc_flush_output:
|
||||||
; Lit un caractère du buffer clavier (make+ascii)
|
in al, i8042_PS2_CTRL
|
||||||
; Bloque jusqu'à ce qu'une touche soit disponible
|
test al, 0x01 ; OBF ?
|
||||||
; Retour: AX=word (scancode<<8 | ascii)
|
jz .done
|
||||||
; -----------------------------------------------------------
|
in al, i8042_PS2_DATA; jette la donnée
|
||||||
kbd_getch:
|
jmp kbc_flush_output
|
||||||
.wait:
|
.done:
|
||||||
call kbd_poll
|
|
||||||
jc .wait
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; -----------------------------------------------------------
|
|
||||||
; Met à jour les modifiers sur make code
|
kbc_read_cmdbyte:
|
||||||
; -----------------------------------------------------------
|
call kbc_wait_in_empty
|
||||||
|
mov al, 0x20
|
||||||
|
out i8042_PS2_CTRL, al
|
||||||
|
call kbc_wait_out_full
|
||||||
|
in al, i8042_PS2_DATA
|
||||||
|
ret
|
||||||
|
|
||||||
|
kbc_write_cmdbyte:
|
||||||
|
; entrée: AL = nouveau command byte
|
||||||
|
push ax
|
||||||
|
call kbc_wait_in_empty
|
||||||
|
mov al, 0x60
|
||||||
|
out i8042_PS2_CTRL, al
|
||||||
|
call kbc_wait_in_empty
|
||||||
|
pop ax
|
||||||
|
out i8042_PS2_DATA, al
|
||||||
|
ret
|
||||||
kbd_init:
|
kbd_init:
|
||||||
push ds
|
push ds
|
||||||
push ax
|
push ax
|
||||||
|
|
||||||
|
; gestion du buffer clavier
|
||||||
mov ax, BDA_SEGMENT
|
mov ax, BDA_SEGMENT
|
||||||
mov ds, ax
|
mov ds, ax
|
||||||
mov byte [BDA_KBD_HEAD], 0
|
mov byte [BDA_KBD_HEAD], 0
|
||||||
mov byte [BDA_KBD_TAIL], 0
|
mov byte [BDA_KBD_TAIL], 0
|
||||||
mov byte [BDA_KBD_FLAGS], 0
|
mov byte [BDA_KBD_FLAGS], 0
|
||||||
|
|
||||||
; installer INT 09h = IRQ1
|
|
||||||
cli
|
cli
|
||||||
xor ax, ax
|
|
||||||
|
; call kbc_wait_in_empty
|
||||||
|
; mov al, 0x20
|
||||||
|
; out i8042_PS2_CTRL, al
|
||||||
|
;
|
||||||
|
; call kbc_wait_out_full
|
||||||
|
; in al, i8042_PS2_DATA ; AL = command byte
|
||||||
|
;
|
||||||
|
; or al, 0x01 ; bit0: enable IRQ1
|
||||||
|
; and al, 0xEF ; bit4: 0 = keyboard enabled
|
||||||
|
;
|
||||||
|
; mov ah, al ; save new cmd byte
|
||||||
|
;
|
||||||
|
; ; write command byte
|
||||||
|
; call kbc_wait_in_empty
|
||||||
|
; mov al, 0x60
|
||||||
|
; out i8042_PS2_CTRL, al
|
||||||
|
;
|
||||||
|
; call kbc_wait_in_empty
|
||||||
|
; mov al, ah
|
||||||
|
; out i8042_PS2_DATA, al
|
||||||
|
;
|
||||||
|
; ; unmask IRQ1 & IRQ2 (master bit 1 & 2 = 0) bit 1 = IRQ 1
|
||||||
|
; in al, i8259_MASTER_DATA
|
||||||
|
; and al, 0xF9 ; 11111001b
|
||||||
|
; out i8259_MASTER_DATA, al
|
||||||
|
|
||||||
|
; setup Interrupt Table
|
||||||
|
; installer IRQ1 : MASTER_OFFSET + 1
|
||||||
|
mov ax, i8259_MASTER_INT ; base offset IRQ0
|
||||||
|
inc ax ; IRQ 1
|
||||||
|
shl ax,2 ; vect * 4
|
||||||
|
mov si, ax
|
||||||
|
|
||||||
|
xor ax, ax ; segment 0x0000
|
||||||
mov ds, ax
|
mov ds, ax
|
||||||
mov si, 0x09*4
|
|
||||||
mov word [ds:si], kbd_isr
|
mov word [ds:si], kbd_isr
|
||||||
mov ax, cs
|
mov ax, cs
|
||||||
mov word [ds:si+2], ax
|
mov word [ds:si+2], ax
|
||||||
sti
|
|
||||||
|
|
||||||
; unmask IRQ1 (master bit1 = 0)
|
mov si, 0x09*4
|
||||||
in al, i8259_MASTER_DATA
|
xor ax, ax
|
||||||
and al, 0xFD
|
mov ds, ax
|
||||||
out i8259_MASTER_DATA, al
|
mov word [ds:si], kbd_isr
|
||||||
|
mov ax, cs
|
||||||
|
mov word [ds:si+2], ax
|
||||||
|
|
||||||
|
sti
|
||||||
|
|
||||||
pop ax
|
pop ax
|
||||||
pop ds
|
pop ds
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; -----------------------------------------------------------
|
; -----------------------------------------------------------
|
||||||
; Met à jour les modifiers sur make code
|
; Keyboard ISR (IRQ -> INT)
|
||||||
; Entrée: AL = scancode (sans bit7)
|
|
||||||
; -----------------------------------------------------------
|
|
||||||
kbd_buf_push:
|
|
||||||
; In: AX = word à pousser
|
|
||||||
; DS = 0x40
|
|
||||||
push bx
|
|
||||||
push di
|
|
||||||
|
|
||||||
mov bl, [BDA_KBD_HEAD]
|
|
||||||
mov bh, [BDA_KBD_TAIL]
|
|
||||||
|
|
||||||
; next_head = (head+1) & MASK
|
|
||||||
mov dl, bl
|
|
||||||
inc dl
|
|
||||||
and dl, KBD_BUF_MASK
|
|
||||||
|
|
||||||
; si next_head == tail => buffer plein => drop
|
|
||||||
cmp dl, bh
|
|
||||||
je .full
|
|
||||||
|
|
||||||
; écrire à BUF[head]
|
|
||||||
; offset = BDA_KBD_BUF + head*2
|
|
||||||
xor bh, bh
|
|
||||||
mov di, bx
|
|
||||||
shl di, 1
|
|
||||||
add di, BDA_KBD_BUF
|
|
||||||
mov [di], ax
|
|
||||||
|
|
||||||
; head = next_head
|
|
||||||
mov [BDA_KBD_HEAD], dl
|
|
||||||
.full:
|
|
||||||
pop di
|
|
||||||
pop bx
|
|
||||||
ret
|
|
||||||
|
|
||||||
; -----------------------------------------------------------
|
|
||||||
; pop un word du buffer clavier (circulaire)
|
|
||||||
; -----------------------------------------------------------
|
|
||||||
kbd_buf_pop:
|
|
||||||
; Out: CF=1 si vide, sinon AX=word, CF=0
|
|
||||||
; DS=0x40
|
|
||||||
push bx
|
|
||||||
push di
|
|
||||||
|
|
||||||
mov bl, [BDA_KBD_HEAD]
|
|
||||||
mov bh, [BDA_KBD_TAIL]
|
|
||||||
cmp bl, bh
|
|
||||||
je .empty
|
|
||||||
|
|
||||||
; lire BUF[tail]
|
|
||||||
xor bh, bh
|
|
||||||
mov di, bx
|
|
||||||
shl di, 1
|
|
||||||
add di, BDA_KBD_BUF
|
|
||||||
mov ax, [di]
|
|
||||||
|
|
||||||
; tail = (tail+1) & MASK
|
|
||||||
inc bh
|
|
||||||
and bh, KBD_BUF_MASK
|
|
||||||
mov [BDA_KBD_TAIL], bh
|
|
||||||
|
|
||||||
clc
|
|
||||||
pop di
|
|
||||||
pop bx
|
|
||||||
ret
|
|
||||||
.empty:
|
|
||||||
stc
|
|
||||||
pop di
|
|
||||||
pop bx
|
|
||||||
ret
|
|
||||||
|
|
||||||
; -----------------------------------------------------------
|
|
||||||
; Keyboard ISR (INT 09h)
|
|
||||||
; -----------------------------------------------------------
|
; -----------------------------------------------------------
|
||||||
kbd_isr:
|
kbd_isr:
|
||||||
pusha
|
|
||||||
|
|
||||||
in al, 0x60 ; consomme scancode (obligatoire)
|
|
||||||
|
|
||||||
mov dx, 0x00E9 ; debugcon
|
|
||||||
mov al, '*'
|
|
||||||
out dx, al
|
|
||||||
|
|
||||||
mov al, 0x20 ; EOI master
|
|
||||||
out 0x20, al
|
|
||||||
|
|
||||||
popa
|
|
||||||
iret
|
|
||||||
|
|
||||||
|
|
||||||
; kbd_isr:
|
|
||||||
push ds
|
|
||||||
pusha
|
pusha
|
||||||
|
push ds
|
||||||
|
|
||||||
mov ax, BDA_SEGMENT
|
in al, 0x60 ; consomme scancode (obligatoire)
|
||||||
mov ds, ax
|
|
||||||
|
|
||||||
in al, PS2_PORT_BUFFER
|
mov ax,0x0050
|
||||||
cmp al, 0xE0
|
mov ds,ax
|
||||||
jne .sc
|
inc byte [0x0000]
|
||||||
or byte [BDA_KBD_FLAGS], 0x10
|
|
||||||
jmp .eoi
|
|
||||||
|
|
||||||
.sc:
|
mov al, PIC_EOI ; EOI master
|
||||||
mov bl, al
|
out i8259_MASTER_CMD, al
|
||||||
|
|
||||||
test bl, 0x80
|
pop ds
|
||||||
jz .make
|
|
||||||
and bl, 0x7F
|
|
||||||
mov al, bl
|
|
||||||
call kbd_update_modifiers_break
|
|
||||||
jmp .clear_eoi
|
|
||||||
|
|
||||||
.make:
|
|
||||||
mov al, bl
|
|
||||||
call kbd_update_modifiers_make
|
|
||||||
|
|
||||||
; filtrer modifiers (ne push pas)
|
|
||||||
cmp bl, 0x2A
|
|
||||||
je .clear_eoi
|
|
||||||
cmp bl, 0x36
|
|
||||||
je .clear_eoi
|
|
||||||
cmp bl, 0x1D
|
|
||||||
je .clear_eoi
|
|
||||||
cmp bl, 0x38
|
|
||||||
je .clear_eoi
|
|
||||||
cmp bl, 0x3A
|
|
||||||
je .clear_eoi
|
|
||||||
|
|
||||||
; scancode -> ASCII
|
|
||||||
mov al, bl
|
|
||||||
xor bh, bh
|
|
||||||
test byte [BDA_KBD_FLAGS], 0x01
|
|
||||||
jz .nomod
|
|
||||||
mov si, kbd_map_shift
|
|
||||||
jmp .doxlat
|
|
||||||
.nomod:
|
|
||||||
mov si, kbd_map_nomod
|
|
||||||
.doxlat:
|
|
||||||
; XLAT uses DS:BX, so set BX = scancode and DS points to table.
|
|
||||||
; On ne veut pas changer DS=0x40. Donc on ne peut pas XLAT directement ici.
|
|
||||||
; => on fait un accès indexé.
|
|
||||||
; AL = [CS:SI + scancode]
|
|
||||||
push ds
|
|
||||||
mov ax, cs
|
|
||||||
mov ds, ax
|
|
||||||
xor ah, ah
|
|
||||||
mov di, si
|
|
||||||
add di, bx
|
|
||||||
mov al, [di]
|
|
||||||
pop ds
|
|
||||||
|
|
||||||
; AX = (scancode<<8) | ascii
|
|
||||||
mov ah, bl
|
|
||||||
call kbd_buf_push
|
|
||||||
|
|
||||||
.clear_eoi:
|
|
||||||
and byte [BDA_KBD_FLAGS], 0xEF ; clear ext
|
|
||||||
.eoi:
|
|
||||||
mov al, i8259_MASTER_CMD
|
|
||||||
out i8259_MASTER_CMD, al
|
|
||||||
popa
|
popa
|
||||||
pop ds
|
iret
|
||||||
iret
|
|
||||||
|
|
||||||
; -----------------------------------------------------------
|
|
||||||
; Met à jour les modifiers sur make code
|
|
||||||
; Entrée: AL = scancode (sans bit7)
|
|
||||||
; -----------------------------------------------------------
|
|
||||||
kbd_update_modifiers_make:
|
|
||||||
; AL = scancode (make)
|
|
||||||
cmp al, 0x2A
|
|
||||||
je .shift_on
|
|
||||||
cmp al, 0x36
|
|
||||||
je .shift_on
|
|
||||||
cmp al, 0x1D
|
|
||||||
je .ctrl_on
|
|
||||||
cmp al, 0x38
|
|
||||||
je .alt_on
|
|
||||||
cmp al, 0x3A
|
|
||||||
je .caps_toggle
|
|
||||||
ret
|
|
||||||
.shift_on:
|
|
||||||
or byte [BDA_KBD_FLAGS], 0x01
|
|
||||||
ret
|
|
||||||
.ctrl_on:
|
|
||||||
or byte [BDA_KBD_FLAGS], 0x02
|
|
||||||
ret
|
|
||||||
.alt_on:
|
|
||||||
or byte [BDA_KBD_FLAGS], 0x04
|
|
||||||
ret
|
|
||||||
.caps_toggle:
|
|
||||||
xor byte [BDA_KBD_FLAGS], 0x08
|
|
||||||
ret
|
|
||||||
|
|
||||||
kbd_update_modifiers_break:
|
|
||||||
; AL = scancode (break)
|
|
||||||
cmp al, 0x2A
|
|
||||||
je .shift_off
|
|
||||||
cmp al, 0x36
|
|
||||||
je .shift_off
|
|
||||||
cmp al, 0x1D
|
|
||||||
je .ctrl_off
|
|
||||||
cmp al, 0x38
|
|
||||||
je .alt_off
|
|
||||||
ret
|
|
||||||
.shift_off:
|
|
||||||
and byte [BDA_KBD_FLAGS], 0xFE
|
|
||||||
ret
|
|
||||||
.ctrl_off:
|
|
||||||
and byte [BDA_KBD_FLAGS], 0xFD
|
|
||||||
ret
|
|
||||||
.alt_off:
|
|
||||||
and byte [BDA_KBD_FLAGS], 0xFB
|
|
||||||
ret
|
|
||||||
|
|
@ -118,12 +118,12 @@ mouse_init:
|
||||||
; Activer le port souris (AUX)
|
; Activer le port souris (AUX)
|
||||||
call ps2_wait_ready_write
|
call ps2_wait_ready_write
|
||||||
mov al, I8042_CMD_EN_AUX
|
mov al, I8042_CMD_EN_AUX
|
||||||
out PS2_PORT_CTRL, al
|
out i8042_PS2_CTRL, al
|
||||||
|
|
||||||
; Lire command byte
|
; Lire command byte
|
||||||
call ps2_wait_ready_write
|
call ps2_wait_ready_write
|
||||||
mov al, I8042_CMD_RD_CBYTE
|
mov al, I8042_CMD_RD_CBYTE
|
||||||
out PS2_PORT_CTRL, al
|
out i8042_PS2_CTRL, al
|
||||||
call ps2_read ; AL = command byte
|
call ps2_read ; AL = command byte
|
||||||
|
|
||||||
; Activer IRQ12 (bit 1)
|
; Activer IRQ12 (bit 1)
|
||||||
|
|
@ -133,10 +133,10 @@ mouse_init:
|
||||||
; Réécrire command byte (commande 0x60 envoyée à 0x64)
|
; Réécrire command byte (commande 0x60 envoyée à 0x64)
|
||||||
call ps2_wait_ready_write
|
call ps2_wait_ready_write
|
||||||
mov al, I8042_CMD_WR_CBYTE
|
mov al, I8042_CMD_WR_CBYTE
|
||||||
out PS2_PORT_CTRL, al
|
out i8042_PS2_CTRL, al
|
||||||
call ps2_wait_ready_write
|
call ps2_wait_ready_write
|
||||||
mov al, ah
|
mov al, ah
|
||||||
out PS2_PORT_BUFFER, al
|
out i8042_PS2_DATA, al
|
||||||
|
|
||||||
call ps2_flush_output
|
call ps2_flush_output
|
||||||
|
|
||||||
|
|
@ -230,7 +230,7 @@ mouse_detect_packet_len:
|
||||||
; attendre que le 8042 soit pret a recevoir de l'information
|
; attendre que le 8042 soit pret a recevoir de l'information
|
||||||
ps2_wait_ready_write:
|
ps2_wait_ready_write:
|
||||||
.wait:
|
.wait:
|
||||||
in al, PS2_PORT_CTRL
|
in al, i8042_PS2_CTRL
|
||||||
test al, 02h ; IBF
|
test al, 02h ; IBF
|
||||||
jnz .wait
|
jnz .wait
|
||||||
ret
|
ret
|
||||||
|
|
@ -238,7 +238,7 @@ ps2_wait_ready_write:
|
||||||
; attendre que le 8042 soit pret a lire de l'information
|
; attendre que le 8042 soit pret a lire de l'information
|
||||||
ps2_wait_ready_read:
|
ps2_wait_ready_read:
|
||||||
.wait:
|
.wait:
|
||||||
in al, PS2_PORT_CTRL
|
in al, i8042_PS2_CTRL
|
||||||
test al, 01h ; OBF
|
test al, 01h ; OBF
|
||||||
jz .wait
|
jz .wait
|
||||||
ret
|
ret
|
||||||
|
|
@ -246,16 +246,16 @@ ps2_wait_ready_read:
|
||||||
; lire de l'information depuis le 8042
|
; lire de l'information depuis le 8042
|
||||||
ps2_read:
|
ps2_read:
|
||||||
call ps2_wait_ready_read
|
call ps2_wait_ready_read
|
||||||
in al, PS2_PORT_BUFFER
|
in al, i8042_PS2_DATA
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; vide le buffer interne du 8042 (information(s) ignorée(s))
|
; vide le buffer interne du 8042 (information(s) ignorée(s))
|
||||||
ps2_flush_output:
|
ps2_flush_output:
|
||||||
.flush:
|
.flush:
|
||||||
in al, PS2_PORT_CTRL
|
in al, i8042_PS2_CTRL
|
||||||
test al, 01h
|
test al, 01h
|
||||||
jz .done
|
jz .done
|
||||||
in al, PS2_PORT_BUFFER
|
in al, i8042_PS2_DATA
|
||||||
jmp .flush
|
jmp .flush
|
||||||
.done:
|
.done:
|
||||||
ret
|
ret
|
||||||
|
|
@ -271,11 +271,11 @@ mouse_sendcmd:
|
||||||
call ps2_wait_ready_write
|
call ps2_wait_ready_write
|
||||||
|
|
||||||
mov al, I8042_CMD_WRITE_AUX
|
mov al, I8042_CMD_WRITE_AUX
|
||||||
out PS2_PORT_CTRL, al
|
out i8042_PS2_CTRL, al
|
||||||
|
|
||||||
call ps2_wait_ready_write
|
call ps2_wait_ready_write
|
||||||
mov al, bl
|
mov al, bl
|
||||||
out PS2_PORT_BUFFER, al
|
out i8042_PS2_DATA, al
|
||||||
|
|
||||||
call ps2_read ; AL = réponse
|
call ps2_read ; AL = réponse
|
||||||
cmp al, MOUSE_ACK
|
cmp al, MOUSE_ACK
|
||||||
|
|
@ -309,7 +309,7 @@ mouse_handler:
|
||||||
push ds
|
push ds
|
||||||
|
|
||||||
; vider le byte qui a déclenché IRQ12
|
; vider le byte qui a déclenché IRQ12
|
||||||
in al, PS2_PORT_BUFFER
|
in al, i8042_PS2_DATA
|
||||||
|
|
||||||
mov dx, 0xE9 ; debugcon
|
mov dx, 0xE9 ; debugcon
|
||||||
mov al, '*'
|
mov al, '*'
|
||||||
|
|
@ -324,10 +324,6 @@ mouse_handler:
|
||||||
popa
|
popa
|
||||||
iret
|
iret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; sauvegarder tout les registres
|
; sauvegarder tout les registres
|
||||||
pusha
|
pusha
|
||||||
push ds
|
push ds
|
||||||
|
|
@ -338,7 +334,7 @@ mouse_handler:
|
||||||
|
|
||||||
; lire un octet depuis le contrôleur
|
; lire un octet depuis le contrôleur
|
||||||
; et le stocker dans le buffer
|
; et le stocker dans le buffer
|
||||||
in al, PS2_PORT_BUFFER ; lire octet souris
|
in al, i8042_PS2_DATA ; lire octet souris
|
||||||
mov byte [BDA_MOUSE_BUFFER + BDA_MOUSE_IDX], al
|
mov byte [BDA_MOUSE_BUFFER + BDA_MOUSE_IDX], al
|
||||||
inc byte [BDA_MOUSE_IDX]
|
inc byte [BDA_MOUSE_IDX]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -203,55 +203,69 @@ ivt_setvector:
|
||||||
pop es
|
pop es
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; ------------------------------------------------------------
|
io_wait:
|
||||||
|
xor al,al
|
||||||
|
out 0x80,al
|
||||||
|
ret
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
; Initialise les PIC 8259 (PC/AT):
|
; Initialise les PIC 8259 (PC/AT):
|
||||||
; - Master offset 0x08
|
; - Master offset 0x08
|
||||||
; - Slave offset 0x70
|
; - Slave offset 0x70
|
||||||
; - Cascade: IRQ2
|
; - Cascade: IRQ2
|
||||||
; https://wiki.nox-rhea.org/back2root/ibm-pc-ms-dos/hardware/8259
|
; https://wiki.nox-rhea.org/back2root/ibm-pc-ms-dos/hardware/8259
|
||||||
; ------------------------------------------------------------
|
; ---------------------------------------------------------------------------
|
||||||
pic_init:
|
pic_init:
|
||||||
push ax
|
push ax
|
||||||
|
; starts the initialization sequence (in cascade mode)
|
||||||
; ICW1: init + ICW4
|
mov al, ICW1_INIT | ICW1_ICW4
|
||||||
mov al, 0x11 ; 000010001b
|
|
||||||
out i8259_MASTER_CMD, al
|
out i8259_MASTER_CMD, al
|
||||||
|
call io_wait
|
||||||
|
|
||||||
|
mov al, ICW1_INIT | ICW1_ICW4
|
||||||
out i8259_SLAVE_CMD, al
|
out i8259_SLAVE_CMD, al
|
||||||
|
call io_wait
|
||||||
|
|
||||||
; ICW2: vector offsets
|
|
||||||
mov al, 0x08
|
|
||||||
out i8259_MASTER_DATA, al
|
|
||||||
mov al, 0x70
|
|
||||||
out i8259_SLAVE_DATA, al
|
|
||||||
|
|
||||||
; ICW3: wiring
|
mov al, i8259_MASTER_INT
|
||||||
mov al, 0x04 ; master: slave on IRQ2: 0100b
|
out i8259_MASTER_DATA, al ; ICW2: Master PIC vector offset
|
||||||
out i8259_MASTER_DATA, al
|
call io_wait
|
||||||
mov al, 0x02 ; slave: cascade identity 2
|
mov al, i8259_SLAVE_INT
|
||||||
out i8259_SLAVE_DATA, al
|
out i8259_SLAVE_DATA, al ; ICW2: Slave PIC vector offset
|
||||||
|
call io_wait
|
||||||
|
|
||||||
|
; Master: cascade (IRQ2 => 1 << IRQ2 = 0x04)
|
||||||
|
mov al, 0x04 ; master: slave on IRQ2: 0100b
|
||||||
|
out i8259_MASTER_DATA, al ; ICW3: tell Master PIC that there is a slave PIC at IRQ2
|
||||||
|
call io_wait
|
||||||
|
|
||||||
|
; Slave: numéro de ligne sur master (2)
|
||||||
|
mov al, 0x02 ; slave: cascade identity 2
|
||||||
|
out i8259_SLAVE_DATA, al ; ICW3: tell Slave PIC its cascade identity (0000 0010)
|
||||||
|
call io_wait
|
||||||
|
|
||||||
; ICW4: 8086 mode
|
; ICW4: 8086 mode
|
||||||
mov al, 0x01
|
mov al, ICW4_8086
|
||||||
out i8259_MASTER_DATA, al
|
out i8259_MASTER_DATA, al
|
||||||
|
call io_wait
|
||||||
|
|
||||||
|
mov al, ICW4_8086
|
||||||
out i8259_SLAVE_DATA, al
|
out i8259_SLAVE_DATA, al
|
||||||
|
call io_wait
|
||||||
|
|
||||||
; Masques: unmask IRQ2 (master) et IRQ12 (slave)
|
|
||||||
in al, i8259_MASTER_DATA
|
; Unmask both PICs.
|
||||||
and al, 0xFB ; clear bit2
|
xor al,al
|
||||||
out i8259_MASTER_DATA, al
|
out i8259_MASTER_DATA, al
|
||||||
|
|
||||||
in al, i8259_SLAVE_DATA
|
|
||||||
and al, 0xEF ; clear bit4
|
|
||||||
out i8259_SLAVE_DATA, al
|
out i8259_SLAVE_DATA, al
|
||||||
|
|
||||||
pop ax
|
pop ax
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
; ---------------------------------------------------------------------------
|
||||||
; Handler par défaut: fait juste IRET
|
; Handler par défaut: fait juste IRET
|
||||||
; IMPORTANT: doit être FAR (appelé par le CPU via IVT), et terminer par IRET
|
; IMPORTANT: doit être FAR (appelé par le CPU via IVT), et terminer par IRET
|
||||||
; ---------------------------------------------------------------------------
|
; ---------------------------------------------------------------------------
|
||||||
default_isr:
|
default_isr:
|
||||||
iret
|
iret
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue