syscinfo.pas 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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..8] of tsyscallinfo = (
  31. ( token: NOTOKEN; procoption: po_syscall; validon: [system_m68k_atari] ),
  32. ( token: _LEGACY; procoption: po_syscall_legacy; validon: [system_powerpc_morphos,system_m68k_amiga] ),
  33. ( token: _SYSV; procoption: po_syscall_sysv; validon: [system_powerpc_morphos] ),
  34. ( token: _SYSVBASE; procoption: po_syscall_sysvbase; validon: [system_powerpc_morphos] ),
  35. ( token: _BASESYSV; procoption: po_syscall_basesysv; validon: [system_powerpc_morphos,system_powerpc_amiga] ),
  36. ( token: _R12BASE; procoption: po_syscall_r12base; validon: [system_powerpc_morphos] ),
  37. ( token: _STACKBASE; procoption: po_syscall_stackbase; validon: [system_i386_aros,system_x86_64_aros] ),
  38. ( token: _EAXBASE; procoption: po_syscall_eaxbase; validon: [system_i386_aros,system_x86_64_aros] ));
  39. function get_syscall_by_token(const token: ttoken): psyscallinfo;
  40. function get_syscall_by_name(const name: string): psyscallinfo;
  41. function get_default_syscall: tprocoption;
  42. procedure set_default_syscall(sc: tprocoption);
  43. implementation
  44. uses
  45. verbose;
  46. const
  47. syscall_conventions_po = [ po_syscall, po_syscall_legacy, po_syscall_sysv,
  48. po_syscall_sysvbase, po_syscall_basesysv, po_syscall_r12base,
  49. po_syscall_stackbase, po_syscall_eaxbase ];
  50. type
  51. tsyscalldefaultinfo = record
  52. system: tsystem;
  53. procoption: tprocoption;
  54. end;
  55. const
  56. default_syscall_conventions: array[0..5] of tsyscalldefaultinfo = (
  57. ( system: system_m68k_atari; procoption: po_syscall ),
  58. ( system: system_m68k_amiga; procoption: po_syscall_legacy ),
  59. ( system: system_powerpc_amiga; procoption: po_syscall_basesysv ),
  60. ( system: system_powerpc_morphos; procoption: po_syscall_legacy ),
  61. ( system: system_i386_aros; procoption: po_syscall_stackbase ),
  62. ( system: system_x86_64_aros; procoption: po_syscall_stackbase ));
  63. var
  64. default_syscall_convention: tprocoption = po_none;
  65. function get_syscall_by_token(const token: ttoken): psyscallinfo;
  66. var
  67. i: longint;
  68. begin
  69. result:=nil;
  70. for i:=low(syscall_conventions) to high(syscall_conventions) do
  71. if syscall_conventions[i].token = token then
  72. begin
  73. result:=@syscall_conventions[i];
  74. break;
  75. end;
  76. end;
  77. function get_syscall_by_name(const name: string): psyscallinfo;
  78. var
  79. i: longint;
  80. begin
  81. result:=nil;
  82. for i:=low(syscall_conventions) to high(syscall_conventions) do
  83. if arraytokeninfo[syscall_conventions[i].token].str = name then
  84. begin
  85. result:=@syscall_conventions[i];
  86. break;
  87. end;
  88. end;
  89. function get_default_syscall: tprocoption;
  90. var
  91. i: longint;
  92. begin
  93. if not (default_syscall_convention in syscall_conventions_po) then
  94. begin
  95. for i:=low(default_syscall_conventions) to high(default_syscall_conventions) do
  96. if default_syscall_conventions[i].system = target_info.system then
  97. default_syscall_convention:=default_syscall_conventions[i].procoption;
  98. if not (default_syscall_convention in syscall_conventions_po) then
  99. internalerror(2016090302);
  100. end;
  101. result:=default_syscall_convention;
  102. end;
  103. procedure set_default_syscall(sc: tprocoption);
  104. begin
  105. if not (sc in syscall_conventions_po) then
  106. internalerror(2016090301);
  107. default_syscall_convention:=sc;
  108. end;
  109. end.