cga68k.pas 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 by Florian Klaempfl, Carl Eric Codere
  4. This unit generates 68000 (or better) assembler from the parse tree
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit cga68k;
  19. interface
  20. uses
  21. objects,cobjects,verbose,systems,globals,tree,symtable,types,strings,
  22. pass_1,hcodegen,aasm,m68k,tgen68k,files,gdb;
  23. procedure emitl(op : tasmop;var l : plabel);
  24. procedure emit_reg_reg(i : tasmop;s : topsize;reg1,reg2 : tregister);
  25. procedure emitcall(const routine:string;add_to_externals : boolean);
  26. procedure emitloadord2reg(location:Tlocation;orddef:Porddef;
  27. destreg:Tregister;delloc:boolean);
  28. { produces jumps to true respectively false labels using boolean expressions }
  29. procedure maketojumpbool(p : ptree);
  30. procedure emitoverflowcheck;
  31. procedure push_int(l : longint);
  32. function maybe_push(needed : byte;p : ptree) : boolean;
  33. procedure restore(p : ptree);
  34. procedure emit_push_mem(const ref : treference);
  35. procedure emitpushreferenceaddr(const ref : treference);
  36. procedure swaptree(p: ptree);
  37. procedure copystring(const dref,sref : treference;len : byte);
  38. procedure concatcopy(source,dest : treference;size : longint;delsource : boolean);
  39. { see implementation }
  40. procedure maybe_loada5;
  41. procedure emit_bounds_check(hp: treference; index: tregister);
  42. procedure loadstring(p:ptree);
  43. procedure floatload(t : tfloattype;const ref : treference; var location:tlocation);
  44. { return a float op_size from a floatb type }
  45. { also does some error checking for problems }
  46. function getfloatsize(t: tfloattype): topsize;
  47. procedure floatstore(t : tfloattype;var location:tlocation; const ref:treference);
  48. { procedure floatloadops(t : tfloattype;var op : tasmop;var s : topsize);
  49. procedure floatstoreops(t : tfloattype;var op : tasmop;var s : topsize); }
  50. procedure firstcomplex(p : ptree);
  51. procedure secondfuncret(var p : ptree);
  52. { initialize respectively terminates the code generator }
  53. { for a new module or procedure }
  54. procedure codegen_doneprocedure;
  55. procedure codegen_donemodule;
  56. procedure codegen_newmodule;
  57. procedure codegen_newprocedure;
  58. { generate entry code for a procedure.}
  59. procedure genentrycode(const proc_names:Tstringcontainer;make_global:boolean;
  60. stackframe:longint;
  61. var parasize:longint;var nostackframe:boolean);
  62. { generate the exit code for a procedure. }
  63. procedure genexitcode(parasize:longint;nostackframe:boolean);
  64. implementation
  65. {
  66. procedure genconstadd(size : topsize;l : longint;const str : string);
  67. begin
  68. if l=0 then
  69. else if l=1 then
  70. exprasmlist^.concat(new(pai68k,op_A_INC,size,str)
  71. else if l=-1 then
  72. exprasmlist^.concat(new(pai68k,op_A_INC,size,str)
  73. else
  74. exprasmlist^.concat(new(pai68k,op_ADD,size,'$'+tostr(l)+','+str);
  75. end;
  76. }
  77. procedure copystring(const dref,sref : treference;len : byte);
  78. var
  79. pushed : tpushed;
  80. begin
  81. pushusedregisters(pushed,$ffff);
  82. emitpushreferenceaddr(dref);
  83. emitpushreferenceaddr(sref);
  84. push_int(len);
  85. emitcall('STRCOPY',true);
  86. maybe_loada5;
  87. popusedregisters(pushed);
  88. end;
  89. procedure loadstring(p:ptree);
  90. begin
  91. case p^.right^.resulttype^.deftype of
  92. stringdef : begin
  93. { load a string ... }
  94. { here two possible choices: }
  95. { if it is a char, then simply }
  96. { load 0 length string }
  97. if (p^.right^.treetype=stringconstn) and
  98. (p^.right^.values^='') then
  99. exprasmlist^.concat(new(pai68k,op_const_ref(
  100. A_MOVE,S_B,0,newreference(p^.left^.location.reference))))
  101. else
  102. copystring(p^.left^.location.reference,p^.right^.location.reference,
  103. min(pstringdef(p^.right^.resulttype)^.len,pstringdef(p^.left^.resulttype)^.len));
  104. end;
  105. orddef : begin
  106. if p^.right^.treetype=ordconstn then
  107. begin
  108. exprasmlist^.concat(new(pai68k,op_const_ref(A_MOVE,S_W,p^.right^.value*256+1,
  109. newreference(p^.left^.location.reference))))
  110. end
  111. else
  112. begin
  113. { not so elegant (goes better with extra register }
  114. if (p^.right^.location.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  115. begin
  116. exprasmlist^.concat(new(pai68k,op_reg_reg(
  117. A_MOVE,S_L,p^.right^.location.register,R_D0)));
  118. ungetregister32(p^.right^.location.register);
  119. end
  120. else
  121. begin
  122. exprasmlist^.concat(new(pai68k,op_ref_reg(
  123. A_MOVE,S_L,newreference(p^.right^.location.reference),R_D0)));
  124. del_reference(p^.right^.location.reference);
  125. end;
  126. if (opt_processors = MC68020) then
  127. { alignment is not a problem on the 68020 and higher processors }
  128. Begin
  129. { add length of string to word }
  130. exprasmlist^.concat(new(pai68k,op_const_reg(A_OR,S_W,$0100,R_D0)));
  131. { put back into mem ... }
  132. exprasmlist^.concat(new(pai68k,op_reg_ref(A_MOVE,S_W,R_D0,
  133. newreference(p^.left^.location.reference))));
  134. end
  135. else
  136. Begin
  137. { alignment can cause problems }
  138. { add length of string to ref }
  139. exprasmlist^.concat(new(pai68k,op_const_ref(A_MOVE,S_B,1,
  140. newreference(p^.left^.location.reference))));
  141. if abs(p^.left^.location.reference.offset) >= 1 then
  142. Begin
  143. { temporarily decrease offset }
  144. Inc(p^.left^.location.reference.offset);
  145. exprasmlist^.concat(new(pai68k,op_reg_ref(A_MOVE,S_B,R_D0,
  146. newreference(p^.left^.location.reference))));
  147. Dec(p^.left^.location.reference.offset);
  148. { restore offset }
  149. end
  150. else
  151. Begin
  152. Comment(V_Debug,'SecondChar2String() internal error.');
  153. internalerror(34);
  154. end;
  155. end;
  156. end;
  157. end;
  158. else
  159. Message(sym_e_type_mismatch);
  160. end;
  161. end;
  162. procedure restore(p : ptree);
  163. var
  164. hregister : tregister;
  165. begin
  166. hregister:=getregister32;
  167. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_L,R_SPPULL,hregister)));
  168. if (p^.location.loc=LOC_REGISTER) or (p^.location.loc=LOC_CREGISTER) then
  169. begin
  170. p^.location.register:=hregister;
  171. end
  172. else
  173. begin
  174. reset_reference(p^.location.reference);
  175. p^.location.reference.index:=hregister;
  176. set_location(p^.left^.location,p^.location);
  177. end;
  178. end;
  179. function maybe_push(needed : byte;p : ptree) : boolean;
  180. var
  181. pushed : boolean;
  182. {hregister : tregister; }
  183. reg: tregister;
  184. begin
  185. if needed>usablereg32 then
  186. begin
  187. if (p^.location.loc=LOC_REGISTER) or
  188. (p^.location.loc=LOC_CREGISTER) then
  189. begin
  190. pushed:=true;
  191. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_L,p^.location.register,R_SPPUSH)));
  192. ungetregister32(p^.location.register);
  193. end
  194. else if ((p^.location.loc=LOC_MEM) or
  195. (p^.location.loc=LOC_REFERENCE)
  196. ) and
  197. ((p^.location.reference.base<>R_NO) or
  198. (p^.location.reference.index<>R_NO)
  199. ) then
  200. begin
  201. del_reference(p^.location.reference);
  202. exprasmlist^.concat(new(pai68k,op_ref_reg(A_LEA,S_L,newreference(p^.location.reference),
  203. R_A0)));
  204. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_L,R_A0,R_SPPUSH)));
  205. pushed:=true;
  206. end
  207. else pushed:=false;
  208. end
  209. else pushed:=false;
  210. maybe_push:=pushed;
  211. end;
  212. { emit out of range check for arrays and sets}
  213. procedure emit_bounds_check(hp: treference; index: tregister);
  214. { index = index of array to check }
  215. { memory of range check information for array }
  216. var
  217. hl : plabel;
  218. begin
  219. if (opt_processors = MC68020) then
  220. begin
  221. exprasmlist^.concat(new(pai68k, op_ref_reg(A_CMP2,S_L,newreference(hp),index)));
  222. getlabel(hl);
  223. emitl(A_BCC, hl);
  224. exprasmlist^.concat(new(pai68k, op_const_reg(A_MOVE,S_L,201,R_D0)));
  225. emitcall('HALT_ERROR',true);
  226. emitl(A_LABEL, hl);
  227. end
  228. else
  229. begin
  230. exprasmlist^.concat(new(pai68k, op_ref_reg(A_LEA,S_L,newreference(hp), R_A1)));
  231. exprasmlist^.concat(new(pai68k, op_reg_reg(A_MOVE, S_L, index, R_D0)));
  232. emitcall('RE_BOUNDS_CHECK',true);
  233. end;
  234. end;
  235. function getfloatsize(t: tfloattype): topsize;
  236. begin
  237. case t of
  238. s32real: getfloatsize := S_S;
  239. s64real: getfloatsize := S_Q;
  240. s80real: getfloatsize := S_X;
  241. {$ifdef extdebug}
  242. else {else case }
  243. begin
  244. Comment(V_Debug,' getfloatsize() trying to get unknown size.');
  245. internalerror(12);
  246. end;
  247. {$endif}
  248. end;
  249. end;
  250. procedure emitl(op : tasmop;var l : plabel);
  251. begin
  252. if op=A_LABEL then
  253. exprasmlist^.concat(new(pai_label,init(l)))
  254. else
  255. exprasmlist^.concat(new(pai_labeled,init(op,l)))
  256. end;
  257. procedure emit_reg_reg(i : tasmop;s : topsize;reg1,reg2 : tregister);
  258. begin
  259. if (reg1 <> reg2) or (i <> A_MOVE) then
  260. exprasmlist^.concat(new(pai68k,op_reg_reg(i,s,reg1,reg2)));
  261. end;
  262. procedure emitcall(const routine:string;add_to_externals : boolean);
  263. begin
  264. exprasmlist^.concat(new(pai68k,op_csymbol(A_JSR,S_NO,newcsymbol(routine,0))));
  265. if assem_need_external_list and add_to_externals and
  266. not (cs_compilesystem in aktswitches) then
  267. concat_external(routine,EXT_NEAR);
  268. end;
  269. procedure maketojumpbool(p : ptree);
  270. begin
  271. if p^.error then
  272. exit;
  273. if (p^.resulttype^.deftype=orddef) and
  274. (porddef(p^.resulttype)^.typ=bool8bit) then
  275. begin
  276. if is_constboolnode(p) then
  277. begin
  278. if p^.value<>0 then
  279. emitl(A_JMP,truelabel)
  280. else emitl(A_JMP,falselabel);
  281. end
  282. else
  283. begin
  284. case p^.location.loc of
  285. LOC_CREGISTER,LOC_REGISTER : begin
  286. exprasmlist^.concat(new(pai68k,op_reg(A_TST,S_B,p^.location.register)));
  287. ungetregister32(p^.location.register);
  288. emitl(A_BNE,truelabel);
  289. emitl(A_JMP,falselabel);
  290. end;
  291. LOC_MEM,LOC_REFERENCE : begin
  292. exprasmlist^.concat(new(pai68k,op_ref(
  293. A_TST,S_B,newreference(p^.location.reference))));
  294. del_reference(p^.location.reference);
  295. emitl(A_BNE,truelabel);
  296. emitl(A_JMP,falselabel);
  297. end;
  298. LOC_FLAGS : begin
  299. emitl(flag_2_jmp[p^.location.resflags],truelabel);
  300. emitl(A_JMP,falselabel);
  301. end;
  302. end;
  303. end;
  304. end
  305. else
  306. Message(sym_e_type_mismatch);
  307. end;
  308. procedure emitoverflowcheck;
  309. var
  310. hl : plabel;
  311. begin
  312. if cs_check_overflow in aktswitches then
  313. begin
  314. getlabel(hl);
  315. emitl(A_BVC,hl);
  316. emitcall('RE_OVERFLOW',true);
  317. emitl(A_LABEL,hl);
  318. end;
  319. end;
  320. procedure push_int(l : longint);
  321. begin
  322. if (l = 0) and (opt_processors = MC68020) then
  323. begin
  324. exprasmlist^.concat(new(pai68k,op_reg(A_CLR,S_L,R_D6)));
  325. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_L,
  326. R_D6, R_SPPUSH)));
  327. end
  328. else
  329. if not(cs_littlesize in aktswitches) and (l >= -128) and (l <= 127) then
  330. begin
  331. exprasmlist^.concat(new(pai68k,op_const_reg(A_MOVEQ,S_L,l,R_D6)));
  332. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_L,R_D6,R_SPPUSH)));
  333. end
  334. else
  335. exprasmlist^.concat(new(pai68k,op_const_reg(A_MOVE,S_L,l,R_SPPUSH)));
  336. end;
  337. procedure emit_push_mem(const ref : treference);
  338. begin
  339. if ref.isintvalue then
  340. push_int(ref.offset)
  341. else
  342. exprasmlist^.concat(new(pai68k,op_ref(A_PEA,S_L,newreference(ref))));
  343. end;
  344. { USES REGISTER R_A1 }
  345. procedure emitpushreferenceaddr(const ref : treference);
  346. begin
  347. if ref.isintvalue then
  348. push_int(ref.offset)
  349. else
  350. begin
  351. if (ref.base=R_NO) and (ref.index=R_NO) then
  352. exprasmlist^.concat(new(pai68k,op_ref(A_PEA,S_L,
  353. newreference(ref))))
  354. else if (ref.base=R_NO) and (ref.index<>R_NO) and
  355. (ref.offset=0) and (ref.scalefactor=0) and (ref.symbol=nil) then
  356. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_L,
  357. ref.index,R_SPPUSH)))
  358. else if (ref.base<>R_NO) and (ref.index=R_NO) and
  359. (ref.offset=0) and (ref.symbol=nil) then
  360. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_L,ref.base,R_SPPUSH)))
  361. else
  362. begin
  363. exprasmlist^.concat(new(pai68k,op_ref_reg(A_LEA,S_L,newreference(ref),R_A1)));
  364. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_L,R_A1,R_SPPUSH)));
  365. end;
  366. end;
  367. end;
  368. procedure swaptree(p:Ptree);
  369. var swapp:Ptree;
  370. begin
  371. swapp:=p^.right;
  372. p^.right:=p^.left;
  373. p^.left:=swapp;
  374. p^.swaped:=not(p^.swaped);
  375. end;
  376. procedure genentrycode(const proc_names:Tstringcontainer;make_global:boolean;
  377. stackframe:longint;
  378. var parasize:longint;var nostackframe:boolean);
  379. {Generates the entry code for a procedure.}
  380. var hs:string;
  381. hp:Pused_unit;
  382. unitinits:taasmoutput;
  383. {$ifdef GDB}
  384. oldaktprocname : string;
  385. stab_function_name:Pai_stab_function_name;
  386. {$endif GDB}
  387. begin
  388. if (aktprocsym^.definition^.options and poproginit<>0) then
  389. begin
  390. {Init the stack checking.}
  391. if (cs_check_stack in aktswitches) and
  392. (target_info.target=target_linux) then
  393. begin
  394. procinfo.aktentrycode^.insert(new(pai68k,
  395. op_csymbol(A_JSR,S_NO,newcsymbol('INIT_STACK_CHECK',0))));
  396. end;
  397. unitinits.init;
  398. {Call the unit init procedures.}
  399. hp:=pused_unit(usedunits.first);
  400. while assigned(hp) do
  401. begin
  402. { call the unit init code and make it external }
  403. if (hp^.u^.flags and uf_init)<>0 then
  404. begin
  405. unitinits.concat(new(pai68k,op_csymbol(A_JSR,S_NO,newcsymbol('INIT$$'+hp^.u^.unitname^,0))));
  406. externals^.concat(new(pai_external,init('INIT$$'+hp^.u^.unitname^,EXT_NEAR)));
  407. end;
  408. hp:=pused_unit(hp^.next);
  409. end;
  410. procinfo.aktentrycode^.insertlist(@unitinits);
  411. unitinits.done;
  412. end;
  413. { a constructor needs a help procedure }
  414. if (aktprocsym^.definition^.options and poconstructor)<>0 then
  415. begin
  416. if procinfo._class^.isclass then
  417. begin
  418. procinfo.aktentrycode^.insert(new(pai_labeled,init(A_BEQ,quickexitlabel)));
  419. procinfo.aktentrycode^.insert(new(pai68k,op_csymbol(A_JSR,S_NO,
  420. newcsymbol('NEW_CLASS',0))));
  421. concat_external('NEW_CLASS',EXT_NEAR);
  422. end
  423. else
  424. begin
  425. procinfo.aktentrycode^.insert(new(pai_labeled,init(A_BEQ,quickexitlabel)));
  426. procinfo.aktentrycode^.insert(new(pai68k,op_csymbol(A_JSR,S_NO,
  427. newcsymbol('HELP_CONSTRUCTOR',0))));
  428. concat_external('HELP_CONSTRUCTOR',EXT_NEAR);
  429. end;
  430. end;
  431. { don't load ESI, does the caller }
  432. { omit stack frame ? }
  433. if procinfo.framepointer=stack_pointer then
  434. begin
  435. Message(cg_d_stackframe_omited);
  436. nostackframe:=true;
  437. if (aktprocsym^.definition^.options and (pounitinit or poproginit)<>0) then
  438. parasize:=0
  439. else
  440. parasize:=aktprocsym^.definition^.parast^.datasize+procinfo.call_offset;
  441. end
  442. else
  443. begin
  444. if (aktprocsym^.definition^.options and (pounitinit or poproginit)<>0) then
  445. parasize:=0
  446. else
  447. parasize:=aktprocsym^.definition^.parast^.datasize+procinfo.call_offset-8;
  448. nostackframe:=false;
  449. if stackframe<>0 then
  450. begin
  451. if cs_littlesize in aktswitches then
  452. begin
  453. if (cs_check_stack in aktswitches) and
  454. (target_info.target<>target_linux) then
  455. begin
  456. procinfo.aktentrycode^.insert(new(pai68k,
  457. op_csymbol(A_JSR,S_NO,newcsymbol('STACKCHECK',0))));
  458. procinfo.aktentrycode^.insert(new(pai68k,op_const_reg(A_MOVE,S_L,stackframe,R_SPPUSH)));
  459. end;
  460. { to allocate stack space }
  461. { here we allocate space using link signed 16-bit version }
  462. { -ve offset to allocate stack space! }
  463. if (stackframe > -32767) and (stackframe < 32769) then
  464. procinfo.aktentrycode^.insert(new(pai68k,op_reg_const(A_LINK,S_W,R_A6,-stackframe)))
  465. else
  466. Message(cg_e_stacklimit_in_local_routine);
  467. end
  468. else
  469. begin
  470. { Not to complicate the code generator too much, and since some }
  471. { of the systems only support this format, the stackframe cannot }
  472. { exceed 32K in size. }
  473. if (stackframe > -32767) and (stackframe < 32769) then
  474. begin
  475. procinfo.aktentrycode^.insert(new(pai68k,op_const_reg(A_SUB,S_L,stackframe,R_SP)));
  476. if (cs_check_stack in aktswitches) then
  477. begin
  478. procinfo.aktentrycode^.insert(new(pai68k,
  479. op_csymbol(A_JSR,S_NO,newcsymbol('STACKCHECK',0))));
  480. procinfo.aktentrycode^.insert(new(pai68k,op_const_reg(A_MOVE,S_L,
  481. stackframe,R_SPPUSH)));
  482. concat_external('STACKCHECK',EXT_NEAR);
  483. end;
  484. procinfo.aktentrycode^.insert(new(pai68k,op_reg_reg(A_MOVE,S_L,R_SP,R_A6)));
  485. procinfo.aktentrycode^.insert(new(pai68k,op_reg_reg(A_MOVE,S_L,R_A6,R_SPPUSH)));
  486. end
  487. else
  488. Message(cg_e_stacklimit_in_local_routine);
  489. end;
  490. end {endif stackframe<>0 }
  491. else
  492. begin
  493. procinfo.aktentrycode^.insert(new(pai68k,op_reg_reg(A_MOVE,S_L,R_SP,R_A6)));
  494. procinfo.aktentrycode^.insert(new(pai68k,op_reg_reg(A_MOVE,S_L,R_A6,R_SPPUSH)));
  495. end;
  496. end;
  497. if (aktprocsym^.definition^.options and pointerrupt)<>0 then
  498. generate_interrupt_stackframe_entry;
  499. {proc_names.insert(aktprocsym^.definition^.mangledname);}
  500. if (aktprocsym^.definition^.owner^.symtabletype=globalsymtable) or
  501. ((procinfo._class<>nil) and (procinfo._class^.owner^.
  502. symtabletype=globalsymtable)) then
  503. make_global:=true;
  504. hs:=proc_names.get;
  505. {$IfDef GDB}
  506. if (cs_debuginfo in aktswitches) and
  507. target_info.use_function_relative_addresses then
  508. stab_function_name := new(pai_stab_function_name,init(strpnew(hs)));
  509. oldaktprocname:=aktprocsym^.name;
  510. {$EndIf GDB}
  511. while hs<>'' do
  512. begin
  513. if make_global then
  514. procinfo.aktentrycode^.insert(new(pai_symbol,init_global(hs)))
  515. else
  516. procinfo.aktentrycode^.insert(new(pai_symbol,init(hs)));
  517. {$ifdef GDB}
  518. if (cs_debuginfo in aktswitches) and
  519. target_info.use_function_relative_addresses then
  520. begin
  521. procinfo.aktentrycode^.insert(new(pai_stab_function_name,init(strpnew(hs))));
  522. { This is not a nice solution to save the name, change it and restore when done }
  523. aktprocsym^.setname(hs);
  524. procinfo.aktentrycode^.insert(new(pai_stabs,init(aktprocsym^.stabstring)));
  525. end;
  526. {$endif GDB}
  527. hs:=proc_names.get;
  528. end;
  529. {$ifdef GDB}
  530. aktprocsym^.setname(oldaktprocname);
  531. if (cs_debuginfo in aktswitches) then
  532. begin
  533. if target_info.use_function_relative_addresses then
  534. procinfo.aktentrycode^.insert(stab_function_name);
  535. if make_global or ((procinfo.flags and pi_is_global) <> 0) then
  536. aktprocsym^.is_global := True;
  537. {This is dead code! Because lexlevel is increased at the
  538. start of compile_proc_body it can never be zero.}
  539. { if (lexlevel > 0) and (oldprocsym^.definition^.localst^.name = nil) then
  540. if oldprocsym^.owner^.symtabletype = objectsymtable then
  541. oldprocsym^.definition^.localst^.name := stringdup(oldprocsym^.owner^.name^+'_'+oldprocsym^.name)
  542. else
  543. oldprocsym^.definition^.localst^.name := stringdup(oldprocsym^.name);}
  544. aktprocsym^.isstabwritten:=true;
  545. end;
  546. {$endif GDB}
  547. { Alignment required for Motorola }
  548. procinfo.aktentrycode^.insert(new(pai_align,init(2)));
  549. {$ifdef extdebug}
  550. procinfo.aktentrycode^.insert(new(pai_direct,init(strpnew(target_info.newline))));
  551. {$endif extdebug}
  552. end;
  553. {Generate the exit code for a procedure.}
  554. procedure genexitcode(parasize:longint;nostackframe:boolean);
  555. var hr:Preference; {This is for function results.}
  556. op:Tasmop;
  557. s:Topsize;
  558. begin
  559. { !!!! insert there automatic destructors }
  560. procinfo.aktexitcode^.insert(new(pai_label,init(aktexitlabel)));
  561. { call the destructor help procedure }
  562. if (aktprocsym^.definition^.options and podestructor)<>0 then
  563. begin
  564. if procinfo._class^.isclass then
  565. begin
  566. procinfo.aktexitcode^.insert(new(pai68k,op_csymbol(A_JSR,S_NO,
  567. newcsymbol('DISPOSE_CLASS',0))));
  568. concat_external('DISPOSE_CLASS',EXT_NEAR);
  569. end
  570. else
  571. begin
  572. procinfo.aktexitcode^.insert(new(pai68k,op_csymbol(A_JSR,S_NO,
  573. newcsymbol('HELP_DESTRUCTOR',0))));
  574. concat_external('HELP_DESTRUCTOR',EXT_NEAR);
  575. end;
  576. end;
  577. { call __EXIT for main program }
  578. { ????????? }
  579. if (aktprocsym^.definition^.options and poproginit)<>0 then
  580. begin
  581. procinfo.aktexitcode^.concat(new(pai68k,op_csymbol(A_JSR,S_NO,newcsymbol('__EXIT',0))));
  582. externals^.concat(new(pai_external,init('__EXIT',EXT_NEAR)));
  583. end;
  584. { handle return value }
  585. if (aktprocsym^.definition^.options and poassembler)=0 then
  586. if (aktprocsym^.definition^.options and poconstructor)=0 then
  587. begin
  588. if procinfo.retdef<>pdef(voiddef) then
  589. begin
  590. if not procinfo.funcret_is_valid then
  591. Message(sym_w_function_result_not_set);
  592. new(hr);
  593. reset_reference(hr^);
  594. hr^.offset:=procinfo.retoffset;
  595. hr^.base:=procinfo.framepointer;
  596. if (procinfo.retdef^.deftype=orddef) then
  597. begin
  598. case porddef(procinfo.retdef)^.typ of
  599. s32bit,u32bit :
  600. procinfo.aktexitcode^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,hr,R_D0)));
  601. u8bit,s8bit,uchar,bool8bit :
  602. procinfo.aktexitcode^.concat(new(pai68k,op_ref_reg(A_MOVE,S_B,hr,R_D0)));
  603. s16bit,u16bit :
  604. procinfo.aktexitcode^.concat(new(pai68k,op_ref_reg(A_MOVE,S_W,hr,R_D0)));
  605. end;
  606. end
  607. else
  608. if (procinfo.retdef^.deftype in [pointerdef,enumdef,procvardef]) or
  609. ((procinfo.retdef^.deftype=setdef) and
  610. (psetdef(procinfo.retdef)^.settype=smallset)) then
  611. procinfo.aktexitcode^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,hr,R_D0)))
  612. else
  613. if (procinfo.retdef^.deftype=floatdef) then
  614. begin
  615. if pfloatdef(procinfo.retdef)^.typ=f32bit then
  616. begin
  617. { Isnt this missing ? }
  618. procinfo.aktexitcode^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,hr,R_D0)));
  619. end
  620. else
  621. begin
  622. { how the return value is handled }
  623. { if in FPU mode, return in FP0 }
  624. if (pfloatdef(procinfo.retdef)^.typ = s32real)
  625. and (cs_fp_emulation in aktswitches) then
  626. begin
  627. procinfo.aktexitcode^.concat(new(pai68k,op_ref_reg(A_MOVE,
  628. S_L,hr,R_D0)))
  629. end
  630. else
  631. begin
  632. if cs_fp_emulation in aktswitches then
  633. procinfo.aktexitcode^.concat(new(pai68k,op_ref_reg(A_MOVE,
  634. S_L,hr,R_D0)))
  635. else
  636. procinfo.aktexitcode^.concat(new(pai68k,op_ref_reg(A_FMOVE,
  637. getfloatsize(pfloatdef(procinfo.retdef)^.typ),hr,R_FP0)));
  638. end;
  639. end;
  640. end
  641. else
  642. dispose(hr);
  643. end
  644. end
  645. else
  646. begin
  647. { successful constructor deletes the zero flag }
  648. { and returns self in accumulator }
  649. procinfo.aktexitcode^.concat(new(pai_label,init(quickexitlabel)));
  650. { eax must be set to zero if the allocation failed !!! }
  651. procinfo.aktexitcode^.concat(new(pai68k,op_reg_reg(A_MOVE,S_L,R_A5,R_D0)));
  652. { faster then OR on mc68000/mc68020 }
  653. procinfo.aktexitcode^.concat(new(pai68k,op_reg(A_TST,S_L,R_D0)));
  654. end;
  655. procinfo.aktexitcode^.concat(new(pai_label,init(aktexit2label)));
  656. if not(nostackframe) then
  657. procinfo.aktexitcode^.concat(new(pai68k,op_reg(A_UNLK,S_NO,R_A6)));
  658. { at last, the return is generated }
  659. if (aktprocsym^.definition^.options and pointerrupt)<>0 then
  660. generate_interrupt_stackframe_exit
  661. else
  662. if (parasize=0) or ((aktprocsym^.definition^.options and poclearstack)<>0)
  663. then
  664. {Routines with the poclearstack flag set use only a ret.}
  665. { also routines with parasize=0 }
  666. procinfo.aktexitcode^.concat(new(pai68k,op_none(A_RTS,S_NO)))
  667. else
  668. { return with immediate size possible here }
  669. { signed! }
  670. if (opt_processors = MC68020) and (parasize < $7FFF) then
  671. procinfo.aktexitcode^.concat(new(pai68k,op_const(
  672. A_RTD,S_NO,parasize)))
  673. { manually restore the stack }
  674. else
  675. begin
  676. { We must pull the PC Counter from the stack, before }
  677. { restoring the stack pointer, otherwise the PC would }
  678. { point to nowhere! }
  679. { save the PC counter (pop it from the stack) }
  680. procinfo.aktexitcode^.concat(new(pai68k,op_reg_reg(
  681. A_MOVE,S_L,R_SPPULL,R_A0)));
  682. { can we do a quick addition ... }
  683. if (parasize > 0) and (parasize < 9) then
  684. procinfo.aktexitcode^.concat(new(pai68k,op_const_reg(
  685. A_ADD,S_L,parasize,R_SP)))
  686. else { nope ... }
  687. procinfo.aktexitcode^.concat(new(pai68k,op_const_reg(
  688. A_ADD,S_L,parasize,R_SP)));
  689. { endif }
  690. { restore the PC counter (push it on the stack) }
  691. procinfo.aktexitcode^.concat(new(pai68k,op_reg_reg(
  692. A_MOVE,S_L,R_A0,R_SPPUSH)));
  693. procinfo.aktexitcode^.concat(new(pai68k,op_none(
  694. A_RTS,S_NO)))
  695. end;
  696. {$ifdef GDB}
  697. if cs_debuginfo in aktswitches then
  698. begin
  699. aktprocsym^.concatstabto(procinfo.aktexitcode);
  700. if assigned(procinfo._class) then
  701. procinfo.aktexitcode^.concat(new(pai_stabs,init(strpnew(
  702. '"$t:v'+procinfo._class^.numberstring+'",'+
  703. tostr(N_PSYM)+',0,0,'+tostr(procinfo.esi_offset)))));
  704. if (porddef(aktprocsym^.definition^.retdef) <> voiddef) then
  705. procinfo.aktexitcode^.concat(new(pai_stabs,init(strpnew(
  706. '"'+aktprocsym^.name+':X'+aktprocsym^.definition^.retdef^.numberstring+'",'+
  707. tostr(N_PSYM)+',0,0,'+tostr(procinfo.retoffset)))));
  708. procinfo.aktexitcode^.concat(new(pai_stabn,init(strpnew('192,0,0,'
  709. +aktprocsym^.definition^.mangledname))));
  710. procinfo.aktexitcode^.concat(new(pai_stabn,init(strpnew('224,0,0,'
  711. +lab2str(aktexit2label)))));
  712. end;
  713. {$endif * GDB *}
  714. end;
  715. { USES REGISTERS R_A0 AND R_A1 }
  716. procedure concatcopy(source,dest : treference;size : longint;delsource : boolean);
  717. var
  718. ecxpushed : boolean;
  719. helpsize : longint;
  720. i : byte;
  721. reg8,reg32 : tregister;
  722. swap : boolean;
  723. hregister : tregister;
  724. iregister : tregister;
  725. jregister : tregister;
  726. hp1 : treference;
  727. hp2 : treference;
  728. hl : plabel;
  729. begin
  730. hregister := getregister32;
  731. if delsource then
  732. del_reference(source);
  733. { from 12 bytes movs is being used }
  734. if (size<=8) or (not(cs_littlesize in aktswitches) and (size<=12)) then
  735. begin
  736. helpsize:=size div 4;
  737. { move a dword x times }
  738. for i:=1 to helpsize do
  739. begin
  740. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,newreference(source),hregister)));
  741. exprasmlist^.concat(new(pai68k,op_reg_ref(A_MOVE,S_L,hregister,newreference(dest))));
  742. inc(source.offset,4);
  743. inc(dest.offset,4);
  744. dec(size,4);
  745. end;
  746. { move a word }
  747. if size>1 then
  748. begin
  749. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_W,newreference(source),hregister)));
  750. exprasmlist^.concat(new(pai68k,op_reg_ref(A_MOVE,S_W,hregister,newreference(dest))));
  751. inc(source.offset,2);
  752. inc(dest.offset,2);
  753. dec(size,2);
  754. end;
  755. { move a single byte }
  756. if size>0 then
  757. begin
  758. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_B,newreference(source),hregister)));
  759. exprasmlist^.concat(new(pai68k,op_reg_ref(A_MOVE,S_B,hregister,newreference(dest))));
  760. end
  761. end
  762. else
  763. begin
  764. if (usableaddress > 1) then
  765. begin
  766. iregister := getaddressreg;
  767. jregister := getaddressreg;
  768. end
  769. else
  770. if (usableaddress = 1) then
  771. begin
  772. iregister := getaddressreg;
  773. jregister := R_A1;
  774. end
  775. else
  776. begin
  777. iregister := R_A0;
  778. jregister := R_A1;
  779. end;
  780. { reference for move (An)+,(An)+ }
  781. reset_reference(hp1);
  782. hp1.base := iregister; { source register }
  783. hp1.direction := dir_inc;
  784. reset_reference(hp2);
  785. hp2.base := jregister;
  786. hp1.direction := dir_inc;
  787. { iregister = source }
  788. { jregister = destination }
  789. exprasmlist^.concat(new(pai68k,op_ref_reg(A_LEA,S_L,newreference(source),iregister)));
  790. exprasmlist^.concat(new(pai68k,op_ref_reg(A_LEA,S_L,newreference(dest),jregister)));
  791. { double word move }
  792. helpsize := size - size mod 4;
  793. size := size mod 4;
  794. exprasmlist^.concat(new(pai68k,op_const_reg(A_MOVE,S_L,helpsize div 4,hregister)));
  795. getlabel(hl);
  796. emitl(A_LABEL,hl);
  797. exprasmlist^.concat(new(pai68k,op_ref_ref(A_MOVE,S_L,newreference(hp1),newreference(hp2))));
  798. exprasmlist^.concat(new(pai68k,op_const_reg(A_SUBQ,S_L,4,hregister)));
  799. emitl(A_BNE,hl);
  800. if size > 1 then
  801. begin
  802. dec(size,2);
  803. exprasmlist^.concat(new(pai68k,op_ref_ref(A_MOVE,S_W,newreference(hp1), newreference(hp2))));
  804. end;
  805. if size = 1 then
  806. exprasmlist^.concat(new(pai68k,op_ref_ref(A_MOVE,S_B,newreference(hp1), newreference(hp2))));
  807. { restore the registers that we have just used olny if they are used! }
  808. if jregister = R_A1 then
  809. hp2.base := R_NO;
  810. if iregister = R_A0 then
  811. hp1.base := R_NO;
  812. del_reference(hp1);
  813. del_reference(hp2);
  814. end;
  815. { loading SELF-reference again }
  816. maybe_loada5;
  817. if delsource then
  818. ungetiftemp(source);
  819. ungetregister32(hregister);
  820. end;
  821. procedure emitloadord2reg(location:Tlocation;orddef:Porddef;
  822. destreg:Tregister;delloc:boolean);
  823. {A lot smaller and less bug sensitive than the original unfolded loads.}
  824. var tai:pai68k;
  825. r:Preference;
  826. begin
  827. case location.loc of
  828. LOC_REGISTER,LOC_CREGISTER:
  829. begin
  830. case orddef^.typ of
  831. u8bit: begin
  832. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_L,location.register,destreg)));
  833. exprasmlist^.concat(new(pai68k,op_const_reg(A_ANDI,S_L,$FF,destreg)));
  834. end;
  835. s8bit: begin
  836. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_B,location.register,destreg)));
  837. if (opt_processors <> MC68020) then
  838. begin
  839. { byte to word }
  840. exprasmlist^.concat(new(pai68k,op_reg(A_EXT,S_W,destreg)));
  841. { word to long }
  842. exprasmlist^.concat(new(pai68k,op_reg(A_EXT,S_L,destreg)));
  843. end
  844. else { 68020+ and later only }
  845. exprasmlist^.concat(new(pai68k,op_reg(A_EXTB,S_L,destreg)));
  846. end;
  847. u16bit: begin
  848. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_W,location.register,destreg)));
  849. exprasmlist^.concat(new(pai68k,op_const_reg(A_ANDI,S_L,$FFFF,destreg)));
  850. end;
  851. s16bit: begin
  852. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_W,location.register,destreg)));
  853. { word to long }
  854. exprasmlist^.concat(new(pai68k,op_reg(A_EXT,S_L,destreg)));
  855. end;
  856. u32bit:
  857. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_L,location.register,destreg)));
  858. s32bit:
  859. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_L,location.register,destreg)));
  860. end;
  861. if delloc then
  862. ungetregister(location.register);
  863. end;
  864. LOC_REFERENCE:
  865. begin
  866. r:=newreference(location.reference);
  867. case orddef^.typ of
  868. u8bit: begin
  869. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,r,destreg)));
  870. exprasmlist^.concat(new(pai68k,op_const_reg(A_ANDI,S_L,$FF,destreg)));
  871. end;
  872. s8bit: begin
  873. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_B,r,destreg)));
  874. if (opt_processors <> MC68020) then
  875. begin
  876. { byte to word }
  877. exprasmlist^.concat(new(pai68k,op_reg(A_EXT,S_W,destreg)));
  878. { word to long }
  879. exprasmlist^.concat(new(pai68k,op_reg(A_EXT,S_L,destreg)));
  880. end
  881. else { 68020+ and later only }
  882. exprasmlist^.concat(new(pai68k,op_reg(A_EXTB,S_L,destreg)));
  883. end;
  884. u16bit: begin
  885. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_W,r,destreg)));
  886. exprasmlist^.concat(new(pai68k,op_const_reg(A_ANDI,S_L,$ffff,destreg)));
  887. end;
  888. s16bit: begin
  889. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_W,r,destreg)));
  890. { word to long }
  891. exprasmlist^.concat(new(pai68k,op_reg(A_EXT,S_L,destreg)));
  892. end;
  893. u32bit:
  894. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,r,destreg)));
  895. s32bit:
  896. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,r,destreg)));
  897. end;
  898. if delloc then
  899. del_reference(location.reference);
  900. end
  901. else
  902. internalerror(6);
  903. end;
  904. end;
  905. { if necessary A5 is reloaded after a call}
  906. procedure maybe_loada5;
  907. var
  908. hp : preference;
  909. p : pprocinfo;
  910. i : longint;
  911. begin
  912. if assigned(procinfo._class) then
  913. begin
  914. if lexlevel>2 then
  915. begin
  916. new(hp);
  917. reset_reference(hp^);
  918. hp^.offset:=procinfo.framepointer_offset;
  919. hp^.base:=procinfo.framepointer;
  920. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,hp,R_A5)));
  921. p:=procinfo.parent;
  922. for i:=3 to lexlevel-1 do
  923. begin
  924. new(hp);
  925. reset_reference(hp^);
  926. hp^.offset:=p^.framepointer_offset;
  927. hp^.base:=R_A5;
  928. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,hp,R_A5)));
  929. p:=p^.parent;
  930. end;
  931. new(hp);
  932. reset_reference(hp^);
  933. hp^.offset:=p^.ESI_offset;
  934. hp^.base:=R_A5;
  935. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,hp,R_A5)));
  936. end
  937. else
  938. begin
  939. new(hp);
  940. reset_reference(hp^);
  941. hp^.offset:=procinfo.ESI_offset;
  942. hp^.base:=procinfo.framepointer;
  943. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,hp,R_A5)));
  944. end;
  945. end;
  946. end;
  947. (***********************************************************************)
  948. (* PROCEDURE FLOATLOAD *)
  949. (* Description: This routine is to be called each time a location *)
  950. (* must be set to LOC_FPU and a value loaded into a FPU register. *)
  951. (* *)
  952. (* Remark: The routine sets up the register field of LOC_FPU correctly*)
  953. (***********************************************************************)
  954. procedure floatload(t : tfloattype;const ref : treference; var location:tlocation);
  955. var
  956. op : tasmop;
  957. s : topsize;
  958. begin
  959. { no emulation }
  960. case t of
  961. s32real : s := S_S;
  962. s64real : s := S_Q;
  963. s80real : s := S_X;
  964. else
  965. begin
  966. Message(cg_f_unknown_float_type);
  967. end;
  968. end; { end case }
  969. location.loc := LOC_FPU;
  970. if not ((cs_fp_emulation) in aktswitches) then
  971. begin
  972. location.fpureg := getfloatreg;
  973. exprasmlist^.concat(new(pai68k,op_ref_reg(A_FMOVE,s,newreference(ref),location.fpureg)))
  974. end
  975. else
  976. { handle emulation }
  977. begin
  978. if t = s32real then
  979. begin
  980. location.fpureg := getregister32;
  981. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,newreference(ref),location.fpureg)))
  982. end
  983. else
  984. { other floating types are not supported in emulation mode }
  985. Message(sym_e_type_id_not_defined);
  986. end;
  987. end;
  988. { procedure floatstoreops(t : tfloattype;var op : tasmop;var s : topsize);
  989. begin
  990. case t of
  991. s32real : begin
  992. op:=A_FSTP;
  993. s:=S_S;
  994. end;
  995. s64real : begin
  996. op:=A_FSTP;
  997. s:=S_L;
  998. end;
  999. s80real : begin
  1000. op:=A_FSTP;
  1001. s:=S_Q;
  1002. end;
  1003. s64bit : begin
  1004. op:=A_FISTP;
  1005. s:=S_Q;
  1006. end;
  1007. else internalerror(17);
  1008. end;
  1009. end; }
  1010. { stores an FPU value to memory }
  1011. { location:tlocation used to free up FPU register }
  1012. { ref: destination of storage }
  1013. procedure floatstore(t : tfloattype;var location:tlocation; const ref:treference);
  1014. var
  1015. op : tasmop;
  1016. s : topsize;
  1017. begin
  1018. if location.loc <> LOC_FPU then
  1019. InternalError(34);
  1020. { no emulation }
  1021. case t of
  1022. s32real : s := S_S;
  1023. s64real : s := S_Q;
  1024. s80real : s := S_X;
  1025. else
  1026. begin
  1027. Message(cg_f_unknown_float_type);
  1028. end;
  1029. end; { end case }
  1030. if not ((cs_fp_emulation) in aktswitches) then
  1031. begin
  1032. exprasmlist^.concat(new(pai68k,op_reg_ref(A_FMOVE,s,location.fpureg,newreference(ref))));
  1033. ungetregister(location.fpureg);
  1034. end
  1035. else
  1036. { handle emulation }
  1037. begin
  1038. if t = s32real then
  1039. begin
  1040. exprasmlist^.concat(new(pai68k,op_reg_ref(A_MOVE,S_L,location.fpureg,newreference(ref))));
  1041. ungetregister32(location.fpureg);
  1042. end
  1043. else
  1044. { other floating types are not supported in emulation mode }
  1045. Message(sym_e_type_id_not_defined);
  1046. end;
  1047. location.fpureg:=R_NO; { no register in LOC_FPU now }
  1048. end;
  1049. procedure firstcomplex(p : ptree);
  1050. var
  1051. hp : ptree;
  1052. begin
  1053. { always calculate boolean AND and OR from left to right }
  1054. if ((p^.treetype=orn) or (p^.treetype=andn)) and
  1055. (p^.left^.resulttype^.deftype=orddef) and
  1056. (porddef(p^.left^.resulttype)^.typ=bool8bit) then
  1057. p^.swaped:=false
  1058. else if (p^.left^.registers32<p^.right^.registers32)
  1059. { the following check is appropriate, because all }
  1060. { 4 registers are rarely used and it is thereby }
  1061. { achieved that the extra code is being dropped }
  1062. { by exchanging not commutative operators }
  1063. and (p^.right^.registers32<=4) then
  1064. begin
  1065. hp:=p^.left;
  1066. p^.left:=p^.right;
  1067. p^.right:=hp;
  1068. p^.swaped:=true;
  1069. end
  1070. else p^.swaped:=false;
  1071. end;
  1072. procedure secondfuncret(var p : ptree);
  1073. var
  1074. hregister : tregister;
  1075. begin
  1076. clear_reference(p^.location.reference);
  1077. p^.location.reference.base:=procinfo.framepointer;
  1078. p^.location.reference.offset:=procinfo.retoffset;
  1079. if ret_in_param(procinfo.retdef) then
  1080. begin
  1081. hregister:=getaddressreg;
  1082. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVEA,S_L,newreference(p^.location.reference),hregister)));
  1083. p^.location.reference.base:=hregister;
  1084. p^.location.reference.offset:=0;
  1085. end;
  1086. end;
  1087. procedure codegen_newprocedure;
  1088. begin
  1089. aktbreaklabel:=nil;
  1090. aktcontinuelabel:=nil;
  1091. { aktexitlabel:=0; is store in oldaktexitlabel
  1092. so it must not be reset to zero before this storage !}
  1093. { the type of this lists isn't important }
  1094. { because the code of this lists is }
  1095. { copied to the code segment }
  1096. procinfo.aktentrycode:=new(paasmoutput,init);
  1097. procinfo.aktexitcode:=new(paasmoutput,init);
  1098. procinfo.aktproccode:=new(paasmoutput,init);
  1099. end;
  1100. procedure codegen_doneprocedure;
  1101. begin
  1102. dispose(procinfo.aktentrycode,done);
  1103. dispose(procinfo.aktexitcode,done);
  1104. dispose(procinfo.aktproccode,done);
  1105. end;
  1106. procedure codegen_newmodule;
  1107. begin
  1108. exprasmlist:=new(paasmoutput,init);
  1109. end;
  1110. procedure codegen_donemodule;
  1111. begin
  1112. dispose(exprasmlist,done);
  1113. dispose(codesegment,done);
  1114. dispose(bsssegment,done);
  1115. dispose(datasegment,done);
  1116. dispose(debuglist,done);
  1117. dispose(externals,done);
  1118. dispose(consts,done);
  1119. end;
  1120. end.
  1121. {
  1122. $Log$
  1123. Revision 1.1 1998-03-25 11:18:13 root
  1124. Initial revision
  1125. Revision 1.15 1998/03/22 12:45:38 florian
  1126. * changes of Carl-Eric to m68k target commit:
  1127. - wrong nodes because of the new string cg in intel, I had to create
  1128. this under m68k also ... had to work it out to fix potential alignment
  1129. problems --> this removes the crash of the m68k compiler.
  1130. - added absolute addressing in m68k assembler (required for Amiga startup)
  1131. - fixed alignment problems (because of byte return values, alignment
  1132. would not be always valid) -- is this ok if i change the offset if odd in
  1133. setfirsttemp ?? -- it seems ok...
  1134. Revision 1.14 1998/03/10 04:20:37 carl
  1135. * extdebug problems
  1136. - removed loadstring as it is not required for the m68k
  1137. Revision 1.13 1998/03/10 01:17:16 peter
  1138. * all files have the same header
  1139. * messages are fully implemented, EXTDEBUG uses Comment()
  1140. + AG... files for the Assembler generation
  1141. Revision 1.12 1998/03/09 10:44:35 peter
  1142. + string='', string<>'', string:='', string:=char optimizes (the first 2
  1143. were already in cg68k2)
  1144. Revision 1.11 1998/03/06 00:52:03 peter
  1145. * replaced all old messages from errore.msg, only ExtDebug and some
  1146. Comment() calls are left
  1147. * fixed options.pas
  1148. Revision 1.10 1998/03/03 04:12:04 carl
  1149. * moved generate routines to this unit
  1150. Revision 1.9 1998/03/02 01:48:17 peter
  1151. * renamed target_DOS to target_GO32V1
  1152. + new verbose system, merged old errors and verbose units into one new
  1153. verbose.pas, so errors.pas is obsolete
  1154. Revision 1.8 1998/02/13 10:34:45 daniel
  1155. * Made Motorola version compilable.
  1156. * Fixed optimizer
  1157. Revision 1.7 1998/02/12 11:49:50 daniel
  1158. Yes! Finally! After three retries, my patch!
  1159. Changes:
  1160. Complete rewrite of psub.pas.
  1161. Added support for DLL's.
  1162. Compiler requires less memory.
  1163. Platform units for each platform.
  1164. Revision 1.6 1998/01/11 03:39:02 carl
  1165. * bugfix of concatcopy , was using wrong reference
  1166. * bugfix of MOVEQ
  1167. Revision 1.3 1997/12/09 13:30:05 carl
  1168. + renamed some stuff
  1169. Revision 1.2 1997/12/03 13:59:01 carl
  1170. + added emitcall as in i386 version.
  1171. Revision 1.1.1.1 1997/11/27 08:32:53 michael
  1172. FPC Compiler CVS start
  1173. Pre-CVS log:
  1174. CEC Carl-Eric Codere
  1175. FK Florian Klaempfl
  1176. PM Pierre Muller
  1177. + feature added
  1178. - removed
  1179. * bug fixed or changed
  1180. History:
  1181. 27th september 1997:
  1182. + first version for MC68000 (using v093 template) (CEC)
  1183. 9th october 1997:
  1184. * fixed a bug in push_int as well as other routines which used
  1185. getregister32 while they are not supposed to (because of how
  1186. the allocation of registers work in parser.pas) (CEC)
  1187. * Fixed some bugs in the concatcopy routine, was allocating
  1188. registers which were not supposed to be allocated. (CEC)
  1189. }