cpupi.pas 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. {
  2. Copyright (c) 2002 by Florian Klaempfl
  3. This unit contains the CPU specific part of tprocinfo
  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 cpupi;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. procinfo,
  22. psub,
  23. aasmdata,aasmbase;
  24. type
  25. tcpuprocinfo=class(tcgprocinfo)
  26. private
  27. scopes: TAsmList;
  28. scopecount: longint;
  29. unwindflags: byte;
  30. public
  31. constructor create(aparent: tprocinfo); override;
  32. destructor destroy; override;
  33. procedure set_first_temp_offset; override;
  34. procedure add_finally_scope(startlabel,endlabel,handler:TAsmSymbol;implicit:Boolean);
  35. procedure add_except_scope(trylabel,exceptlabel,endlabel,filter:TAsmSymbol);
  36. procedure dump_scopes(list:tasmlist);
  37. end;
  38. implementation
  39. uses
  40. cutils,
  41. fmodule,
  42. symtable,
  43. tgobj,
  44. cpubase,
  45. aasmtai;
  46. const
  47. SCOPE_FINALLY=0;
  48. SCOPE_CATCHALL=1;
  49. SCOPE_IMPLICIT=2;
  50. constructor tcpuprocinfo.create(aparent: tprocinfo);
  51. begin
  52. inherited;
  53. { use the stack pointer as framepointer, because
  54. 1) we exactly know the offsets of the temps from the stack pointer
  55. after pass 1 (based on the require parameter stack size for called
  56. routines), while we don't know it for the frame pointer (it depends
  57. on the number of saved registers)
  58. 2) temp offsets from the stack pointer are positive while those from
  59. the frame pointer are negative, and we can directly encode much
  60. bigger positive offsets in the instructions
  61. }
  62. framepointer:=NR_STACK_POINTER_REG;
  63. end;
  64. destructor tcpuprocinfo.destroy;
  65. begin
  66. scopes.free;
  67. inherited destroy;
  68. end;
  69. procedure tcpuprocinfo.set_first_temp_offset;
  70. begin
  71. { leave room for allocated parameters }
  72. tg.setfirsttemp(align(maxpushedparasize,16));
  73. end;
  74. procedure tcpuprocinfo.add_finally_scope(startlabel,endlabel,handler:TAsmSymbol;implicit:Boolean);
  75. begin
  76. unwindflags:=unwindflags or 2;
  77. if implicit then { also needs catch functionality }
  78. unwindflags:=unwindflags or 1;
  79. inc(scopecount);
  80. if scopes=nil then
  81. scopes:=TAsmList.Create;
  82. if implicit then
  83. scopes.concat(tai_const.create_32bit(SCOPE_IMPLICIT))
  84. else
  85. scopes.concat(tai_const.create_32bit(SCOPE_FINALLY));
  86. scopes.concat(tai_const.create_rva_sym(startlabel));
  87. scopes.concat(tai_const.create_rva_sym(endlabel));
  88. scopes.concat(tai_const.create_rva_sym(handler));
  89. end;
  90. procedure tcpuprocinfo.add_except_scope(trylabel,exceptlabel,endlabel,filter:TAsmSymbol);
  91. begin
  92. unwindflags:=unwindflags or 3;
  93. inc(scopecount);
  94. if scopes=nil then
  95. scopes:=TAsmList.Create;
  96. if Assigned(filter) then
  97. scopes.concat(tai_const.create_rva_sym(filter))
  98. else
  99. scopes.concat(tai_const.create_32bit(SCOPE_CATCHALL));
  100. scopes.concat(tai_const.create_rva_sym(trylabel));
  101. scopes.concat(tai_const.create_rva_sym(exceptlabel));
  102. scopes.concat(tai_const.create_rva_sym(endlabel));
  103. end;
  104. procedure tcpuprocinfo.dump_scopes(list: tasmlist);
  105. var
  106. hdir: tai_seh_directive;
  107. begin
  108. if (scopecount=0) then
  109. exit;
  110. hdir:=cai_seh_directive.create_name(ash_handler,'__FPC_specific_handler');
  111. if not systemunit.iscurrentunit then
  112. current_module.add_extern_asmsym('__FPC_specific_handler',AB_EXTERNAL,AT_FUNCTION);
  113. hdir.data.flags:=unwindflags;
  114. list.concat(hdir);
  115. list.concat(cai_seh_directive.create(ash_handlerdata));
  116. inc(list.section_count);
  117. list.concat(tai_const.create_32bit(scopecount));
  118. list.concatlist(scopes);
  119. { return to text, required for GAS compatibility }
  120. { This creates a tai_align which is redundant here (although harmless) }
  121. new_section(list,sec_code,lower(procdef.mangledname),0);
  122. end;
  123. begin
  124. cprocinfo:=tcpuprocinfo;
  125. end.