1 |
148 |
jeremybenn |
/* syscall defines for MMIXware.
|
2 |
|
|
|
3 |
|
|
Copyright (C) 2001, 2002, 2007 Hans-Peter Nilsson
|
4 |
|
|
|
5 |
|
|
Permission to use, copy, modify, and distribute this software is
|
6 |
|
|
freely granted, provided that the above copyright notice, this notice
|
7 |
|
|
and the following disclaimer are preserved with no changes.
|
8 |
|
|
|
9 |
|
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
10 |
|
|
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
11 |
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
12 |
|
|
PURPOSE. */
|
13 |
|
|
|
14 |
|
|
/* These are the mmixware simulator calls that are of use in newlib. */
|
15 |
|
|
|
16 |
|
|
#define SYS_halt 0
|
17 |
|
|
#define SYS_Fopen 1
|
18 |
|
|
#define SYS_Fclose 2
|
19 |
|
|
#define SYS_Fread 3
|
20 |
|
|
#define SYS_Fgets 4
|
21 |
|
|
#define SYS_Fwrite 6
|
22 |
|
|
#define SYS_Fseek 9
|
23 |
|
|
#define SYS_Ftell 10
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
enum MMIX_filemode
|
27 |
|
|
{
|
28 |
|
|
TextRead = 0,
|
29 |
|
|
TextWrite = 1,
|
30 |
|
|
BinaryRead = 2,
|
31 |
|
|
BinaryWrite = 3,
|
32 |
|
|
BinaryReadWrite = 4
|
33 |
|
|
};
|
34 |
|
|
|
35 |
|
|
#define N_MMIX_FILEHANDLES 32
|
36 |
|
|
|
37 |
|
|
/* We store a bitmap of allocated filehandles
|
38 |
|
|
_MMIX_allocated_filehandle[fileno] in an array. There are 32 of them.
|
39 |
|
|
Indexes 0, 1 and 2 are allocated from start. The reason we keep track
|
40 |
|
|
of them is that *we* have to allocate a filehandle when opening a file.
|
41 |
|
|
Had we got a filehandle from the simulator, we wouldn't have to keep
|
42 |
|
|
track of it. A value of 0 denotes a free handle. */
|
43 |
|
|
extern unsigned char _MMIX_allocated_filehandle[N_MMIX_FILEHANDLES];
|
44 |
|
|
|
45 |
|
|
/* Simulator call with one argument. Also used for zero-argument calls;
|
46 |
|
|
pass a zero as ARG1. Make the asm volatile so we can safely ignore the
|
47 |
|
|
return-value and only get the benefit from the supposed side-effect
|
48 |
|
|
without the asm being optimized away. */
|
49 |
|
|
#define TRAP1i(FUN, ARG1) \
|
50 |
|
|
({ long ret_; \
|
51 |
|
|
__asm__ __volatile__ \
|
52 |
|
|
("TRAP 0,%1,%2\n\tSET %0,$255" \
|
53 |
|
|
: "=r" (ret_) : "i" (FUN), "i" (ARG1) \
|
54 |
|
|
: "memory"); \
|
55 |
|
|
ret_; \
|
56 |
|
|
})
|
57 |
|
|
|
58 |
|
|
/* Helper macros to cope with the file-handle parameter to the simulator
|
59 |
|
|
being *constant*. We support up to 32 simultaneously open files. Make
|
60 |
|
|
the asm volatile so we can safely ignore the return-value and get the
|
61 |
|
|
benefit from the supposed side-effect without the asm being optimized
|
62 |
|
|
away. */
|
63 |
|
|
|
64 |
|
|
#define I3f(FUN, ARG1, N, ARGS) \
|
65 |
|
|
if (ARG1 == N) \
|
66 |
|
|
__asm__ __volatile__ \
|
67 |
|
|
("SET $255,%3\n\tTRAP 0,%1,%2\n\tSET %0,$255" \
|
68 |
|
|
: "=r" (ret_) : "i" (FUN), "i" (N), "r" (ARGS) \
|
69 |
|
|
: "memory")
|
70 |
|
|
|
71 |
|
|
/* Using if:s rather than switches to help GCC optimize the rest away. */
|
72 |
|
|
#define DO32(FUN, ARG1, ARGS) \
|
73 |
|
|
I3f (FUN, ARG1, 0, ARGS); \
|
74 |
|
|
else I3f (FUN, ARG1, 1, ARGS); \
|
75 |
|
|
else I3f (FUN, ARG1, 2, ARGS); \
|
76 |
|
|
else I3f (FUN, ARG1, 3, ARGS); \
|
77 |
|
|
else I3f (FUN, ARG1, 4, ARGS); \
|
78 |
|
|
else I3f (FUN, ARG1, 5, ARGS); \
|
79 |
|
|
else I3f (FUN, ARG1, 6, ARGS); \
|
80 |
|
|
else I3f (FUN, ARG1, 7, ARGS); \
|
81 |
|
|
else I3f (FUN, ARG1, 8, ARGS); \
|
82 |
|
|
else I3f (FUN, ARG1, 9, ARGS); \
|
83 |
|
|
else I3f (FUN, ARG1, 10, ARGS); \
|
84 |
|
|
else I3f (FUN, ARG1, 11, ARGS); \
|
85 |
|
|
else I3f (FUN, ARG1, 12, ARGS); \
|
86 |
|
|
else I3f (FUN, ARG1, 13, ARGS); \
|
87 |
|
|
else I3f (FUN, ARG1, 14, ARGS); \
|
88 |
|
|
else I3f (FUN, ARG1, 15, ARGS); \
|
89 |
|
|
else I3f (FUN, ARG1, 16, ARGS); \
|
90 |
|
|
else I3f (FUN, ARG1, 17, ARGS); \
|
91 |
|
|
else I3f (FUN, ARG1, 18, ARGS); \
|
92 |
|
|
else I3f (FUN, ARG1, 19, ARGS); \
|
93 |
|
|
else I3f (FUN, ARG1, 20, ARGS); \
|
94 |
|
|
else I3f (FUN, ARG1, 21, ARGS); \
|
95 |
|
|
else I3f (FUN, ARG1, 22, ARGS); \
|
96 |
|
|
else I3f (FUN, ARG1, 23, ARGS); \
|
97 |
|
|
else I3f (FUN, ARG1, 24, ARGS); \
|
98 |
|
|
else I3f (FUN, ARG1, 25, ARGS); \
|
99 |
|
|
else I3f (FUN, ARG1, 26, ARGS); \
|
100 |
|
|
else I3f (FUN, ARG1, 27, ARGS); \
|
101 |
|
|
else I3f (FUN, ARG1, 28, ARGS); \
|
102 |
|
|
else I3f (FUN, ARG1, 29, ARGS); \
|
103 |
|
|
else I3f (FUN, ARG1, 30, ARGS); \
|
104 |
|
|
else I3f (FUN, ARG1, 31, ARGS); \
|
105 |
|
|
else \
|
106 |
|
|
{ \
|
107 |
|
|
errno = EBADF; \
|
108 |
|
|
return -1; \
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
#define TRAP1f(FUN, ARG1) \
|
112 |
|
|
({ long ret_; \
|
113 |
|
|
DO32 (FUN, ARG1, 0); \
|
114 |
|
|
ret_; \
|
115 |
|
|
})
|
116 |
|
|
|
117 |
|
|
#define TRAP2f(FUN, ARG1, ARG2) \
|
118 |
|
|
({ long ret_; \
|
119 |
|
|
DO32 (FUN, ARG1, ARG2); \
|
120 |
|
|
ret_; \
|
121 |
|
|
})
|
122 |
|
|
|
123 |
|
|
#define TRAP3f(FUN, ARG1, ARG2, ARG3) \
|
124 |
|
|
({ long ret_; \
|
125 |
|
|
unsigned long args_[] \
|
126 |
|
|
= { (unsigned long) (ARG2), (unsigned long) (ARG3) }; \
|
127 |
|
|
DO32 (FUN, ARG1, args_); \
|
128 |
|
|
ret_; \
|
129 |
|
|
})
|
130 |
|
|
|
131 |
|
|
#ifndef __GNUC__
|
132 |
|
|
/* Probably will not happen. Nevertheless... */
|
133 |
|
|
# define UNIMPLEMENTED(MSG)
|
134 |
|
|
#else
|
135 |
|
|
# define UNIMPLEMENTED(MSG) UNIMPLEMENTEDi MSG
|
136 |
|
|
# define UNIMPLEMENTEDi(MSG, ARGS...) \
|
137 |
|
|
do { \
|
138 |
|
|
char buf[2000]; \
|
139 |
|
|
sprintf (buf, "UNIMPLEMENTED %s in %s\n", __FUNCTION__, __FILE__); \
|
140 |
|
|
write (2, buf, strlen (buf)); \
|
141 |
|
|
sprintf (buf, MSG , ##ARGS); \
|
142 |
|
|
write (2, buf, strlen (buf)); \
|
143 |
|
|
write (2, "\n", 1); \
|
144 |
|
|
} while (0)
|
145 |
|
|
#endif
|