og386.pas 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. {
  2. $Id$
  3. Copyright (c) 1999 by Florian Klaempfl
  4. Contains the base stuff for 386 binary object file writers
  5. * This code was inspired by the NASM sources
  6. The Netwide Assembler is copyright (C) 1996 Simon Tatham and
  7. Julian Hall. All rights reserved.
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. ****************************************************************************
  20. }
  21. unit og386;
  22. interface
  23. uses
  24. dos,
  25. owbase,owar,
  26. systems,i386base,aasm;
  27. type
  28. tsecsize = array[tsection] of longint;
  29. relative_type = (relative_false,relative_true,relative_rva);
  30. pobjectalloc = ^tobjectalloc;
  31. tobjectalloc = object
  32. currsec : tsection;
  33. secsize : tsecsize;
  34. constructor init;
  35. destructor done;
  36. procedure setsection(sec:tsection);
  37. function sectionsize:longint;
  38. procedure sectionalloc(l:longint);
  39. procedure resetsections;
  40. end;
  41. pobjectoutput = ^tobjectoutput;
  42. tobjectoutput = object
  43. writer : pobjectwriter;
  44. path : pathstr;
  45. ObjFile : string;
  46. IsEndFile : boolean; { special 'end' file for import dir ? }
  47. currsec : tsection;
  48. constructor init;
  49. destructor done;virtual;
  50. { Writing }
  51. procedure NextSmartName;
  52. procedure initwriting;virtual;
  53. procedure donewriting;virtual;
  54. procedure writebytes(var data;len:longint);virtual;
  55. procedure writealloc(len:longint);virtual;
  56. procedure writereloc(data,len:longint;p:pasmsymbol;relative:relative_type);virtual;
  57. procedure writesymbol(p:pasmsymbol);virtual;
  58. procedure writestabs(section:tsection;offset:longint;p:pchar;nidx,nother,line:longint;reloc:boolean);virtual;
  59. procedure defaultsection(sec:tsection);
  60. end;
  61. var
  62. objectalloc : pobjectalloc;
  63. objectoutput : pobjectoutput;
  64. implementation
  65. uses
  66. globtype,globals,verbose,files,
  67. assemble;
  68. {****************************************************************************
  69. tobjectoutput
  70. ****************************************************************************}
  71. constructor tobjectalloc.init;
  72. begin
  73. end;
  74. destructor tobjectalloc.done;
  75. begin
  76. end;
  77. procedure tobjectalloc.setsection(sec:tsection);
  78. begin
  79. currsec:=sec;
  80. end;
  81. procedure tobjectalloc.resetsections;
  82. begin
  83. FillChar(secsize,sizeof(secsize),0);
  84. end;
  85. procedure tobjectalloc.sectionalloc(l:longint);
  86. begin
  87. inc(secsize[currsec],l);
  88. end;
  89. function tobjectalloc.sectionsize:longint;
  90. begin
  91. sectionsize:=secsize[currsec];
  92. end;
  93. {****************************************************************************
  94. tobjectoutput
  95. ****************************************************************************}
  96. constructor tobjectoutput.init;
  97. var
  98. i : longint;
  99. begin
  100. objfile:=current_module^.objfilename^;
  101. { Which path will be used ? }
  102. if (cs_smartlink in aktmoduleswitches) and
  103. (cs_asm_leave in aktglobalswitches) then
  104. begin
  105. path:=current_module^.path^+FixFileName(current_module^.modulename^)+target_info.smartext;
  106. {$I-}
  107. mkdir(path);
  108. {$I+}
  109. i:=ioresult;
  110. path:=FixPath(path,false);
  111. end
  112. else
  113. path:=current_module^.path^;
  114. { init writer }
  115. if (cs_smartlink in aktmoduleswitches) and
  116. not(cs_asm_leave in aktglobalswitches) then
  117. writer:=New(parobjectwriter,Init(current_module^.staticlibfilename^))
  118. else
  119. writer:=New(pobjectwriter,Init);
  120. end;
  121. destructor tobjectoutput.done;
  122. begin
  123. Dispose(writer,done);
  124. end;
  125. procedure tobjectoutput.NextSmartName;
  126. var
  127. s : string;
  128. begin
  129. inc(SmartLinkFilesCnt);
  130. if SmartLinkFilesCnt>999999 then
  131. Message(assem_f_too_many_asm_files);
  132. if (cs_asm_leave in aktglobalswitches) then
  133. begin
  134. if IsEndFile then
  135. begin
  136. s:=current_module^.asmprefix^+'e';
  137. IsEndFile:=false;
  138. end
  139. else
  140. s:=current_module^.asmprefix^;
  141. ObjFile:=Path+FixFileName(s+tostr(SmartLinkFilesCnt)+target_info.objext)
  142. end
  143. else
  144. begin
  145. if IsEndFile then
  146. begin
  147. s:=current_module^.modulename^+'_e';
  148. IsEndFile:=false;
  149. end
  150. else
  151. s:=current_module^.modulename^+'_';
  152. ObjFile:=FixFileName(s+tostr(SmartLinkFilesCnt)+target_info.objext);
  153. end;
  154. end;
  155. procedure tobjectoutput.initwriting;
  156. begin
  157. if (cs_smartlink in aktmoduleswitches) then
  158. NextSmartName;
  159. writer^.create(objfile);
  160. end;
  161. procedure tobjectoutput.donewriting;
  162. begin
  163. writer^.close;
  164. end;
  165. procedure tobjectoutput.defaultsection(sec:tsection);
  166. begin
  167. currsec:=sec;
  168. end;
  169. procedure tobjectoutput.writesymbol(p:pasmsymbol);
  170. begin
  171. RunError(211);
  172. end;
  173. procedure tobjectoutput.writereloc(data,len:longint;p:pasmsymbol;relative:relative_type);
  174. begin
  175. RunError(211);
  176. end;
  177. procedure tobjectoutput.writebytes(var data;len:longint);
  178. begin
  179. RunError(211);
  180. end;
  181. procedure tobjectoutput.writealloc(len:longint);
  182. begin
  183. RunError(211);
  184. end;
  185. procedure tobjectoutput.writestabs(section:tsection;offset:longint;p:pchar;nidx,nother,line:longint;reloc:boolean);
  186. begin
  187. RunError(211);
  188. end;
  189. end.
  190. {
  191. $Log$
  192. Revision 1.2 1999-05-02 22:41:54 peter
  193. * moved section names to systems
  194. * fixed nasm,intel writer
  195. Revision 1.1 1999/05/01 13:24:23 peter
  196. * merged nasm compiler
  197. * old asm moved to oldasm/
  198. Revision 1.8 1999/03/18 20:30:48 peter
  199. + .a writer
  200. Revision 1.7 1999/03/10 13:41:09 pierre
  201. + partial implementation for win32 !
  202. winhello works but pp still does not !
  203. Revision 1.6 1999/03/08 14:51:08 peter
  204. + smartlinking for ag386bin
  205. Revision 1.5 1999/03/05 13:09:51 peter
  206. * first things for tai_cut support for ag386bin
  207. Revision 1.4 1999/03/03 01:36:45 pierre
  208. + stabs output working (though not really tested)
  209. for a simple file the only difference to GAS output is due
  210. to the VMA of the different sections
  211. Revision 1.3 1999/03/02 02:56:26 peter
  212. + stabs support for binary writers
  213. * more fixes and missing updates from the previous commit :(
  214. Revision 1.2 1999/02/25 21:03:09 peter
  215. * ag386bin updates
  216. + coff writer
  217. Revision 1.1 1999/02/16 17:59:39 peter
  218. + initial files
  219. }