~ubuntu-branches/debian/lenny/fpc/lenny

« back to all changes in this revision

Viewing changes to compiler/i386/n386cal.pas

  • Committer: Bazaar Package Importer
  • Author(s): Mazen Neifer, Torsten Werner, Mazen Neifer
  • Date: 2008-05-17 17:12:11 UTC
  • mfrom: (3.1.9 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080517171211-9qi33xhd9evfa0kg
Tags: 2.2.0-dfsg1-9
[ Torsten Werner ]
* Add Mazen Neifer to Uploaders field.

[ Mazen Neifer ]
* Moved FPC sources into a version dependent directory from /usr/share/fpcsrc
  to /usr/share/fpcsrc/${FPCVERSION}. This allow installing more than on FPC
  release.
* Fixed far call issue in compiler preventing building huge binearies.
  (closes: #477743)
* Updated building dependencies, recomennded and suggested packages.
* Moved fppkg to fp-utils as it is just a helper tool and is not required by
  compiler.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
{
2
 
    $Id: n386cal.pas,v 1.99 2003/11/07 15:58:32 florian Exp $
3
 
    Copyright (c) 1998-2002 by Florian Klaempfl
4
 
 
5
 
    Generate i386 assembler for in call nodes
6
 
 
7
 
    This program is free software; you can redistribute it and/or modify
8
 
    it under the terms of the GNU General Public License as published by
9
 
    the Free Software Foundation; either version 2 of the License, or
10
 
    (at your option) any later version.
11
 
 
12
 
    This program is distributed in the hope that it will be useful,
13
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
    GNU General Public License for more details.
16
 
 
17
 
    You should have received a copy of the GNU General Public License
18
 
    along with this program; if not, write to the Free Software
19
 
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
 
 
21
 
 ****************************************************************************
22
 
}
23
 
unit n386cal;
24
 
 
25
 
{$i fpcdefs.inc}
26
 
 
27
 
interface
28
 
 
29
 
{ $define AnsiStrRef}
30
 
 
31
 
    uses
32
 
      ncgcal;
33
 
 
34
 
    type
35
 
       ti386callnode = class(tcgcallnode)
36
 
       protected
37
 
          function  align_parasize:longint;override;
38
 
          procedure pop_parasize(pop_size:longint);override;
39
 
          procedure extra_interrupt_code;override;
40
 
       end;
41
 
 
42
 
 
43
 
implementation
44
 
 
45
 
    uses
46
 
      globtype,systems,
47
 
      cutils,verbose,globals,
48
 
{$ifdef GDB}
49
 
      gdb,
50
 
{$endif GDB}
51
 
      cgbase,
52
 
      cpubase,paramgr,
53
 
      aasmtai,aasmcpu,
54
 
      ncal,nbas,nmem,nld,ncnv,
55
 
      cga,cgobj,cpuinfo;
56
 
 
57
 
 
58
 
{*****************************************************************************
59
 
                             TI386CALLNODE
60
 
*****************************************************************************}
61
 
 
62
 
 
63
 
    procedure ti386callnode.extra_interrupt_code;
64
 
      begin
65
 
        emit_none(A_PUSHF,S_L);
66
 
        emit_reg(A_PUSH,S_L,NR_CS);
67
 
      end;
68
 
 
69
 
 
70
 
    function ti386callnode.align_parasize:longint;
71
 
      var
72
 
         pop_size : longint;
73
 
{$ifdef OPTALIGN}
74
 
         pop_esp : boolean;
75
 
         push_size : longint;
76
 
{$endif OPTALIGN}
77
 
         i : integer;
78
 
      begin
79
 
        pop_size:=0;
80
 
        { This parasize aligned on 4 ? }
81
 
        i:=pushedparasize and 3;
82
 
        if i>0 then
83
 
         inc(pop_size,4-i);
84
 
        { insert the opcode and update pushedparasize }
85
 
        { never push 4 or more !! }
86
 
        pop_size:=pop_size mod 4;
87
 
        if pop_size>0 then
88
 
         begin
89
 
           inc(pushedparasize,pop_size);
90
 
           exprasmlist.concat(taicpu.op_const_reg(A_SUB,S_L,pop_size,NR_ESP));
91
 
{$ifdef GDB}
92
 
           if (cs_debuginfo in aktmoduleswitches) and
93
 
              (exprasmList.first=exprasmList.last) then
94
 
             exprasmList.concat(Tai_force_line.Create);
95
 
{$endif GDB}
96
 
         end;
97
 
{$ifdef OPTALIGN}
98
 
         if pop_allowed and (cs_align in aktglobalswitches) then
99
 
           begin
100
 
              pop_esp:=true;
101
 
              push_size:=pushedparasize;
102
 
              { !!!! here we have to take care of return type, self
103
 
                and nested procedures
104
 
              }
105
 
              inc(push_size,12);
106
 
              emit_reg_reg(A_MOV,S_L,rsp,R_EDI);
107
 
              if (push_size mod 8)=0 then
108
 
                emit_const_reg(A_AND,S_L,$fffffff8,rsp)
109
 
              else
110
 
                begin
111
 
                   emit_const_reg(A_SUB,S_L,push_size,rsp);
112
 
                   emit_const_reg(A_AND,S_L,$fffffff8,rsp);
113
 
                   emit_const_reg(A_SUB,S_L,push_size,rsp);
114
 
                end;
115
 
              r.enum:=R_INTREGISTER;
116
 
              r.number:=R_EDI;
117
 
              emit_reg(A_PUSH,S_L,r);
118
 
           end
119
 
         else
120
 
           pop_esp:=false;
121
 
{$endif OPTALIGN}
122
 
        align_parasize:=pop_size;
123
 
      end;
124
 
 
125
 
 
126
 
    procedure ti386callnode.pop_parasize(pop_size:longint);
127
 
      var
128
 
        hreg : tregister;
129
 
      begin
130
 
        { better than an add on all processors }
131
 
        if pop_size=4 then
132
 
          begin
133
 
            hreg:=cg.getintregister(exprasmlist,OS_INT);
134
 
            exprasmlist.concat(taicpu.op_reg(A_POP,S_L,hreg));
135
 
            cg.ungetregister(exprasmlist,hreg);
136
 
          end
137
 
        { the pentium has two pipes and pop reg is pairable }
138
 
        { but the registers must be different!        }
139
 
        else
140
 
          if (pop_size=8) and
141
 
             not(cs_littlesize in aktglobalswitches) and
142
 
             (aktoptprocessor=ClassPentium) then
143
 
            begin
144
 
               hreg:=cg.getintregister(exprasmlist,OS_INT);
145
 
               exprasmlist.concat(taicpu.op_reg(A_POP,S_L,hreg));
146
 
               cg.ungetregister(exprasmlist,hreg);
147
 
               hreg:=cg.getintregister(exprasmlist,OS_INT);
148
 
               exprasmlist.concat(taicpu.op_reg(A_POP,S_L,hreg));
149
 
               cg.ungetregister(exprasmlist,hreg);
150
 
            end
151
 
        else
152
 
          if pop_size<>0 then
153
 
            exprasmlist.concat(taicpu.op_const_reg(A_ADD,S_L,pop_size,NR_ESP));
154
 
 
155
 
{$ifdef OPTALIGN}
156
 
        if pop_esp then
157
 
          emit_reg(A_POP,S_L,NR_ESP);
158
 
{$endif OPTALIGN}
159
 
      end;
160
 
 
161
 
 
162
 
begin
163
 
   ccallnode:=ti386callnode;
164
 
end.
165
 
{
166
 
  $Log: n386cal.pas,v $
167
 
  Revision 1.99  2003/11/07 15:58:32  florian
168
 
    * Florian's culmutative nr. 1; contains:
169
 
      - invalid calling conventions for a certain cpu are rejected
170
 
      - arm softfloat calling conventions
171
 
      - -Sp for cpu dependend code generation
172
 
      - several arm fixes
173
 
      - remaining code for value open array paras on heap
174
 
 
175
 
  Revision 1.98  2003/10/10 17:48:14  peter
176
 
    * old trgobj moved to x86/rgcpu and renamed to trgx86fpu
177
 
    * tregisteralloctor renamed to trgobj
178
 
    * removed rgobj from a lot of units
179
 
    * moved location_* and reference_* to cgobj
180
 
    * first things for mmx register allocation
181
 
 
182
 
  Revision 1.97  2003/10/09 21:31:37  daniel
183
 
    * Register allocator splitted, ans abstract now
184
 
 
185
 
  Revision 1.96  2003/10/01 20:34:49  peter
186
 
    * procinfo unit contains tprocinfo
187
 
    * cginfo renamed to cgbase
188
 
    * moved cgmessage to verbose
189
 
    * fixed ppc and sparc compiles
190
 
 
191
 
  Revision 1.95  2003/09/23 17:56:06  peter
192
 
    * locals and paras are allocated in the code generation
193
 
    * tvarsym.localloc contains the location of para/local when
194
 
      generating code for the current procedure
195
 
 
196
 
  Revision 1.94  2003/09/03 15:55:01  peter
197
 
    * NEWRA branch merged
198
 
 
199
 
  Revision 1.93.2.1  2003/08/29 17:29:00  peter
200
 
    * next batch of updates
201
 
 
202
 
  Revision 1.93  2003/05/30 23:57:08  peter
203
 
    * more sparc cleanup
204
 
    * accumulator removed, splitted in function_return_reg (called) and
205
 
      function_result_reg (caller)
206
 
 
207
 
  Revision 1.92  2003/05/26 21:17:18  peter
208
 
    * procinlinenode removed
209
 
    * aktexit2label removed, fast exit removed
210
 
    + tcallnode.inlined_pass_2 added
211
 
 
212
 
  Revision 1.91  2003/05/22 21:32:29  peter
213
 
    * removed some unit dependencies
214
 
 
215
 
  Revision 1.90  2003/04/23 14:42:08  daniel
216
 
    * Further register allocator work. Compiler now smaller with new
217
 
      allocator than without.
218
 
    * Somebody forgot to adjust ppu version number
219
 
 
220
 
  Revision 1.89  2003/04/22 14:33:38  peter
221
 
    * removed some notes/hints
222
 
 
223
 
  Revision 1.88  2003/04/22 10:09:35  daniel
224
 
    + Implemented the actual register allocator
225
 
    + Scratch registers unavailable when new register allocator used
226
 
    + maybe_save/maybe_restore unavailable when new register allocator used
227
 
 
228
 
  Revision 1.87  2003/04/04 15:38:56  peter
229
 
    * moved generic code from n386cal to ncgcal, i386 now also
230
 
      uses the generic ncgcal
231
 
 
232
 
  Revision 1.86  2003/03/30 20:59:07  peter
233
 
    * fix classmethod from classmethod call
234
 
    * move BeforeDestruction/AfterConstruction calls to
235
 
      genentrycode/genexitcode instead of generating them on the fly
236
 
      after a call to a constructor
237
 
 
238
 
  Revision 1.85  2003/03/28 19:16:57  peter
239
 
    * generic constructor working for i386
240
 
    * remove fixed self register
241
 
    * esi added as address register for i386
242
 
 
243
 
  Revision 1.84  2003/03/13 19:52:23  jonas
244
 
    * and more new register allocator fixes (in the i386 code generator this
245
 
      time). At least now the ppc cross compiler can compile the linux
246
 
      system unit again, but I haven't tested it.
247
 
 
248
 
  Revision 1.83  2003/03/06 11:35:50  daniel
249
 
    * Fixed internalerror 7843 issue
250
 
 
251
 
  Revision 1.82  2003/02/19 22:00:15  daniel
252
 
    * Code generator converted to new register notation
253
 
    - Horribily outdated todo.txt removed
254
 
 
255
 
  Revision 1.81  2003/01/30 21:46:57  peter
256
 
    * self fixes for static methods (merged)
257
 
 
258
 
  Revision 1.80  2003/01/13 18:37:44  daniel
259
 
    * Work on register conversion
260
 
 
261
 
  Revision 1.79  2003/01/08 18:43:57  daniel
262
 
   * Tregister changed into a record
263
 
 
264
 
  Revision 1.78  2002/12/15 21:30:12  florian
265
 
    * tcallnode.paraitem introduced, all references to defcoll removed
266
 
 
267
 
  Revision 1.77  2002/11/27 20:05:06  peter
268
 
    * cdecl array of const fixes
269
 
 
270
 
  Revision 1.76  2002/11/25 17:43:26  peter
271
 
    * splitted defbase in defutil,symutil,defcmp
272
 
    * merged isconvertable and is_equal into compare_defs(_ext)
273
 
    * made operator search faster by walking the list only once
274
 
 
275
 
  Revision 1.75  2002/11/18 17:32:00  peter
276
 
    * pass proccalloption to ret_in_xxx and push_xxx functions
277
 
 
278
 
  Revision 1.74  2002/11/15 01:58:57  peter
279
 
    * merged changes from 1.0.7 up to 04-11
280
 
      - -V option for generating bug report tracing
281
 
      - more tracing for option parsing
282
 
      - errors for cdecl and high()
283
 
      - win32 import stabs
284
 
      - win32 records<=8 are returned in eax:edx (turned off by default)
285
 
      - heaptrc update
286
 
      - more info for temp management in .s file with EXTDEBUG
287
 
 
288
 
  Revision 1.73  2002/10/05 12:43:29  carl
289
 
    * fixes for Delphi 6 compilation
290
 
     (warning : Some features do not work under Delphi)
291
 
 
292
 
  Revision 1.72  2002/09/17 18:54:03  jonas
293
 
    * a_load_reg_reg() now has two size parameters: source and dest. This
294
 
      allows some optimizations on architectures that don't encode the
295
 
      register size in the register name.
296
 
 
297
 
  Revision 1.71  2002/09/16 19:07:37  peter
298
 
    * push 0 instead of VMT when calling a constructor from a member
299
 
 
300
 
  Revision 1.70  2002/09/07 15:25:10  peter
301
 
    * old logs removed and tabs fixed
302
 
 
303
 
  Revision 1.69  2002/09/01 18:43:27  peter
304
 
    * include FUNCTION_RETURN_REG in regs_to_push list
305
 
 
306
 
  Revision 1.68  2002/09/01 12:13:00  peter
307
 
    * use a_call_reg
308
 
    * ungetiftemp for procvar of object temp
309
 
 
310
 
  Revision 1.67  2002/08/25 19:25:21  peter
311
 
    * sym.insert_in_data removed
312
 
    * symtable.insertvardata/insertconstdata added
313
 
    * removed insert_in_data call from symtable.insert, it needs to be
314
 
      called separatly. This allows to deref the address calculation
315
 
    * procedures now calculate the parast addresses after the procedure
316
 
      directives are parsed. This fixes the cdecl parast problem
317
 
    * push_addr_param has an extra argument that specifies if cdecl is used
318
 
      or not
319
 
 
320
 
  Revision 1.66  2002/08/23 16:14:49  peter
321
 
    * tempgen cleanup
322
 
    * tt_noreuse temp type added that will be used in genentrycode
323
 
 
324
 
  Revision 1.65  2002/08/18 20:06:30  peter
325
 
    * inlining is now also allowed in interface
326
 
    * renamed write/load to ppuwrite/ppuload
327
 
    * tnode storing in ppu
328
 
    * nld,ncon,nbas are already updated for storing in ppu
329
 
 
330
 
  Revision 1.64  2002/08/17 09:23:45  florian
331
 
    * first part of procinfo rewrite
332
 
 
333
 
  Revision 1.63  2002/08/12 15:08:42  carl
334
 
    + stab register indexes for powerpc (moved from gdb to cpubase)
335
 
    + tprocessor enumeration moved to cpuinfo
336
 
    + linker in target_info is now a class
337
 
    * many many updates for m68k (will soon start to compile)
338
 
    - removed some ifdef or correct them for correct cpu
339
 
 
340
 
  Revision 1.62  2002/08/11 14:32:30  peter
341
 
    * renamed current_library to objectlibrary
342
 
 
343
 
  Revision 1.61  2002/08/11 13:24:16  peter
344
 
    * saving of asmsymbols in ppu supported
345
 
    * asmsymbollist global is removed and moved into a new class
346
 
      tasmlibrarydata that will hold the info of a .a file which
347
 
      corresponds with a single module. Added librarydata to tmodule
348
 
      to keep the library info stored for the module. In the future the
349
 
      objectfiles will also be stored to the tasmlibrarydata class
350
 
    * all getlabel/newasmsymbol and friends are moved to the new class
351
 
 
352
 
  Revision 1.60  2002/07/20 11:58:01  florian
353
 
    * types.pas renamed to defbase.pas because D6 contains a types
354
 
      unit so this would conflicts if D6 programms are compiled
355
 
    + Willamette/SSE2 instructions to assembler added
356
 
 
357
 
  Revision 1.59  2002/07/11 14:41:33  florian
358
 
    * start of the new generic parameter handling
359
 
 
360
 
  Revision 1.58  2002/07/07 09:52:34  florian
361
 
    * powerpc target fixed, very simple units can be compiled
362
 
    * some basic stuff for better callparanode handling, far from being finished
363
 
 
364
 
  Revision 1.57  2002/07/06 20:27:26  carl
365
 
  + generic set handling
366
 
 
367
 
  Revision 1.56  2002/07/01 18:46:31  peter
368
 
    * internal linker
369
 
    * reorganized aasm layer
370
 
 
371
 
  Revision 1.55  2002/07/01 16:23:56  peter
372
 
    * cg64 patch
373
 
    * basics for currency
374
 
    * asnode updates for class and interface (not finished)
375
 
 
376
 
  Revision 1.54  2002/05/20 13:30:40  carl
377
 
  * bugfix of hdisponen (base must be set, not index)
378
 
  * more portability fixes
379
 
 
380
 
  Revision 1.53  2002/05/18 13:34:23  peter
381
 
    * readded missing revisions
382
 
 
383
 
  Revision 1.52  2002/05/16 19:46:51  carl
384
 
  + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
385
 
  + try to fix temp allocation (still in ifdef)
386
 
  + generic constructor calls
387
 
  + start of tassembler / tmodulebase class cleanup
388
 
 
389
 
  Revision 1.50  2002/05/13 19:54:38  peter
390
 
    * removed n386ld and n386util units
391
 
    * maybe_save/maybe_restore added instead of the old maybe_push
392
 
 
393
 
  Revision 1.49  2002/05/12 16:53:17  peter
394
 
    * moved entry and exitcode to ncgutil and cgobj
395
 
    * foreach gets extra argument for passing local data to the
396
 
      iterator function
397
 
    * -CR checks also class typecasts at runtime by changing them
398
 
      into as
399
 
    * fixed compiler to cycle with the -CR option
400
 
    * fixed stabs with elf writer, finally the global variables can
401
 
      be watched
402
 
    * removed a lot of routines from cga unit and replaced them by
403
 
      calls to cgobj
404
 
    * u32bit-s32bit updates for and,or,xor nodes. When one element is
405
 
      u32bit then the other is typecasted also to u32bit without giving
406
 
      a rangecheck warning/error.
407
 
    * fixed pascal calling method with reversing also the high tree in
408
 
      the parast, detected by tcalcst3 test
409
 
 
410
 
}