syscinfo.pas 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. {
  2. Copyright (c) 2016 by Karoly Balogh
  3. Contains information on syscalls
  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. unit syscinfo;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype, systems, tokens, symconst;
  22. type
  23. tsyscallinfo = record
  24. token: ttoken;
  25. procoption: tprocoption;
  26. validon: set of tsystem;
  27. end;
  28. psyscallinfo = ^tsyscallinfo;
  29. const
  30. syscall_conventions: array[1..7] of tsyscallinfo = (
  31. ( token: _LEGACY; procoption: po_syscall_legacy; validon: [system_powerpc_morphos,system_m68k_amiga] ),
  32. ( token: _SYSV; procoption: po_syscall_sysv; validon: [system_powerpc_morphos] ),
  33. ( token: _SYSVBASE; procoption: po_syscall_sysvbase; validon: [system_powerpc_morphos] ),
  34. ( token: _BASESYSV; procoption: po_syscall_basesysv; validon: [system_powerpc_morphos,system_powerpc_amiga] ),
  35. ( token: _R12BASE; procoption: po_syscall_r12base; validon: [system_powerpc_morphos] ),
  36. ( token: _STACKBASE; procoption: po_syscall_stackbase; validon: [system_i386_aros,system_x86_64_aros] ),
  37. ( token: _EAXBASE; procoption: po_syscall_eaxbase; validon: [system_i386_aros,system_x86_64_aros] ));
  38. function get_syscall_by_token(const token: ttoken): psyscallinfo;
  39. function get_syscall_by_name(const name: string): psyscallinfo;
  40. function get_default_syscall: tprocoption;
  41. procedure set_default_syscall(sc: tprocoption);
  42. implementation
  43. uses
  44. verbose;
  45. const
  46. syscall_conventions_po = [ po_syscall_legacy, po_syscall_sysv, po_syscall_sysvbase, po_syscall_basesysv,
  47. po_syscall_r12base, po_syscall_stackbase, po_syscall_eaxbase ];
  48. type
  49. tsyscalldefaultinfo = record
  50. system: tsystem;
  51. procoption: tprocoption;
  52. end;
  53. const
  54. default_syscall_conventions: array[0..4] of tsyscalldefaultinfo = (
  55. ( system: system_m68k_amiga; procoption: po_syscall_legacy ),
  56. ( system: system_powerpc_amiga; procoption: po_syscall_basesysv ),
  57. ( system: system_powerpc_morphos; procoption: po_syscall_legacy ),
  58. ( system: system_i386_aros; procoption: po_syscall_stackbase ),
  59. ( system: system_x86_64_aros; procoption: po_syscall_stackbase ));
  60. var
  61. default_syscall_convention: tprocoption = po_none;
  62. function get_syscall_by_token(const token: ttoken): psyscallinfo;
  63. var
  64. i: longint;
  65. begin
  66. result:=nil;
  67. for i:=low(syscall_conventions) to high(syscall_conventions) do
  68. if syscall_conventions[i].token = token then
  69. begin
  70. result:=@syscall_conventions[i];
  71. break;
  72. end;
  73. end;
  74. function get_syscall_by_name(const name: string): psyscallinfo;
  75. var
  76. i: longint;
  77. begin
  78. result:=nil;
  79. for i:=low(syscall_conventions) to high(syscall_conventions) do
  80. if arraytokeninfo[syscall_conventions[i].token].str = name then
  81. begin
  82. result:=@syscall_conventions[i];
  83. break;
  84. end;
  85. end;
  86. function get_default_syscall: tprocoption;
  87. var
  88. i: longint;
  89. begin
  90. if not (default_syscall_convention in syscall_conventions_po) then
  91. begin
  92. for i:=low(default_syscall_conventions) to high(default_syscall_conventions) do
  93. if default_syscall_conventions[i].system = target_info.system then
  94. default_syscall_convention:=default_syscall_conventions[i].procoption;
  95. if not (default_syscall_convention in syscall_conventions_po) then
  96. internalerror(2016090302);
  97. end;
  98. result:=default_syscall_convention;
  99. end;
  100. procedure set_default_syscall(sc: tprocoption);
  101. begin
  102. if not (sc in syscall_conventions_po) then
  103. internalerror(2016090301);
  104. default_syscall_convention:=sc;
  105. end;
  106. end.