2 * Copyright (c) 1996, 2001-2003, 2005, Juniper Networks, Inc.
5 * defs.h -- Simple universal types and definitions for use by the microkernel
6 * Jim Hayes, November 1996
8 * JNPR: defs.h,v 1.3.2.1 2007/09/10 08:16:32 girish
16 * Paranoid compilation. If defined, the PARANOID flag will enable asserts,
17 * data structure magic stamping and a suite of other debug tools. To disable
18 * it, comment out its definition.
23 * This is the ONLY place you should see hardware specific information
24 * encoded as #ifdefs. (Well, except for stdarg.h, perhaps.)
25 * I apologize in advance!
27 #include <machine/defs_mips.h>
30 #if !defined(CPU_GOT_ONE)
31 #error "YOU NEED TO SPECIFY ONE CPU TYPE TO USE THIS FILE"
49 * Make NULL a pointer within the microkernel environment to catch
50 * pointer semantic miscreants.
52 * The reason it's conditional here is that some of the BSD includes
53 * define it multiple times as a straight integer and GCC barfs on
54 * the alternative prototypes.
58 #define NULL (void *)0
62 * Define some standard sized types. (Defined in cpu-specific type files
70 #define MAX_U16 0xffff
71 #define MIN_S16 ((int16_t)(1 << 15))
72 #define MAX_S16 ((int16_t)~MIN_S16)
74 #define MAX_U32 0xffffffff
75 #define MIN_S32 ((int32_t)(1 << 31))
76 #define MAX_S32 ((int32_t)~MIN_S32)
78 #define MAX_U64 ((u_int64_t)0 - 1)
79 #define MAX_S64 ((int64_t)(MAX_U64 >> 1))
80 #define MIN_S64 (-MAX_S64-1)
83 * Solaris uses _SIZE_T to mark the fact that "size_t" has already
84 * been defined. _SYS_TYPES_H_ is used by BSD.
87 #if !defined(_SYS_TYPES_H_) && !defined(_SIZE_T)
88 typedef UNSIGNED_32 size_t;
92 #if !defined(_SYS_TYPES_H_)
93 typedef char * caddr_t;
95 typedef UNSIGNED_8 u_int8_t;
96 typedef SIGNED_8 int8_t;
98 typedef UNSIGNED_16 u_int16_t;
99 typedef SIGNED_16 int16_t;
101 typedef UNSIGNED_32 u_int32_t;
102 typedef SIGNED_32 int32_t;
104 typedef UNSIGNED_64 u_int64_t;
105 typedef SIGNED_64 int64_t;
107 typedef UNSIGNED_32 u_long;
108 typedef UNSIGNED_16 u_short;
109 typedef UNSIGNED_8 u_char;
113 * Define the standard terminology used in the diag software
114 * with regards to bytes, words, etc.
116 * HWORD (halfword) = 2 bytes or 16 bits
117 * WORD = 4 bytes or 32 bits
118 * QUAD = 8 bytes or 64 bits
120 * (The term QUAD seems less-than-intuitive here, but it is
121 * derived from BSD sources where it is defined as int64_t.)
123 * For consistency use the following defines wherever appropriate.
127 NBI_BYTE = (sizeof(u_int8_t) * 8),
128 NBI_HWORD = (sizeof(u_int16_t) * 8),
129 NBI_WORD = (sizeof(u_int32_t) * 8),
130 NBI_QUAD = (sizeof(u_int64_t) * 8)
134 NBY_BYTE = sizeof(u_int8_t),
135 NBY_HWORD = sizeof(u_int16_t),
136 NBY_WORD = sizeof(u_int32_t),
137 NBY_QUAD = sizeof(u_int64_t)
141 * We assume that pid values are 16 bit integers
144 typedef u_int16_t pid_t;
146 #endif /* _SYS_TYPES_H_ */
148 typedef UNSIGNED_32 magic_t;
149 typedef int status_t;
151 #define BITS_IN_BYTE 8
154 * Packed definition. We use this for fields in network frames where we
155 * don't want the compiler to pack out to even alignment
161 #define PACKED(x) x __attribute__ ((packed))
164 * __unused is a FreeBSDism that prevents the compiler from choking
165 * on function parameters that remain unused through the life of a
166 * function. This is not an issue for the Cygnus toolchain. In general
167 * it SHOULD NOT BE USED in the martini embedded software repository.
168 * It should only be used inside of shared code.
171 #define __unused __attribute__ ((__unused__))
175 * Basic memory multiples
178 #define SIZE_1K 0x00000400
179 #define SIZE_2K 0x00000800
180 #define SIZE_4K 0x00001000
181 #define SIZE_8K 0x00002000
182 #define SIZE_16K 0x00004000
183 #define SIZE_32K 0x00008000
184 #define SIZE_64K 0x00010000
185 #define SIZE_128K 0x00020000
186 #define SIZE_256K 0x00040000
187 #define SIZE_512K 0x00080000
188 #define SIZE_1M 0x00100000
189 #define SIZE_2M 0x00200000
190 #define SIZE_4M 0x00400000
191 #define SIZE_8M 0x00800000
192 #define SIZE_16M 0x01000000
193 #define SIZE_32M 0x02000000
194 #define SIZE_64M 0x04000000
195 #define SIZE_128M 0x08000000
196 #define SIZE_256M 0x10000000
197 #define SIZE_512M 0x20000000
198 #define SIZE_1G 0x40000000
199 #define SIZE_2G 0x80000000
205 * Byteswap a 16 and 32 bit quantities
208 static inline u_int16_t
209 swap16_inline(u_int16_t data)
211 return(((data & 0x00ff) << 8) |
212 ((data & 0xff00) >> 8));
215 static inline u_int32_t
216 swap32_inline(u_int32_t data)
218 return(((data & 0x000000ff) << 24) |
219 ((data & 0x0000ff00) << 8) |
220 ((data & 0x00ff0000) >> 8) |
221 ((data & 0xff000000) >> 24));
225 * Define errno_t here as it is needed by the rom and ukernel
227 typedef u_int32_t errno_t;
232 * Define the main communication structure used for passing
233 * information from the rom to the ukernel (done here as it is
236 typedef struct rom_info_ rom_info_t;
239 * Typedef the return code from the ukernel to the ROM
241 typedef u_int32_t rom_return_t;
244 * Pull in the relevant global environment header file
246 * This file is shared by the uKernel and the system simulation effort.
248 #if defined(ENV_UKERN) || defined (ENV_SYS_SIM)
250 #endif /* ENV_UKERN */
256 #endif /* __DEFS_H__ */