beos.inc 16 KB

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