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