cga68k.pas 50 KB

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