965
|
1 ********************************************************************
|
|
2 * ReBoot - Reboot into OS-9 or DECB
|
|
3 *
|
|
4 * $Id$
|
|
5 *
|
1255
|
6 * Edt/Rev YYYY/MM/DD Modified by
|
|
7 * Comment
|
965
|
8 * ------------------------------------------------------------------
|
1255
|
9 * 1 ????/??/?? Alan DeKok
|
|
10 * Started.
|
965
|
11
|
|
12 nam ReBoot
|
|
13 ttl Reboot into OS-9 or DECB
|
|
14
|
|
15 ifp1
|
|
16 use defsfile
|
|
17 endc
|
|
18
|
|
19 tylg set Prgrm+Objct
|
|
20 atrv set ReEnt+Rev
|
1255
|
21 rev set $00
|
965
|
22
|
|
23 mod eom,name,tylg,atrv,start,size
|
|
24
|
|
25 *==================================================================
|
|
26 * On boot-up, OS9p2 does (in order)
|
|
27 * an I$ChDir to the directory specified in the Init file
|
|
28 * this opens an RBF buffer for the device, and at the minimum,
|
|
29 * allocates:
|
|
30 * $0100 1 page by IOMan for the IRQ/VIRQ polling table
|
|
31 * $0100 1 page by IOMan for the disk driver static storage
|
|
32 * $0100 1 page by IOMan for the disk PD.BUF buffer
|
|
33 * (the path descriptor comes out of memory allocated already by OS9p1
|
|
34 * from block 0)
|
|
35 *
|
|
36 * Next, OS9p2 does an I$Open to '/term' (or whatever, from the Init module)
|
|
37 * $0100 1 page allocated for '/term' device static storage
|
|
38 * $0100 1 page allocated for '/term' PD.BUF buffer
|
|
39 *
|
1933
|
40 * VTIO does an F$Load to get GrfDrv into memory, and we then have
|
965
|
41 * $0200 2 pages allocated by IOMan via F$AllPrc, for the F$Load
|
|
42 *------- total
|
|
43 * $0700 pages UP from $4000, so GrfDrv can load
|
|
44
|
|
45 *==================================================================
|
|
46 * The system's memory map is set up as:
|
|
47 * $0000-$1FFF: block 0, global system memory
|
|
48 * $2000-$3FFF: this block MUST be free: grfdrv is loaded here on boot
|
|
49 * once booted, process descriptors, etc. get allocated here
|
|
50 * $4000-$46FF: initial data storage for system prior to loading GrfDrv
|
|
51 * $4700-$ECFF: OS9Boot file: $A600 maximum size
|
|
52 * $ED00-$FEFF: kernel, and constant page at $FE00
|
|
53 * $FF00-$FFFF: hardware, and RAM under block $3F that's unused by everyone!
|
|
54 *==================================================================
|
|
55
|
|
56 maxOS9Bt equ $A600 max. size of the OS9Boot file
|
|
57
|
|
58 org 0
|
|
59 OS9Boot rmb maxOS9Bt
|
|
60 Kernel rmb $1200 size of the kernel to use
|
|
61 PrcDsc rmb $0200 current process descriptor
|
|
62 param.pt rmb 2 parameter pointer
|
|
63 os9btsz rmb 2 size of the OS9Boot file
|
|
64 rbflag rmb 2 -b -r flags
|
|
65 oflag rmb 1 OS9Boot reload flag
|
|
66 kflag rmb 1 kernel reload flag
|
|
67 gflag rmb 1 GrfDrv reload flag
|
|
68 Param rmb $C000-. shift everything up to $C000
|
|
69 Stack equ .
|
|
70 GrfDrv rmb $2000 so we now have all of the memory full
|
|
71 SIZE equ .
|
|
72
|
|
73 *==================================================================
|
|
74 * We'll put all of the 'magic' code in GrfDrv's stack, which doesn't
|
|
75 * care about being uninitialize
|
|
76 *
|
|
77 * Actually, this program puts it at offset $0000 in block $3F,
|
|
78 * which is $E000 when the system is rebooted. BOOT then copies
|
|
79 * all of the information down to $1C80 before loading in the new OS9Boot
|
|
80 * file, and copying the original BOOT module back to $ED00+$0130
|
|
81 *==================================================================
|
|
82 org $1C80 where memory is ALWAYS mapped in
|
|
83 os9.siz rmb 2 size of the os9boot file
|
|
84 grf.flg rmb 1 flag: reload GrfDrv?
|
|
85 os9.dat rmb 16 DAT image
|
|
86 boot rmb $01D0 original BOOT module
|
|
87
|
|
88 NAME fcs /ReBoot/
|
|
89 fcb $01
|
|
90
|
|
91 *==================================================================
|
|
92 * Start of the program: Move the stack to lower memory, and
|
|
93 * copy the parameters there, too.
|
|
94 *==================================================================
|
|
95 Start lds #stack point the stack to somewhere safe
|
|
96 tfr d,y now Y = size of the parameter area
|
|
97 ldu #param U=$0000 always in the Coco, so this is OK
|
|
98
|
|
99 s.copy lda ,x+
|
|
100 sta ,u+
|
|
101 leay -1,y
|
|
102 bne s.copy
|
|
103
|
|
104 clra
|
|
105 sta >oflag no os9boot
|
|
106 sta >kflag no kernel
|
|
107 sta >gflag no GrfDrv
|
|
108 sta >rbflag default to allowing '-r -b' options
|
|
109
|
|
110 ldx #Param point to the start of the parameters again
|
|
111 stx >param.pt save pointer
|
|
112
|
|
113 *==================================================================
|
|
114 * Check for more parameters
|
|
115 *==================================================================
|
|
116 Check ldx >param.pt get the current parameter pointer
|
|
117 check.p ldd ,x
|
|
118 cmpa #C$SPAC skip leading spaces
|
|
119 bne Contin
|
|
120 leax 1,x
|
|
121 bra check.p
|
|
122
|
|
123 Contin cmpa #C$CR simply reboot
|
|
124 bne Hy check for hyphens
|
|
125 tst >rbflag are the '-r' '-b' options valid?
|
|
126 lbne Finalize no, finalize the boot, and reboot
|
|
127 lbra CrashIt yes, go ahead and crash the system.
|
|
128
|
|
129 Hy cmpa #'- hyphen?
|
|
130 lbne Help
|
|
131 cmpb #'? help?
|
|
132 lbeq Help
|
|
133 andb #$DF make uppercase
|
|
134 tst >rbflag are the '-r' '-b' options valid?
|
|
135 bne o.flag no, skip ahead to checking other flags
|
|
136 cmpb #'B
|
|
137 lbeq CrashIt
|
|
138
|
|
139 cmpb #'R reboot?
|
|
140 lbeq LoadIt
|
|
141
|
|
142 *==================================================================
|
|
143 * Only -L -K -G options are valid here
|
|
144 *==================================================================
|
|
145 o.flag cmpb #'L load the OS9Boot file?
|
|
146 lbeq load.os9 yes, go load it
|
|
147
|
|
148 cmpb #'K load the kernel file?
|
|
149 lbeq load.krn yes, go load it
|
|
150
|
|
151 cmpb #'G load GrfDrv?
|
|
152 lbne Help no, print out a help message
|
|
153
|
|
154 *==================================================================
|
|
155 * load in GrfDrv
|
|
156 *==================================================================
|
|
157 load.grf tst >gflag
|
|
158 lbne Help
|
|
159 stb >gflag
|
|
160 ldu #grfdrv where to put grfdrv
|
|
161 ldy #$2000 the maximum size it can be
|
|
162 bsr load.fil
|
|
163 lbra Check check for more options
|
|
164
|
|
165 *==================================================================
|
|
166 * Load in the kernel
|
|
167 *==================================================================
|
|
168 load.krn tst >kflag already loaded the kernel?
|
|
169 lbne Help yes, print error
|
|
170 stb >kflag we're loading the kernel
|
|
171 ldu #kernel where to put the kernel
|
|
172 ldy #$1200 the size of the kernel
|
|
173 bsr load.fil load in the kernel file
|
|
174 lbra Check check for more options
|
|
175
|
|
176 *==================================================================
|
|
177 * load the specified file
|
|
178 * Entry: X = parameter pointer
|
|
179 * Y = maximum size of the file to read
|
|
180 * U = pointer to load address for the file
|
|
181 *==================================================================
|
|
182 load.fil stb >rbflag don't allow -r -b any more
|
|
183 leax 2,x skip '-X' option
|
|
184 lda ,x+ grab the next character
|
|
185 cmpa #C$SPAC space?
|
|
186 lbne Help no, print help message
|
|
187
|
|
188 pshs x save filename for later
|
|
189 lda #READ. read-only permissions
|
|
190 os9 I$Open open the file
|
|
191 lbcs fil.err
|
|
192
|
|
193 stx >param.pt save parameter pointer for later
|
|
194
|
|
195 tfr u,x put load address into X
|
|
196 os9 I$Read read in the OS9Boot file
|
|
197 lbcs fil.err
|
|
198 puls x,pc restore unused X, and exit
|
|
199
|
|
200 *==================================================================
|
|
201 * load a new OS9Boot file
|
|
202 *==================================================================
|
|
203 load.os9 tst >oflag
|
|
204 lbne Help
|
|
205 stb >oflag flag we have an OS9Boot file requested
|
|
206 stb >rbflag and the '-r' or '-b' options are no longer valid
|
|
207
|
|
208 ldu #$0000 where to put the information
|
|
209 ldy #MaxOS9Bt
|
|
210 lbsr load.fil go load the file into memory
|
|
211 sty >os9btsz save the size of the OS9Boot file for later
|
|
212 * do some syntax checking on the OS9Boot file...
|
|
213 lbra Check go check for more parameters
|
|
214
|
|
215 *==================================================================
|
|
216 * finalize the crash of the system
|
|
217 *==================================================================
|
|
218 Finalize lbsr Seek seek /DD to 0
|
|
219 os9 F$ID get my ID and process #
|
|
220 ldx #PrcDsc point to where to put the process descriptor
|
|
221 os9 F$GPrDsc get it
|
|
222 lbcs Exit
|
|
223 leax P$DATImg,x point to it's DAT image
|
|
224
|
|
225 orcc #IntMasks shut off IRQ's
|
|
226 lda #$3F block $3F
|
|
227 sta >$FFA8 map in block $3F
|
|
228
|
|
229 lda >oflag do OS9Boot?
|
|
230 bne do.os9bt yup, skip ahead
|
|
231 lda >gflag OS9Boot OR GrfDrv?
|
|
232 beq do.kern neither one, just do the kernel
|
|
233 lbra Help no OS9Boot, but trying to reload GrfDrv: invalid
|
|
234
|
|
235 * copy our DAT image to block 0
|
|
236 do.os9bt ldu #$0000 to the start of block $3F
|
|
237 ldd >os9btsz get the size of the OS9Boot file
|
|
238 std ,u++ save it for later
|
|
239 lda >gflag do we reload GrfDrv?
|
|
240 sta ,u+ save flag for later
|
|
241 ldb #16 copy the whole DAT image...
|
|
242 dat.lp lda ,x+
|
|
243 sta ,u+
|
|
244 decb
|
|
245 bne dat.lp
|
|
246
|
|
247 lda >kflag do we move the kernel over?
|
|
248 beq no.kern if clear, we don't have a kernel in high memory
|
|
249
|
|
250 do.kern pshs u save current pointer to $E000+x
|
|
251 ldu #$0D00 where to put the new kernel
|
|
252 ldx #kernel where the new kernel currently is located
|
|
253 ldy #$1200 the size of the kernel
|
|
254 bsr bt.lp copy the kernel over a byte at a time
|
|
255 puls u restore low memory pointer
|
|
256
|
|
257 lda >oflag
|
|
258 ora >gflag OS9Boot OR GrfDrv?
|
|
259 lbeq LoadIt.0 nope, just the kernel: reboot quickly
|
|
260
|
|
261 * copy the original BOOT module to block 0
|
|
262 no.kern ldx #$0D00+$0130 block 0, offset $0D00+REL
|
|
263 bsr bt.copy
|
|
264 leax eom,pc point to the end of the module
|
|
265 ldu #$0D00+$0130 over top of the original BOOT module
|
|
266 bsr bt.copy
|
|
267 lbra LoadIt.0 and go re-load the OS9Boot file
|
|
268
|
|
269 bt.copy ldy #$01D0
|
|
270 bt.lp lda ,x+
|
|
271 sta ,u+
|
|
272 leay -1,y
|
|
273 bne bt.lp
|
|
274 rts
|
|
275
|
|
276 *==================================================================
|
|
277 * crash the system
|
|
278 *==================================================================
|
|
279 CrashIt lbsr Seek seek /DD to track 0
|
|
280 orcc #IntMasks turn off IRQ's
|
|
281 clrb
|
|
282 stb >$FFA8 map in block 0
|
|
283 stb >$0071 cold reboot
|
|
284 lda #$38 bottom of DECB block mapping
|
|
285 sta >$FFA8 map in block zero
|
|
286 stb >$0071 and cold reboot here, too
|
|
287 ldu #$0000 force code to go at offset $0000
|
|
288 leax ReBoot,pc reboot code
|
|
289 ldy #BtSize
|
|
290 cit.loop lda ,x+
|
|
291 sta ,u+
|
|
292 leay -1,y
|
|
293 bne cit.loop
|
|
294 clr >$FEED cold reboot
|
|
295 clr >$FFD8 go to low speed
|
|
296 jmp >$0000 jump to the reset code
|
|
297
|
|
298 *==================================================================
|
|
299 * reboot the system
|
|
300 *==================================================================
|
|
301 ReBoot ldd #$3808 block $38, 8 times
|
|
302 ldx #$FFA0 where to put it
|
|
303 Lp sta 8,x put into map 1
|
|
304 sta ,x+ and into map 0
|
|
305 inca
|
|
306 decb count down
|
|
307 bne Lp
|
|
308
|
|
309 lda #$4C standard DECB mapping
|
|
310 sta >$FF90
|
|
311 clr >$FF91 go to map type 0
|
|
312 clr >$FFDE and to all-ROM mode
|
|
313 ldd #$FFFF
|
|
314 * clrd executes as CLRA on a 6809
|
|
315 fdb $104F
|
|
316 tstb is it a 6809?
|
|
317 bne Reset yup, skip ahead
|
|
318 * ldmd #$00 go to 6809 mode!
|
|
319 fcb $11,$3D,$00
|
|
320 Reset jmp [$FFFE] do a reset
|
|
321 BtSize equ *-Reboot
|
|
322
|
|
323 *==================================================================
|
|
324 * reload the OS9Boot file
|
|
325 *==================================================================
|
|
326 LoadIt lbsr Seek seek /DD to track 0
|
|
327 orcc #IntMasks
|
|
328 LoadIt.0 clr >$FFA8 map in block 0
|
|
329 ldu #$0520 somewhere unused
|
|
330 leax <ReLoad,pc point to code to reboot the system
|
|
331 ldy #LoadSiz
|
|
332 lit.loop lda ,x+
|
|
333 sta ,u+
|
|
334 leay -1,y
|
|
335 bne lit.loop
|
|
336 jmp >$0520 and jump to it
|
|
337
|
|
338 ReLoad clr >$FF91 go to map type 0
|
|
339 ldx #$ED00 where REL is located
|
|
340
|
|
341 RLp leax 1,x to to the next byte (OS...)
|
|
342 ldd ,x
|
|
343 cmpd #M$ID12
|
|
344 bne RLp if not the start of a module
|
|
345 ldd M$Exec,x get execution address of the module (REL)
|
|
346 jmp d,x and go to it
|
|
347 LoadSiz equ *-ReLoad
|
|
348
|
|
349 *==================================================================
|
|
350 * print out the help message
|
|
351 *==================================================================
|
|
352 Help leax HMsg,pc
|
|
353 ldy #HLen
|
|
354 Print lda #1 to STDOUT
|
|
355 os9 I$Write
|
|
356 ClnExit clrb
|
|
357 Exit os9 F$Exit
|
|
358
|
|
359 HMsg fcc /ReBoot: Reboots the system, or returns to DECB./
|
|
360 fcb C$CR,C$LF
|
|
361 fcc / use: reboot [-b] [-r] [-k filename] [-l filename]/
|
|
362 fcc / [-g filename]/
|
|
363 fcb C$CR,C$LF
|
|
364 fcc / -b = return to DECB (default)/
|
|
365 fcb C$CR,C$LF
|
|
366 fcc / ( equivalent to <CTRL><ALT><RESET> )/
|
|
367 fcb C$CR,C$LF
|
|
368 fcc / -r = reload OS9Boot/
|
|
369 fcb C$CR,C$LF
|
|
370 fcc / ( equivalent to pressing <RESET> )/
|
|
371 fcb C$CR,C$LF
|
|
372 fcc /** The previous 2 options are mutually exclusive to the/
|
|
373 fcc / next 3.**/
|
|
374 fcb C$CR,C$LF
|
|
375 fcc / -k [filename] = load in a new kernel track from [filename]/
|
|
376 fcb C$CR,C$LF
|
|
377 fcc / -l [filename] = reload the OS9Boot file from [filename]/
|
|
378 fcb C$CR,C$LF
|
|
379 fcc / -g [filename] = load in a new GrfDrv from [filename]/
|
|
380 fcb C$CR,C$LF
|
|
381 fcc / If you reload GrfDrv, you MUST also reload the/
|
|
382 fcc / OS9Boot file./
|
|
383 fcb C$CR,C$LF
|
|
384 HLen equ *-HMsg
|
|
385
|
|
386 DD fcs '/DD'
|
|
387
|
|
388 *==================================================================
|
|
389 * Seek /DD to sector 0... why not?
|
|
390 *==================================================================
|
|
391 Seek leax <DD,pc
|
|
392 lda #READ.
|
|
393 os9 I$Open
|
|
394 bcs seek.ex
|
|
395 ldx #$0000
|
|
396 ldu #$0000
|
|
397 os9 I$Seek restore head on /DD to track 0
|
|
398 os9 I$Close
|
|
399 seek.ex rts
|
|
400
|
|
401 fil.err puls u restore pointer to filename we had error with
|
|
402 pshs b,cc save error code, condition
|
|
403 leax >fil.msg,pc
|
|
404 ldy #fil.len
|
|
405 lda #$02 to STDERR
|
|
406 os9 I$Write
|
|
407
|
|
408 * A=$02 still...
|
|
409 leax ,u
|
|
410 fil.lp ldb ,u+
|
|
411 cmpb #C$SPAC
|
|
412 bhi fil.lp
|
|
413 ldb #C$CR get a CR
|
|
414 stb -1,u save for later
|
|
415
|
|
416 ldy #$0100 maximum amount of junk to write
|
|
417 os9 I$WritLn dump out the filename
|
|
418 puls b,cc restore error code, condition
|
|
419 os9 F$Exit and exit
|
|
420
|
|
421 fil.msg fcc /ReBoot: Error reading file: /
|
|
422 fil.len equ *-fil.msg
|
|
423
|
|
424 fcc 'MAGIC Boot Module is next!'
|
|
425
|
|
426 emod
|
|
427 eom equ *
|
|
428 end
|