Mercurial > hg > Members > kono > nitros9-code
annotate level2/modules/kernel/funlink.asm @ 3195:6eb2edad80d8
L2: Introduce symbol KrnBlk to define kernel block number
This is the block number that the kernel is loaded into. This is
platform-specific, a function of the behaviour of the platform MMU/DAT.
CRCs are unaffected by this change.
author | Neal Crook <foofoobedoo@gmail.com> |
---|---|
date | Thu, 01 Jun 2017 22:13:49 +0100 |
parents | 039ddb7c8ad7 |
children |
rev | line source |
---|---|
1145 | 1 ************************************************** |
2 * System Call: F$UnLink | |
3 * | |
4 * Function: Unlink a module | |
5 * | |
6 * Input: U = Address of module header | |
7 * | |
8 * Output: None | |
9 * | |
10 * Error: CC = C bit set; B = error code | |
11 * | |
12 FUnLink pshs d,u preserve register stack pointer and make a buffer | |
13 ldd R$U,u get pointer to module header | |
14 tfr d,x copy it to X | |
15 lsra divide MSB by 32 to get DAT block offset | |
16 lsra | |
17 lsra | |
18 lsra | |
19 lsra | |
20 sta ,s save DAT block offset | |
21 lbeq L01D0 zero, can't use so exit | |
22 ldu <D.Proc get pointer to current process | |
23 leay P$DATImg,u point Y to it's DAT image | |
24 lsla account for 2 bytes/entry | |
25 ldd a,y get block # | |
26 ldu <D.BlkMap get pointer to system block map | |
27 IFNE H6309 | |
28 tim #ModBlock,d,u Is memory block a module type? | |
29 ELSE | |
30 ldb d,u | |
31 bitb #ModBlock | |
32 ENDC | |
33 beq L01D0 no, exit without error | |
34 leau (P$Links-P$DATImg),y point to block link counts | |
35 bra L0161 go unlink block | |
36 | |
37 L015D dec ,s we done? | |
38 beq L01D0 yes, go on | |
39 L0161 ldb ,s get current offset | |
40 lslb account for 2 bytes entry | |
41 ldd b,u get block link count | |
42 beq L015D already zero, get next one | |
43 lda ,s get block offset | |
44 lsla find offset into 64k map by multiplying by 32 | |
3123
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1145
diff
changeset
|
45 lsla |
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1145
diff
changeset
|
46 lsla |
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1145
diff
changeset
|
47 lsla |
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1145
diff
changeset
|
48 lsla |
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1145
diff
changeset
|
49 clrb |
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1145
diff
changeset
|
50 nega |
1145 | 51 IFNE H6309 |
52 addr d,x | |
53 ELSE | |
54 leax d,x | |
55 ENDC | |
56 ldb ,s get block offset | |
57 lslb account for 2 bytes/entry | |
58 ldd b,y get block # | |
59 ldu <D.ModDir get module directory pointer | |
60 bra L0185 go look for it | |
61 | |
62 * Main module directory search routine | |
63 L017C leau MD$ESize,u move to next module entry | |
64 cmpu <D.ModEnd done entire directory? | |
65 bhs L01D0 Yes, exit | |
66 L0185 cmpx MD$MPtr,u is module pointer the same? | |
67 bne L017C no, keep looking | |
68 cmpd [MD$MPDAT,u] DAT match? | |
69 bne L017C no, keep looking | |
70 * Module is found decrement link count | |
71 * NOTE: COULD WE USE D? | |
72 * L0198 - Safe, destroys D immediately | |
73 * Fall through- safe, destroys D immediately | |
74 * L01B5 - Seems to be safe | |
75 ldd MD$Link,u get module link count | |
76 beq L0198 it's zero, go unlink it | |
77 IFNE H6309 | |
78 decd decrement link count | |
79 ELSE | |
80 subd #$0001 | |
81 ENDC | |
82 std MD$Link,u save it back | |
83 bne L01B5 go on | |
84 * Module link count is zero check if he's unlinking a I/O module | |
85 L0198 ldx 2,s get pointer to register stack | |
86 ldx R$U,x get pointer to module | |
87 ldd #M$Type get offset to module type | |
88 os9 F$LDDDXY get module type | |
89 cmpa #FlMgr is it a I/O module? | |
90 blo L01B3 no, don't process for I/O | |
91 os9 F$IODel device still being used by somebody else? | |
92 bcc L01B3 no, go on | |
93 ldd MD$Link,u put the link count back to where it was | |
94 IFNE H6309 | |
95 incd | |
96 ELSE | |
97 addd #$0001 | |
98 ENDC | |
99 std MD$Link,u | |
100 bra L01D1 return error | |
101 * Clear module from memory | |
102 L01B3 bsr DelMod delete module from memory & module dir | |
103 L01B5 ldb ,s get block | |
104 lslb account for 2 bytes/entry | |
105 leay b,y point to block | |
106 ldd (P$Links-P$DATImg),y get block link count | |
107 IFNE H6309 | |
108 decd decrement it | |
109 ELSE | |
110 subd #$0001 | |
111 ENDC | |
112 std (P$Links-P$DATImg),y save new link count | |
113 bne L01D0 not zero, return to user | |
114 * Clear module blocks in process DAT image | |
115 ldd MD$MBSiz,u get block size | |
116 bsr L0226 calculate # blocks to delete | |
117 ldx #DAT.Free get DAT free marker | |
118 L01CB stx ,y++ save it in DAT image | |
119 deca done? | |
120 bne L01CB no, keep going | |
121 L01D0 clrb clear errors | |
122 L01D1 leas 2,s purge local data | |
123 puls u,pc restore & return | |
124 | |
125 * Delete module from module directory & from memory | |
126 * Entry: U=Module directory entry pointer to delete | |
127 * Exit : None | |
128 DelMod ldx <D.BlkMap get pointer to memory block map | |
129 ldd [MD$MPDAT,u] get pointer to module DAT image | |
130 lda d,x is block type ROM? | |
131 bmi L0225 yes can't delete it, return | |
132 ldx <D.ModDir get pointer to module directory | |
133 L01DF ldd [MD$MPDAT,x] get offset to DAT | |
134 cmpd [MD$MPDAT,u] match what we're looking for? | |
135 bne L01EA no, keep looking | |
136 ldd MD$Link,x get module link count | |
137 bne L0225 not zero, return | |
138 L01EA leax MD$ESize,x move to next module | |
139 cmpx <D.ModEnd at the end? | |
140 bcs L01DF no, keep going | |
141 ldx <D.BlkMap get pointer to block map | |
142 ldd MD$MBSiz,u get memory block size | |
143 bsr L0226 calculate # blocks to clear | |
144 IFNE H6309 | |
145 pshs u Preserve U (faster than original Y below) | |
146 clrb Setup for faster block in use clears | |
147 ldu MD$MPDAT,u get pointer to module DAT image | |
148 L01FB ldw ,u++ Get first block | |
149 stb -2,u clear it in DAT image | |
150 stb -1,u | |
151 addr x,w point to block in block map | |
152 aim #^(ModBlock!RAMinUse),,w | |
153 deca | |
154 bne L01FB | |
155 puls u Restore module ptr | |
156 ELSE | |
3123
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1145
diff
changeset
|
157 pshs y save y |
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1145
diff
changeset
|
158 ldy MD$MPDAT,u module image ptr |
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1145
diff
changeset
|
159 L01FB pshs a,x save #blocks, ptr |
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1145
diff
changeset
|
160 ldd ,y get block number |
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1145
diff
changeset
|
161 clr ,y+ clear the image |
1145 | 162 clr ,y+ |
3123
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1145
diff
changeset
|
163 leax d,x point to blkmap entry |
1145 | 164 ldb ,x |
165 andb #^(RAMinUse+ModBlock) free block | |
166 stb ,x | |
167 puls a,x | |
3123
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1145
diff
changeset
|
168 deca last block done? |
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1145
diff
changeset
|
169 bne L01FB ..no, loop |
1145 | 170 puls y |
171 ENDC | |
172 ldx <D.ModDir get module directory pointer | |
173 ldd MD$MPDAT,u get module DAT pointer | |
174 L0216 cmpd MD$MPDAT,x match? | |
175 bne L021F no, keep looking | |
176 clr MD$MPDAT,x clear module DAT image pointer | |
177 clr MD$MPDAT+1,x | |
178 L021F leax MD$ESize,x point to next module entry | |
179 cmpx <D.ModEnd at the end? | |
180 blo L0216 no, keep looking | |
181 L0225 rts return | |
182 | |
183 L0226 addd #$1FFF round up to nearest block | |
184 lsra calculate block # within 64k workspace | |
3123
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1145
diff
changeset
|
185 lsra |
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1145
diff
changeset
|
186 lsra |
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1145
diff
changeset
|
187 lsra |
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1145
diff
changeset
|
188 lsra |
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1145
diff
changeset
|
189 rts |