1145
|
1 **************************************************
|
|
2 * System Call: F$SRqMem
|
|
3 *
|
|
4 * Function: Request memory
|
|
5 *
|
1345
|
6 * It also updates 8K DAT blocks-if it finds an empty block, it re-does the 32
|
|
7 * entries in the SMAP table to indicate that they are free
|
|
8 *
|
1145
|
9 * Input: D = Byte count
|
|
10 *
|
|
11 * Output: U = Address of allocated memory area
|
|
12 *
|
|
13 * Error: CC = C bit set; B = error code
|
|
14 *
|
|
15 FSRqMem ldd R$D,u get size requested
|
|
16 addd #$00FF round it up to nearest 256 byte page
|
1387
|
17 clrb just keep # of pages (and start 8K block #)
|
1145
|
18 std R$D,u save rounded version back to user
|
1387
|
19 IFGT Level-1
|
|
20 ldy <D.SysMem get ptr to SMAP table
|
1145
|
21 leay $ED,y
|
1387
|
22 ENDC
|
1145
|
23
|
1387
|
24 * leay $20,y skip Block 0 (always reserved for system)
|
1145
|
25 * Change to pshs a,b:use 1,s for block # to check, and ,s for TFM spot
|
1387
|
26 * incb skip block 0 (always reserved for system)
|
|
27 pshs d reserve a byte & put 0 byte on stack
|
1145
|
28
|
|
29 * This loop updates the SMAP table if anything can be marked as unused
|
|
30 *L082F ldx <D.SysDAT get pointer to system DAT block list
|
|
31 * lslb adjust block offset for 2 bytes/entry
|
|
32 * ldd b,x get block type/# from system DAT
|
|
33 * cmpd #DAT.Free Unused block?
|
|
34 * beq L0847 yes, mark it free in SMAP table
|
|
35 * ldx <D.BlkMap No, get ptr to MMAP table
|
|
36 * lda d,x Get block marker for 2 meg mem map
|
|
37 * cmpa #RAMinUse Is it in use (not free, ROM or used by module)?
|
|
38 * bne L0848 No, mark it as type it is in SMAP table
|
|
39 * leay $20,y Yes, move to next block in pages
|
|
40 * bra L084F move to next block & try again
|
|
41
|
|
42 *L0847 clra Byte to fill system page map with (0=Not in use)
|
|
43 *L0848 sta ,s Put it on stack
|
|
44 * ldw #$0020 Get size of 8K block in pages
|
|
45 * tfm s,y+ Mark entire block's worth of pages with A
|
|
46 *L084F inc 1,s Bump up to next block to check
|
|
47 * ldb 1,s Get it
|
|
48 * cmpb #8 Done whole 64k system space?
|
|
49 * blo L082F no, keep checking
|
|
50 * Now we can actually attempt to allocate the system RAM requested
|
|
51 * NOTE: Opt for Coco/TC9 OS9 ONLY: skip last 17 pages with leay -17,y since
|
|
52 * they are: Kernal (REL/BOOT/OS9P1 - 15 pages), vector RAM & I/O (2 pages)
|
|
53 * (Already permanently marked @ L01D2)
|
|
54 * At the start, Y is pointing to the end of the SMAP table+1
|
|
55 ldx <D.SysMem Get start of table ptr
|
|
56 ldb #$20 skip block 0: it's always full
|
|
57 abx same size, but faster than leax $20,x
|
1239
|
58 * leay -17,y Skip Kernel, Vector RAM & I/O (Can't be free)
|
1145
|
59 L0857 ldb R$A,u Get # 256 byte pages requested
|
|
60 * Loop (from end of system mem map) to look for # continuous pages requested
|
|
61 L0859 equ *
|
|
62 IFNE H6309
|
|
63 cmpr x,y We still have any system RAM left to try?
|
|
64 ELSE
|
1239
|
65 pshs x
|
|
66 cmpy ,s++
|
1145
|
67 ENDC
|
|
68 bhi L0863 Yes, continue
|
|
69 comb Exit with No System RAM Error
|
1387
|
70 ldb #E$NoRAM
|
1145
|
71 bra L0894 Eat stack & exit
|
|
72
|
|
73 L0863 lda ,-y Get page marker (starting @ end of SMAP)
|
|
74 bne L0857 Used, try next lower page
|
|
75 decb Found 1 page, dec # pages we need to allocate
|
|
76 bne L0859 Still more pages needed, check if we can get more
|
1239
|
77 sty ,s Found free contiguous pages, save SMAP entry ptr
|
1145
|
78 lda 1,s Get LSB of ptr
|
|
79 lsra Divide by 32 (Calculate start 8K block #)
|
|
80 lsra
|
|
81 lsra
|
|
82 lsra
|
|
83 lsra
|
|
84 ldb 1,s Get LSB of ptr again
|
|
85 andb #%00011111 Keep only within 8K block offset
|
|
86 addb R$A,u Add # pages requested
|
|
87 addb #$1F Round up to nearest 8K block
|
|
88 lsrb Divide by 32 (Calculate end 8K block #)
|
|
89 lsrb
|
|
90 lsrb
|
|
91 lsrb
|
|
92 lsrb
|
|
93 ldx <D.SysPrc Get ptr to system proc. dsc.
|
|
94 lbsr L09BE Allocate an image with our start/end block #'s
|
|
95 bcs L0894 Couldn't, exit with error
|
|
96 ldb R$A,u Get # pages requested
|
|
97 lda #RAMinUse Get SMAP in use flag
|
|
98 L088A sta ,y+ Mark all the pages requested as In Use
|
|
99 decb
|
|
100 bne L088A
|
|
101 lda 1,s Get MSB of ptr to start of newly allocated Sys RAM
|
|
102 std R$U,u Save for caller
|
|
103 clrb No error
|
|
104 L0894 puls u,pc Eat stack (U is changed after it exits) & return
|
|
105
|
|
106
|
|
107 **************************************************
|
|
108 * System Call: F$SRtMem
|
|
109 *
|
|
110 * Function: Return memory
|
|
111 *
|
|
112 * Input: U = Address of memory to return
|
|
113 * D = Number of bytes to return
|
|
114 *
|
|
115 * Output: None
|
|
116 *
|
|
117 * Error: CC = C bit set; B = error code
|
|
118 *
|
|
119 FSRtMem ldd R$D,u get # pages to free up
|
|
120 beq L08F2 nothing to free, return without error
|
|
121 addd #$00FF round it up to nearest page
|
|
122 ldb R$U+1,u get LSB of address
|
|
123 beq L08A6 it's a even page, skip ahead
|
|
124 comb set carry
|
|
125 ldb #E$BPAddr get error code
|
|
126 rts return
|
|
127
|
|
128 L08A6 ldb R$U,u get MSB of page address
|
|
129 beq L08F2 not a legal page, return without error
|
|
130 ldx <D.SysMem get pointer to system memory map
|
|
131 abx set pointer into map
|
|
132 L08AD equ *
|
|
133 IFNE H6309
|
|
134 aim #^RAMinUse,,x+
|
|
135 ELSE
|
|
136 ldb ,x
|
|
137 andb #^RAMinUse
|
|
138 stb ,x+
|
|
139 ENDC
|
|
140 deca
|
|
141 bne L08AD
|
|
142 * Scan DAT image to find memory blocks to free up
|
|
143 ldx <D.SysDAT get pointer to system DAT image
|
|
144 IFNE H6309
|
1239
|
145 lde #DAT.BlCt get # blocks to check
|
1145
|
146 ELSE
|
|
147 ldy #DAT.BlCt
|
|
148 ENDC
|
|
149 L08BC ldd ,x get block image
|
|
150 cmpd #DAT.Free is it already free?
|
|
151 beq L08EC yes, skip to next one
|
|
152 ldu <D.BlkMap get pointer to MMU block map
|
|
153 lda d,u get allocation flag for this block: 16-bit offset
|
|
154 cmpa #RAMinUse being used?
|
|
155 bne L08EC no, move to next block
|
|
156 tfr x,d
|
|
157 subd <D.SysDAT
|
|
158 lslb
|
|
159 lslb
|
|
160 lslb
|
|
161 lslb
|
|
162 ldu <D.SysMem get pointer to system map
|
|
163 IFNE H6309
|
|
164 addr d,u
|
|
165 * Check if we can remove the entire memory block from system map
|
|
166 ldf #16 get # pages per block/2
|
|
167 L08DA ldd ,u++ Either of these 2 pages allocated?
|
|
168 ELSE
|
|
169 leau d,u
|
|
170 ldb #32
|
|
171 L08DA lda ,u+ Either of these 2 pages allocated?
|
|
172 ENDC
|
|
173 bne L08EC yes, can't free block, skip to next one
|
|
174 IFNE H6309
|
|
175 decf checked all pages?
|
|
176 ELSE
|
|
177 decb
|
|
178 ENDC
|
|
179 bne L08DA no, keep looking
|
|
180 ldd ,x get block # into B: could be >$80
|
|
181 ldu <D.BlkMap point to allocation table
|
|
182 IFNE H6309
|
|
183 sta d,u clear the block using 16-bit offset
|
|
184 ELSE
|
|
185 clr d,u
|
|
186 ENDC
|
|
187 ldd #DAT.Free get free block marker
|
|
188 std ,x save it into DAT image
|
|
189 L08EC leax 2,x move to next DAT block
|
|
190 IFNE H6309
|
|
191 dece done?
|
|
192 ELSE
|
|
193 leay -1,y
|
|
194 ENDC
|
|
195 bne L08BC no, keep checking
|
|
196 L08F2 clrb clear errors
|
|
197 L08F3 rts return
|
|
198
|
1345
|
199
|
|
200 **************************************************
|
|
201 * System Call: F$Boot
|
|
202 *
|
|
203 * Function: Bootstrap the system
|
|
204 *
|
|
205 * Optimized for size, as it's only called once...
|
|
206 *
|
|
207 * Input: None
|
|
208 *
|
|
209 * Output: None
|
|
210 *
|
|
211 * Error: CC = C bit set; B = error code
|
|
212 *
|
1145
|
213 FBoot lda #'t tried to boot
|
|
214 jsr <D.BtBug
|
|
215 coma Set boot flag
|
|
216 lda <D.Boot we booted once before?
|
|
217 bne L08F3 Yes, return
|
|
218 inc <D.Boot Set boot flag
|
|
219 ldx <D.Init Get ptr to init module if it exists
|
|
220 beq L0908 it doesn't, point to boot name
|
|
221 ldd <BootStr,x Get offset to text
|
|
222 beq L0908 Doesn't exist, get hard coded text
|
|
223 leax d,x Adjust X to point to boot module
|
|
224 bra L090C Try & link to module
|
|
225
|
|
226 boot fcs /Boot/
|
|
227
|
|
228 L0908 leax <boot,pcr
|
|
229 * Link to module and execute
|
|
230 L090C lda #Systm+Objct
|
|
231 os9 F$Link
|
|
232 bcs L08F3
|
|
233 lda #'b calling boot
|
|
234 jsr <D.BtBug
|
|
235 jsr ,y load boot file
|
|
236 bcs L08F3
|
|
237 std <D.BtSz save boot file size
|
|
238 stx <D.BtPtr save start pointer of bootfile
|
|
239 lda #'b boot returns OK
|
|
240 jsr <D.BtBug
|
|
241
|
|
242 * added for IOMan system memory extentions
|
1236
|
243 IFNE H6309
|
1145
|
244 ldd M$Name,x grab the name offset
|
|
245 ldd d,x find the first 2 bytes of the first module
|
|
246 cmpd #$4E69 'Ni' ? (NitrOS9 module?)
|
|
247 bne not.ext no, not system memory extensions
|
|
248 ldd M$Exec,x grab the execution ptr
|
|
249 jmp d,x and go execute the system memory extension module
|
1236
|
250 ENDC
|
1145
|
251
|
|
252 not.ext ldd <D.BtSz
|
|
253 bsr I.VBlock internal verify block routine
|
|
254 ldx <D.SysDAT get system DAT pointer
|
|
255 ldb $0D,x get highest allocated block number
|
|
256 incb allocate block 0, too
|
|
257 ldx <D.BlkMap point to the memory block map
|
|
258 lbra L01DF and go mark the blocks as used.
|
|
259
|
1345
|
260
|
|
261 **************************************************
|
|
262 * System Call: F$VBlock
|
|
263 *
|
|
264 * Function: ???
|
|
265 *
|
|
266 * Input: D = Size of block to verify
|
|
267 * X = Start address to verify
|
|
268 *
|
|
269 * Output: None
|
|
270 *
|
|
271 * Error: CC = C bit set; B = error code
|
|
272 *
|
1145
|
273 FVBlock ldd R$D,u size of block to verify
|
|
274 ldx R$X,u start address to verify
|
|
275
|
|
276 I.VBlock leau d,x point to end of bootfile
|
|
277 tfr x,d
|
|
278 anda #$E0
|
|
279 clrb
|
|
280 pshs d,u
|
|
281 lsra
|
|
282 lsra
|
|
283 lsra
|
|
284 lsra
|
|
285 ldy <D.SysDAT get pointer to system DAT
|
|
286 leay a,y offset to bootfile
|
|
287 L092D ldd M$ID,x get module ID
|
|
288 cmpd #M$ID12 legal ID?
|
|
289 bne L0954 no, keep looking
|
|
290 ldd M$Name,x find name offset pointer
|
|
291 pshs x
|
|
292 leax d,x
|
|
293
|
1247
|
294 bsr name.prt
|
|
295 *name.prt lda ,x+ get first character of the name
|
|
296 * jsr <D.BtBug print it out
|
|
297 * bpl name.prt
|
|
298 * lda #C$SPAC a space
|
|
299 * jsr <D.BtBug
|
1145
|
300
|
|
301 puls x
|
|
302 IFNE H6309
|
|
303 ldd ,s offset into block
|
|
304 subr d,x make X=offset into block
|
|
305 ELSE
|
|
306 tfr x,d
|
|
307 subd ,s
|
|
308 tfr d,x
|
|
309 ENDC
|
|
310 tfr y,d
|
|
311 os9 F$VModul
|
|
312 IFNE H6309
|
|
313 ldw ,s
|
|
314 leax w,x
|
|
315 ELSE
|
|
316 pshs b
|
|
317 ldd 1,s
|
|
318 leax d,x
|
|
319 puls b
|
|
320 ENDC
|
|
321 bcc L094E
|
|
322 cmpb #E$KwnMod
|
|
323 bne L0954
|
|
324 L094E ldd M$Size,x
|
|
325 leax d,x
|
|
326 fcb $8C skip 2 bytes
|
|
327
|
|
328 L0954 leax 1,x move to next byte
|
|
329 L0956 cmpx 2,s gone thru whole bootfile?
|
|
330 bcs L092D no, keep looking
|
|
331 leas 4,s purge stack
|
|
332 clrb
|
|
333 rts
|
1247
|
334
|
|
335
|
|
336 name.prt lda ,x+ get first character of the name
|
|
337 jsr <D.BtBug print it out
|
|
338 bpl name.prt
|
|
339 lda #C$SPAC a space
|
|
340 jsr <D.BtBug
|
|
341 rts
|
|
342
|