OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib-1.10.0/] [newlib/] [libc/] [sys/] [mmixware/] [sys/] [syscall.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1010 ivang
/* syscall defines for MMIXware.
2
 
3
   Copyright (C) 2001 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_Fwrite      6
21
#define SYS_Fseek       9
22
#define SYS_Ftell       10
23
 
24
 
25
enum MMIX_filemode
26
 {
27
   TextRead = 0,
28
   TextWrite = 1,
29
   BinaryRead = 2,
30
   BinaryWrite = 3,
31
   BinaryReadWrite = 4
32
 };
33
 
34
#define N_MMIX_FILEHANDLES 32
35
 
36
/* We store a bitmap of allocated filehandles
37
   _MMIX_allocated_filehandle[fileno] in an array.  There are 32 of them.
38
   Indexes 0, 1 and 2 are allocated from start.  The reason we keep track
39
   of them is that *we* have to allocate a filehandle when opening a file.
40
   Had we got a filehandle from the simulator, we wouldn't have to keep
41
   track of it.  A value of 0 denotes a free handle.  */
42
extern unsigned char _MMIX_allocated_filehandle[N_MMIX_FILEHANDLES];
43
 
44
/* We use this file-handle number as a temporary; not used by usual file
45
   I/O.  */
46
#define TMPFNO 127
47
 
48
/* Simulator call with one argument.  Also used for zero-argument calls;
49
   pass a zero as ARG1.  */
50
#define TRAP1i(FUN, ARG1)                               \
51
 ({ long ret_;                                          \
52
    __asm__ ("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.  */
60
#define I3f(FUN, ARG1, N, ARGS)                                 \
61
 if (ARG1 == N)                                                 \
62
   __asm__ ("SET $255,%3\n\tTRAP 0,%1,%2\n\tSET %0,$255"        \
63
            : "=r" (ret_) : "i" (FUN), "i" (N), "r" (ARGS)      \
64
            : "memory")
65
 
66
/* Using if:s rather than switches to help GCC optimize the rest away.  */
67
#define DO32(FUN, ARG1, ARGS)                   \
68
    I3f (FUN, ARG1, 0, ARGS);                    \
69
    else I3f (FUN, ARG1, 1, ARGS);              \
70
    else I3f (FUN, ARG1, 2, ARGS);              \
71
    else I3f (FUN, ARG1, 3, ARGS);              \
72
    else I3f (FUN, ARG1, 4, ARGS);              \
73
    else I3f (FUN, ARG1, 5, ARGS);              \
74
    else I3f (FUN, ARG1, 6, ARGS);              \
75
    else I3f (FUN, ARG1, 7, ARGS);              \
76
    else I3f (FUN, ARG1, 8, ARGS);              \
77
    else I3f (FUN, ARG1, 9, ARGS);              \
78
    else I3f (FUN, ARG1, 10, ARGS);             \
79
    else I3f (FUN, ARG1, 11, ARGS);             \
80
    else I3f (FUN, ARG1, 12, ARGS);             \
81
    else I3f (FUN, ARG1, 13, ARGS);             \
82
    else I3f (FUN, ARG1, 14, ARGS);             \
83
    else I3f (FUN, ARG1, 15, ARGS);             \
84
    else I3f (FUN, ARG1, 16, ARGS);             \
85
    else I3f (FUN, ARG1, 17, ARGS);             \
86
    else I3f (FUN, ARG1, 18, ARGS);             \
87
    else I3f (FUN, ARG1, 19, ARGS);             \
88
    else I3f (FUN, ARG1, 20, ARGS);             \
89
    else I3f (FUN, ARG1, 21, ARGS);             \
90
    else I3f (FUN, ARG1, 22, ARGS);             \
91
    else I3f (FUN, ARG1, 23, ARGS);             \
92
    else I3f (FUN, ARG1, 24, ARGS);             \
93
    else I3f (FUN, ARG1, 25, ARGS);             \
94
    else I3f (FUN, ARG1, 26, ARGS);             \
95
    else I3f (FUN, ARG1, 27, ARGS);             \
96
    else I3f (FUN, ARG1, 28, ARGS);             \
97
    else I3f (FUN, ARG1, 29, ARGS);             \
98
    else I3f (FUN, ARG1, 30, ARGS);             \
99
    else I3f (FUN, ARG1, 31, ARGS);             \
100
    else                                        \
101
      {                                         \
102
        errno = EBADF;                          \
103
        return -1;                              \
104
      }
105
 
106
#define TRAP1f(FUN, ARG1)                       \
107
 ({ long ret_;                                  \
108
    DO32 (FUN, ARG1, 0);                 \
109
    ret_;                                       \
110
 })
111
 
112
#define TRAP2f(FUN, ARG1, ARG2)                 \
113
 ({ long ret_;                                  \
114
    DO32 (FUN, ARG1, ARG2);                     \
115
    ret_;                                       \
116
 })
117
 
118
#define TRAP3f(FUN, ARG1, ARG2, ARG3)                           \
119
 ({ long ret_;                                                  \
120
    unsigned long args_[]                                       \
121
      = { (unsigned long) (ARG2), (unsigned long) (ARG3) };     \
122
    DO32 (FUN, ARG1, args_);                                    \
123
    ret_;                                                       \
124
 })
125
 
126
#ifndef __GNUC__
127
/* Probably will not happen.  Nevertheless...  */
128
# define UNIMPLEMENTED(MSG)
129
#else
130
# define UNIMPLEMENTED(MSG) UNIMPLEMENTEDi MSG
131
# define UNIMPLEMENTEDi(MSG, ARGS...)                                   \
132
 do {                                                                   \
133
     char buf[2000];                                                    \
134
     sprintf (buf, "UNIMPLEMENTED %s in %s\n", __FUNCTION__, __FILE__); \
135
     write (2, buf, strlen (buf));                                      \
136
     sprintf (buf, MSG , ##ARGS);                                       \
137
     write (2, buf, strlen (buf));                                      \
138
     write (2, "\n", 1);                                                \
139
 } while (0)
140
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.