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