1 | /* Support files for newlib/GDB simulator. |
---|
2 | * $Id$ |
---|
3 | */ |
---|
4 | |
---|
5 | #include <_ansi.h> |
---|
6 | #include <sys/types.h> |
---|
7 | #include <sys/stat.h> |
---|
8 | #include <sys/fcntl.h> |
---|
9 | #include <stdio.h> |
---|
10 | #include <time.h> |
---|
11 | #include <sys/time.h> |
---|
12 | #include <sys/times.h> |
---|
13 | #include <errno.h> |
---|
14 | #include <reent.h> |
---|
15 | #include "swi.h" |
---|
16 | |
---|
17 | int armulator_stdin; |
---|
18 | int armulator_stdout; |
---|
19 | int armulator_stderr; |
---|
20 | |
---|
21 | #ifdef ARM_RDI_MONITOR |
---|
22 | |
---|
23 | static inline int |
---|
24 | do_AngelSWI (int reason, void * arg) |
---|
25 | { |
---|
26 | int value; |
---|
27 | asm volatile ("mov r0, %1; mov r1, %2; swi %a3; mov %0, r0" |
---|
28 | : "=r" (value) /* Outputs */ |
---|
29 | : "r" (reason), "r" (arg), "i" (AngelSWI) /* Inputs */ |
---|
30 | : "r0", "r1", "lr" |
---|
31 | /* Clobbers r0 and r1, and lr if in supervisor mode */); |
---|
32 | return value; |
---|
33 | } |
---|
34 | #endif /* ARM_RDI_MONITOR */ |
---|
35 | |
---|
36 | void |
---|
37 | initialize_monitor_handles (void) |
---|
38 | { |
---|
39 | int i; |
---|
40 | |
---|
41 | #ifdef ARM_RDI_MONITOR |
---|
42 | int volatile block[3]; |
---|
43 | |
---|
44 | block[0] = (int) ":tt"; |
---|
45 | block[2] = 3; /* length of filename */ |
---|
46 | block[1] = 0; /* mode "r" */ |
---|
47 | armulator_stdin = do_AngelSWI (AngelSWI_Reason_Open, block); |
---|
48 | |
---|
49 | block[0] = (int) ":tt"; |
---|
50 | block[2] = 3; /* length of filename */ |
---|
51 | block[1] = 4; /* mode "w" */ |
---|
52 | armulator_stdout = armulator_stderr = do_AngelSWI (AngelSWI_Reason_Open, block); |
---|
53 | #else |
---|
54 | int fh; |
---|
55 | const char * name; |
---|
56 | |
---|
57 | name = ":tt"; |
---|
58 | asm ("mov r0,%2; mov r1, #0; swi %a1; mov %0, r0" |
---|
59 | : "=r"(fh) |
---|
60 | : "i" (SWI_Open),"r"(name) |
---|
61 | : "r0","r1"); |
---|
62 | armulator_stdin = fh; |
---|
63 | |
---|
64 | name = ":tt"; |
---|
65 | asm ("mov r0,%2; mov r1, #4; swi %a1; mov %0, r0" |
---|
66 | : "=r"(fh) |
---|
67 | : "i" (SWI_Open),"r"(name) |
---|
68 | : "r0","r1"); |
---|
69 | armulator_stdout = armulator_stderr = fh; |
---|
70 | #endif |
---|
71 | } |
---|
72 | |
---|
73 | /* Returns # chars not! read */ |
---|
74 | |
---|
75 | int |
---|
76 | _swiread (int file, |
---|
77 | char * ptr, |
---|
78 | int len) |
---|
79 | { |
---|
80 | int fh = file; |
---|
81 | #ifdef ARM_RDI_MONITOR |
---|
82 | int block[3]; |
---|
83 | |
---|
84 | block[0] = fh; |
---|
85 | block[1] = (int) ptr; |
---|
86 | block[2] = len; |
---|
87 | |
---|
88 | return do_AngelSWI (AngelSWI_Reason_Read, block); |
---|
89 | #else |
---|
90 | asm ("mov r0, %1; mov r1, %2;mov r2, %3; swi %a0" |
---|
91 | : /* No outputs */ |
---|
92 | : "i"(SWI_Read), "r"(fh), "r"(ptr), "r"(len) |
---|
93 | : "r0","r1","r2"); |
---|
94 | #endif |
---|
95 | } |
---|
96 | |
---|
97 | /* Returns #chars not! written */ |
---|
98 | int |
---|
99 | _swiwrite ( |
---|
100 | int file, |
---|
101 | char * ptr, |
---|
102 | int len) |
---|
103 | { |
---|
104 | int fh = file; |
---|
105 | #ifdef ARM_RDI_MONITOR |
---|
106 | int block[3]; |
---|
107 | |
---|
108 | block[0] = fh; |
---|
109 | block[1] = (int) ptr; |
---|
110 | block[2] = len; |
---|
111 | |
---|
112 | return do_AngelSWI (AngelSWI_Reason_Write, block); |
---|
113 | #else |
---|
114 | asm ("mov r0, %1; mov r1, %2;mov r2, %3; swi %a0" |
---|
115 | : /* No outputs */ |
---|
116 | : "i"(SWI_Write), "r"(fh), "r"(ptr), "r"(len) |
---|
117 | : "r0","r1","r2"); |
---|
118 | #endif |
---|
119 | } |
---|
120 | |
---|
121 | /* |
---|
122 | * Move me |
---|
123 | */ |
---|
124 | |
---|
125 | void |
---|
126 | bsp_cleanup (void ) |
---|
127 | { |
---|
128 | /* FIXME: return code is thrown away */ |
---|
129 | |
---|
130 | #ifdef ARM_RDI_MONITOR |
---|
131 | do_AngelSWI (AngelSWI_Reason_ReportException, |
---|
132 | (void *) ADP_Stopped_ApplicationExit); |
---|
133 | #else |
---|
134 | asm ("swi %a0" :: "i" (SWI_Exit)); |
---|
135 | #endif |
---|
136 | } |
---|
137 | |
---|
138 | /* |
---|
139 | * Technically could use this as guts of a "real-time clock driver" |
---|
140 | */ |
---|
141 | |
---|
142 | #if 0 |
---|
143 | int |
---|
144 | _gettimeofday (struct timeval * tp, struct timezone * tzp) |
---|
145 | { |
---|
146 | |
---|
147 | if (tp) |
---|
148 | { |
---|
149 | /* Ask the host for the seconds since the Unix epoch */ |
---|
150 | #ifdef ARM_RDI_MONITOR |
---|
151 | tp->tv_sec = do_AngelSWI (AngelSWI_Reason_Time,NULL); |
---|
152 | #else |
---|
153 | { |
---|
154 | int value; |
---|
155 | asm ("swi %a1; mov %0, r0" : "=r" (value): "i" (SWI_Time) : "r0"); |
---|
156 | tp->tv_sec = value; |
---|
157 | } |
---|
158 | #endif |
---|
159 | tp->tv_usec = 0; |
---|
160 | } |
---|
161 | |
---|
162 | /* Return fixed data for the timezone */ |
---|
163 | if (tzp) |
---|
164 | { |
---|
165 | tzp->tz_minuteswest = 0; |
---|
166 | tzp->tz_dsttime = 0; |
---|
167 | } |
---|
168 | |
---|
169 | return 0; |
---|
170 | } |
---|
171 | #endif |
---|
172 | |
---|