1/* 2 * Copyright (c) 1992 Regents of the University of California. 3 * All rights reserved. 4 * 5 * This software was developed by the Computer Systems Engineering group 6 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 7 * contributed to Berkeley. 8 * 9 * All advertising materials mentioning features or use of this software 10 * must display the following acknowledgement: 11 * This product includes software developed by the University of 12 * California, Lawrence Berkeley Laboratories. 13 * 14 * %sccs.include.redist.c% 15 * 16 * @(#)bsd_audiointr.s 7.3 (Berkeley) 10/11/92 17 * 18 * from: $Header: bsd_audiointr.s,v 1.4 92/07/03 23:24:17 mccanne Exp $ (LBL) 19 */ 20 21#ifndef AUDIO_C_HANDLER 22#ifndef LOCORE 23#define LOCORE 24#endif 25#include "assym.s" 26#if BSD < 199103 27/* SunOS */ 28#include <machine/intreg.h> 29#define IE_L4 IR_SOFT_INT4 30#else 31/* 4.4BSD */ 32#include <sparc/sparc/intreg.h> 33/* XXX this goes in a header file -- currently, it's hidden in locore.s */ 34#define INTREG_ADDR 0xf8002000 35#endif 36 37#define R_amd %l2 38#define R_cb %l3 39#define R_h %l4 40#define R_t %l5 41 42#if AUCB_SIZE > 4096 43#define MASK %l1 44#else 45#define MASK AUCB_SIZE - 1 46#endif 47 48 .seg "data" 49 .align 8 50audio_savepc: 51 .word 0 52#if AUCB_SIZE > 4096 53 .word 0 54#endif 55 .seg "text" 56 .align 4 57 .global _audio_trap 58 .global _audio_au 59 60_audio_trap: 61#if AUCB_SIZE > 4096 62 set audio_savepc, %l7 63 st %l1, [%l7] 64 st %l2, [%l7 + 4] 65 set AUCB_SIZE - 1, %l1 66#else 67 sethi %hi(audio_savepc), %l7 68 st %l2, [%l7 + %lo(audio_savepc)] 69#endif 70 sethi %hi(_audio_au), %l7 71 ld [%l7 + %lo(_audio_au)], %l7 72 ld [%l7 + AU_AMD], R_amd 73 add %l7, AU_RB, R_cb ! set up read cb ptr 74 ldsb [R_amd + AMD_IR], %g0 ! clear interrupt 75 ld [%l7 + AU_STAMP], %l6 76 inc %l6 77 st %l6, [%l7 + AU_STAMP] ! bump time stamp 78 79 ! receive incoming data 80 ld [R_cb + CB_HEAD], R_h 81 ld [R_cb + CB_TAIL], R_t 82 add R_t, 1, %l7 ! compute next tail ptr 83 and %l7, MASK, %l7 84 cmp R_h, %l7 85 bne 2f 86 nop 87 ld [R_cb + CB_DROPS], %l7 88 inc %l7 89 ba 7f 90 st %l7, [R_cb + CB_DROPS] 912: 92 lduh [R_cb + CB_PAUSE], %l6 93 tst %l6 94 be 3f 95 nop 96 ld [R_cb + CB_PDROPS], %l7 97 inc %l7 98 ba 7f 99 st %l7, [R_cb + CB_PDROPS] 1003: 101 ldsb [R_amd + AMD_BBRB], %l6 ! get sample 102 add R_t, CB_DATA, R_t ! adjust for struct offset 103 stb %l6, [R_cb + R_t] ! store sample in buffer 104 st %l7, [R_cb + CB_TAIL] ! update tail 105 mov %l7, R_t ! " " 1067: 107 ld [R_cb + CB_THRESH], %l6 108 sub R_t, R_h, %l7 ! enough data? 109 and %l7, MASK, %l7 110 cmp %l7, %l6 111 bl 1f 112 nop 113#if AUCB_SIZE >= 4096 114 set AUCB_SIZE, %l7 115#else 116 mov AUCB_SIZE, %l7 117#endif 118 st %l7, [R_cb + CB_THRESH] ! disable threshold 119 mov 1, %l7 120 sth %l7, [R_cb + CB_WAKING] ! set waking 121 122 sethi %hi(INTREG_ADDR), %l7 123 ldub [%l7 + %lo(INTREG_ADDR)], %l6 124 or %l6, IE_L4, %l6 125 stb %l6, [%l7 + %lo(INTREG_ADDR)] ! set software interrupt 1261: 127 /* write */ 128 set AU_WB - AU_RB, %l6 ! avoid loading _audio_au ptr 129 add R_cb, %l6, R_cb ! set up write cb ptr 130 131 ld [R_cb + CB_HEAD], R_h 132 ld [R_cb + CB_TAIL], R_t 133 cmp R_h, R_t 134 bne 2f 135 nop 136 ld [R_cb + CB_DROPS], %l7 137 inc %l7 138 ba 4f 139 st %l7, [R_cb + CB_DROPS] 1402: 141 lduh [R_cb + CB_PAUSE], %l7 142 tst %l7 143 be 3f 144 nop 145 ld [R_cb + CB_PDROPS], %l7 146 inc %l7 147 ba 4f 148 st %l7, [R_cb + CB_PDROPS] 1493: 150 inc R_h 151 and R_h, MASK, R_h ! compute new head ptr 152 st R_h, [R_cb + CB_HEAD] 153 add R_h, CB_DATA, R_h ! adjust for struct offset 154 ldsb [R_cb + R_h], %l6 ! load sample from buffer 155 stb %l6, [R_amd + AMD_BBTB] ! output sample to device 1564: 157 ld [R_cb + CB_THRESH], %l6 158 sub R_t, R_h, %l7 ! test if below low water 159 and %l7, MASK, %l7 160 cmp %l7, %l6 161 bg 5f 162 ! nop 163 164 mov -1, %l7 165 st %l7, [R_cb + CB_THRESH] ! disable threshold 166 sth %l7, [R_cb + CB_WAKING] ! set waking 167 168 ! set software interrupt 169 sethi %hi(INTREG_ADDR), %l7 170 ldsb [%l7 + %lo(INTREG_ADDR)], %l6 171 or %l6, IE_L4, %l6 172 stb %l6, [%l7 + %lo(INTREG_ADDR)] 1735: 174 /* 175 * Restore psr -- note: psr delay honored by pc restore loads. 176 */ 177 mov %l0, %psr 178#if AUCB_SIZE > 4096 179 sethi %hi(audio_savepc), %l7 180 ldd [%l7 + %lo(audio_savepc)], %l2 181 jmp %l2 182 rett %l3 183#else 184 sethi %hi(audio_savepc), %l7 185 ld [%l7 + %lo(audio_savepc)], %l2 186 jmp %l1 187 rett %l2 188#endif 189#endif 190