2 .globl begtext, begdata, begbss !! needed by linker
5 .globl _resetVideo,_getc,_putc,_diskr,_setes,_inces
7 .globl _tswitch,_running,_scheduler
11 .globl _get_byte,_put_byte
12 .globl _proc, _procsize
14 .globl _lock, _unlock,_restore, _in_byte, _out_byte
16 .globl _tinth, _thandler
17 .globl _kbinth,_kbhandler
18 .globl _s0inth, _s0handler
19 .globl _s1inth, _s1handler
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
81 ! as86 macro: parameters are ?1 ?2, etc
82 ! as86 -m -l listing src (generates listing with macro expansion)
98 inc _inkmode ! enter Kmode : ++inkmode
99 cmp _inkmode,#1 ! if inkmode == 1 ==> interrupt was in Umode
100 jg ?1 ! imode>1 : was in Kmode: bypass saving uss,usp
102 ! was in Umode: save interrupted (SS,SP) into proc
103 mov si,_running ! ready to access proc
104 mov USS[si],ss ! save SS in proc.USS
105 mov USP[si],sp ! save SP in proc.USP
107 ! change DS,ES,SS to Kernel segment
108 mov di,ds ! stupid !!
109 mov es,di ! CS=DS=SS=ES in Kmode
112 mov sp, _running ! sp -> running's kstack[] high end
115 ?1: call _?1 ! call handler in C
117 br _ireturn ! return to interrupted point
123 _tinth: INTH thandler
124 _kbinth: INTH kbhandler
125 _s0inth: INTH s0handler
126 _s1inth: INTH s1handler
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
158 !--------------------------------
159 ! resetVideo[] : clear screen, home cursor
160 !--------------------------------
162 mov ax, #0x0012 ! 640x480 color
163 int 0x10 ! call BIOS to do it
164 mov ax, #0x0200 ! Home the cursor
167 int 0x10 ! call BIOS to home cursor
170 !---------------------------------------
171 ! int diskr[cyl, head, sector, buf]
173 !---------------------------------------
178 movb dl, #0x00 ! drive 0=fd0
179 movb dh, 6[bp] ! head
180 movb cl, 8[bp] ! sector
181 incb cl ! inc sector by 1 to suit BIOS
183 mov ax, #0x0202 ! READ 2 sectors
184 mov bx, 10[bp] ! put buf value in BX ==> addr=[ES,BX]
185 int 0x13 ! call BIOS to read the block
186 jb error ! to error if CarryBit is on [read failed]
192 !---------------------------------------------
193 ! char getc[] function: returns a char
194 !---------------------------------------------
196 xorb ah,ah ! clear ah
197 int 0x16 ! call BIOS to get a char in AX
200 !----------------------------------------------
201 ! void putc[char c] function: print a char
202 !----------------------------------------------
207 movb al,4[bp] ! get the char into aL
208 movb ah,#14 ! aH = 14
210 mov bx,_color ! bL = color B Cyan C Red
211 int 0x10 ! call BIOS to display the char
228 _inces: ! inces[] inc ES by 0x40, or 1K
234 !------------------------------
236 !------------------------------
246 !*===========================================================================*
248 !*===========================================================================*
249 ! This routine is used to fetch a byte from anywhere in memory.
251 ! c = get_byte[segment, offset]
253 ! 'segment' is the value to put in es
254 ! 'offset' is the offset from the es value
257 mov bp,sp ! we need to access parameters
262 mov es,4[bp] ! load es with segment value
263 mov bx,6[bp] ! load bx with offset from segment
264 seg es ! go get the byte
265 movb al,[bx] ! al = byte
266 xorb ah,ah ! ax = byte
273 ret ! return to caller
276 !*===========================================================================*
278 !*===========================================================================*
279 ! This routine is used to put a word to anywhere in memory.
281 ! put_byte[char,segment,offset]
284 ! 'segment' is a segment
285 ! 'offset' is the offset from the segment
288 mov bp,sp ! we need to access parameters
293 mov es,6[bp] ! load es with segment value
294 mov bx,8[bp] ! load bx with offset from segment
295 movb al,4[bp] ! load byte in aL
296 seg es ! go put the byte to [ES, BX]
297 movb [bx],al ! there it goes
304 ret ! return to caller
305 !*===========================================================================*
307 !*===========================================================================*
308 ! Disable CPU interrupts.
310 pushf ! save flags on stack
311 cli ! disable interrupts
312 pop ax ! pop saved flag into ax
313 ret ! return old_flag
316 !*===========================================================================*
318 !*===========================================================================*
319 ! Enable CPU interrupts.
321 sti ! enable interrupts
322 ret ! return to caller
324 !*===========================================================================*
325 !* restore(old_flag) *
326 !*===========================================================================*
327 ! Restore enable/disable bit to the value it had before last lock.
333 popf ! restore old_flag
337 ret ! return to caller
340 !*===========================================================================*
342 !*===========================================================================*
343 ! PUBLIC unsigned in_byte[port_t port];
344 ! Read an [unsigned] byte from the i/o port port and return it.
350 in ax,dx ! input 1 byte
351 subb ah,ah ! unsign extend
355 !*===========================================================================*
357 !*==============================================================
358 ! out_byte[port_t port, int value];
359 ! Write value [cast to a byte] to the I/O port port.
366 outb dx,al ! output 1 byte