Mercurial > hg > Members > kono > nitros9-code
comparison level2/modules/kernel/fallbit.asm @ 1145:ca83286ded5b
Start of new OS-9 L2 Kernel
author | boisy |
---|---|
date | Tue, 22 Apr 2003 19:35:48 +0000 |
parents | |
children | 90bad6d8388c |
comparison
equal
deleted
inserted
replaced
1144:2cdb7acff8aa | 1145:ca83286ded5b |
---|---|
1 ************************************************** | |
2 * System Call: F$AllBit | |
3 * | |
4 * Function: Sets bits in an allocation bitmap | |
5 * | |
6 * Input: X = Address of allocation bitmap | |
7 * D = Number of first bit to set | |
8 * Y = Bit count (number of bits to set) | |
9 * | |
10 * Output: None | |
11 * | |
12 * Error: CC = C bit set; B = error code | |
13 * | |
14 FAllBit ldd R$D,u get bit # to start with | |
15 ldx R$X,u get address of allocation bit map | |
16 bsr CalcBit calculate byte & position & get first bit mask | |
17 ldy <D.Proc get current task # | |
18 ldb P$Task,y get task number | |
19 bra SetBit go do it | |
20 | |
21 * F$AllBit (System State) | |
22 FSAllBit ldd R$D,u get bit # to start with | |
23 ldx R$X,u get address of allocation bit map | |
24 bsr CalcBit calculate byte & pos & get first bit mask | |
25 ldb <D.SysTsk Get system task # | |
26 | |
27 * Main bit setting loop | |
28 SetBit equ * | |
29 IFNE H6309 | |
30 ldw R$Y,u get # bits to set | |
31 ELSE | |
32 ldy R$Y,u get # bits to set | |
33 ENDC | |
34 beq BitEx nothing to set, return | |
35 sta ,-s preserve current mask | |
36 bmi SkpBit If high bit set, skip ahead | |
37 os9 F$LDABX Go get original value from bit map | |
38 NxtBitLp ora ,s OR it with the current mask | |
39 IFNE H6309 | |
40 decw Dec the bit counter | |
41 ELSE | |
42 leay -1,y | |
43 ENDC | |
44 beq BitStEx Done, go put the byte back into the task's map | |
45 lsr ,s Shift out the lowest bit of original | |
46 bcc NxtBitLp If it is a 0, do next bit | |
47 os9 F$STABX If it was a 1 (which means whole byte done), | |
48 leax 1,x Store finished byte and bump ptr | |
49 SkpBit lda #$FF Preload a finished byte | |
50 bra SkpBit2 Skip ahead | |
51 | |
52 StFulByt os9 F$STABX Store full byte | |
53 leax 1,x Bump ptr up 1 | |
54 IFNE H6309 | |
55 subw #8 Bump counter down by 8 | |
56 SkpBit2 cmpw #8 Is there at least 8 more (a full byte) to do? | |
57 ELSE | |
58 leay -8,y | |
59 SkpBit2 cmpy #$0008 | |
60 ENDC | |
61 bhi StFulByt More than 1, go do current | |
62 beq BitStEx Exactly 1 byte left, do final store & exit | |
63 | |
64 * Last byte: Not a full byte left loop | |
65 L085A lsra Bump out least sig. bit | |
66 IFNE H6309 | |
67 decw Dec the bit counter | |
68 ELSE | |
69 leay -1,y | |
70 ENDC | |
71 bne L085A Keep going until last one is shifted out | |
72 coma Invert byte to get proper result | |
73 sta ,s Preserve a sec | |
74 os9 F$LDABX Get byte for original map | |
75 ora ,s Merge with new mask | |
76 BitStEx os9 F$STABX Store finished byte into task | |
77 leas 1,s Eat the working copy of the mask | |
78 BitEx clrb No error & return | |
79 rts | |
80 | |
81 * Calculate address of first byte we want, and which bit in that byte, from | |
82 * a bit allocation map given the address of the map & the bit # we want to | |
83 * point to | |
84 * Entry: D=Bit # | |
85 * X=Ptr to bit mask table | |
86 * Exit: A=Mask to point to bit # within byte we are starting on | |
87 * X=Ptr in allocation map to first byte we are starting on | |
88 CalcBit pshs b,y preserve registers | |
89 IFNE H6309 | |
90 lsrd divide bit # by 8 to calculate byte # to start | |
91 lsrd allocating at | |
92 lsrd | |
93 addr d,x Offset that far into the map | |
94 ELSE | |
95 lsra | |
96 rorb | |
97 lsra | |
98 rorb | |
99 lsra | |
100 rorb | |
101 leax d,x | |
102 ENDC | |
103 puls b restore bit position LSB | |
104 leay <L0883,pc point to mask table | |
105 andb #7 round it down to nearest bit | |
106 lda b,y get bit mask | |
107 puls y,pc restore & return | |
108 | |
109 * Bit position table (NOTE that bit #'s are done by left to right) | |
110 L0883 fcb $80,$40,$20,$10,$08,$04,$02,$01 | |
111 | |
112 | |
113 ************************************************** | |
114 * System Call: F$DelBit | |
115 * | |
116 * Function: Clears bits in an allocation bitmap | |
117 * | |
118 * Input: X = Address of allocation bitmap | |
119 * D = Number of first bit to clear | |
120 * Y = Bit count (number of bits to clear) | |
121 * | |
122 * Output: None | |
123 * | |
124 * Error: CC = C bit set; B = error code | |
125 * | |
126 FDelBit ldd R$D,u Get bit # to start with | |
127 ldx R$X,u Get addr. of bit allocation map | |
128 bsr CalcBit Point to starting bit | |
129 ldy <D.Proc Get current Task # | |
130 ldb P$Task,y get task # | |
131 bra L08A0 Do rest of 0 bits | |
132 | |
133 * F$DelBit entry point for system state | |
134 FSDelBit ldd R$D,u Get bit # to start with | |
135 ldx R$X,u Get addr. of bit allocation map | |
136 bsr CalcBit Point to starting bit | |
137 ldb <D.SysTsk Get system task # | |
138 | |
139 L08A0 equ * | |
140 IFNE H6309 | |
141 ldw R$Y,u Get # bits to clear | |
142 ELSE | |
143 ldy R$Y,u Get # bits to clear | |
144 ENDC | |
145 beq L08E0 None, return | |
146 coma Invert current bit mask | |
147 sta ,-s Preserve on stack | |
148 bpl L08BC If high bit clear, skip ahead | |
149 os9 F$LDABX Go get byte from user's map | |
150 L08AD anda ,s AND it with current mask | |
151 IFNE H6309 | |
152 decw Dec the bits left counter | |
153 ELSE | |
154 leay -1,y | |
155 ENDC | |
156 beq BitDone Done, store finished byte back in task's map | |
157 asr ,s Shift out lowest bit, leaving highest alone | |
158 bcs L08AD If it is a 1, do next bit | |
159 os9 F$STABX If it was a 0 (which means whole byte done), | |
160 leax 1,x store finished byte & inc. ptr | |
161 L08BC clra Preload a cleared byte | |
162 bra ChkFull skip ahead | |
163 L08BF os9 F$STABX Store full byte | |
164 leax 1,x Bump ptr up by 1 | |
165 IFNE H6309 | |
166 subw #8 Dec bits left counter by 8 | |
167 ChkFull cmpw #8 At least 1 full byte left? | |
168 ELSE | |
169 leay -8,y | |
170 ChkFull cmpy #8 | |
171 ENDC | |
172 bhi L08BF Yes, do a whole byte in 1 shot | |
173 beq BitDone Exactly 1, store byte & exit | |
174 coma < full byte left, invert bits | |
175 L08CF lsra Shift out rightmost bit | |
176 IFNE H6309 | |
177 decw Dec bits left counter | |
178 ELSE | |
179 leay -1,y | |
180 ENDC | |
181 bne L08CF Keep doing till done | |
182 sta ,s Save finished mask | |
183 os9 F$LDABX Get original byte from task | |
184 anda ,s Merge cleared bits with it | |
185 BitDone os9 F$STABX Store finished byte into task | |
186 leas 1,s Eat working copy of mask | |
187 L08E0 clrb Eat error & return | |
188 rts | |
189 | |
190 | |
191 ************************************************** | |
192 * System Call: F$SchBit | |
193 * | |
194 * Function: Search bitmap for a free area | |
195 * | |
196 * Input: X = Address of allocation bitmap | |
197 * D = Starting bit number | |
198 * Y = Bit count (free bit block size) | |
199 * U = Address of end of allocation bitmap | |
200 * | |
201 * Output: D = Beginning bit number | |
202 * Y = Bit count | |
203 * | |
204 * Error: CC = C bit set; B = error code | |
205 * | |
206 FSchBit ldd R$D,u Get start bit # | |
207 ldx R$X,u Get addr. of allocation bit map | |
208 bsr CalcBit Point to starting bit | |
209 ldy <D.Proc Get task # | |
210 ldb P$Task,y | |
211 bra L08F8 skip ahead | |
212 | |
213 * F$SchBit entry point for system | |
214 FSSchBit ldd R$D,u Get start bit # | |
215 ldx R$X,u Get addr. of allocation bit map | |
216 lbsr CalcBit Point to starting bit | |
217 ldb <D.SysTsk Get task # | |
218 * Stack: 0,s : byte we are working on (from original map) | |
219 * 1,s : Mask of which bit in current byte to start on | |
220 * 2,s : Task number the allocation bit map is in | |
221 * 3,s : Largest block found so far | |
222 * 5,s : Starting bit # of requested (or closest) size found | |
223 * 7,s : Starting bit # of current block being checked (2 bytes) (NOW IN Y) | |
224 IFNE H6309 | |
225 L08F8 pshs cc,d,x,y Preserve task # & bit mask & reserve stack space | |
226 clrd Faster than 2 memory clears | |
227 ELSE | |
228 L08F8 pshs cc,d,x,y,u Preserve task # & bit mask & reserve stack space | |
229 clra | |
230 clrb | |
231 ENDC | |
232 std 3,s Preserve it | |
233 IFNE H6309 | |
234 ldw R$D,u get start bit # | |
235 tfr w,y save as current block starting bit # | |
236 ELSE | |
237 ldy R$D,u | |
238 sty 7,s | |
239 ENDC | |
240 bra Skipper skip ahead | |
241 | |
242 * New start point for search at current location | |
243 RstSrch equ * | |
244 IFNE H6309 | |
245 tfr w,y Preserve current block bit # start | |
246 ELSE | |
247 sty 7,s | |
248 ENDC | |
249 * Move to next bit position, and to next byte if current byte is done | |
250 MoveBit lsr 1,s Move to next bit position | |
251 bcc CheckBit If not the last one, check it | |
252 ror 1,s Move bit position marker to 1st bit again | |
253 leax 1,x Move byte ptr (in map) to next byte | |
254 | |
255 * Check if we are finished allocation map | |
256 Skipper cmpx R$U,u done entire map? | |
257 bhs BadNews yes, couldn't fit in 1 block, notify caller | |
258 ldb 2,s Get task number | |
259 os9 F$LDABX Get byte from bit allocation map | |
260 sta ,s Preserve in scratch area | |
261 | |
262 * Main checking | |
263 CheckBit equ * | |
264 IFNE H6309 | |
265 incw Increment current bit # | |
266 ELSE | |
267 leay 1,y | |
268 ENDC | |
269 lda ,s Get current byte | |
270 anda 1,s Mask out all but current bit position | |
271 bne RstSrch If bit not free, restart search from next bit | |
272 IFNE H6309 | |
273 tfr w,d Dupe current bit # into D | |
274 subr y,d Calculate size we have free so far | |
275 cmpd R$Y,u As big as user requested? | |
276 ELSE | |
277 tfr y,d | |
278 subd 7,s | |
279 cmpd R$Y,u | |
280 ENDC | |
281 bhs WereDone Yes, we are done | |
282 cmpd $03,s As big as the largest one we have found so far? | |
283 bls MoveBit No, move to next bit and keep going | |
284 std $03,s It is the largest, save current size | |
285 IFNE H6309 | |
286 sty $05,s Save as start bit # of largest block found so far | |
287 ELSE | |
288 ldd 7,s | |
289 std 5,s | |
290 ENDC | |
291 bra MoveBit Move to next bit and keep going | |
292 | |
293 * Couldn't find requested size block; tell user where the closest was found | |
294 * and how big it was | |
295 BadNews ldd $03,s Get size of largest block we found | |
296 std R$Y,u Put into callers Y register | |
297 comb Set carry to indicate we couldn't get full size | |
298 ldd 5,s Get starting bit # of largest block we found | |
299 bra BadSkip skip ahead | |
300 * Found one, tell user where it is | |
301 WereDone equ * | |
302 IFNE H6309 | |
303 tfr y,d Get start bit # of the block we found | |
304 ELSE | |
305 ldd 7,s | |
306 ENDC | |
307 BadSkip std R$D,u Put starting bit # of block into callers D register | |
308 IFNE H6309 | |
309 leas $07,s Eat our temporary stack area & return | |
310 ELSE | |
311 leas $09,s | |
312 ENDC | |
313 rts |