beos.inc 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. {
  2. Copyright (c) 2001 by Carl Eric Codere
  3. Implements BeOS system calls and types
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. const
  18. { BeOS specific calls }
  19. syscall_nr_create_area = $14;
  20. syscall_nr_resize_area = $08;
  21. syscall_nr_delete_area = $15;
  22. syscall_nr_load_image = $34;
  23. syscall_nr_wait_thread = $22;
  24. syscall_nr_rstat = $30;
  25. syscall_nr_statfs = $5F;
  26. syscall_nr_get_team_info = $3b;
  27. syscall_nr_kill_team = $3a;
  28. syscall_nr_get_system_info = $56;
  29. syscall_nr_kget_tzfilename = $AF;
  30. syscall_nr_get_next_image_info = $3C;
  31. const
  32. { -----
  33. system-wide constants;
  34. ----- *}
  35. MAXPATHLEN = PATH_MAX;
  36. B_FILE_NAME_LENGTH = NAME_MAX;
  37. B_OS_NAME_LENGTH = 32;
  38. B_PAGE_SIZE = 4096;
  39. (* -----
  40. types
  41. ----- *)
  42. type area_id = longint;
  43. type port_id = longint;
  44. type sem_id = longint;
  45. type thread_id = longint;
  46. type team_id = longint;
  47. type bigtime_t = int64;
  48. type status_t = longint;
  49. {*************************************************************}
  50. {*********************** KERNEL KIT **************************}
  51. {*************************************************************}
  52. { ------------------------- Areas --------------------------- }
  53. const
  54. { create_area constant definitions }
  55. { lock type }
  56. B_NO_LOCK = 0;
  57. B_LAZY_LOCK = 1;
  58. B_FULL_LOCK = 2;
  59. B_CONTIGUOUS = 3;
  60. B_LOMEM = 4;
  61. { address type }
  62. B_ANY_ADDRESS = 0;
  63. B_EXACT_ADDRESS = 1;
  64. B_BASE_ADDRESS = 2;
  65. B_CLONE_ADDRESS = 3;
  66. B_ANY_KERNEL_ADDRESS = 4;
  67. { protection bits }
  68. B_READ_AREA = 1;
  69. B_WRITE_AREA = 2;
  70. type
  71. area_info = packed record
  72. area: area_id;
  73. name: array[0..B_OS_NAME_LENGTH-1] of char;
  74. size: size_t;
  75. lock: cardinal;
  76. protection: cardinal;
  77. team: team_id;
  78. ram_size: cardinal;
  79. copy_count: cardinal;
  80. in_count: cardinal;
  81. out_count: cardinal;
  82. address: pointer;
  83. end;
  84. function create_area(name : pchar; var addr : longint;
  85. addr_typ : longint; size : longint; lock_type: longint; protection : longint): area_id;
  86. var
  87. args : SysCallArgs;
  88. begin
  89. args.param[1] := cint(name);
  90. args.param[2] := cint(@addr);
  91. args.param[3] := cint(addr_typ);
  92. args.param[4] := cint(size);
  93. args.param[5] := cint(lock_type);
  94. args.param[6] := cint(protection);
  95. create_area := SysCall(syscall_nr_create_area, args);
  96. end;
  97. function delete_area(area : area_id): status_t;
  98. var
  99. args: SysCallargs;
  100. begin
  101. args.param[1] := cint(area);
  102. delete_area:= SysCall(syscall_nr_delete_area, args);
  103. end;
  104. function resize_area(area: area_id; new_size: size_t): status_t;
  105. var
  106. args: SysCallArgs;
  107. begin
  108. args.param[1] := cint(area);
  109. args.param[2] := cint(new_size);
  110. resize_area := SysCall(syscall_nr_resize_area, args);
  111. end;
  112. { the buffer should at least have MAXPATHLEN+1 bytes in size }
  113. function kget_tzfilename(buffer:pchar): cint;
  114. var
  115. args: SysCallArgs;
  116. begin
  117. args.param[1] := cint(buffer);
  118. kget_tzfilename := SysCall(syscall_nr_kget_tzfilename,args);
  119. end;
  120. (*
  121. extern _IMPEXP_ROOT area_id clone_area(const char *name, void **dest_addr,
  122. uint32 addr_spec, uint32 protection,
  123. area_id source);
  124. extern _IMPEXP_ROOT area_id find_area(const char *name);
  125. extern _IMPEXP_ROOT area_id area_for(void *addr);
  126. extern _IMPEXP_ROOT status_t set_area_protection(area_id id,
  127. uint32 new_protection);
  128. extern _IMPEXP_ROOT status_t _get_area_info(area_id id, area_info *ainfo,
  129. size_t size);
  130. extern _IMPEXP_ROOT status_t _get_next_area_info(team_id team, int32 *cookie,
  131. area_info *ainfo, size_t size);
  132. *)
  133. { ------------------------- Threads --------------------------- }
  134. const
  135. { thread state }
  136. B_THREAD_RUNNING = 1;
  137. B_THREAD_READY = 2;
  138. B_THREAD_RECEIVING = 3;
  139. B_THREAD_ASLEEP = 4;
  140. B_THREAD_SUSPENDED = 5;
  141. B_THREAD_WAITING = 6;
  142. { thread priorities }
  143. B_LOW_PRIORITY = 5;
  144. B_NORMAL_PRIORITY = 10;
  145. B_DISPLAY_PRIORITY = 15;
  146. B_URGENT_DISPLAY_PRIORITY = 20;
  147. B_REAL_TIME_DISPLAY_PRIORITY= 100;
  148. B_URGENT_PRIORITY = 110;
  149. B_REAL_TIME_PRIORITY = 120;
  150. type
  151. thread_info = packed record
  152. thread: thread_id;
  153. team: team_id;
  154. name: array[0..B_OS_NAME_LENGTH-1] of char;
  155. state: longint; { thread_state enum }
  156. priority:longint;
  157. sem:sem_id;
  158. user_time:bigtime_t;
  159. kernel_time:bigtime_t;
  160. stack_base:pointer;
  161. stack_end:pointer;
  162. end;
  163. {
  164. extern _IMPEXP_ROOT thread_id spawn_thread (
  165. thread_func function_name,
  166. const char *thread_name,
  167. int32 priority,
  168. void *arg
  169. );
  170. extern _IMPEXP_ROOT thread_id find_thread(const char *name);
  171. extern _IMPEXP_ROOT status_t kill_thread(thread_id thread);
  172. extern _IMPEXP_ROOT status_t resume_thread(thread_id thread);
  173. extern _IMPEXP_ROOT status_t suspend_thread(thread_id thread);
  174. extern _IMPEXP_ROOT status_t rename_thread(thread_id thread, const char *new_name);
  175. extern _IMPEXP_ROOT status_t set_thread_priority (thread_id thread, int32 new_priority);
  176. extern _IMPEXP_ROOT void exit_thread(status_t status);
  177. extern _IMPEXP_ROOT status_t _get_thread_info(thread_id thread, thread_info *info, size_t size);
  178. extern _IMPEXP_ROOT status_t _get_next_thread_info(team_id tmid, int32 *cookie, thread_info *info, size_t size);
  179. extern _IMPEXP_ROOT status_t send_data(thread_id thread,
  180. int32 code,
  181. const void *buf,
  182. size_t buffer_size);
  183. extern _IMPEXP_ROOT status_t receive_data(thread_id *sender,
  184. void *buf,
  185. size_t buffer_size);
  186. extern _IMPEXP_ROOT bool has_data(thread_id thread);
  187. extern _IMPEXP_ROOT status_t snooze(bigtime_t microseconds);
  188. /*
  189. Right now you can only snooze_until() on a single time base, the
  190. system time base given by system_time(). The "time" argument is
  191. the time (in the future) relative to the current system_time() that
  192. you want to snooze until. Eventually there will be multiple time
  193. bases (and a way to find out which ones exist) but for now just pass
  194. the value B_SYSTEM_TIMEBASE.
  195. */
  196. extern _IMPEXP_ROOT status_t snooze_until(bigtime_t time, int timebase);
  197. #define B_SYSTEM_TIMEBASE (0)
  198. }
  199. function wait_for_thread(thread: thread_id; var status : status_t): status_t;
  200. var
  201. args: SysCallArgs;
  202. i: longint;
  203. begin
  204. args.param[1] := cint(thread);
  205. args.param[2] := cint(@status);
  206. wait_for_thread := SysCall(syscall_nr_wait_thread, args);
  207. end;
  208. { ------------------------- Teams --------------------------- }
  209. const
  210. B_SYSTEM_TEAM = 2;
  211. type
  212. team_info = packed record
  213. team: team_id;
  214. image_count: longint;
  215. thread_count: longint;
  216. area_count: longint;
  217. debugger_nub_thread: thread_id;
  218. debugger_nub_port: port_id;
  219. argc:longint; (* number of args on the command line *)
  220. args: array[0..63] of char; {* abbreviated command line args *}
  221. uid: uid_t;
  222. gid: gid_t;
  223. end;
  224. {
  225. extern _IMPEXP_ROOT status_t _get_next_team_info(int32 *cookie, team_info *info, size_t size);
  226. }
  227. function get_team_info(team: team_id; var info : team_info): status_t;
  228. var
  229. args: SysCallArgs;
  230. begin
  231. args.param[1] := cint(team);
  232. args.param[2] := cint(@info);
  233. get_team_info := SysCall(syscall_nr_get_team_info, args);
  234. end;
  235. function kill_team(team: team_id): status_t;
  236. var
  237. args: SysCallArgs;
  238. begin
  239. args.param[1] := cint(team);
  240. kill_team := SysCall(syscall_nr_kill_team, args);
  241. end;
  242. { ------------------------- Images --------------------------- }
  243. type image_id = longint;
  244. { image types }
  245. const
  246. B_APP_IMAGE = 1;
  247. B_LIBRARY_IMAGE = 2;
  248. B_ADD_ON_IMAGE = 3;
  249. B_SYSTEM_IMAGE = 4;
  250. type
  251. image_info = packed record
  252. id : image_id;
  253. _type : longint;
  254. sequence: longint;
  255. init_order: longint;
  256. init_routine: pointer;
  257. term_routine: pointer;
  258. device: dev_t;
  259. node: ino_t;
  260. name: array[0..MAXPATHLEN-1] of char;
  261. text: pointer;
  262. data: pointer;
  263. text_size: longint;
  264. data_size: longint;
  265. end;
  266. function get_next_image_info(team : team_id; var cookie: longint;var info : image_info): status_t;
  267. var
  268. args: SysCallArgs;
  269. begin
  270. args.param[1] := cint(team);
  271. args.param[2] := cint(@cookie);
  272. args.param[3] := cint(@info);
  273. args.param[4] := cint(sizeof(image_info));
  274. get_next_image_info := SysCall(syscall_nr_get_next_image_info, args);
  275. end;
  276. {
  277. extern _IMPEXP_ROOT image_id load_add_on(const char *path);
  278. extern _IMPEXP_ROOT status_t unload_add_on(image_id imid);
  279. /* private; use the macros, below */
  280. extern _IMPEXP_ROOT status_t _get_image_info (image_id image,
  281. image_info *info, size_t size);
  282. extern _IMPEXP_ROOT status_t _get_next_image_info (team_id team, int32 *cookie,
  283. image_info *info, size_t size);
  284. }
  285. (*----- symbol types and functions ------------------------*)
  286. const B_SYMBOL_TYPE_DATA = $1;
  287. const B_SYMBOL_TYPE_TEXT = $2;
  288. const B_SYMBOL_TYPE_ANY = $5;
  289. {
  290. extern _IMPEXP_ROOT status_t get_image_symbol(image_id imid,
  291. const char *name, int32 sclass, void **ptr);
  292. extern _IMPEXP_ROOT status_t get_nth_image_symbol(image_id imid, int32 index,
  293. char *buf, int32 *bufsize, int32 *sclass,
  294. void **ptr);
  295. }
  296. {*----- cache manipulation --------------------------------*}
  297. const
  298. B_FLUSH_DCACHE =$0001; {* dcache = data cache *}
  299. B_FLUSH_ICACHE =$0004; {* icache = instruction cache *}
  300. B_INVALIDATE_DCACHE =$0002;
  301. B_INVALIDATE_ICACHE =$0008;
  302. {
  303. extern _IMPEXP_ROOT void clear_caches(void *addr, size_t len, uint32 flags);
  304. }
  305. function load_image(argc : longint; argv : ppchar; envp : ppchar): thread_id;
  306. var
  307. args: SysCallArgs;
  308. i: longint;
  309. begin
  310. args.param[1] := cint(argc);
  311. args.param[2] := cint(argv);
  312. args.param[3] := cint(envp);
  313. load_image := SysCall(syscall_nr_load_image, args);
  314. end;
  315. { ------------------------ System information --------------------------- }
  316. { for both intel and ppc platforms }
  317. const B_MAX_CPU_COUNT = 8;
  318. type
  319. system_info = packed record
  320. id: array[0..1] of longint; {* unique machine ID *}
  321. boot_time: bigtime_t; {* time of boot (# usec since 1/1/70) *}
  322. cpu_count: longint; {* # of cpus *}
  323. cpu_type: longint; {* type of cpu *}
  324. cpu_revision:longint ; {* revision # of cpu *}
  325. cpu_infos: array [0..B_MAX_CPU_COUNT-1] of bigtime_t; {* info about individual cpus *}
  326. cpu_clock_speed:int64; {* processor clock speed (Hz) *}
  327. bus_clock_speed:int64; {* bus clock speed (Hz) * }
  328. platform_type:longint; {* type of machine we're on *}
  329. max_pages:longint; {* total # physical pages *}
  330. used_pages:longint; {* # physical pages in use *}
  331. page_faults:longint; {* # of page faults *}
  332. max_sems:longint; {* maximum # semaphores *}
  333. used_sems:longint; {* # semaphores in use *}
  334. max_ports:longint; {* maximum # ports *}
  335. used_ports:longint; {* # ports in use *}
  336. max_threads:longint; {* maximum # threads *}
  337. used_threads:longint; {* # threads in use *}
  338. max_teams:longint; {* maximum # teams *}
  339. used_teams:longint; {* # teams in use *}
  340. kernel_name: array[0..B_FILE_NAME_LENGTH-1] of char; {* name of kernel *}
  341. kernel_build_date: array[0..B_OS_NAME_LENGTH-1] of char; {* date kernel built *}
  342. kernel_build_time: array[0..B_OS_NAME_LENGTH-1] of char; {* time kernel built *}
  343. kernel_version:int64; {* version of this kernel *}
  344. _busy_wait_time:bigtime_t; {* reserved for Be *}
  345. pad:array[1..4] of longint; {* just in case... *}
  346. end;
  347. function get_system_info(var info: system_info): status_t;
  348. var
  349. args: SysCallArgs;
  350. i: longint;
  351. begin
  352. args.param[1] := cint(@info);
  353. i := SysCall(syscall_nr_get_system_info, args);
  354. get_system_info := i;
  355. end;
  356. {*************************************************************}
  357. {*********************** STORAGE KIT *************************}
  358. {*************************************************************}
  359. const
  360. { file system flags }
  361. B_FS_IS_READONLY = $00000001;
  362. B_FS_IS_REMOVABLE = $00000002;
  363. B_FS_IS_PERSISTENT = $00000004;
  364. B_FS_IS_SHARED = $00000008;
  365. B_FS_HAS_MIME = $00010000;
  366. B_FS_HAS_ATTR = $00020000;
  367. B_FS_HAS_QUERY = $00040000;
  368. type
  369. fs_info = packed record
  370. dev : dev_t; { fs dev_t }
  371. root : ino_t; { root ino_t }
  372. flags : cardinal; { file system flags }
  373. block_size:off_t; { fundamental block size }
  374. io_size:off_t; { optimal io size }
  375. total_blocks:off_t; { total number of blocks }
  376. free_blocks:off_t; { number of free blocks }
  377. total_nodes:off_t; { total number of nodes }
  378. free_nodes:off_t; { number of free nodes }
  379. device_name: array[0..127] of char; { device holding fs }
  380. volume_name: array[0..B_FILE_NAME_LENGTH-1] of char;{ volume name }
  381. fsh_name : array[0..B_OS_NAME_LENGTH-1] of char;{ name of fs handler }
  382. end;
  383. function dev_for_path(const pathname : pchar): dev_t;
  384. var
  385. args: SysCallArgs;
  386. buffer: array[1..15] of longint;
  387. i: cint;
  388. begin
  389. args.param[1] := $FFFFFFFF;
  390. args.param[2] := cint(pathname);
  391. args.param[3] := cint(@buffer);
  392. args.param[4] := $01000000;
  393. if SysCall(syscall_nr_rstat, args)=0 then
  394. i:=buffer[1]
  395. else
  396. i:=-1;
  397. dev_for_path := i;
  398. end;
  399. function fs_stat_dev(device: dev_t; var info: fs_info): dev_t;
  400. var
  401. args: SysCallArgs;
  402. begin
  403. args.param[1] := cint(device);
  404. args.param[2] := 0;
  405. args.param[3] := $FFFFFFFF;
  406. args.param[4] := 0;
  407. args.param[5] := cint(@info);
  408. fs_stat_dev := SysCall(syscall_nr_statfs, args);
  409. end;
  410. {
  411. _IMPEXP_ROOT dev_t next_dev(int32 *pos);
  412. }
  413. {*****************************************************************}