chiark / gitweb /
Initial revision
[ssr] / StraySrc / Libraries / Core / h / swiv
1 /*
2  * swiv.h
3  *
4  * Interface to SWI veneer
5  *
6  * © 1997, 1998 Straylight
7  */
8
9 /*----- Licensing note ----------------------------------------------------*
10  *
11  * This file is part of Straylight's core library (corelib).
12  *
13  * Corelib is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2, or (at your option)
16  * any later version.
17  *
18  * Corelib is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with Corelib.  If not, write to the Free Software Foundation,
25  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26  */
27
28 #ifndef ___swis_h
29 #define ___swis_h
30
31 #ifdef __cplusplus
32   extern "C" {
33 #endif
34
35 #ifndef __kernel_h
36   #include "kernel.h"
37 #endif
38
39 /* --- SWI veneer functions --- *
40  *
41  * Arguments:   int swi == the SWI to call
42  *              unsigned flags == a definition of the SWIs registers
43  *
44  * Returns:     _swi returns the value of the `return' register in the flags
45  *              _swix returns 0, or a pointer to an error block
46  *
47  * Use:         Calls a SWI, passing it a collection of registers, and
48  *              filling in the registers as given in the function call.
49  *
50  *              Order of arguments is as follows:
51  *
52  *              Input registers:        One word for each input register
53  *              Output registers:       Address to store each reg value
54  *              Flags address:          Address to store PC+flags value
55  *              Block contents:         Build contents of local block at end
56  */
57
58 extern int _swi(int /*swi*/, unsigned /*flags*/,...);
59 extern _kernel_oserror *_swix(int /*swi*/, unsigned /*flags*/,...);
60
61 /* --- Various flags settings --- *
62  *
63  * _in(n) -- declare Rn as an input register
64  * _inr(m, n) -- declare Rm--Rn as input registers
65  * _out(n) -- declare Rn as an output register
66  * _outr(m, n) -- declare Rm--Rn as output registers
67  * _return(n) -- return Rn from _swi
68  * _block(n) -- point Rn at block containing remaining arguments
69  */
70
71 #ifndef _FLAGS
72
73   /* --- _flags -- return or output processor flags --- */
74
75   #define _flags        (0x10)
76
77   /* --- _in and _inr -- input a register, or a range of registers --- */
78
79   #define _in(r)        (1u << (r))
80   #define _inr(ra,rb)   (((~0) << (ra)) ^ ((~0) << ((rb)+1)))
81
82   /* --- _out and _outr -- output a register, or a range of registers --- */
83
84   #define _out(r)       (1u << (31-((r) == _flags ? 10 : (r))))
85   #define _outr(ra,rb)  (((~0) << (31-(rb))) ^ ((~0) << (32-(ra))))
86
87   /* --- _block -- point a register at block built from arguments --- */
88
89   #define _block(r)     (((r) << 12) | 0x800)
90
91   /* --- _return -- return register from _swi (not _swix) --- */
92
93   #define _return(r)    ((r) == _flags ? 0xF0000 : (r) << 16)
94
95   /* --- Constants for ARM processor flags --- */
96
97   #define _n            (0x80000000u)
98   #define _z            (0x40000000u)
99   #define _c            (0x20000000u)
100   #define _v            (0x10000000u)
101
102   /* --- Acorn style capital-letter macros --- */
103
104   #define _FLAGS        _flags
105   #define _IN(x)        _in(x)
106   #define _INR(x,y)     _inr(x,y)
107   #define _OUT(x)       _out(x)
108   #define _OUTR(x,y)    _outr(x,y)
109   #define _BLOCK(x)     _block(x)
110   #define _RETURN(x)    _return(x)
111   #define _N            _n
112   #define _Z            _z
113   #define _C            _c
114   #define _V            _v
115
116 #endif
117
118 #ifdef __cplusplus
119   }
120 #endif
121
122 #endif