Welcome to mirror list, hosted at ThFree Co, Russian Federation.

syscall.h « sys « mmixware « sys « libc « newlib - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 15a2d1c09d32ceaa3c19bdaac82c4b591715cd69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/* syscall defines for MMIXware.

   Copyright (C) 2001, 2002 Hans-Peter Nilsson

   Permission to use, copy, modify, and distribute this software is
   freely granted, provided that the above copyright notice, this notice
   and the following disclaimer are preserved with no changes.

   THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
   IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   PURPOSE.  */

/* These are the mmixware simulator calls that are of use in newlib.  */

#define SYS_halt	0
#define	SYS_Fopen	1
#define	SYS_Fclose	2
#define	SYS_Fread	3
#define	SYS_Fwrite	6
#define	SYS_Fseek	9
#define	SYS_Ftell	10


enum MMIX_filemode
 {
   TextRead = 0,
   TextWrite = 1,
   BinaryRead = 2,
   BinaryWrite = 3,
   BinaryReadWrite = 4
 };

#define N_MMIX_FILEHANDLES 32

/* We store a bitmap of allocated filehandles
   _MMIX_allocated_filehandle[fileno] in an array.  There are 32 of them.
   Indexes 0, 1 and 2 are allocated from start.  The reason we keep track
   of them is that *we* have to allocate a filehandle when opening a file.
   Had we got a filehandle from the simulator, we wouldn't have to keep
   track of it.  A value of 0 denotes a free handle.  */
extern unsigned char _MMIX_allocated_filehandle[N_MMIX_FILEHANDLES];

/* We use this file-handle number as a temporary; not used by usual file
   I/O.  */
#define TMPFNO 127

/* Simulator call with one argument.  Also used for zero-argument calls;
   pass a zero as ARG1.  Make the asm volatile so we can safely ignore the
   return-value and only get the benefit from the supposed side-effect
   without the asm being optimized away.  */
#define TRAP1i(FUN, ARG1)			\
 ({ long ret_;					\
    __asm__ __volatile__			\
      ("TRAP 0,%1,%2\n\tSET %0,$255"		\
       : "=r" (ret_) : "i" (FUN), "i" (ARG1)	\
       : "memory");				\
    ret_;					\
 })

/* Helper macros to cope with the file-handle parameter to the simulator
   being *constant*.  We support up to 32 simultaneously open files.  Make
   the asm volatile so we can safely ignore the return-value and get the
   benefit from the supposed side-effect without the asm being optimized
   away.  */

#define I3f(FUN, ARG1, N, ARGS)				\
 if (ARG1 == N)						\
   __asm__ __volatile__					\
     ("SET $255,%3\n\tTRAP 0,%1,%2\n\tSET %0,$255"	\
      : "=r" (ret_) : "i" (FUN), "i" (N), "r" (ARGS)	\
      : "memory")

/* Using if:s rather than switches to help GCC optimize the rest away.  */
#define DO32(FUN, ARG1, ARGS)			\
    I3f (FUN, ARG1, 0, ARGS);			\
    else I3f (FUN, ARG1, 1, ARGS);		\
    else I3f (FUN, ARG1, 2, ARGS);		\
    else I3f (FUN, ARG1, 3, ARGS);		\
    else I3f (FUN, ARG1, 4, ARGS);		\
    else I3f (FUN, ARG1, 5, ARGS);		\
    else I3f (FUN, ARG1, 6, ARGS);		\
    else I3f (FUN, ARG1, 7, ARGS);		\
    else I3f (FUN, ARG1, 8, ARGS);		\
    else I3f (FUN, ARG1, 9, ARGS);		\
    else I3f (FUN, ARG1, 10, ARGS);		\
    else I3f (FUN, ARG1, 11, ARGS);		\
    else I3f (FUN, ARG1, 12, ARGS);		\
    else I3f (FUN, ARG1, 13, ARGS);		\
    else I3f (FUN, ARG1, 14, ARGS);		\
    else I3f (FUN, ARG1, 15, ARGS);		\
    else I3f (FUN, ARG1, 16, ARGS);		\
    else I3f (FUN, ARG1, 17, ARGS);		\
    else I3f (FUN, ARG1, 18, ARGS);		\
    else I3f (FUN, ARG1, 19, ARGS);		\
    else I3f (FUN, ARG1, 20, ARGS);		\
    else I3f (FUN, ARG1, 21, ARGS);		\
    else I3f (FUN, ARG1, 22, ARGS);		\
    else I3f (FUN, ARG1, 23, ARGS);		\
    else I3f (FUN, ARG1, 24, ARGS);		\
    else I3f (FUN, ARG1, 25, ARGS);		\
    else I3f (FUN, ARG1, 26, ARGS);		\
    else I3f (FUN, ARG1, 27, ARGS);		\
    else I3f (FUN, ARG1, 28, ARGS);		\
    else I3f (FUN, ARG1, 29, ARGS);		\
    else I3f (FUN, ARG1, 30, ARGS);		\
    else I3f (FUN, ARG1, 31, ARGS);		\
    else					\
      {						\
        errno = EBADF;				\
	return -1;				\
      }

#define TRAP1f(FUN, ARG1)			\
 ({ long ret_;					\
    DO32 (FUN, ARG1, 0);			\
    ret_;					\
 })

#define TRAP2f(FUN, ARG1, ARG2)			\
 ({ long ret_;					\
    DO32 (FUN, ARG1, ARG2);			\
    ret_;					\
 })

#define TRAP3f(FUN, ARG1, ARG2, ARG3)				\
 ({ long ret_;							\
    unsigned long args_[]					\
      = { (unsigned long) (ARG2), (unsigned long) (ARG3) };	\
    DO32 (FUN, ARG1, args_);					\
    ret_;							\
 })

#ifndef __GNUC__
/* Probably will not happen.  Nevertheless...  */
# define UNIMPLEMENTED(MSG)
#else
# define UNIMPLEMENTED(MSG) UNIMPLEMENTEDi MSG
# define UNIMPLEMENTEDi(MSG, ARGS...)					\
 do {									\
     char buf[2000];							\
     sprintf (buf, "UNIMPLEMENTED %s in %s\n", __FUNCTION__, __FILE__);	\
     write (2, buf, strlen (buf));					\
     sprintf (buf, MSG , ##ARGS);					\
     write (2, buf, strlen (buf));					\
     write (2, "\n", 1);						\
 } while (0)
#endif