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