4 ; OSCLI and system support for DLLs and clients
9 ;----- Standard header ------------------------------------------------------
14 ;----- External dependencies ------------------------------------------------
17 IMPORT |_kernel_system|
18 IMPORT |x$stack_overflow|
20 ;----- Main code ------------------------------------------------------------
22 AREA |DLL$$Code|,CODE,READONLY
26 ; On entry: a1 == pointer to command line string (passed to system)
27 ; On exit: a1 == return code, as for system()
32 ; --- Standard APCS bit on the top ---
34 MOV ip,sp ;Keep current stack pointer
35 STMFD sp!,{v1,v2,fp,ip,lr,pc} ;Create new stack frame
36 SUB fp,ip,#4 ;Point fp at new stack frame
37 CMP sp,sl ;Is there enough stack?
38 BLLT |x$stack_overflow| ;No -- create some more
40 ; --- Preserve the old application handle ---
42 MOV v2,a1 ;Preserve string pointer
43 SWI DLL_SaveHandle ;Get the current handle
44 MOV v1,a1 ;Preserve its value
46 ; --- Call the actual command ---
48 MOV a1,v2 ;Restore string pointer
49 BL system ;Do whatever it is we do
51 ; --- Restore the handle and exit ---
53 MOV v2,a1 ;Keep hold of return value
54 MOV a1,v1 ;Transfer old handle
55 SWI DLL_RestoreHandle ;Set up the handle again
56 MOV a1,v2 ;Reinstate the return value
57 LDMDB fp,{v1,v2,fp,sp,pc}^ ;Return to caller
61 ; --- _dll_ksystem ---
63 ; On entry: R0 == pointer to command to execute
64 ; R1 == 0 to run as a subprocess, nonzero to replace
65 ; On exit: >=0 for success, <0 for failure
70 ; --- Standard APCS bit on the top ---
72 MOV ip,sp ;Keep current stack pointer
73 STMFD sp!,{v1,v2,fp,ip,lr,pc} ;Create new stack frame
74 SUB fp,ip,#4 ;Point fp at new stack frame
75 CMP sp,sl ;Is there enough stack?
76 BLLT |x$stack_overflow| ;No -- create some more
78 ; --- Preserve the old application handle ---
80 MOV v2,a1 ;Preserve string pointer
81 SWI DLL_SaveHandle ;Get the current handle
82 MOV v1,a1 ;Preserve its value
84 ; --- Call the actual command ---
86 MOV a1,v2 ;Restore string pointer
87 BL |_kernel_system| ;Do whatever it is we do
89 ; --- Restore the handle and exit ---
91 MOV v2,a1 ;Keep hold of return value
92 MOV a1,v1 ;Transfer old handle
93 SWI DLL_RestoreHandle ;Set up the handle again
94 MOV a1,v2 ;Reinstate the return value
95 LDMDB fp,{v1,v2,fp,sp,pc}^ ;Return to caller
101 ; On entry: R0 == pointer to command string for OS_CLI
102 ; On exit: R0 == pointer to error, or 0
107 MOV ip,lr ;Keep link register
108 MOV a2,a1 ;Keep pointer to string
109 SWI DLL_SaveHandle ;Get our current handle
110 MOV a3,a1 ;Save it away
111 MOV a1,a2 ;Restore pointer to command
112 SWI XOS_CLI ;Do the actual command
113 MOVVS a2,a1 ;Save error ptr if it failed
114 MOVVC a2,#0 ;Otherwise remember it worked
115 MOV a1,a3 ;Restore the old handle
116 SWI DLL_RestoreHandle ;Resinstate the handle
117 MOV a1,a2 ;Point at error block
118 MOVS pc,ip ;And return to caller
122 ; --- _dll_starttask ---
124 ; On entry: R0 == pointer to command to run as a separate task
125 ; On exit: R0 == pointer to error, or 0
127 EXPORT |_dll_starttask|
128 |_dll_starttask| ROUT
130 MOV ip,lr ;Keep link register
131 MOV a2,a1 ;Keep pointer to string
132 SWI DLL_SaveHandle ;Get our current handle
133 MOV a3,a1 ;Save it away
134 MOV a1,a2 ;Restore pointer to command
135 SWI XWimp_StartTask ;Do the actual command
136 MOVVS a2,a1 ;Save error ptr if it failed
137 MOVVC a2,#0 ;Otherwise remember it worked
138 MOV a1,a3 ;Restore the old handle
139 SWI DLL_RestoreHandle ;Resinstate the handle
140 MOV a1,a2 ;Point at error block
141 MOVS pc,ip ;And return to caller
145 ;----- That's all, folks ----------------------------------------------------