2 .globl begtext, begdata, begbss !! needed by linker
7 .globl _tswitch,_running,_scheduler
12 .globl _proc, _procsize
15 .globl _in_byte, _out_byte
18 .globl _lock,_restore,_unlock
19 .globl _kbinth, _kbhandler
21 .text !! these tell as:
22 begtext: !! text,data,bss segments
23 .data !! are all the same.
29 mov ax,cs ! establish segments
30 mov ds,ax ! we know ES,CS=0x1000. Let DS=CS
31 mov ss,ax ! SS = CS ===> all point to 0x1000
34 mov sp,#_proc ! SP -> proc[0].kstack HIGH end
40 call _main ! call main[] in C
42 ! if ever return, just hang
47 msg: .asciz "BACK TO ASSEMBLY AND HANG\n\r"
49 !*************************************************************
50 ! KCW added functions for MT system
51 !************************************************************
66 resume: mov bx, _running
80 !These offsets are defined in struct proc
84 ! as86 macro: parameters are ?1 ?2, etc
85 ! as86 -m -l listing src (generates listing with macro expansion)
101 inc _inkmode ! enter Kmode : ++inkmode
102 cmp _inkmode,#1 ! if inkmode == 1 ==> interrupt was in Umode
103 jg ?1 ! imode>1 : was in Kmode: bypass saving uss,usp
105 ! was in Umode: save interrupted (SS,SP) into proc
106 mov si,_running ! ready to access proc
107 mov USS[si],ss ! save SS in proc.USS
108 mov USP[si],sp ! save SP in proc.USP
110 ! change DS,ES,SS to Kernel segment
111 mov di,ds ! stupid !!
112 mov es,di ! CS=DS=SS=ES in Kmode
115 mov sp, _running ! sp -> running's kstack[] high end
118 ?1: call _?1 ! call handler in C
120 br _ireturn ! return to interrupted point
126 _kbinth: INTH kbhandler
128 !*===========================================================================*
129 !* _ireturn and goUmode() *
130 !*===========================================================================*
131 ! ustack contains flag,ucs,upc, ax,bx,cx,dx,bp,si,di,es,ds
132 ! uSS and uSP are in proc
136 dec _inkmode ! --inkmode
137 cmp _inkmode,#0 ! inkmode==0 means was in Umode
140 ! restore uSS, uSP from running PROC
141 mov si,_running ! si -> proc
143 mov ss,ax ! restore SS
144 mov sp,USP[si] ! restore SP
157 !*===========================================================================*
159 !*===========================================================================*
160 ! PUBLIC unsigned in_byte[port_t port];
161 ! Read an [unsigned] byte from the i/o port port and return it.
167 inb al,dx ! input 1 byte
168 subb ah,ah ! unsign extend
172 !*===========================================================================*
174 !*==============================================================
175 ! out_byte[port_t port, int value];
176 ! Write value [cast to a byte] to the I/O port port.
183 outb dx,al ! output 1 byte
188 _int_off: ! cli, return old flag register
194 _int_on: ! int_on(int SR)
198 mov ax,4[bp] ! get SR passed in
209 !*===========================================================================*
211 !*===========================================================================*
212 ! Disable CPU interrupts.
214 pushf ! save flags on stack
215 cli ! disable interrupts
216 pop lockvar ! save flags for possible restoration later
217 ret ! return to caller
220 !*===========================================================================*
222 !*===========================================================================*
223 ! Enable CPU interrupts.
225 sti ! enable interrupts
226 ret ! return to caller
229 !*===========================================================================*
231 !*===========================================================================*
232 ! Restore enable/disable bit to the value it had before last lock.
234 push lockvar ! push flags as they were before previous lock
236 ret ! return to caller