cos2000v1/noyau/8259a.asm

336 lines
8.1 KiB
NASM
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

;Adresses de port du contr“leur IRQ
MASTERPIC = 020h ;Adresse de base du PIC maŒtre
SLAVEPIC = 0A0h ;Adresse de base du PIC esclave
IRQMASK = 001h ;Offset sur port de masquage
;Commandes IRQ OCW2
DISABLEROTATION = 000h ;Desactiver la rotation de priorités en mode EOI automatique
EOI = 020h ;End of Interrupt non spcifi
COMMANDEOI = 060h ;Commande EOI particulière
ENABLEROTATION = 080h ;Activer la rotation de priorités en mode EOI automatique
ROTATIONNOSPEC = 0A0h ;Rotation des priorités en mode EOI automatique
SETPRIORITY = 0C0h ;Definir la priorité
ROTATIONSPEC = 0E0h ;Rotation des priorités en mode EOI spécifié
;Position des vecteurs d'interruptions
MASTERFIRSTVECTOR = 008h ;Vecteurs logiciels des interruptions
SLAVEFIRSTVECTOR = 070h ;lectroniques
;OCW3 codes registres
IRR = 002h ;Interrupt Request Register
ISR = 003h ;In Service Register
;OCW3 et modes
OCW3 = 008h ;OCW3
POLLING = 004h ;Polling bit
ISR = 0Bh ; Pas d'opration, pas de Poll, lire ISR OCW3
IRR = 0Ah ; Pas d'opration, pas de Poll, lire IRR
;Autorise une interruption lectronique
;Entre : %1 - Numro de l'interruption (0-15) … autoriser 0-7 = MASTERPIC , 8-15 = SLAVEPIC
PROC enableirq FAR
ARG @irq:word
USES ax,cx,dx
mov ax,[@irq]
mov dx,MASTERPIC+IRQMASK
cmp al,7
jbe @@master
mov dx,SLAVEPIC+IRQMASK
@@master:
mov cl,al
and cl,7
mov al,1
shl al,cl
not al
mov ah,al
in al,dx
and al,ah
out dx,al
ret
endp enableirq
;Desactive une interruption lectronique
;Entre : %0 - Numro de l'interruption (0-15) … desactiver 0-7 = MASTERPIC , 8-15 = SLAVEPIC
PROC disableirq FAR
ARG @irq:word
USES ax,cx,dx
mov ax,[@irq]
mov dx,MASTERPIC+IRQMASK
cmp al,7
jbe @@master
mov dx,SLAVEPIC+IRQMASK
@@master:
mov cl,al
and cl,7
mov al,1
shl al,cl
not al
mov ah,al
in al,dx
or al,ah
out dx,al
ret
endp disableirq
;Signale "End Of Interrupt" de l'interruption %0
PROC seteoi FAR
ARG @irq:word
USES ax,dx
mov ax,[@irq]
cmp al,7
jbe @@master
mov al,EOI
out SLAVEPIC,al
@@master:
mov al,EOI
out MASTERPIC,al
ret
endp seteoi
;Lit les masques d'un contr“leur IRQ dans ax, 0 master ou slave 1 ds %1
PROC readmaskirq FAR
ARG @controleur:word
USES bx,dx
mov bx,[@controleur]
mov dx,MASTERPIC+ IRQMASK
cmp bl,0
jne @@master
mov dx,SLAVEPIC+ IRQMASK
@@master:
xor ah,ah
in al,dx
pop dx
ret
endp readmaskirq
;Lit le registre d'tat d'un contr“leur IRQ dans ax, 0 master ou slave 1 ds %1
PROC readisr FAR
ARG @controleur:word
USES bx,dx
mov bx,[@controleur]
mov dx,MASTERPIC
cmp bh,0
jne @@master
mov dx,SLAVEPIC
@@master:
mov al,ISR
out dx,al
xor ah,ah
in al,dx
ret
endp readisr
;Lit le registre d'tat d'un contr“leur IRQ dans al, 0 master ou slave 1 ds bh
PROC readirr FAR
ARG @controleur:word
USES bx,dx
mov bx,[@controleur]
mov dx,MASTERPIC
cmp bh,0
jne @@master
mov dx,SLAVEPIC
@@master:
mov al,IRR
out dx,al
xor ah,ah
in al,dx
ret
endp readirr
interruptionbloc db '/interrupts',0
PROC installirqhandler FAR
USES eax,bx,cx,edx,si,di,ds,es
push fs
call mbcreate,offset interruptionbloc,256*size ints
mov es,ax
mov ax,0x0000
mov ds,ax
xor si,si
@@searchdummypointer:
mov fs,[(vector si).data.seg]
mov bx,[(vector si).data.off]
cmp [byte ptr fs:bx],0xCF ;iret
je @@founded
add si,size vector
cmp si,256*4
jb @@searchdummypointer
xor edx,edx
jmp @@suite
@@founded:
mov edx,[(vector si).content]
@@suite:
xor cx,cx
xor si,si
xor di,di
cli
@@copy:
mov [es:(ints di).number],cl
mov [es:(ints di).locked],0
mov [es:(ints di).vector1.content],0
mov [es:(ints di).vector3.content],0
mov [es:(ints di).vector4.content],0
mov [es:(ints di).vector5.content],0
mov [es:(ints di).vector6.content],0
mov [es:(ints di).vector7.content],0
mov [es:(ints di).vector8.content],0
mov [es:(ints di).launchedlow],0
mov [es:(ints di).launchedhigh],0
mov [es:(ints di).calledlow],0
mov [es:(ints di).calledhigh],0
mov eax,[(vector si).content]
cmp eax,edx
je @@notarealvector
mov [es:(ints di).vector1.content],eax
mov [es:(ints di).activated],1
jmp @@copynext
@@notarealvector:
mov [es:(ints di).vector1.content],0
mov [es:(ints di).activated],0
@@copynext:
mov bx,cx
shl bx,3
sub bx,cx
add bx,offset coupling
mov [(vector si).data.seg],cs
mov [(vector si).data.off],bx
add si,size vector
add di,size ints
inc cl
cmp cl,0
jne @@copy
@@end:
pop fs
sti
ret
endp installirqhandler
PROC savecontext far
ARG @pointer:word
USES si
push [ss:bp]
push esi
pushfd
mov si,[@pointer]
pop [dword ptr cs:(regs si).seflags]
pop [dword ptr cs:(regs si).sesi]
pop bp
mov [cs:(regs si).seax],eax
mov [cs:(regs si).sebx],ebx
mov [cs:(regs si).secx],ecx
mov [cs:(regs si).sedx],edx
mov [cs:(regs si).sedi],edi
mov [cs:(regs si).sebp],ebp
mov [cs:(regs si).sesp],esp
mov [cs:(regs si).scs],cs
mov [cs:(regs si).sds],ds
mov [cs:(regs si).ses],es
mov [cs:(regs si).sfs],fs
mov [cs:(regs si).sgs],gs
mov [cs:(regs si).sss],ss
ret
endp savecontext
PROC restorecontextg FAR
ARG @pointer:word
mov si,[@pointer]
pushd [cs:(regs si).sesi]
pushd [cs:(regs si).seflags]
mov eax,[cs:(regs si).seax]
mov ebx,[cs:(regs si).sebx]
mov ecx,[cs:(regs si).secx]
mov edx,[cs:(regs si).sedx]
mov edi,[cs:(regs si).sedi]
mov ebp,[cs:(regs si).sebp]
mov es,[cs:(regs si).ses]
mov fs,[cs:(regs si).sfs]
mov gs,[cs:(regs si).sgs]
mov ds,[cs:(regs si).sds]
popfd
pop esi
pop [cs:dummy]
db 0xCA,0x02,0x00 ;retf 2
endp restorecontextg
coupling:
counter = 0
REPEAT 256
push counter+256
push offset irqhandlers
ret
counter = counter + 1
ENDM
interrupt dw 0
dummy dw 0
calling_reg regs <>
function_reg regs <>
irqhandlers:
cli
pop [cs:interrupt]
call savecontext,offset calling_reg
call irqhandler,[cs:interrupt]
call restorecontextg,offset calling_reg
sti
iret
PROC irqhandler NEAR
ARG @int:word
push cs
pop ds
call mbfindsb,offset interruptionbloc,cs
jc @@end
mov es,ax
mov ax,[@int]
sub ax,256
mov cx,size ints
mul cx
mov si,ax
add [es:(ints si).calledlow],1
adc [es:(ints si).calledhigh],0
cmp [es:(ints si).activated],1
jne @@end
add [es:(ints si).launchedlow],1
adc [es:(ints si).launchedhigh],0
lea si,[es:(ints si).vector1]
mov cl,8
@@launchall:
cmp [es:(vector si).content],0
je @@end
push [word ptr cs:calling_reg.seflags]
push cs
push offset @@back
push [es:(vector si).data.seg]
push [es:(vector si).data.off]
call savecontext,offset function_reg
call restorecontextg,offset calling_reg
db 0xCB
@@back:
cli
call savecontext,offset calling_reg
call restorecontextg,offset function_reg
@@next:
add si,size vector
dec cl
jnz @@launchall
@@end:
ret
endp irqhandler
PROC