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