xref: /haiku/headers/os/kernel/OS.h (revision a1163de83ea633463a79de234b8742ee106531b2)
1 /* Kernel specific structures and functions
2  *
3  * Copyright 2004-2006, Haiku Inc. All Rights Reserved.
4  * Distributed under the terms of the MIT License.
5  */
6 #ifndef _OS_H
7 #define _OS_H
8 
9 
10 #include <stdarg.h>
11 
12 #include <SupportDefs.h>
13 #include <StorageDefs.h>
14 
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 /*-------------------------------------------------------------*/
21 /* System constants */
22 
23 #define B_OS_NAME_LENGTH	32
24 #define B_PAGE_SIZE			4096
25 #define B_INFINITE_TIMEOUT	(9223372036854775807LL)
26 
27 enum {
28 	B_TIMEOUT						= 0x8,	/* relative timeout */
29 	B_RELATIVE_TIMEOUT				= 0x8,	/* fails after a relative timeout
30 												with B_TIMED_OUT */
31 	B_ABSOLUTE_TIMEOUT				= 0x10,	/* fails after an absolute timeout
32 												with B_TIMED_OUT */
33 
34 	/* experimental Haiku only API */
35 	B_TIMEOUT_REAL_TIME_BASE		= 0x40,
36 	B_ABSOLUTE_REAL_TIME_TIMEOUT	= B_ABSOLUTE_TIMEOUT
37 										| B_TIMEOUT_REAL_TIME_BASE
38 };
39 
40 /*-------------------------------------------------------------*/
41 /* Types */
42 
43 typedef int32 area_id;
44 typedef int32 port_id;
45 typedef int32 sem_id;
46 typedef int32 team_id;
47 typedef int32 thread_id;
48 
49 
50 /*-------------------------------------------------------------*/
51 /* Areas */
52 
53 typedef struct area_info {
54 	area_id		area;
55 	char		name[B_OS_NAME_LENGTH];
56 	size_t		size;
57 	uint32		lock;
58 	uint32		protection;
59 	team_id		team;
60 	uint32		ram_size;
61 	uint32		copy_count;
62 	uint32		in_count;
63 	uint32		out_count;
64 	void		*address;
65 } area_info;
66 
67 /* area locking */
68 #define B_NO_LOCK				0
69 #define B_LAZY_LOCK				1
70 #define B_FULL_LOCK				2
71 #define B_CONTIGUOUS			3
72 #define	B_LOMEM					4
73 
74 /* address spec for create_area(), and clone_area() */
75 #define B_ANY_ADDRESS			0
76 #define B_EXACT_ADDRESS			1
77 #define B_BASE_ADDRESS			2
78 #define B_CLONE_ADDRESS			3
79 #define	B_ANY_KERNEL_ADDRESS	4
80 
81 /* area protection */
82 #define B_READ_AREA				1
83 #define B_WRITE_AREA			2
84 
85 extern area_id	create_area(const char *name, void **startAddress, uint32 addressSpec,
86 					size_t size, uint32 lock, uint32 protection);
87 extern area_id	clone_area(const char *name, void **destAddress, uint32 addressSpec,
88 					uint32 protection, area_id source);
89 extern area_id	find_area(const char *name);
90 extern area_id	area_for(void *address);
91 extern status_t	delete_area(area_id id);
92 extern status_t	resize_area(area_id id, size_t newSize);
93 extern status_t	set_area_protection(area_id id, uint32 newProtection);
94 
95 /* system private, use macros instead */
96 extern status_t	_get_area_info(area_id id, area_info *areaInfo, size_t size);
97 extern status_t	_get_next_area_info(team_id team, int32 *cookie,
98 					area_info *areaInfo, size_t size);
99 
100 #define get_area_info(id, areaInfo) \
101 			_get_area_info((id), (areaInfo),sizeof(*(areaInfo)))
102 #define get_next_area_info(team, cookie, areaInfo) \
103 			_get_next_area_info((team), (cookie), (areaInfo), sizeof(*(areaInfo)))
104 
105 
106 /*-------------------------------------------------------------*/
107 /* Ports */
108 
109 typedef struct port_info {
110 	port_id		port;
111 	team_id		team;
112 	char		name[B_OS_NAME_LENGTH];
113 	int32		capacity;		/* queue depth */
114 	int32		queue_count;	/* # msgs waiting to be read */
115 	int32		total_count;	/* total # msgs read so far */
116 } port_info;
117 
118 extern port_id	create_port(int32 capacity, const char *name);
119 extern port_id	find_port(const char *name);
120 extern ssize_t	read_port(port_id port, int32 *code, void *buffer, size_t bufferSize);
121 extern ssize_t	read_port_etc(port_id port, int32 *code, void *buffer, size_t bufferSize,
122 					uint32 flags, bigtime_t timeout);
123 extern status_t write_port(port_id port, int32 code, const void *buffer, size_t bufferSize);
124 extern status_t write_port_etc(port_id port, int32 code, const void *buffer,
125 					size_t bufferSize, uint32 flags, bigtime_t timeout);
126 extern status_t close_port(port_id port);
127 extern status_t delete_port(port_id port);
128 
129 extern ssize_t	port_buffer_size(port_id port);
130 extern ssize_t	port_buffer_size_etc(port_id port, uint32 flags, bigtime_t timeout);
131 extern ssize_t	port_count(port_id port);
132 extern status_t set_port_owner(port_id port, team_id team);
133 
134 /* system private, use the macros instead */
135 extern status_t _get_port_info(port_id port, port_info *portInfo, size_t portInfoSize);
136 extern status_t _get_next_port_info(team_id team, int32 *cookie, port_info *portInfo,
137 					size_t portInfoSize);
138 
139 #define get_port_info(port, info) \
140 			_get_port_info((port), (info), sizeof(*(info)))
141 #define get_next_port_info(team, cookie, info) \
142 			_get_next_port_info((team), (cookie), (info), sizeof(*(info)))
143 
144 
145 /* WARNING: The following is Haiku experimental API. It might be removed or
146    changed in the future. */
147 
148 typedef struct port_message_info {
149 	size_t		size;
150 	uid_t		sender;
151 	gid_t		sender_group;
152 	team_id		sender_team;
153 } port_message_info;
154 
155 /* similar to port_buffer_size_etc(), but returns (more) info */
156 extern status_t _get_port_message_info_etc(port_id port,
157 					port_message_info *info, size_t infoSize, uint32 flags,
158 					bigtime_t timeout);
159 
160 #define get_port_message_info_etc(port, info, flags, timeout) \
161 			_get_port_message_info_etc((port), (info), sizeof(*(info)), flags, \
162 					timeout)
163 
164 /*-------------------------------------------------------------*/
165 /* Semaphores */
166 
167 typedef struct sem_info {
168 	sem_id		sem;
169 	team_id		team;
170 	char		name[B_OS_NAME_LENGTH];
171 	int32		count;
172 	thread_id	latest_holder;
173 } sem_info;
174 
175 /* semaphore flags */
176 enum {
177 	B_CAN_INTERRUPT				= 0x01,	/* acquisition of the semaphore can be
178 										   interrupted (system use only) */
179 	B_CHECK_PERMISSION			= 0x04,	/* ownership will be checked (system use
180 										   only) */
181 	B_KILL_CAN_INTERRUPT		= 0x20,	/* acquisition of the semaphore can be
182 										   interrupted by SIGKILL[THR], even
183 										   if not B_CAN_INTERRUPT (system use
184 										   only) */
185 
186 	/* release_sem_etc() only flags */
187 	B_DO_NOT_RESCHEDULE			= 0x02,	/* thread is not rescheduled */
188 	B_RELEASE_ALL				= 0x08,	/* all waiting threads will be woken up,
189 										   count will be zeroed */
190 	B_RELEASE_IF_WAITING_ONLY	= 0x10	/* release count only if there are any
191 										   threads waiting */
192 };
193 
194 extern sem_id	create_sem(int32 count, const char *name);
195 extern status_t	delete_sem(sem_id id);
196 extern status_t	acquire_sem(sem_id id);
197 extern status_t	acquire_sem_etc(sem_id id, int32 count, uint32 flags, bigtime_t timeout);
198 extern status_t	release_sem(sem_id id);
199 extern status_t	release_sem_etc(sem_id id, int32 count, uint32 flags);
200 /* ToDo: the following two calls are not part of the BeOS API, and might be
201    changed or even removed for the final release of Haiku R1 */
202 extern status_t	switch_sem(sem_id semToBeReleased, sem_id id);
203 extern status_t	switch_sem_etc(sem_id semToBeReleased, sem_id id, int32 count,
204 					uint32 flags, bigtime_t timeout);
205 extern status_t	get_sem_count(sem_id id, int32 *threadCount);
206 extern status_t	set_sem_owner(sem_id id, team_id team);
207 
208 /* system private, use the macros instead */
209 extern status_t	_get_sem_info(sem_id id, struct sem_info *info, size_t infoSize);
210 extern status_t	_get_next_sem_info(team_id team, int32 *cookie, struct sem_info *info,
211 					size_t infoSize);
212 
213 #define get_sem_info(sem, info) \
214 			_get_sem_info((sem), (info), sizeof(*(info)))
215 
216 #define get_next_sem_info(team, cookie, info) \
217 			_get_next_sem_info((team), (cookie), (info), sizeof(*(info)))
218 
219 
220 /*-------------------------------------------------------------*/
221 /* Teams */
222 
223 typedef struct {
224 	team_id			team;
225 	int32			thread_count;
226 	int32			image_count;
227 	int32			area_count;
228 	thread_id		debugger_nub_thread;
229 	port_id			debugger_nub_port;
230 	int32			argc;
231 	char			args[64];
232 	uid_t			uid;
233 	gid_t			gid;
234 } team_info;
235 
236 #define B_CURRENT_TEAM	0
237 #define B_SYSTEM_TEAM	1
238 
239 extern status_t kill_team(team_id team);
240 	/* see also: send_signal() */
241 
242 /* system private, use macros instead */
243 extern status_t _get_team_info(team_id id, team_info *info, size_t size);
244 extern status_t _get_next_team_info(int32 *cookie, team_info *info, size_t size);
245 
246 #define get_team_info(id, info) \
247 			_get_team_info((id), (info), sizeof(*(info)))
248 
249 #define get_next_team_info(cookie, info) \
250 			_get_next_team_info((cookie), (info), sizeof(*(info)))
251 
252 /* team usage info */
253 
254 typedef struct {
255 	bigtime_t		user_time;
256 	bigtime_t		kernel_time;
257 } team_usage_info;
258 
259 enum {
260 	/* compatible to sys/resource.h RUSAGE_SELF and RUSAGE_CHILDREN */
261 	B_TEAM_USAGE_SELF		= 0,
262 	B_TEAM_USAGE_CHILDREN	= -1
263 };
264 
265 /* system private, use macros instead */
266 extern status_t	_get_team_usage_info(team_id team, int32 who, team_usage_info *info, size_t size);
267 
268 #define get_team_usage_info(team, who, info) \
269 			_get_team_usage_info((team), (who), (info), sizeof(*(info)))
270 
271 /*-------------------------------------------------------------*/
272 /* Threads */
273 
274 typedef enum {
275 	B_THREAD_RUNNING	= 1,
276 	B_THREAD_READY,
277 	B_THREAD_RECEIVING,
278 	B_THREAD_ASLEEP,
279 	B_THREAD_SUSPENDED,
280 	B_THREAD_WAITING
281 } thread_state;
282 
283 typedef struct {
284 	thread_id		thread;
285 	team_id			team;
286 	char			name[B_OS_NAME_LENGTH];
287 	thread_state	state;
288 	int32			priority;
289 	sem_id			sem;
290 	bigtime_t		user_time;
291 	bigtime_t		kernel_time;
292 	void			*stack_base;
293 	void			*stack_end;
294 } thread_info;
295 
296 #define B_IDLE_PRIORITY					0
297 #define B_LOWEST_ACTIVE_PRIORITY		1
298 #define B_LOW_PRIORITY					5
299 #define B_NORMAL_PRIORITY				10
300 #define B_DISPLAY_PRIORITY				15
301 #define	B_URGENT_DISPLAY_PRIORITY		20
302 #define	B_REAL_TIME_DISPLAY_PRIORITY	100
303 #define	B_URGENT_PRIORITY				110
304 #define B_REAL_TIME_PRIORITY			120
305 
306 #define B_SYSTEM_TIMEBASE				0
307 
308 #define B_FIRST_REAL_TIME_PRIORITY		B_REAL_TIME_DISPLAY_PRIORITY
309 
310 typedef status_t (*thread_func)(void *);
311 #define thread_entry thread_func
312 	/* thread_entry is for backward compatibility only! Use thread_func */
313 
314 extern thread_id	spawn_thread(thread_func, const char *name, int32 priority, void *data);
315 extern status_t		kill_thread(thread_id thread);
316 extern status_t		resume_thread(thread_id thread);
317 extern status_t		suspend_thread(thread_id thread);
318 
319 extern status_t		rename_thread(thread_id thread, const char *newName);
320 extern status_t		set_thread_priority (thread_id thread, int32 newPriority);
321 extern void			exit_thread(status_t status);
322 extern status_t		wait_for_thread (thread_id thread, status_t *threadReturnValue);
323 extern status_t		on_exit_thread(void (*callback)(void *), void *data);
324 
325 extern thread_id 	find_thread(const char *name);
326 
327 extern status_t		send_data(thread_id thread, int32 code, const void *buffer,
328 						size_t bufferSize);
329 extern int32		receive_data(thread_id *sender, void *buffer, size_t bufferSize);
330 extern bool			has_data(thread_id thread);
331 
332 extern status_t		snooze(bigtime_t amount);
333 extern status_t		snooze_etc(bigtime_t amount, int timeBase, uint32 flags);
334 extern status_t		snooze_until(bigtime_t time, int timeBase);
335 
336 /* system private, use macros instead */
337 extern status_t		_get_thread_info(thread_id id, thread_info *info, size_t size);
338 extern status_t		_get_next_thread_info(team_id team, int32 *cookie,
339 						thread_info *info, size_t size);
340 
341 #define get_thread_info(id, info) \
342 			_get_thread_info((id), (info), sizeof(*(info)))
343 
344 #define get_next_thread_info(team, cookie, info) \
345 			_get_next_thread_info((team), (cookie), (info), sizeof(*(info)))
346 
347 
348 /*-------------------------------------------------------------*/
349 /* Time */
350 
351 extern uint32		real_time_clock(void);
352 extern void			set_real_time_clock(uint32 secs_since_jan1_1970);
353 extern bigtime_t	real_time_clock_usecs(void);
354 extern status_t		set_timezone(char *timezone);
355 extern bigtime_t	system_time(void);     /* time since booting in microseconds */
356 
357 
358 /*-------------------------------------------------------------*/
359 /* Alarm */
360 
361 enum {
362 	B_ONE_SHOT_ABSOLUTE_ALARM	= 1,
363 	B_ONE_SHOT_RELATIVE_ALARM,
364 	B_PERIODIC_ALARM			/* "when" specifies the period */
365 };
366 
367 extern bigtime_t set_alarm(bigtime_t when, uint32 flags);
368 
369 
370 /*-------------------------------------------------------------*/
371 /* Debugger */
372 
373 extern void	debugger(const char *message);
374 
375 /*
376    calling this function with a non-zero value will cause your thread
377    to receive signals for any exceptional conditions that occur (i.e.
378    you'll get SIGSEGV for data access exceptions, SIGFPE for floating
379    point errors, SIGILL for illegal instructions, etc).
380 
381    to re-enable the default debugger pass a zero.
382 */
383 extern int disable_debugger(int state);
384 
385 /* TODO: Remove. Temporary debug helper. */
386 extern void debug_printf(const char *format, ...)
387 	__attribute__ ((format (__printf__, 1, 2)));
388 extern void debug_vprintf(const char *format, va_list args);
389 extern void ktrace_printf(const char *format, ...)
390 	__attribute__ ((format (__printf__, 1, 2)));
391 extern void ktrace_vprintf(const char *format, va_list args);
392 
393 
394 /*-------------------------------------------------------------*/
395 /* System information */
396 
397 #if __INTEL__
398 #	define B_MAX_CPU_COUNT	8
399 #elif __POWERPC__
400 #	define B_MAX_CPU_COUNT	8
401 #elif __M68K__
402 #	define B_MAX_CPU_COUNT	1
403 #elif __ARM__
404 #	define B_MAX_CPU_COUNT	1
405 #elif __MIPSEL__
406 #	define B_MAX_CPU_COUNT	1
407 #else
408 #	warning Unknown cpu
409 #	define B_MAX_CPU_COUNT	1
410 #endif
411 
412 #define OBOS_CPU_TYPES
413 
414 typedef enum cpu_types {
415 	/* ToDo: add latest models */
416 
417 	/* Motorola/IBM */
418 	B_CPU_PPC_UNKNOWN					= 0,
419 	B_CPU_PPC_601						= 1,
420 	B_CPU_PPC_602						= 7,
421 	B_CPU_PPC_603						= 2,
422 	B_CPU_PPC_603e						= 3,
423 	B_CPU_PPC_603ev						= 8,
424 	B_CPU_PPC_604						= 4,
425 	B_CPU_PPC_604e						= 5,
426 	B_CPU_PPC_604ev						= 9,
427 	B_CPU_PPC_620						= 10,
428 	B_CPU_PPC_750   					= 6,
429 	B_CPU_PPC_686						= 13,
430 	B_CPU_PPC_860						= 25,
431 	B_CPU_PPC_7400						= 26,
432 	B_CPU_PPC_7410						= 27,
433 	B_CPU_PPC_7447A						= 28,
434 	B_CPU_PPC_7448						= 29,
435 	B_CPU_PPC_7450						= 30,
436 	B_CPU_PPC_7455						= 31,
437 	B_CPU_PPC_7457						= 32,
438 	B_CPU_PPC_8240						= 33,
439 	B_CPU_PPC_8245						= 34,
440 
441 	B_CPU_PPC_IBM_401A1					= 35,
442 	B_CPU_PPC_IBM_401B2					= 36,
443 	B_CPU_PPC_IBM_401C2					= 37,
444 	B_CPU_PPC_IBM_401D2					= 38,
445 	B_CPU_PPC_IBM_401E2					= 39,
446 	B_CPU_PPC_IBM_401F2					= 40,
447 	B_CPU_PPC_IBM_401G2					= 41,
448 	B_CPU_PPC_IBM_403					= 42,
449 	B_CPU_PPC_IBM_405GP					= 43,
450 	B_CPU_PPC_IBM_405L					= 44,
451 	B_CPU_PPC_IBM_750FX					= 45,
452 	B_CPU_PPC_IBM_POWER3				= 46,
453 
454 	/* Intel */
455 
456 	/* Updated according to Intel(R) Processor Identification and
457 	 * the  CPUID instruction (Table 4)
458 	 * AP-485 Intel - 24161832.pdf
459 	 */
460 	B_CPU_INTEL_x86						= 0x1000,
461 	B_CPU_INTEL_PENTIUM					= 0x1051,
462 	B_CPU_INTEL_PENTIUM75,
463 	B_CPU_INTEL_PENTIUM_486_OVERDRIVE,
464 	B_CPU_INTEL_PENTIUM_MMX,
465 	B_CPU_INTEL_PENTIUM_MMX_MODEL_4		= B_CPU_INTEL_PENTIUM_MMX,
466 	B_CPU_INTEL_PENTIUM_MMX_MODEL_8		= 0x1058,
467 	B_CPU_INTEL_PENTIUM75_486_OVERDRIVE,
468 	B_CPU_INTEL_PENTIUM_PRO				= 0x1061,
469 	B_CPU_INTEL_PENTIUM_II				= 0x1063,
470 	B_CPU_INTEL_PENTIUM_II_MODEL_3		= 0x1063,
471 	B_CPU_INTEL_PENTIUM_II_MODEL_5		= 0x1065,
472 	B_CPU_INTEL_CELERON					= 0x1066,
473 	B_CPU_INTEL_CELERON_MODEL_22		= 0x11066,
474 	B_CPU_INTEL_PENTIUM_III				= 0x1067,
475 	B_CPU_INTEL_PENTIUM_III_MODEL_8		= 0x1068,
476 	B_CPU_INTEL_PENTIUM_M				= 0x1069,
477 	B_CPU_INTEL_PENTIUM_III_XEON		= 0x106a,
478 	B_CPU_INTEL_PENTIUM_III_MODEL_11 	= 0x106b,
479 	B_CPU_INTEL_ATOM			= 0x1106c,
480 	B_CPU_INTEL_PENTIUM_M_MODEL_13		= 0x106d, /* Dothan */
481 	B_CPU_INTEL_PENTIUM_CORE,
482 	B_CPU_INTEL_PENTIUM_CORE_2,
483 	B_CPU_INTEL_PENTIUM_CORE_2_EXTREME	= 0x11067, /* Core 2 Extreme or Xeon
484 	                                                   model 23 on 45 nm */
485 	B_CPU_INTEL_PENTIUM_IV				= 0x10f0,
486 	B_CPU_INTEL_PENTIUM_IV_MODEL_1,
487 	B_CPU_INTEL_PENTIUM_IV_MODEL_2,
488 	B_CPU_INTEL_PENTIUM_IV_MODEL_3,
489 	B_CPU_INTEL_PENTIUM_IV_MODEL_4,
490 
491 	/* AMD */
492 
493 	/* Checked with "AMD Processor Recognition Application Note"
494 	 * (Table 3)
495 	 * 20734.pdf
496 	 */
497 	B_CPU_AMD_x86						= 0x1100,
498 	B_CPU_AMD_K5_MODEL_0				= 0x1150,
499 	B_CPU_AMD_K5_MODEL_1,
500 	B_CPU_AMD_K5_MODEL_2,
501 	B_CPU_AMD_K5_MODEL_3,
502 	B_CPU_AMD_K6_MODEL_6				= 0x1156,
503 	B_CPU_AMD_K6_MODEL_7				= 0x1157,
504 	B_CPU_AMD_K6_MODEL_8				= 0x1158,
505 	B_CPU_AMD_K6_2						= 0x1158,
506 	B_CPU_AMD_K6_MODEL_9				= 0x1159,
507 	B_CPU_AMD_K6_III					= 0x1159,
508 	B_CPU_AMD_K6_III_MODEL_13			= 0x115d,
509 
510 	B_CPU_AMD_ATHLON_MODEL_1			= 0x1161,
511 	B_CPU_AMD_ATHLON_MODEL_2			= 0x1162,
512 
513 	B_CPU_AMD_DURON 					= 0x1163,
514 
515 	B_CPU_AMD_ATHLON_THUNDERBIRD		= 0x1164,
516 	B_CPU_AMD_ATHLON_XP 				= 0x1166,
517 	B_CPU_AMD_ATHLON_XP_MODEL_7,
518 	B_CPU_AMD_ATHLON_XP_MODEL_8,
519 	B_CPU_AMD_ATHLON_XP_MODEL_10		= 0x116a, /* Barton */
520 
521 	B_CPU_AMD_SEMPRON_MODEL_8			= B_CPU_AMD_ATHLON_XP_MODEL_8,
522 	B_CPU_AMD_SEMPRON_MODEL_10			= B_CPU_AMD_ATHLON_XP_MODEL_10,
523 
524 	/* According to "Revision Guide for AMD Family 10h
525 	 * Processors" (41322.pdf)
526 	 */
527 	B_CPU_AMD_PHENOM					= 0x11f2,
528 
529 	/* According to "Revision guide for AMD Athlon 64
530 	 * and AMD Opteron Processors" (25759.pdf)
531 	 */
532 	B_CPU_AMD_ATHLON_64_MODEL_3			= 0x11f3,
533 	B_CPU_AMD_ATHLON_64_MODEL_4,
534 	B_CPU_AMD_ATHLON_64_MODEL_5,
535 	B_CPU_AMD_OPTERON					= B_CPU_AMD_ATHLON_64_MODEL_5,
536 	B_CPU_AMD_ATHLON_64_FX				= B_CPU_AMD_ATHLON_64_MODEL_5,
537 	B_CPU_AMD_ATHLON_64_MODEL_7			= 0x11f7,
538 	B_CPU_AMD_ATHLON_64_MODEL_8,
539 	B_CPU_AMD_ATHLON_64_MODEL_11		= 0x11fb,
540 	B_CPU_AMD_ATHLON_64_MODEL_12,
541 	B_CPU_AMD_ATHLON_64_MODEL_14		= 0x11fe,
542 	B_CPU_AMD_ATHLON_64_MODEL_15,
543 
544 	B_CPU_AMD_GEODE_LX					= 0x115a,
545 
546 	/* VIA/Cyrix */
547 	B_CPU_CYRIX_x86						= 0x1200,
548 	B_CPU_VIA_CYRIX_x86					= 0x1200,
549 	B_CPU_CYRIX_GXm						= 0x1254,
550 	B_CPU_CYRIX_6x86MX					= 0x1260,
551 
552 	/* VIA/IDT */
553 	B_CPU_IDT_x86						= 0x1300,
554 	B_CPU_VIA_IDT_x86					= 0x1300,
555 	B_CPU_IDT_WINCHIP_C6				= 0x1354,
556 	B_CPU_IDT_WINCHIP_2					= 0x1358,
557 	B_CPU_IDT_WINCHIP_3,
558 	B_CPU_VIA_C3_SAMUEL					= 0x1366,
559 	B_CPU_VIA_C3_SAMUEL_2				= 0x1367,
560 	B_CPU_VIA_C3_EZRA_T					= 0x1368,
561 	B_CPU_VIA_C3_NEHEMIAH				= 0x1369,
562 	B_CPU_VIA_C7_ESTHER					= 0x136a,
563 	B_CPU_VIA_C7_ESTHER_2				= 0x136d,
564 	B_CPU_VIA_NANO_ISAIAH				= 0x136f,
565 
566 	/* Transmeta */
567 	B_CPU_TRANSMETA_x86					= 0x1600,
568 	B_CPU_TRANSMETA_CRUSOE				= 0x1654,
569 	B_CPU_TRANSMETA_EFFICEON			= 0x16f2,
570 	B_CPU_TRANSMETA_EFFICEON_2			= 0x16f3,
571 
572 	/* Rise */
573 	B_CPU_RISE_x86						= 0x1400,
574 	B_CPU_RISE_mP6						= 0x1450,
575 
576 	/* National Semiconductor */
577 	B_CPU_NATIONAL_x86					= 0x1500,
578 	B_CPU_NATIONAL_GEODE_GX1			= 0x1554,
579 	B_CPU_NATIONAL_GEODE_GX2,
580 
581 	/* For compatibility */
582 	B_CPU_AMD_29K						= 14,
583 	B_CPU_x86,
584 	B_CPU_MC6502,
585 	B_CPU_Z80,
586 	B_CPU_ALPHA,
587 	B_CPU_MIPS,
588 	B_CPU_HPPA,
589 	B_CPU_M68K,
590 	B_CPU_ARM,
591 	B_CPU_SH,
592 	B_CPU_SPARC
593 } cpu_type;
594 
595 #define B_CPU_x86_VENDOR_MASK	0xff00
596 
597 #ifdef __INTEL__
598 typedef union {
599 	struct {
600 		uint32	max_eax;
601 		char	vendor_id[12];
602 	} eax_0;
603 
604 	struct {
605 		uint32	stepping		: 4;
606 		uint32	model			: 4;
607 		uint32	family			: 4;
608 		uint32	type			: 2;
609 		uint32	reserved_0		: 2;
610 		uint32	extended_model	: 4;
611 		uint32	extended_family	: 8;
612 		uint32	reserved_1		: 4;
613 
614 		uint32	brand_index		: 8;
615 		uint32	clflush			: 8;
616 		uint32	logical_cpus	: 8;
617 		uint32	apic_id			: 8;
618 
619 		uint32	features;
620 		uint32	extended_features;
621 	} eax_1;
622 
623 	struct {
624 		uint8	call_num;
625 		uint8	cache_descriptors[15];
626 	} eax_2;
627 
628 	struct {
629 		uint32	reserved[2];
630 		uint32	serial_number_high;
631 		uint32	serial_number_low;
632 	} eax_3;
633 
634 	char		as_chars[16];
635 
636 	struct {
637 		uint32	eax;
638 		uint32	ebx;
639 		uint32	edx;
640 		uint32	ecx;
641 	} regs;
642 } cpuid_info;
643 
644 extern status_t get_cpuid(cpuid_info *info, uint32 eaxRegister, uint32 cpuNum);
645 #endif
646 
647 
648 typedef enum platform_types {
649 	B_BEBOX_PLATFORM = 0,
650 	B_MAC_PLATFORM,
651 	B_AT_CLONE_PLATFORM,
652 	B_ENIAC_PLATFORM,
653 	B_APPLE_II_PLATFORM,
654 	B_CRAY_PLATFORM,
655 	B_LISA_PLATFORM,
656 	B_TI_994A_PLATFORM,
657 	B_TIMEX_SINCLAIR_PLATFORM,
658 	B_ORAC_1_PLATFORM,
659 	B_HAL_PLATFORM,
660 	B_BESM_6_PLATFORM,
661 	B_MK_61_PLATFORM,
662 	B_NINTENDO_64_PLATFORM,
663 	B_AMIGA_PLATFORM,
664 	B_ATARI_PLATFORM
665 } platform_type;
666 
667 typedef struct {
668 	bigtime_t	active_time;	/* usec of doing useful work since boot */
669 } cpu_info;
670 
671 
672 typedef int32 machine_id[2];	/* unique machine ID */
673 
674 typedef struct {
675 	machine_id		id;							/* unique machine ID */
676 	bigtime_t		boot_time;					/* time of boot (usecs since 1/1/1970) */
677 
678 	int32			cpu_count;					/* number of cpus */
679 	enum cpu_types	cpu_type;					/* type of cpu */
680 	int32			cpu_revision;				/* revision # of cpu */
681 	cpu_info		cpu_infos[B_MAX_CPU_COUNT];	/* info about individual cpus */
682 	int64			cpu_clock_speed;	 		/* processor clock speed (Hz) */
683 	int64			bus_clock_speed;			/* bus clock speed (Hz) */
684 	enum platform_types platform_type;          /* type of machine we're on */
685 
686 	int32			max_pages;					/* total # physical pages */
687 	int32			used_pages;					/* # physical pages in use */
688 	int32			page_faults;				/* # of page faults */
689 	int32			max_sems;
690 	int32			used_sems;
691 	int32			max_ports;
692 	int32			used_ports;
693 	int32			max_threads;
694 	int32			used_threads;
695 	int32			max_teams;
696 	int32			used_teams;
697 
698 	char			kernel_name[B_FILE_NAME_LENGTH];		/* name of kernel */
699 	char			kernel_build_date[B_OS_NAME_LENGTH];	/* date kernel built */
700 	char			kernel_build_time[B_OS_NAME_LENGTH];	/* time kernel built */
701 	int64			kernel_version;             			/* version of this kernel */
702 
703 	bigtime_t		_busy_wait_time;			/* reserved for whatever */
704 	int32			cached_pages;
705 
706 	uint32			abi;						/* the system API */
707 
708 	int32			pad[2];   	               	/* just in case... */
709 } system_info;
710 
711 /* system private, use macro instead */
712 extern status_t _get_system_info(system_info *info, size_t size);
713 
714 #define get_system_info(info) \
715 			_get_system_info((info), sizeof(*(info)))
716 
717 extern int32	is_computer_on(void);
718 extern double	is_computer_on_fire(void);
719 
720 
721 /* WARNING: Experimental API! */
722 
723 enum {
724 	B_OBJECT_TYPE_FD		= 0,
725 	B_OBJECT_TYPE_SEMAPHORE	= 1,
726 	B_OBJECT_TYPE_PORT		= 2,
727 	B_OBJECT_TYPE_THREAD	= 3
728 };
729 
730 enum {
731 	B_EVENT_READ				= 0x0001,	/* FD/port readable */
732 	B_EVENT_WRITE				= 0x0002,	/* FD/port writable */
733 	B_EVENT_ERROR				= 0x0004,	/* FD error */
734 	B_EVENT_PRIORITY_READ		= 0x0008,	/* FD priority readable */
735 	B_EVENT_PRIORITY_WRITE		= 0x0010,	/* FD priority writable */
736 	B_EVENT_HIGH_PRIORITY_READ	= 0x0020,	/* FD high priority readable */
737 	B_EVENT_HIGH_PRIORITY_WRITE	= 0x0040,	/* FD high priority writable */
738 	B_EVENT_DISCONNECTED		= 0x0080,	/* FD disconnected */
739 
740 	B_EVENT_ACQUIRE_SEMAPHORE	= 0x0001,	/* semaphore can be acquired */
741 
742 	B_EVENT_INVALID				= 0x1000	/* FD/port/sem/thread ID not or
743 											   no longer valid (e.g. has been
744 											   close/deleted) */
745 };
746 
747 typedef struct object_wait_info {
748 	int32		object;						/* ID of the object */
749 	uint16		type;						/* type of the object */
750 	uint16		events;						/* events mask */
751 } object_wait_info;
752 
753 /* wait_for_objects[_etc]() waits until at least one of the specified events or,
754    if given, the timeout occurred. When entering the function the
755    object_wait_info::events field specifies the events for each object the
756    caller is interested in. When the function returns the fields reflect the
757    events that actually occurred. The events B_EVENT_INVALID, B_EVENT_ERROR,
758    and B_EVENT_DISCONNECTED don't need to be specified. They will always be
759    reported, when they occur. */
760 
761 extern ssize_t 	wait_for_objects(object_wait_info* infos, int numInfos);
762 extern ssize_t 	wait_for_objects_etc(object_wait_info* infos, int numInfos,
763 					uint32 flags, bigtime_t timeout);
764 
765 
766 #ifdef __cplusplus
767 }
768 #endif
769 
770 #endif /* _OS_H */
771