1c4b2bec483cb588e19feb025e66032d0939b1ef
[dragonfly.git] / sys / boot / arc / include / arcfuncs.h
1 /*
2  * Copyright (c) 1999, Stefan Esser <se@freebsd.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice unmodified, this list of conditions, and the following
10  *    disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * $FreeBSD: src/sys/boot/arc/include/arcfuncs.h,v 1.2 1999/08/28 00:39:34 peter Exp $
27  * $DragonFly: src/sys/boot/arc/include/Attic/arcfuncs.h,v 1.3 2003/11/10 06:08:30 dillon Exp $
28  */
29
30 #ifdef __GNUC__
31 #define INLINE inline
32 #else
33 #define INLINE /**/
34 #endif
35
36 /* System Parameter Block holding ARC and VENDOR function vector addresses */
37
38 #define SPBlock ((SPB *)0xffffffff806fe000ul)
39
40 /*
41  * Convert between 32bit (ARC) and 64bit (Alpha) pointers
42  */
43
44 static INLINE void*
45 ptr(arcptr p)
46 {
47    return (void*)(int64_t)p.adr;
48 }
49
50 static INLINE arcptr
51 toarcptr(void *p)
52 {
53    arcptr p32;
54    p32.adr = (int32_t)(int64_t) p;
55    return (p32);
56 }
57
58 /*
59  * Return entry point for ARC BIOS function "funcno"
60  */
61
62 static INLINE void *
63 get_arc_vector(int funcno)
64 {
65    arcptr (*arc_vector)[] = ptr(SPBlock->FirmwareVectorP);
66    return ptr((*arc_vector)[funcno -1]);
67 }
68
69 /*
70  * Return entry point for VENDOR function "funcno"
71  */
72
73 static INLINE void *
74 get_vendor_vector(int funcno)
75 {
76    arcptr (*arc_vector)[] = ptr(SPBlock->PrivateVectorP);
77    return ptr((*arc_vector)[funcno -1]);
78 }
79
80 static INLINE int
81 get_vendor_vector_length(void)
82 {
83    return SPBlock->PrivateVectorLength;
84 }
85
86 /*
87  * Macros to create inline wrappers for ARCS BIOS functions
88  * 
89  * Parameter:
90  *      num     function number (starting at 1)
91  *      result  result type
92  *      fn      function name
93  *      param   parameter list (types and formal args)
94  *      args    parameter list (formal args only)
95  */
96
97 #define ARC_FN(num,result,fn,param,args) \
98 static inline result fn param { \
99         typedef result _fn_t param; \
100         _fn_t *p_ ## fn = get_arc_vector(num); \
101         return p_ ## fn args; \
102 }
103
104 #define VND_FN(num,result,fn,param,args) \
105 static INLINE result fn param { \
106         typedef result _fn_t param; \
107         _fn_t *p_ ## fn = get_vendor_vector(num); \
108         return p_ ## fn args; \
109 }
110
111 /* function codes as defined in ARC Specification Version 1.2 */
112
113 ARC_FN(1, int32_t, Load, 
114        (char *Path, u_int32_t TopAddr, u_int32_t *ExecAddr, u_int32_t *LowAddr),
115        (Path, TopAddr, ExecAddr, LowAddr))
116 ARC_FN(2, int32_t, Invoke, 
117        (u_int32_t ExecAddr, u_int32_t StackAddr, u_int32_t Argc, char *Argv[], char *Envp[]),
118        (ExecAddr, StackAddr, Argc, Argv, Envp))
119 ARC_FN(3, int32_t, Execute,
120        (char *Path, u_int32_t Argc, char *Argv[], char *Envp[]),
121        (Path, Argc, Argv, Envp))
122 ARC_FN(4, void, Halt, (void), ())
123 ARC_FN(5, void, PowerDown, (void), ())
124 ARC_FN(6, void, Restart, (void), ())
125 ARC_FN(7, void, FwReboot, (void), ())
126 ARC_FN(8, void, EnterInteractiveMode, (void), ())
127 ARC_FN(10, CONFIGURATION_COMPONENT *, GetPeer,
128        (CONFIGURATION_COMPONENT *Current),
129        (Current))
130 ARC_FN(11, CONFIGURATION_COMPONENT *, GetChild,
131        (CONFIGURATION_COMPONENT *Current),
132        (Current))
133 ARC_FN(12, CONFIGURATION_COMPONENT *, GetParent,
134        (CONFIGURATION_COMPONENT *Current),
135        (Current))
136 ARC_FN(13, CONFIGURATION_COMPONENT *, AddChild,
137        (CONFIGURATION_COMPONENT *Current, CONFIGURATION_COMPONENT *Template, 
138         void *ConfigurationData),
139        (Current, Template, ConfigurationData))
140 ARC_FN(14, int32_t, DeleteComponent,
141        (CONFIGURATION_COMPONENT *ComponentToDelete),
142        (ComponentToDelete))
143 ARC_FN(15, CONFIGURATION_COMPONENT *, GetComponent, (char *Path), (Path))
144 ARC_FN(16, int32_t, GetConfigurationData,
145        (void *ConfigurationData, CONFIGURATION_COMPONENT *Component),
146        (ConfigurationData, Component))
147 ARC_FN(17, int32_t, SaveConfiguration, (void), ())
148 ARC_FN(18, SYSTEM_ID *, GetSystemId, (void), ())
149 ARC_FN(19, MEMORY_DESCRIPTOR *, GetMemoryDescriptor, 
150        (MEMORY_DESCRIPTOR *Current),
151        (Current))
152 ARC_FN(21, TIME_FIELDS *, GetTime, (void), ())
153 ARC_FN(22, u_int32_t, GetRelativeTime, (void), ())
154 ARC_FN(23, int32_t, GetDirectoryEntry,
155        (u_int32_t FileId, DIRECTORY_ENTRY *Buffer, u_int32_t Length, u_int32_t *Count),
156        (FileId, Buffer, Length, Count))
157 ARC_FN(24, int32_t, Open, 
158        (const char *Path, OPEN_MODE OpenMode, u_int32_t *FileId),
159        (Path, OpenMode, FileId))
160 ARC_FN(25, int32_t, Close, (u_int32_t FileId), (FileId))
161 ARC_FN(26, int32_t, Read, 
162        (u_int32_t FileId, void *Buffer,  u_int32_t N, u_int32_t *Count),
163        (FileId, Buffer, N, Count))
164 ARC_FN(27, int32_t, GetReadStatus, (u_int32_t FileId), (FileId))
165 ARC_FN(28, int32_t, Write, 
166        (u_int32_t FileId, void const *Buffer, u_int32_t N, u_int32_t *Count),
167        (FileId, Buffer, N, Count))
168 ARC_FN(29, int32_t, Seek, 
169        (u_int32_t FileId, fpos_t *Position, SEEK_MODE SeekMode),
170        (FileId, Position, SeekMode))
171 ARC_FN(30, int32_t, Mount, 
172        (char *Path, MOUNT_OPERATION Operation), 
173        (Path, Operation))
174 ARC_FN(31, char *, GetEnvironmentVariable, (char *Name), (Name))
175 ARC_FN(32, int32_t, SetEnvironmentVariable, 
176        (char *Name, char *Value), 
177        (Name, Value))
178 ARC_FN(33, int32_t, GetFileInformation, 
179        (u_int32_t FileId, FILE_INFORMATION *Information),
180        (FileId, Information))
181 ARC_FN(34, int32_t, SetFileInformation,
182        (u_int32_t FileId, u_int32_t AttributeFlags, u_int32_t AttributeMask),
183        (FileId, AttributeFlags, AttributeMask))
184 ARC_FN(35, void, FlushAllCaches, (void), ())
185 ARC_FN(36, int32_t, TestUnicodeCharacter, 
186        (u_int32_t FileId, WCHAR UnicodeCharacter),
187        (FileId, UnicodeCharacter))
188 ARC_FN(37, ARC_DISPLAY_STATUS *, GetDisplayStatus, (u_int32_t FileId), (FileId))
189
190 /* Vendor specific function codes have not been verified beyond function 4 */
191
192 VND_FN(1, void *, AllocatePool, (u_int32_t NumberOfBytes), (NumberOfBytes))
193 VND_FN(2, void, StallExecution, (u_int32_t Microseconds), (Microseconds))
194 VND_FN(3, u_int32_t, Print, 
195        (char *Format, int32_t Arg1, int32_t Arg2, int32_t Arg3), 
196        (Format, Arg1, Arg2, Arg3))
197 VND_FN(4, void, ReturnExtendedSystemInformation, 
198        (EXTENDED_SYSTEM_INFORMATION *SystemInfo),
199        (SystemInfo))