Mercurial > hg > Members > kono > nitros9-code
annotate level2/modules/kernel/fchain.asm @ 3198:734862561313
3rdparty/packages: Rename particularly cryptic folder names
author | Tormod Volden <debian.tormod@gmail.com> |
---|---|
date | Sat, 03 Jun 2017 10:34:39 +0200 |
parents | 039ddb7c8ad7 |
children |
rev | line source |
---|---|
1145 | 1 ************************************************** |
2 * System Call: F$Chain | |
3 * | |
4 * Function: Starts a new child process and terminates the calling process. | |
5 * | |
6 * Input: X = Address of module or filename | |
7 * Y = Parameter area size (256 byte pages) | |
8 * U = Address of parameter area | |
9 * A = Language/Type code | |
10 * B = Optional data area size (256 byte pages) | |
11 * | |
12 * Output: None | |
13 * | |
14 * Error: CC = C bit set; B = error code | |
15 * | |
16 FChain pshs u preserve register stack pointer | |
17 lbsr AllPrc allocate a new process descriptor | |
18 bcc L03B7 do the chain if no error | |
19 puls u,pc return to caller with error | |
20 | |
21 * Copy Process Descriptor Data | |
22 L03B7 ldx <D.Proc get pointer to current process | |
23 pshs x,u save old & new descriptor pointers | |
24 leax P$SP,x point to source | |
25 leau P$SP,u point to destination | |
26 IFNE H6309 | |
27 ldw #$00fc get size (P$SP+$FC) | |
28 tfm x+,u+ move it | |
29 ELSE | |
1239 | 30 ldy #$00FC |
3123
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1363
diff
changeset
|
31 L03C3 ldd ,x++ copy bytes |
1145 | 32 std ,u++ |
1239 | 33 leay -2,y |
1145 | 34 bne L03C3 |
35 ENDC | |
36 L03CB ldu 2,s get new descriptor pointer | |
37 leau <P$DATImg,u | |
38 ldx ,s get old descriptor pointer | |
39 lda P$Task,x get task # | |
40 lsla 2 bytes per entry | |
41 ldx <D.TskIpt get task image table pointer | |
42 stu a,x save updated DAT image pointer for later | |
43 * Question: are the previous 7 lines necessary? The F$AllTsk call, below | |
44 * should take care of everything! | |
45 ldx <D.Proc get process descriptor | |
46 IFNE H6309 | |
47 clrd Faster than 2 memory clears | |
48 ELSE | |
49 clra | |
50 clrb | |
51 ENDC | |
52 stb P$Task,x old process has no task number | |
53 std <P$SWI,x clear out all sorts of signals and vectors | |
54 std <P$SWI2,x | |
55 std <P$SWI3,x | |
56 sta <P$Signal,x | |
57 std <P$SigVec,x | |
58 ldu <P$PModul,x | |
59 os9 F$UnLink unlink from the primary module | |
60 ldb P$PagCnt,x grab the page count | |
61 addb #$1F round up to the nearest block | |
3123
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1363
diff
changeset
|
62 lsrb |
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1363
diff
changeset
|
63 lsrb |
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1363
diff
changeset
|
64 lsrb |
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1363
diff
changeset
|
65 lsrb |
1145 | 66 lsrb get number of blocks used |
3123
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1363
diff
changeset
|
67 lda #$08 |
1145 | 68 IFNE H6309 |
69 subr b,a A=number of blocks unused | |
70 ELSE | |
71 pshs b | |
72 suba ,s+ | |
73 ENDC | |
74 leay <P$DATImg,x set up the initial DAT image | |
3123
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1363
diff
changeset
|
75 lslb |
1145 | 76 leay b,y go to the offset |
77 ldu #DAT.Free mark the blocks as free | |
78 L040C stu ,y++ do all of them | |
3123
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1363
diff
changeset
|
79 deca |
1145 | 80 bne L040C |
81 ldu 2,s get new process descriptor pointer | |
82 stu <D.Proc make it the new process | |
83 ldu 4,s | |
84 lbsr L04B1 link to new module & setup register stack | |
85 IFNE H6309 | |
86 bcs L04A1 | |
87 ELSE | |
88 lbcs L04A1 | |
89 ENDC | |
90 pshs d somehow D = memory size? Or parameter size? | |
91 os9 F$AllTsk allocate a new task number | |
92 * ignore errors here | |
93 * Hmmm.. the code above FORCES the new process to have the same DAT image ptr | |
94 * as the old process, not that it matters... | |
95 | |
1247 | 96 IFNE H6309 |
3123
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1363
diff
changeset
|
97 fcb $24,$00 TODO: Identify this! |
1247 | 98 ENDC |
1145 | 99 ldu <D.Proc get nre process |
100 lda P$Task,u new task number | |
101 ldb P$Task,x old task number | |
102 leau >(P$Stack-R$Size),x set up the stack for the new process | |
3123
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1363
diff
changeset
|
103 leax ,y |
1145 | 104 ldu R$X,u where to copy from |
105 IFNE H6309 | |
106 cmpr x,u check From/To addresses | |
107 ELSE | |
3123
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1363
diff
changeset
|
108 pshs x src ptr |
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1363
diff
changeset
|
109 cmpu ,s++ dest ptr |
1145 | 110 ENDC |
3123
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1363
diff
changeset
|
111 puls y size |
1145 | 112 bhi L0471 To < From: do F$Move |
113 beq L0474 To == From, skip F$Move | |
114 | |
115 * To > From: do special copy | |
116 leay ,y any bytes to move? | |
117 beq L0474 no, skip ahead | |
118 IFNE H6309 | |
119 pshs x save address | |
120 addr y,x add size to FROM address | |
121 cmpr x,u is it | |
122 puls x | |
123 ELSE | |
124 pshs d,x | |
125 tfr y,d | |
126 leax d,x | |
1239 | 127 pshs x |
128 cmpu ,s++ | |
1145 | 129 puls d,x |
130 ENDC | |
131 bls L0471 end of FROM <= start of TO: do F$Move | |
132 | |
133 * The areas to copy overlap: do special move routine | |
134 pshs d,x,y,u save regs | |
135 IFNE H6309 | |
3123
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1363
diff
changeset
|
136 addr y,x go to the END of the area to copy FROM |
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1363
diff
changeset
|
137 addr y,u end of area to copy TO |
1145 | 138 ELSE |
139 tfr y,d | |
140 leax d,x | |
1239 | 141 leau d,u |
1145 | 142 ENDC |
143 | |
144 * This all appears to be doing a copy where destination <= source, | |
145 * in the same address space. | |
146 L0457 ldb ,s grab ?? | |
147 leax -1,x back up one | |
3123
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1363
diff
changeset
|
148 os9 F$LDABX |
1145 | 149 exg x,u |
150 ldb 1,s | |
151 leax -1,x back up another one | |
3123
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1363
diff
changeset
|
152 os9 F$STABX |
1145 | 153 exg x,u |
154 leay -1,y | |
155 bne L0457 | |
156 | |
157 puls d,x,y,u restore regs | |
158 bra L0474 skip over F$Move | |
159 | |
160 L0471 os9 F$Move move data over? | |
161 L0474 lda <D.SysTsk get system task number | |
162 ldx ,s old process dsc ptr | |
163 ldu P$SP,x | |
164 leax >(P$Stack-R$Size),x | |
165 ldy #R$Size | |
166 os9 F$Move move the stack over | |
167 puls u,x restore new, old process dsc's | |
168 lda P$ID,u | |
169 lbsr L0386 check alarms | |
170 os9 F$DelTsk delete the old task | |
171 orcc #IntMasks | |
172 ldd <D.SysPrc | |
173 std <D.Proc | |
174 IFNE H6309 | |
175 aim #^SysState,P$State,x | |
176 ELSE | |
177 lda P$State,x | |
178 anda #^SysState | |
179 sta P$State,x | |
180 ENDC | |
181 os9 F$AProc activate the process | |
182 os9 F$NProc go to it | |
183 | |
184 * comes here on error with link to new module | |
185 L04A1 puls u,x | |
186 stx <D.Proc | |
187 pshs b | |
188 lda ,u | |
189 lbsr L0386 kill signals | |
190 puls b | |
191 os9 F$Exit exit from the process with error condition | |
192 | |
193 * Setup new process DAT image with module | |
194 L04B1 pshs d,x,y,u preserve everything | |
195 ldd <D.Proc get pointer to current process | |
196 pshs d save it | |
197 stx <D.Proc save pointer to new process | |
198 lda R$A,u get module type | |
199 ldx R$X,u get pointer to module name | |
200 ldy ,s get pointer to current process | |
201 leay P$DATImg,y point to DAT image | |
202 os9 F$SLink map it into new process DAT image | |
203 bcc L04D7 no error, keep going | |
204 ldd ,s restore to current process | |
205 std <D.Proc | |
206 ldu 4,s get pointer to new process | |
207 os9 F$Load try & load it | |
208 bcc L04D7 no error, keep going | |
209 leas 4,s purge stack | |
210 puls x,y,u,pc restore & return | |
3123
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1363
diff
changeset
|
211 * |
1145 | 212 L04D7 stu 2,s save pointer to module |
213 pshs a,y save module type & entry point | |
214 ldu $0B,s restore register stack pointer | |
215 stx R$X,u save updated name pointer | |
216 ldx $07,s restore process pointer | |
217 stx <D.Proc make it current | |
218 ldd 5,s get pointer to new module | |
219 std P$PModul,x save it into process descriptor | |
220 puls a restore module type | |
221 cmpa #Prgrm+Objct regular module? | |
222 beq L04FB yes, go | |
223 cmpa #Systm+Objct system module? | |
224 beq L04FB | |
1363 | 225 IFNE H6309 |
1145 | 226 *--- these lines added to allow 6309 native mode modules to be executed |
227 cmpa #Prgrm+Obj6309 regular module? | |
228 beq L04FB yes, go | |
229 cmpa #Systm+Obj6309 system module? | |
230 beq L04FB | |
231 *--- | |
1244 | 232 ENDC |
1145 | 233 ldb #E$NEMod return unknown module |
234 L04F4 leas 2,s purge stack | |
235 stb 3,s save error | |
236 comb set carry | |
237 bra L053E return | |
238 * Setup up data memory | |
239 L04FB ldd #M$Mem get offset to module memory size | |
240 leay P$DATImg,x get pointer to DAT image | |
241 ldx P$PModul,x get pointer to module header | |
242 os9 F$LDDDXY get module memory size | |
243 cmpa R$B,u bigger or smaller than callers request? | |
244 bcc L050E bigger, use it instead | |
245 lda R$B,u get callers memory size instead | |
246 clrb clear LSB of mem size | |
247 L050E os9 F$Mem try & get the data memory | |
248 bcs L04F4 can't do it, exit with error | |
249 ldx 6,s restore process pointer | |
250 leay (P$Stack-R$Size),x point to new register stack | |
251 pshs d preserve memory size | |
252 subd R$Y,u take off size of paramater area | |
253 std R$X,y save pointer to parameter area | |
254 subd #R$Size take off size of register stack | |
255 std P$SP,x save new SP | |
256 ldd R$Y,u get parameter count | |
257 std R$A,y save it to new process | |
258 std 6,s save it for myself to | |
259 puls d,x restore top of mem & program entry point | |
260 std R$Y,y set top of mem pointer | |
261 ldd R$U,u get pointer to parameters | |
262 std 6,s | |
263 lda #Entire | |
264 sta R$CC,y save condition code | |
3123
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1363
diff
changeset
|
265 clra |
1145 | 266 sta R$DP,y save direct page |
3123
039ddb7c8ad7
l2 kernel: Remove tabs and trailing whitespace, align comments
Neal Crook <foofoobedoo@gmail.com>
parents:
1363
diff
changeset
|
267 clrb |
1145 | 268 std R$U,y save data area start |
269 stx R$PC,y save program entry point | |
270 L053E puls d restore process pointer | |
271 std <D.Proc save it as current | |
272 puls d,x,y,u,pc |