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