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
18 .text !! these tell as:
19 begtext
: !! text
,data
,bss segments
20 .data !! are all the same.
26 mov ax
,cs
! establish segments
27 mov ds
,ax
! we know ES
,CS
=0x1000. Let DS=CS
28 mov ss
,ax
! SS
= CS
===> all point to
0x1000
31 mov sp
,#_proc ! SP -> proc[0].kstack HIGH end
37 call _main
! call main
[] in C
39 ! if ever return
, just hang
44 msg
: .asciz "BACK TO ASSEMBLY AND HANG\n\r"
46 !*************************************************************
47 ! KCW added functions for MT system
48 !************************************************************
63 resume
: mov bx
, _running
78 ! as86 macro
: parameters are ?
1 ?
2, etc
79 ! as86
-m
-l listing src
(generates listing with macro expansion
)
95 inc _inkmode
! enter Kmode
: ++inkmode
96 cmp _inkmode
,#1 ! if inkmode == 1 ==> interrupt was in Umode
97 jg ?
1 ! imode
>1 : was in Kmode
: bypass saving uss
,usp
99 ! was in Umode
: save interrupted
(SS
,SP
) into proc
100 mov si
,_running
! ready to access proc
101 mov USS
[si
],ss
! save SS in proc.USS
102 mov USP
[si
],sp
! save SP in proc.USP
104 ! change DS
,ES
,SS to Kernel segment
105 mov di
,ds
! stupid
!!
106 mov es
,di
! CS
=DS
=SS
=ES in Kmode
109 mov sp
, _running
! sp
-> running
's kstack[] high end
112 ?1: call _?1 ! call handler in C
114 br _ireturn ! return to interrupted point
121 _tinth: INTH thandler
123 !*===========================================================================*
124 !* _ireturn and goUmode() *
125 !*===========================================================================*
126 ! ustack contains flag,ucs,upc, ax,bx,cx,dx,bp,si,di,es,ds
127 ! uSS and uSP are in proc
131 dec _inkmode ! --inkmode
132 cmp _inkmode,#0 ! inkmode==0 means was in Umode
135 ! restore uSS, uSP from running PROC
136 mov si,_running ! si -> proc
138 mov ss,ax ! restore SS
139 mov sp,USP[si] ! restore SP
153 !--------------------------------
154 ! resetVideo[] : clear screen, home cursor
155 !--------------------------------
157 mov ax, #0x0012 ! 640x480 color
158 int 0x10 ! call BIOS to do it
159 mov ax, #0x0200 ! Home the cursor
162 int 0x10 ! call BIOS to home cursor
165 !---------------------------------------
166 ! int diskr[cyl, head, sector, buf]
168 !---------------------------------------
173 movb dl, #0x00 ! drive 0=fd0
174 movb dh, 6[bp] ! head
175 movb cl, 8[bp] ! sector
176 incb cl ! inc sector by 1 to suit BIOS
178 mov ax, #0x0202 ! READ 2 sectors
179 mov bx, 10[bp] ! put buf value in BX ==> addr=[ES,BX]
180 int 0x13 ! call BIOS to read the block
181 jb error ! to error if CarryBit is on [read failed]
187 !---------------------------------------------
188 ! char getc[] function: returns a char
189 !---------------------------------------------
191 xorb ah,ah ! clear ah
192 int 0x16 ! call BIOS to get a char in AX
195 !----------------------------------------------
196 ! void putc[char c] function: print a char
197 !----------------------------------------------
202 movb al,4[bp] ! get the char into aL
203 movb ah,#14 ! aH = 14
205 mov bx,_color ! bL = color B Cyan C Red
206 int 0x10 ! call BIOS to display the char
223 _inces: ! inces[] inc ES by 0x40, or 1K
229 !------------------------------
231 !------------------------------
241 !*===========================================================================*
243 !*===========================================================================*
244 ! This routine is used to fetch a byte from anywhere in memory.
246 ! c = get_byte[segment, offset]
248 ! 'segment
' is the value to put in es
249 ! 'offset
' is the offset from the es value
252 mov bp,sp ! we need to access parameters
257 mov es,4[bp] ! load es with segment value
258 mov bx,6[bp] ! load bx with offset from segment
259 seg es ! go get the byte
260 movb al,[bx] ! al = byte
261 xorb ah,ah ! ax = byte
268 ret ! return to caller
271 !*===========================================================================*
273 !*===========================================================================*
274 ! This routine is used to put a word to anywhere in memory.
276 ! put_byte[char,segment,offset]
279 ! 'segment
' is a segment
280 ! 'offset
' is the offset from the segment
283 mov bp,sp ! we need to access parameters
288 mov es,6[bp] ! load es with segment value
289 mov bx,8[bp] ! load bx with offset from segment
290 movb al,4[bp] ! load byte in aL
291 seg es ! go put the byte to [ES, BX]
292 movb [bx],al ! there it goes
299 ret ! return to caller
300 !*===========================================================================*
302 !*===========================================================================*
303 ! Disable CPU interrupts.
305 pushf ! save flags on stack
306 cli ! disable interrupts
307 pop ax ! pop saved flag into ax
308 ret ! return old_flag
311 !*===========================================================================*
313 !*===========================================================================*
314 ! Enable CPU interrupts.
316 sti ! enable interrupts
317 ret ! return to caller
319 !*===========================================================================*
320 !* restore(old_flag) *
321 !*===========================================================================*
322 ! Restore enable/disable bit to the value it had before last lock.
328 popf ! restore old_flag
332 ret ! return to caller
335 !*===========================================================================*
337 !*===========================================================================*
338 ! PUBLIC unsigned in_byte[port_t port];
339 ! Read an [unsigned] byte from the i/o port port and return it.
345 in ax,dx ! input 1 byte
346 subb ah,ah ! unsign extend
350 !*===========================================================================*
352 !*==============================================================
353 ! out_byte[port_t port, int value];
354 ! Write value [cast to a byte] to the I/O port port.
361 outb dx,al ! output 1 byte