;   maskirq.inc, Copyright (c) 1997-1998 by Lukas Ruf,
;   Swiss Federal Institute of Technology,
;   Computer Engineering and Networks Laboratory.
;
;   TOPSY -- A Teachable Operating System.
;            Implementation of a tiny and simple
;            micro kernel for teaching purposes.
;
;   For further information, please visit http://www.tik.ee.ethz.ch/~topsy
;
;   This software is provided under the terms of the GNU General Public Licence.
;   A full copy of the GNU GPL is provided in the file COPYING found in the 
;   development root of Topsy.
;
;       This copyright notice supercedes all originally or previously used 
;       copyrights being used within the source code.
;       
;       Author: Lukas Ruf, lr@lpr.ch


;Topsy i386                                             Lukas Ruf, November 1997
;-------------------------------------------------------------------------------

; Mask_ALL_IRQ
; This sets IRQ00-0F vectors in the 8259s
; to be Int20 thru 2F.
;
; When the PICUs are initialized, all the hardware interrupts are MASKED.
; Each driver that uses a hardware interrupt(s) is responsible
; for unmasking that particular IRQ.
;
PICU1          EQU 0x0020
PICU2          EQU 0x00A0

;Mask_ALL_IRQ    PROC    NEAR
; /* LR 000712 */
; Taken from linux 2.2.16 /usr/src/linux-2.2.16/arch/i386/boot/setup.S
;

MASK_ALL_IRQ:
! make sure any possible coprocessor is properly reset..

;	xor	ax,ax
;	out	#0xf0,al
;	call	delay
;	out	#0xf1,al
;	call	delay
;
! well, that went ok, I hope. Now we have to reprogram the interrupts :-(
! we put them right after the intel-reserved hardware interrupts, at
! int 0x20-0x2F. There they won't mess up anything. Sadly IBM really
! messed this up with the original PC, and they haven't been able to
! rectify it afterwards. Thus the bios puts interrupts at 0x08-0x0f,
! which is used for the internal hardware interrupts as well. We just
! have to reprogram the 8259's, and it isn't fun.

  cli
	mov	al,#0x11		! initialization sequence
	out	#0x20,al		! send it to 8259A-1
	call	delay
	out	#0xA0,al		! and to 8259A-2
	call	delay
	mov	al,#0x20		! start of hardware int's (0x20)
	out	#0x21,al
	call	delay
	mov	al,#0x28		! start of hardware int's 2 (0x28)
	out	#0xA1,al
	call	delay
	mov	al,#0x04		! 8259-1 is master
	out	#0x21,al
	call	delay
	mov	al,#0x02		! 8259-2 is slave
	out	#0xA1,al
	call	delay
	mov	al,#0x01		! 8086 mode for both
	out	#0x21,al
	call	delay
	out	#0xA1,al
	call	delay
	mov	al,#0xFF		! mask off all interrupts for now
	out	#0xA1,al
	call	delay
	mov	al,#0xFB		! mask all irq's but irq2 which
	;mov	al,#0xFA		! mask all irq's but irq2 which
	out	#0x21,al		! is cascaded
  call delay
  ret

delay:
  .word 0x00eb    ; jmp $+2
  ret


; Old Version:
;MASK_ALL_IRQ:
;        MOV     AL,#%00010001
;        OUT     #PICU1+0,AL                  ;ICW1 - MASTER
;        PUSH    EAX
;        POP     EAX
;        OUT     #PICU2+0,AL                  ;ICW1 - SLAVE
;        PUSH    EAX
;        POP     EAX
;        MOV     AL,#0x20
;        OUT     #PICU1+1,AL                  ;ICW2 - MASTER
;        PUSH    EAX
;        POP     EAX
;        MOV     AL,#0x28
;        OUT     #PICU2+1,AL                  ;ICW2 - SLAVE
;        PUSH    EAX
;        POP     EAX
;        MOV     AL,#%00000100
;        OUT     #PICU1+1,AL                  ;ICW3 - MASTER
;        PUSH    EAX
;        POP     EAX
;        MOV     AL,#%00000010
;        OUT     #PICU2+1,AL                  ;ICW3 - SLAVE
;        PUSH    EAX
;        POP     EAX
;        MOV     AL,#%00000001
;        OUT     #PICU1+1,AL                  ;ICW4 - MASTER
;        PUSH    EAX
;        POP     EAX
;        OUT     #PICU2+1,AL                  ;ICW4 - SLAVE
;        PUSH    EAX
;        POP     EAX
;        MOV     AL,#%11111010                ;Masked all but cascade/timer
;        OUT     #PICU1+1,AL                  ;MASK - MASTER (0= Ints ON)
;        PUSH    EAX
;        POP     EAX
;        MOV     AL,#%11111111
;        OUT     #PICU2+1,AL                  ;MASK - SLAVE
;        PUSH    EAX
;        POP     EAX
;        RET
;;Mask_ALL_IRQ    ENDP

