]> cloudbase.mooo.com Git - z180-stamp-cpm3.git/blob - cbios/bioskrnl.180
correct merge errors.
[z180-stamp-cpm3.git] / cbios / bioskrnl.180
1 title 'Root module of relocatable BIOS for CP/M 3.0'
2
3 ; version 1.0 15 Sept 82
4
5 include config.inc
6 include z180reg.inc
7
8
9 ; Copyright (C), 1982
10 ; Digital Research, Inc
11 ; P.O. Box 579
12 ; Pacific Grove, CA 93950
13
14
15 ; This is the invariant portion of the modular BIOS and is
16 ; distributed as source for informational purposes only.
17 ; All desired modifications should be performed by
18 ; adding or changing externally defined modules.
19 ; This allows producing "standard" I/O modules that
20 ; can be combined to support a particular system
21 ; configuration.
22
23 ctlQ equ 'Q'-'@'
24 ctlS equ 'S'-'@'
25
26 ccp equ 0100h ; Console Command Processor gets loaded
27 ; into the TPA
28
29 cseg ; GENCPM puts CSEG stuff in common memory
30
31
32 ; variables in system data page
33
34 extrn @covec,@civec,@aovec,@aivec,@lovec ; I/O redirection vectors
35 extrn @mxtpa ; addr of system entry point
36 extrn @bnkbf ; 128 byte scratch buffer
37
38 ; initialization
39
40 extrn hwinit,?init ; general initialization and signon
41 extrn ?ldccp,?rlccp ; load & reload CCP for BOOT & WBOOT
42
43 ; user defined character I/O routines
44
45 extrn ?ci,?co,?cist,?cost ; each take device in <B>
46 extrn ?cinit ; (re)initialize device in <C>
47 extrn ioctl
48 extrn @ctbl ; physical character device table
49
50 ; disk communication data items
51
52 extrn @dtbl ; table of pointers to XDPHs
53 public @adrv,@rdrv,@trk,@sect ; parameters for disk I/O
54 public @dma,@dbnk,@cnt ; '' '' '' ''
55 public @xdph,@op
56
57 ; memory control
58
59 public @cbnk ; current bank
60 extrn ?xmove,?move ; select move bank, and block move
61 extrn ?bank ; select CPU bank
62
63 ; clock support
64
65 extrn ?time ; signal time operation
66
67 extrn stampf
68 extrn ijphl ; vectored call
69
70 maclib modebaud.inc ; define mode bits
71
72
73 ; External names for BIOS entry points
74
75 public ?boot,?wboot,boot,?const,?conin,?cono,?list,?auxo,?auxi
76 public ?home,?sldsk,?sttrk,?stsec,?stdma,?read,?write
77 public ?lists,?sctrn
78 public ?conos,?auxis,?auxos,?dvtbl,?devin,?drtbl
79 public ?mltio,?flush,?mov,?tim,?bnksl,?stbnk,?xmov
80
81 public bs$stack
82
83
84 ; BIOS Jump vector.
85
86 ; All BIOS routines are invoked by calling these
87 ; entry points.
88
89 ?boot: jp boot ; initial entry on cold start
90 ?wboot: jp wboot ; reentry on program exit, warm start
91
92 ?const: jp const ; return console input status
93 ?conin: jp conin ; return console input character
94 ?cono: jp conout ; send console output character
95 ?list: jp list ; send list output character
96 ?auxo: jp auxout ; send auxiliary output character
97 ?auxi: jp auxin ; return auxiliary input character
98
99 ?home: jp home ; set disks to logical home
100 ?sldsk: jp seldsk ; select disk drive, return disk parameter info
101 ?sttrk: jp settrk ; set disk track
102 ?stsec: jp setsec ; set disk sector
103 ?stdma: jp setdma ; set disk I/O memory address
104 ?read: jp read ; read physical block(s)
105 ?write: jp write ; write physical block(s)
106
107 ?lists: jp listst ; return list device status
108 ?sctrn: jp sectrn ; translate logical to physical sector
109
110 ?conos: jp conost ; return console output status
111 ?auxis: jp auxist ; return aux input status
112 ?auxos: jp auxost ; return aux output status
113 ?dvtbl: jp devtbl ; return address of device def table
114 ?devin: jp ?cinit ; change baud rate of device
115
116 ?drtbl: jp getdrv ; return address of disk drive table
117 ?mltio: jp multio ; set multiple record count for disk I/O
118 ?flush: jp flush ; flush BIOS maintained disk caching
119
120 ?mov: jp ?move ; block move memory to memory
121 ?tim: jp ?time ; Signal Time and Date operation
122 ?bnksl: jp bnksel ; select bank for code execution and default DMA
123 ?stbnk: jp setbnk ; select different bank for disk I/O DMA operations
124 ?xmov: jp ?xmove ; set source and destination banks for one operation
125
126 jp stampf ; stamp system specific functions
127 ; reserved for system implementor
128 jp 0 ; reserved for future expansion
129 jp 0 ; reserved for future expansion
130 ?ioctl jp ioctl ;
131
132
133 ; BOOT
134 ; Initial entry point for system startup.
135
136 dseg ; this part can be banked
137
138 boot:
139 ld a,SYS$CBR
140 out0 (cbr),a
141 ld a,USR$CBAR
142 out0 (cbar),a
143 ld sp,bs$stack
144
145 call hwinit ; first time hardware initialisation
146
147 ld bc,16*256 + 0 ; initialize all 16 character devices
148 c$init$loop:
149 push bc
150 call ?cinit
151 pop bc
152 inc c
153 djnz c$init$loop
154
155 call ?init ; perform any additional system initialization
156 ; and print signon message
157
158 ld bc,16*256+0
159 ld hl,@dtbl ; init all 16 logical disk drives
160 d$init$loop:
161 push bc ; save remaining count and abs drive
162 ld e,(hl)
163 inc hl
164 ld d,(hl)
165 inc hl ; grab @drv entry
166 ld a,e
167 or d
168 jr z,d$init$next ; if null, no drive
169 push hl ; save @drv pointer
170 push de
171 pop ix ; XDPH address in <DE>
172 ld b,(ix-2)
173 ld (@ADRV),bc ; save absolute and relative drive code
174 ld l,(ix-4)
175 ld h,(ix-3) ; get init pointer
176 call ijphl ; call init routine
177 pop hl ; recover @drv pointer
178 d$init$next:
179 pop bc ; recover counter and drive #
180 inc c
181 djnz d$init$loop ; and loop for each drive
182 jp boot$1
183
184 cseg ; following in resident memory
185
186 boot$1:
187 call set$jumps
188 call ?ldccp ; fetch CCP for first time
189 jp ccp
190
191
192 ; WBOOT
193 ; Entry for system restarts.
194
195 wboot:
196 ld sp,bs$stack
197 call set$jumps ; initialize page zero
198 call ?rlccp ; reload CCP
199 jp ccp ; then reset jmp vectors and exit to ccp
200
201
202 set$jumps:
203
204 if banked
205 ld a,1
206 call ?bnksl
207 endif
208
209 ld a,0C3h ; jp opcode
210 ld (0),a
211 ld (5),a ; set up jumps in page zero
212 ld hl,?wboot
213 ld (1),hl ; BIOS warm start entry
214 ld hl,(@MXTPA)
215 ld (6),hl ; BDOS system call entry
216 ret
217
218
219 ds bs$stack$size
220 bs$stack equ $
221
222
223 ; DEVTBL
224 ; Return address of character device table
225
226 devtbl:
227 ld hl,@ctbl
228 ret
229
230
231 ; GETDRV
232 ; Return address of drive table
233
234 getdrv:
235 ld hl,@dtbl
236 ret
237
238
239
240 ; LIST
241 ; List Output. Send character in <C>
242 ; to all selected devices.
243
244 list:
245 ld hl,(@lovec) ; fetch list output bit vector
246 jr out$scan
247
248
249 ; AUXOUT
250 ; Auxiliary Output. Send character in <C>
251 ; to all selected devices
252
253 auxout:
254 ld hl,(@aovec) ; fetch aux output bit vector
255 jr out$scan
256
257
258 ; CONOUT
259 ; Console Output. Send character in <C>
260 ; to all selected devices
261
262 conout:
263
264 ld hl,(@covec) ; fetch console output bit vector
265
266 out$scan:
267 ld b,0 ; start with device 0
268 co$next:
269 add hl,hl ; shift out next bit
270 jr nc,not$out$device
271 push hl ; save the vector
272 push bc ; save device num and the character
273 call ?co ; if device selected, print it
274 pop bc ; recover count and character
275 pop hl ; recover the rest of the vector
276 not$out$device:
277 inc b ; next device number
278 ld a,h
279 or l ; see if any devices left
280 jr nz,co$next ; and go find them...
281 ret
282
283
284 ; LISTST
285 ; List Output Status. Return true if
286 ; all selected list output devices
287 ; are ready.
288
289 listst:
290 ld hl,(@lovec) ; get list output bit vector
291 jr ost$scan
292
293
294 ; AUXOST
295 ; Auxiliary Output Status. Return true if
296 ; all selected auxiliary output devices
297 ; are ready.
298
299 auxost:
300 ld hl,(@aovec) ; get aux output bit vector
301 jr ost$scan
302
303
304 ; CONOST
305 ; Console Output Status. Return true if
306 ; all selected console output devices
307 ; are ready.
308
309 conost:
310 ld hl,(@covec) ; get console output bit vector
311
312 ost$scan:
313 ld b,0 ; start with device 0
314 cos$next:
315 add hl,hl ; check next bit
316 push hl ; save the vector
317 push bc ; save the count
318 ld a,0FFh ; assume device ready
319 call c,?cost ; check status for this device
320 pop bc ; recover count
321 pop hl ; recover bit vector
322 or a ; see if device ready
323 ret z ; if any not ready, return false
324 inc b ; drop device number
325 ld a,h
326 or l ; see if any more selected devices
327 jr nz,cos$next
328 or 0FFh ; all selected were ready, return true
329 ret
330
331
332 cist1: ; get input status with <BC> and <HL> saved
333 push bc
334 push hl
335 call ?cist
336 pop hl
337 pop bc
338 or a
339 ret
340
341
342 ; AUXIST
343 ; Auxiliary Input Status. Return true if
344 ; any selected auxiliary input device
345 ; has an available character.
346
347 auxist:
348 ld hl,(@aivec) ; get aux input bit vector
349 jr ist$scan
350
351
352 ; CONST
353 ; Console Input Status. Return true if
354 ; any selected console input device
355 ; has an available character.
356
357 const:
358 ld hl,(@civec) ; get console input bit vector
359
360 ist$scan:
361 ld b,0 ; start with device 0
362 cis$next:
363 xor a ; assume next device not ready
364 add hl,hl ; check next bit (lets z flag unaffected)
365 call c,cist1 ; check status for this device
366 ret nz ; if any ready, return true
367 inc b ; next device number
368 ld a,h
369 or l ; see if any more selected devices
370 ret z ; all selected were not ready, return false
371 jr cis$next
372
373
374 ; AUXIN
375 ; Auxiliary Input. Return character from first
376 ; ready auxiliary input device.
377
378 auxin:
379 ld hl,(@aivec)
380 jr in$scan
381
382
383 ; CONIN
384 ; Console Input. Return character from first
385 ; ready console input device.
386
387 conin:
388 ld hl,(@civec)
389
390 ;check if only one device assigned
391
392 push hl ; save bit vector
393 ld b,0
394 insc_0:
395 or a ; clear carry
396 adc hl,hl ; shift out next bit
397 jr nc,insc_1 ;
398 jr z,ci$rdy ; single device
399 jr ci$check ;
400
401 insc_1:
402 inc b ; else, next device
403 ld a,h
404 or l ; see if any more devices
405 jr nz,insc_0 ; no,
406 pop hl
407
408 in$scan:
409 push hl ; save bit vector
410 ld b,0
411 ci$next:
412 xor a ; assume next device not ready
413 add hl,hl ; shift out next bit
414 ci$check:
415 call c,cist1 ; see if the device has a character
416 jr nz,ci$rdy ; this device has a character
417 inc b ; else, next device
418 ld a,h
419 or l ; see if any more devices
420 jr nz,ci$next ; go look at them
421 pop hl ; recover bit vector
422 jr in$scan ; loop til we find a character
423
424 ci$rdy:
425 pop hl ; discard extra stack
426 jp ?ci
427
428
429 ;-------------------------------------------------------------------------------
430 ; Utility Subroutines
431
432 ; BNKSEL
433 ; Bank Select. Select CPU bank for further execution.
434
435 bnksel:
436 ld (@cbnk),a ; remember current bank
437 jp ?bank ; and go exit through users
438 ; physical bank select routine
439
440 dseg ; following resides in banked memory
441
442 ; Disk I/O interface routines
443
444
445 ; SELDSK
446 ; Select Disk Drive. Drive code in <C>.
447 ; Invoke login procedure for drive
448 ; if this is first select. Return
449 ; address of disk parameter header
450 ; in <HL>
451
452 seldsk:
453 ld a,c ; save drive select code
454 ld (@adrv),a
455 xor a
456 ld (@op),a
457 ld (@cnt),a
458 ld b,a ; create index from drive code
459 ld hl,@dtbl
460 add hl,bc ; get pointer to dispatch table
461 add hl,bc
462 ld a,(hl)
463 inc hl
464 ld h,(hl)
465 ld l,a ; point at disk descriptor
466 ld (@xdph),hl ; save descriptor pointer
467 or h
468 ret z ; if no entry in table, no disk
469
470 bit 0,e ; login bit to zero flag
471 ex de,hl
472 ld hl,-2 ; get relative drive
473 add hl,de
474 ld a,(hl)
475 ld (@RDRV),a
476 jr nz,notfirst ; examine login bit
477 ld hl,-6
478 add hl,de
479 ld a,(hl)
480 inc hl
481 ld h,(hl)
482 ld l,a
483 call ijphl ; call LOGIN
484 notfirst:
485 ld hl,(@xdph) ; recover DPH pointer
486 ret
487
488
489 ; HOME
490 ; Home selected drive. Treated as SETTRK(0).
491
492 home:
493 ld bc,0 ; same as set track zero
494
495
496 ; SETTRK
497 ; Set Track. Saves track address from <BC>
498 ; in @TRK for further operations.
499
500 settrk:
501 ld (@trk),bc
502 ret
503
504
505 ; SETSEC
506 ; Set Sector. Saves sector number from <BC>
507 ; in @sect for further operations.
508
509 setsec:
510 ld (@sect),bc
511 ret
512
513
514 ; SETDMA
515 ; Set Disk Memory Address. Saves DMA address
516 ; from <BC> in @DMA and sets @DBNK to @CBNK
517 ; so that further disk operations take place
518 ; in current bank.
519
520 setdma:
521 ld (@dma),bc
522
523 ld a,(@cbnk) ; default DMA bank is current bank
524 ; fall through to set DMA bank
525
526 ; SETBNK
527 ; Set Disk Memory Bank. Saves bank number
528 ; in @DBNK for future disk data
529 ; transfers.
530
531 setbnk:
532 ld (@dbnk),a
533 ret
534
535
536 ; SECTRN
537 ; Sector Translate. Indexes skew table in <DE>
538 ; with sector in <BC>. Returns physical sector
539 ; in <HL>. If no skew table (<DE>=0) then
540 ; returns physical=logical.
541
542 sectrn:
543 ld l,c
544 ld h,b
545 ld a,d
546 or e
547 ret z
548 ex de,hl
549 add hl,bc
550 ld l,(hl)
551 ld h,0
552 ret
553
554
555 ; READ
556 ; Read physical record from currently selected drive.
557 ; Finds address of proper read routine from
558 ; extended disk parameter header (XDPH).
559
560 read:
561 ld a,1
562 ld (@op),a
563 ld ix,(@xdph) ; get drive descriptor pointer
564 ld l,(ix-8) ; get read routine entry
565 ld h,(ix-7)
566 jp (hl)
567
568
569 ; WRITE
570 ; Write physical sector from currently selected drive.
571 ; Finds address of proper write routine from
572 ; extended disk parameter header (XDPH).
573
574 write:
575 ld a,2
576 ld (@op),a
577 ld ix,(@xdph) ; get drive descriptor pointer
578 ld l,(ix-10) ; get write routine entry
579 ld h,(ix- 9)
580 jp (hl)
581
582
583
584 ; MULTIO
585 ; Set multiple sector count. Saves passed count in
586 ; @CNT
587
588 multio:
589 ld (@cnt),a
590 ret
591
592
593 ; FLUSH
594 ; BIOS deblocking buffer flush. Not implemented.
595
596 flush:
597 xor a
598 ret ; return with no error
599
600
601 ; disk communication data items
602 ; do not change order. sd driver depends on this
603
604 @xdph: ds 2 ; pointer to currently selected drives dph
605 @op ds 1 ; current disk operation 0:select, 1:read, 2 write
606 @adrv: ds 1 ; currently selected disk drive
607 @rdrv: ds 1 ; controller relative disk drive
608 @trk: ds 2 ; current track number
609 @sect: ds 2 ; current sector number
610 @dma: ds 2 ; current DMA address
611 @dbnk: db 0 ; bank for DMA operations
612 @cnt: db 0 ; record count for multisector transfer
613
614
615 cseg ; common memory
616
617 @cbnk: db 0 ; bank for processor operations
618
619
620 end