og386.pas 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. {$ifdef Delphi}
  25. dmisc,
  26. {$endif Delphi}
  27. dos,
  28. owbase,owar,
  29. systems,i386base,aasm;
  30. type
  31. tsecsize = array[tsection] of longint;
  32. relative_type = (relative_false,relative_true,relative_rva);
  33. pobjectalloc = ^tobjectalloc;
  34. tobjectalloc = object
  35. currsec : tsection;
  36. secsize : tsecsize;
  37. constructor init;
  38. destructor done;
  39. procedure setsection(sec:tsection);
  40. function sectionsize:longint;
  41. procedure sectionalloc(l:longint);
  42. procedure staballoc(p:pchar);
  43. procedure resetsections;
  44. end;
  45. pobjectoutput = ^tobjectoutput;
  46. tobjectoutput = object
  47. writer : pobjectwriter;
  48. path : pathstr;
  49. ObjFile : string;
  50. IsEndFile : boolean; { special 'end' file for import dir ? }
  51. currsec : tsection;
  52. constructor init;
  53. destructor done;virtual;
  54. { Writing }
  55. procedure NextSmartName;
  56. procedure initwriting;virtual;
  57. procedure donewriting;virtual;
  58. procedure setsectionsizes(var s:tsecsize);virtual;
  59. procedure writebytes(var data;len:longint);virtual;
  60. procedure writealloc(len:longint);virtual;
  61. procedure writereloc(data,len:longint;p:pasmsymbol;relative:relative_type);virtual;
  62. procedure writesymbol(p:pasmsymbol);virtual;
  63. procedure writestabs(section:tsection;offset:longint;p:pchar;nidx,nother,line:longint;reloc:boolean);virtual;
  64. procedure defaultsection(sec:tsection);
  65. end;
  66. var
  67. objectalloc : pobjectalloc;
  68. objectoutput : pobjectoutput;
  69. implementation
  70. uses
  71. strings,
  72. globtype,globals,verbose,files,
  73. assemble;
  74. {****************************************************************************
  75. tobjectoutput
  76. ****************************************************************************}
  77. constructor tobjectalloc.init;
  78. begin
  79. end;
  80. destructor tobjectalloc.done;
  81. begin
  82. end;
  83. procedure tobjectalloc.setsection(sec:tsection);
  84. begin
  85. currsec:=sec;
  86. end;
  87. procedure tobjectalloc.resetsections;
  88. begin
  89. FillChar(secsize,sizeof(secsize),0);
  90. end;
  91. procedure tobjectalloc.sectionalloc(l:longint);
  92. begin
  93. inc(secsize[currsec],l);
  94. end;
  95. procedure tobjectalloc.staballoc(p:pchar);
  96. begin
  97. inc(secsize[sec_stab]);
  98. if assigned(p) and (p[0]<>#0) then
  99. inc(secsize[sec_stabstr],strlen(p)+1);
  100. end;
  101. function tobjectalloc.sectionsize:longint;
  102. begin
  103. sectionsize:=secsize[currsec];
  104. end;
  105. {****************************************************************************
  106. tobjectoutput
  107. ****************************************************************************}
  108. constructor tobjectoutput.init;
  109. var
  110. i : longint;
  111. begin
  112. objfile:=current_module^.objfilename^;
  113. { Which path will be used ? }
  114. if (cs_smartlink in aktmoduleswitches) and
  115. (cs_asm_leave in aktglobalswitches) then
  116. begin
  117. path:=current_module^.path^+FixFileName(current_module^.modulename^)+target_info.smartext;
  118. {$I-}
  119. mkdir(path);
  120. {$I+}
  121. i:=ioresult;
  122. path:=FixPath(path,false);
  123. end
  124. else
  125. path:=current_module^.path^;
  126. { init writer }
  127. if (cs_smartlink in aktmoduleswitches) and
  128. not(cs_asm_leave in aktglobalswitches) then
  129. writer:=New(parobjectwriter,Init(current_module^.staticlibfilename^))
  130. else
  131. writer:=New(pobjectwriter,Init);
  132. end;
  133. destructor tobjectoutput.done;
  134. begin
  135. Dispose(writer,done);
  136. end;
  137. procedure tobjectoutput.NextSmartName;
  138. var
  139. s : string;
  140. begin
  141. inc(SmartLinkFilesCnt);
  142. if SmartLinkFilesCnt>999999 then
  143. Message(asmw_f_too_many_asm_files);
  144. if (cs_asm_leave in aktglobalswitches) then
  145. begin
  146. if IsEndFile then
  147. begin
  148. s:=current_module^.asmprefix^+'e';
  149. IsEndFile:=false;
  150. end
  151. else
  152. s:=current_module^.asmprefix^;
  153. ObjFile:=Path+FixFileName(s+tostr(SmartLinkFilesCnt)+target_info.objext)
  154. end
  155. else
  156. begin
  157. if IsEndFile then
  158. begin
  159. s:=current_module^.modulename^+'_e';
  160. IsEndFile:=false;
  161. end
  162. else
  163. s:=current_module^.modulename^+'_';
  164. ObjFile:=FixFileName(s+tostr(SmartLinkFilesCnt)+target_info.objext);
  165. end;
  166. end;
  167. procedure tobjectoutput.initwriting;
  168. begin
  169. if (cs_smartlink in aktmoduleswitches) then
  170. NextSmartName;
  171. writer^.create(objfile);
  172. end;
  173. procedure tobjectoutput.donewriting;
  174. begin
  175. writer^.close;
  176. end;
  177. procedure tobjectoutput.setsectionsizes(var s:tsecsize);
  178. begin
  179. end;
  180. procedure tobjectoutput.defaultsection(sec:tsection);
  181. begin
  182. currsec:=sec;
  183. end;
  184. procedure tobjectoutput.writesymbol(p:pasmsymbol);
  185. begin
  186. RunError(211);
  187. end;
  188. procedure tobjectoutput.writereloc(data,len:longint;p:pasmsymbol;relative:relative_type);
  189. begin
  190. RunError(211);
  191. end;
  192. procedure tobjectoutput.writebytes(var data;len:longint);
  193. begin
  194. RunError(211);
  195. end;
  196. procedure tobjectoutput.writealloc(len:longint);
  197. begin
  198. RunError(211);
  199. end;
  200. procedure tobjectoutput.writestabs(section:tsection;offset:longint;p:pchar;nidx,nother,line:longint;reloc:boolean);
  201. begin
  202. RunError(211);
  203. end;
  204. end.
  205. {
  206. $Log$
  207. Revision 1.5 1999-05-05 22:21:57 peter
  208. * updated messages
  209. Revision 1.4 1999/05/05 17:34:30 peter
  210. * output is more like as 2.9.1
  211. * stabs really working for go32v2
  212. Revision 1.3 1999/05/04 21:44:50 florian
  213. * changes to compile it with Delphi 4.0
  214. Revision 1.2 1999/05/02 22:41:54 peter
  215. * moved section names to systems
  216. * fixed nasm,intel writer
  217. Revision 1.1 1999/05/01 13:24:23 peter
  218. * merged nasm compiler
  219. * old asm moved to oldasm/
  220. Revision 1.8 1999/03/18 20:30:48 peter
  221. + .a writer
  222. Revision 1.7 1999/03/10 13:41:09 pierre
  223. + partial implementation for win32 !
  224. winhello works but pp still does not !
  225. Revision 1.6 1999/03/08 14:51:08 peter
  226. + smartlinking for ag386bin
  227. Revision 1.5 1999/03/05 13:09:51 peter
  228. * first things for tai_cut support for ag386bin
  229. Revision 1.4 1999/03/03 01:36:45 pierre
  230. + stabs output working (though not really tested)
  231. for a simple file the only difference to GAS output is due
  232. to the VMA of the different sections
  233. Revision 1.3 1999/03/02 02:56:26 peter
  234. + stabs support for binary writers
  235. * more fixes and missing updates from the previous commit :(
  236. Revision 1.2 1999/02/25 21:03:09 peter
  237. * ag386bin updates
  238. + coff writer
  239. Revision 1.1 1999/02/16 17:59:39 peter
  240. + initial files
  241. }