;-------------------- ; testINT.asm ; Test interrupt mechanisms. ; Load this at x0200 ; LC3 hardware revision: INTs are off at power up. ; ; Aside: LC3 starts in super mode (PSR[15] = 0). Can switch ; to user mode by executing RTI with preset PSR word on stack. ; Then use illegal opcode exception to switch to super mode. ; This can be used in place of the LC3 trap mechanism as a way ; to jump into OS code from user mode. ;-------------------- .ORIG x0200 ;------- Initialize keyboard interrupt handling. ;-- Set up super's stack. ld r6, stackPtr ;-- r6 <== pointer to bottom of stack. ;-- Set up IVT for keyboard interrupt. ld r0, kbIVTloc ;-- r0 <== addr of kb's vector. lea r1, kbCode ;-- r1 <== kbCode's address. ... ;-- MEM[vec addr] <== kbCode's address. ;-- Enable KB INTs, wait for an interrupt. ldi r3, KBSR ;-- r3 <== current content of KBSR. ld r4, ENmask ;-- r4 <== interrupt enable mask. ... ;-- ... sti r3, KBSR ;-- KBSR <== r3 ;-- Global INTs on. (see Modules/ints.asm) ... ;-- new_PSR_value <== PSR_INTS_ON push__( R0 ) ;-- push new_PSR_value .... ;-- fake_PC <== HERE push__( R0 ) ;-- push fake_PC rti ;-- PC <== HERE, PSR <== PSR_INTS_ON ;------- Faking execution of user's or super's program: HERE: ld r3, Limit ;-- cnt <== Limit LOOP: ;-- Loop mov__(r3,r3) ;-- test cnt BRp LOOP ;-- Until(cnt <= 0) ld r4, STOP ;-- r4 <== Disable sys_clk signal. sti r4, MCR ;-- MCR <== r4: shuts down hardware. ;------- Keyboard interrupt handler. NB--Has side effects! KBcode: add r3, r3, -1 ;-- do something on INT: cnt-- ldi r0, KBDR ;-- get data and handshake kb_ctl (KBSR[15]<==0) rti ;------- Data area. kbIVTloc: .FILL x0180 ;-- keyboard's vector slot in IVT. stackPtr: .FILL x3000 ;-- address of bottom of stack. ENmask: .FILL x4000 ;-- ENmask[14]=1 enable INTs Limit: .FILL x0003 ;-- Allow for 3 interrupts KBSR: .FILL xFE00 ;-- address of KBSR. KBDR: .FILL xFE02 ;-- address of KBDR. PSR_INTS_ON: .FILL x0000 ;-- PSR={Priv=0, Prio=7, CC=0} MCR: .FILL xFFFE ;-- address of mach. ctl reg STOP: .FILL x8000 ;-- MCR[15]=1 disables sys_clk .END