annotate level2/modules/kernel/ffork.asm @ 1145:ca83286ded5b

Start of new OS-9 L2 Kernel
author boisy
date Tue, 22 Apr 2003 19:35:48 +0000
parents
children 90bad6d8388c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1145
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
1 **************************************************
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
2 * System Call: F$Fork
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
3 *
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
4 * Function: Starts a new child process
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
5 *
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
6 * Input: X = Address of module or filename
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
7 * Y = Parameter area size (256 byte pages)
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
8 * U = Address of parameter area
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
9 * A = Language/Type code
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
10 * B = Optional data area size (256 byte pages)
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
11 *
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
12 * Output: X = Updated past the name string
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
13 * A = Child's process ID
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
14 *
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
15 * Error: CC = C bit set; B = error code
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
16 *
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
17 FFork pshs u preserve register stack pointer
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
18 lbsr AllPrc setup a new process descriptor
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
19 bcc GotNPrc went ok, keep going
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
20 puls u,pc restore & return with error
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
21
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
22 * Copy user # & priority
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
23 GotNPrc pshs u save pointer to new descriptor
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
24 ldx <D.Proc get current process pointer
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
25 IFNE H6309
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
26 ldq P$User,x Get user # & priority from forking process
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
27 std P$User,u Save user # in new process
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
28 ste P$Prior,u Save priority in new process
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
29 ELSE
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
30 ldd P$User,x
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
31 std P$User,u
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
32 lda P$Prior,x
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
33 sta P$Prior,u
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
34 pshs x,u
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
35 ENDC
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
36 * Copy network I/O pointers to new descriptor
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
37 IFEQ Network-1
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
38 pshs x,u preserve pointers to descriptors
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
39 leax >P$NIO,x point to current NIO pointers
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
40 leau >P$NIO,u point to buffer for new ones
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
41 IFNE H6309
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
42 ldw #NefIOSiz get size
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
43 tfm x+,u+ move 'em
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
44 ELSE
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
45 ldb #NefIOSiz
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
46 L0250 lda ,x+
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
47 sta ,u+
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
48 decb
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
49 bne L0250
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
50 ENDC
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
51 puls x,u restore pointers to descriptors
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
52 ENDC
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
53 * Copy I/O pointers to new descriptor
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
54 leax P$DIO,x
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
55 leau P$DIO,u
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
56 IFNE H6309
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
57 ldw #DefIOSiz
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
58 tfm x+,u+
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
59 * Copy Standard paths to new descriptor
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
60 lde #3 get # paths
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
61 ELSE
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
62 ldb #DefIOSiz
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
63 L0261 lda ,x+
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
64 sta ,u+
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
65 decb
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
66 bne L0261
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
67 ldy #3
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
68 ENDC
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
69
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
70 * Duplicate 1st 3 paths
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
71 GetOPth lda ,x+ get a path #
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
72 beq SveNPth don't exist, go on
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
73 os9 I$Dup dupe it
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
74 bcc SveNPth no error, go on
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
75 clra clear it
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
76
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
77 * As std in/out/err
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
78 SveNPth sta ,u+ save new path #
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
79 IFNE H6309
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
80 dece done?
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
81 ELSE
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
82 leay -1,y
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
83 ENDC
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
84 bne GetOPth no, keep going
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
85 * Link to new module & setup task map
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
86 ldx ,s get pointer to new descriptor
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
87 ldu 2,s get pointer to register stack
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
88 lbsr L04B1 link to module & setup register stack
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
89 bcs L02CF exit if error
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
90 pshs d
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
91 os9 F$AllTsk allocate the task & setup MMU
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
92 bcs L02CF Error, skip ahead
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
93
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
94 * Copy parameters to new process
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
95 lda P$PagCnt,x get memory page count
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
96 clrb
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
97 subd ,s calculate destination
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
98 tfr d,u set parameter destination pointer
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
99 ldb P$Task,x get source task #
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
100 ldx <D.Proc get destination task #
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
101 lda P$Task,x
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
102 leax ,y point to parameters
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
103 puls y restore parameter count
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
104 os9 F$Move move parameters to new process
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
105
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
106 * Setup the new stack
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
107 ldx ,s get pointer to process descriptor
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
108 lda <D.SysTsk get task #
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
109 ldu P$SP,x get new stack pointer
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
110 leax >(P$Stack-R$Size),x point to register stack
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
111 ldy #R$Size get size of register stack
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
112 os9 F$Move move the register stack over
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
113 puls u,x
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
114 os9 F$DelTsk
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
115 ldy <D.Proc
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
116 lda P$ID,x
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
117 sta R$A,u
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
118 ldb P$CID,y
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
119 sta P$CID,y
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
120 lda P$ID,y
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
121 std P$PID,x
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
122 IFNE H6309
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
123 aim #^SysState,P$State,x switch to non-system state
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
124 ELSE
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
125 lda P$State,x
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
126 anda #^SysState
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
127 sta P$State,x
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
128 ENDC
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
129 * Put date & time of creation into descriptor
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
130 * pshs x preserve process pointer
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
131 * leax P$DatBeg,x point to time buffer
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
132 * os9 F$Time put date/time into it
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
133 * puls x restore pointer
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
134 os9 F$AProc and start the process
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
135 rts return
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
136
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
137 * Fork error goes here
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
138 L02CF puls x
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
139 pshs b save error
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
140 lbsr L05A5 close paths & unlink mem
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
141 lda P$ID,x get bad ID
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
142 lbsr L0386 delete proc desc & task #
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
143 comb set carry
ca83286ded5b Start of new OS-9 L2 Kernel
boisy
parents:
diff changeset
144 puls pc,u,b pull error code & u & return