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