chiark / gitweb /
Initial revision
[ssr] / StraySrc / Libraries / DLLLib / s / oscli
1 ;
2 ; oscli.s
3 ;
4 ; OSCLI and system support for DLLs and clients
5 ;
6 ; © 1994 Straylight
7 ;
8
9 ;----- Standard header ------------------------------------------------------
10
11                 GET     libs:swis
12                 GET     libs:header
13
14 ;----- External dependencies ------------------------------------------------
15
16                 IMPORT  system
17                 IMPORT  |_kernel_system|
18                 IMPORT  |x$stack_overflow|
19
20 ;----- Main code ------------------------------------------------------------
21
22                 AREA    |DLL$$Code|,CODE,READONLY
23
24 ; --- _dll_system ---
25 ;
26 ; On entry:     a1 == pointer to command line string (passed to system)
27 ; On exit:      a1 == return code, as for system()
28
29                 EXPORT  |_dll_system|
30 |_dll_system|   ROUT
31
32                 ; --- Standard APCS bit on the top ---
33
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
39
40                 ; --- Preserve the old application handle ---
41
42                 MOV     v2,a1                   ;Preserve string pointer
43                 SWI     DLL_SaveHandle          ;Get the current handle
44                 MOV     v1,a1                   ;Preserve its value
45
46                 ; --- Call the actual command ---
47
48                 MOV     a1,v2                   ;Restore string pointer
49                 BL      system                  ;Do whatever it is we do
50
51                 ; --- Restore the handle and exit ---
52
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
58
59                 LTORG
60
61 ; --- _dll_ksystem ---
62 ;
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
66
67                 EXPORT  |_dll_ksystem|
68 |_dll_ksystem|  ROUT
69
70                 ; --- Standard APCS bit on the top ---
71
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
77
78                 ; --- Preserve the old application handle ---
79
80                 MOV     v2,a1                   ;Preserve string pointer
81                 SWI     DLL_SaveHandle          ;Get the current handle
82                 MOV     v1,a1                   ;Preserve its value
83
84                 ; --- Call the actual command ---
85
86                 MOV     a1,v2                   ;Restore string pointer
87                 BL      |_kernel_system|        ;Do whatever it is we do
88
89                 ; --- Restore the handle and exit ---
90
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
96
97                 LTORG
98
99 ; --- _dll_oscli ---
100 ;
101 ; On entry:     R0 == pointer to command string for OS_CLI
102 ; On exit:      R0 == pointer to error, or 0
103
104                 EXPORT  |_dll_oscli|
105 |_dll_oscli|    ROUT
106
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
119
120                 LTORG
121
122 ; --- _dll_starttask ---
123 ;
124 ; On entry:     R0 == pointer to command to run as a separate task
125 ; On exit:      R0 == pointer to error, or 0
126
127                 EXPORT  |_dll_starttask|
128 |_dll_starttask| ROUT
129
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
142
143                 LTORG
144
145 ;----- That's all, folks ----------------------------------------------------
146
147                 END