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 | #ifdef ARM_RDI_MONITOR |
---|
40 | int volatile block[3]; |
---|
41 | |
---|
42 | block[0] = (int) ":tt"; |
---|
43 | block[2] = 3; /* length of filename */ |
---|
44 | block[1] = 0; /* mode "r" */ |
---|
45 | armulator_stdin = do_AngelSWI (AngelSWI_Reason_Open, (void *)block); |
---|
46 | |
---|
47 | block[0] = (int) ":tt"; |
---|
48 | block[2] = 3; /* length of filename */ |
---|
49 | block[1] = 4; /* mode "w" */ |
---|
50 | armulator_stdout = armulator_stderr = do_AngelSWI (AngelSWI_Reason_Open, (void *)block); |
---|
51 | #else |
---|
52 | int fh; |
---|
53 | const char * name; |
---|
54 | |
---|
55 | name = ":tt"; |
---|
56 | asm ("mov r0,%2; mov r1, #0; swi %a1; mov %0, r0" |
---|
57 | : "=r"(fh) |
---|
58 | : "i" (SWI_Open),"r"(name) |
---|
59 | : "r0","r1"); |
---|
60 | armulator_stdin = fh; |
---|
61 | |
---|
62 | name = ":tt"; |
---|
63 | asm ("mov r0,%2; mov r1, #4; swi %a1; mov %0, r0" |
---|
64 | : "=r"(fh) |
---|
65 | : "i" (SWI_Open),"r"(name) |
---|
66 | : "r0","r1"); |
---|
67 | armulator_stdout = armulator_stderr = fh; |
---|
68 | #endif |
---|
69 | } |
---|
70 | |
---|
71 | /* Returns # chars not! read */ |
---|
72 | |
---|
73 | int |
---|
74 | _swiread (int file, |
---|
75 | char * ptr, |
---|
76 | int len) |
---|
77 | { |
---|
78 | int fh = file; |
---|
79 | #ifdef ARM_RDI_MONITOR |
---|
80 | int block[3]; |
---|
81 | |
---|
82 | block[0] = fh; |
---|
83 | block[1] = (int) ptr; |
---|
84 | block[2] = len; |
---|
85 | |
---|
86 | return do_AngelSWI (AngelSWI_Reason_Read, block); |
---|
87 | #else |
---|
88 | asm ("mov r0, %1; mov r1, %2;mov r2, %3; swi %a0" |
---|
89 | : /* No outputs */ |
---|
90 | : "i"(SWI_Read), "r"(fh), "r"(ptr), "r"(len) |
---|
91 | : "r0","r1","r2"); |
---|
92 | #endif |
---|
93 | } |
---|
94 | |
---|
95 | /* Returns #chars not! written */ |
---|
96 | int |
---|
97 | _swiwrite ( |
---|
98 | int file, |
---|
99 | char * ptr, |
---|
100 | int len) |
---|
101 | { |
---|
102 | int fh = file; |
---|
103 | #ifdef ARM_RDI_MONITOR |
---|
104 | int block[3]; |
---|
105 | |
---|
106 | block[0] = fh; |
---|
107 | block[1] = (int) ptr; |
---|
108 | block[2] = len; |
---|
109 | |
---|
110 | return do_AngelSWI (AngelSWI_Reason_Write, block); |
---|
111 | #else |
---|
112 | asm ("mov r0, %1; mov r1, %2;mov r2, %3; swi %a0" |
---|
113 | : /* No outputs */ |
---|
114 | : "i"(SWI_Write), "r"(fh), "r"(ptr), "r"(len) |
---|
115 | : "r0","r1","r2"); |
---|
116 | #endif |
---|
117 | } |
---|
118 | |
---|
119 | /* |
---|
120 | * Move me |
---|
121 | */ |
---|
122 | |
---|
123 | void |
---|
124 | bsp_cleanup (void ) |
---|
125 | { |
---|
126 | /* FIXME: return code is thrown away */ |
---|
127 | |
---|
128 | #ifdef ARM_RDI_MONITOR |
---|
129 | do_AngelSWI (AngelSWI_Reason_ReportException, |
---|
130 | (void *) ADP_Stopped_ApplicationExit); |
---|
131 | #else |
---|
132 | asm ("swi %a0" :: "i" (SWI_Exit)); |
---|
133 | #endif |
---|
134 | } |
---|
135 | |
---|
136 | /* |
---|
137 | * Technically could use this as guts of a "real-time clock driver" |
---|
138 | */ |
---|
139 | |
---|
140 | #if 0 |
---|
141 | int |
---|
142 | _gettimeofday (struct timeval * tp, struct timezone * tzp) |
---|
143 | { |
---|
144 | |
---|
145 | if (tp) |
---|
146 | { |
---|
147 | /* Ask the host for the seconds since the Unix epoch */ |
---|
148 | #ifdef ARM_RDI_MONITOR |
---|
149 | tp->tv_sec = do_AngelSWI (AngelSWI_Reason_Time,NULL); |
---|
150 | #else |
---|
151 | { |
---|
152 | int value; |
---|
153 | asm ("swi %a1; mov %0, r0" : "=r" (value): "i" (SWI_Time) : "r0"); |
---|
154 | tp->tv_sec = value; |
---|
155 | } |
---|
156 | #endif |
---|
157 | tp->tv_usec = 0; |
---|
158 | } |
---|
159 | |
---|
160 | /* Return fixed data for the timezone */ |
---|
161 | if (tzp) |
---|
162 | { |
---|
163 | tzp->tz_minuteswest = 0; |
---|
164 | tzp->tz_dsttime = 0; |
---|
165 | } |
---|
166 | |
---|
167 | return 0; |
---|
168 | } |
---|
169 | #endif |
---|
170 | |
---|