;***************************************************************************************** ;* Indiana University * ;* Computer Science Department * ;* * ;* AUTHOR: * ;* * ;* Bryce Himebaugh (bhimebau@cs.indiana.edu) * ;* IUCS Staff * ;* 6/15/99 * ;* * ;* TRAP #15 Service Handler (C335 Lab System) * ;* * ;* DESCRIPTION: * ;* * ;* The TRAP handler is installed by the lab system monitor program. The code is stored * ;* in EPROM at location 0x804000. The code is handled like user code by the monitor. The * ;* start address of the routine is installed by the monitor at location 0xBC (TRAP #15 * ;* address in the vector table) after the first line of the program is executed (see * ;* idpec040.h). The TRAP handler expects that user's program to pass the desired * ;* operating mode in the low byte of D1. The character information to be exchanged will * ;* be done through the low byte of D0. * ;* * ;* INPUT: D1 (low byte) = operating mode * ;* 0 = trap back to the simulated operating system (used for program termination) * ;* 1 = putcon - put one character to the terminal * ;* 2 = getcon - wait for 1 character from the terminal, return character * ;* 3 = constat - sample the terminal interface, return character or 0 * ;* 4 = 7 seg out - send value in D0 (0-F) out to seven seg * ;* 5 = enable caches * ;* 6 = disable caches * ;* 7 = initialize/start timer * ;* 8 = stop/reset timer * ;* 9 = output stack - outputs the stack in hex to the terminal * ;* A = memory checkout - checks each memory location for read/write capability * ;* B = set time * ;* C = cycle the seven segment display * ;* * ;* OUTPUT: D0 (low byte) = returned data from TRAP function. If the mode provided is * ;* invalid, a 0xFF will be returned in D0 * ;* * ;***************************************************************************************** SECTION code START: movem.l d1/a0,-(sp) cmpi.b #0,d1 beq .t15_simul_os cmpi.b #1,d1 beq .t15_putchar cmpi.b #2,d1 beq .t15_getchar cmpi.b #3,d1 beq .t15_check_inbuf cmpi.b #4,d1 beq .send_seven_seg cmpi.b #5,d1 beq .enable_caches cmpi.b #6,d1 beq .disable_caches cmpi.b #7,d1 beq .start_timer cmpi.b #8,d1 beq .stop_timer bra .t15_exit .t15_simul_os: lea os_message,a0 next_char: move.b (a0)+,d0 beq message_done jsr p_char bra next_char message_done: movem.l (sp)+,d1/a0 loop_forever: bra loop_forever .t15_putchar: move.b $b00027.l,d1 ; move ch b sr into d0 andi.b #4,d1 ; and off all but the txrdy bit beq .t15_putchar ; wait for txrdy to be set - transmitter empty move.b d0,$b0002f.l ; transmitter is empty - send out character left by user in mem bra .t15_exit ; quit the trap handler .t15_getchar: move.b $b00027.l,d1 ; move ch b sr into d0 andi.b #$1,d1 ; and off all but the rx char in bit beq .t15_getchar ; wait for the character to come in move.b $b0002f.l,d0 ; write the char at the top of the rx fifo to memory bra .t15_exit ; go to the exit .t15_check_inbuf: move.b $b00027.l,d1 ; move ch b sr into d0 andi.b #1,d1 ; and off all but the rx char in bit beq .t15_no_new_char ; wait for the character to come in move.b $b0002f.l,d0 ; write the char at the top of the rx fifo to memory bra .t15_exit ; quit the trap handler .t15_no_new_char: move.b #0,d0 ; write a null char to d0 bra .t15_exit ; quit the trap handler .send_seven_seg: move.l a0,-(sp) ; save a0 lea seg_out_dat,a0 ; load address of hex digit constants andi.l #0x000f,d0 ; mask low nibble of index into table move.b (a0,d0),0xd00003.l ; read indexed by d0 and write to the 7-seg register move.l (sp)+,a0 ; restore a0 bra .t15_exit ; quit the trap handler .enable_caches cinva BOTH ; invalidate both caches (prevents getting stale data) move.l #0x80008000,d0 ; setup to enable the caches movec d0,CACR ; write to the cache configuration register bra .t15_exit ; quit the trap handler .disable_caches cpusha BOTH ; push all of the dirty data out of the cache move.l #0x00000000,d0 ; setup to disable the caches movec d0,CACR ; write to the cache configuration register cinva BOTH ; invaildate all entries in the both caches bra .t15_exit ; quit the trap handler .start_timer move.b #0xC8,0xC00047.L ; Timer Interrupt Vector - set to vector 200 move.b #0xFF,0xC0004F.L ; Timer Preload High Byte move.b #0xFF,0xC00053.L ; Timer Preload Middle Byte move.b #0xFF,0xC00057.L ; Timer Preload Low Byte move.b #0x11,0xC00043.L ; Timer control - System Clock , Counter on bra .t15_exit ; quit the trap handler .stop_timer move.b #0x10,0xC00043.L ; Timer control - counter off clr.l d0 ; clear temp register d0 add.b 0xC0005F.L,d0 ; move the counter high byte into d0 lsl.l #8,d0 ; shift the counter high byte up by 1 byte add.b 0xC00063.L,d0 ; add in the counter middle byte lsl.l #8,d0 ; shift the result up by one byte add.b 0xC00067.L,d0 ; add in the counter low byte, d0 now contains the 24 bit count bra .t15_exit ; quit the trap handler .t15_exit: movem.l (sp)+,d1/a0 ; restore register rte ; exit p_char: move.b $b00027.l,d1 ; move ch b sr into d0 andi.b #4,d1 ; and off all but the txrdy bit beq p_char ; wait for txrdy to be set - transmitter empty move.b d0,$b0002f.l ; transmitter is empty - send out char in d0 rts SECTION data os_message: DC.B "\n\r ##################################################" DC.B "\n\r # SYSTEM MESSAGE: Program Exited Using TRAP #15 #" DC.B "\n\r ##################################################" DC.B "\n\r\n\r\x00" seg_out_dat: DC.B $FF,$F9,$A4,$B0,$99,$92,$82,$F8,$80,$98,$88,$83,$C6,$A1,$86,$87