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