summaryrefslogtreecommitdiff
path: root/fpcsrc/tests/test/tcg1.pp
blob: bd8f702c83fa7c240928d91ea89e1fb70207dd6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
{ %CPU=i386 }
{$R-}
program test_register_pushing;

var
  before, after : longint;
  wpush,lpush : longint;
const
  haserror : boolean = false;

begin
{$ifdef CPUI386}
{$asmmode att}
  asm
{$ifndef FPC_PIC}
    movl   %esp,before
    pushw  %es
    movl   %esp,after
    popw   %es
{$else not FPC_PIC}
    call   .LPIC
.LPIC:
    popl   %ecx
{$ifdef darwin}
    movl   %esp,before-.LPIC(%ecx)
    pushw  %es
    movl   %esp,after-.LPIC(%ecx)
    popw   %es
{$else darwin}
    addl   $_GLOBAL_OFFSET_TABLE_,%ecx
    movl   %esp,before@GOT(%ecx)
    pushw  %es
    movl   %esp,after@GOT(%ecx)
    popw   %es
{$endif darwin}
{$endif not FPC_PIC}
  end;
  wpush:=before-after;
  if wpush<>2 then
    begin
      Writeln('Compiler does not push "pushw %es" into 2 bytes');
      haserror:=true;
    end;
  asm
{$ifndef FPC_PIC}
    movl   %esp,before
    pushl  %es
    movl   %esp,after
    popl   %es
{$else not FPC_PIC}
    call   .LPIC
.LPIC:
    popl   %ecx
{$ifdef darwin}
    movl   %esp,before-.LPIC(%ecx)
    pushl  %es
    movl   %esp,after-.LPIC(%ecx)
    popl   %es
{$else darwin}
    addl   $_GLOBAL_OFFSET_TABLE_,%ecx
    movl   %esp,before@GOT(%ecx)
    pushl  %es
    movl   %esp,after@GOT(%ecx)
    popl   %es
{$endif darwin}
{$endif not FPC_PIC}
  end;
  lpush:=before-after;

  if lpush<>4 then
    begin
      Writeln('Compiler does not push "pushl %es" into 4 bytes');
      haserror:=true;
    end;

  asm
{$ifndef FPC_PIC}
    movl   %esp,before
    pushw  %gs
    movl   %esp,after
    popw   %gs
{$else not FPC_PIC}
    call   .LPIC
.LPIC:
    popl   %ecx
{$ifdef darwin}
    movl   %esp,before-.LPIC(%ecx)
    pushw  %gs
    movl   %esp,after-.LPIC(%ecx)
    popw   %gs
{$else darwin}
    addl   $_GLOBAL_OFFSET_TABLE_,%ecx
    movl   %esp,before@GOT(%ecx)
    pushw  %gs
    movl   %esp,after@GOT(%ecx)
    popw   %gs
{$endif darwin}
{$endif not FPC_PIC}
  end;
  wpush:=before-after;
  if wpush<>2 then
    begin
      Writeln('Compiler does not push "pushw %gs" into 2 bytes');
      haserror:=true;
    end;
  asm
{$ifndef FPC_PIC}
    movl   %esp,before
    pushl  %gs
    movl   %esp,after
    popl   %gs
{$else not FPC_PIC}
    call   .LPIC
.LPIC:
    popl   %ecx
{$ifdef darwin}
    movl   %esp,before-.LPIC(%ecx)
    pushl  %gs
    movl   %esp,after-.LPIC(%ecx)
    popl   %gs
{$else darwin}
    addl   $_GLOBAL_OFFSET_TABLE_,%ecx
    movl   %esp,before@GOT(%ecx)
    pushl  %gs
    movl   %esp,after@GOT(%ecx)
    popl   %gs
{$endif darwin}
{$endif not FPC_PIC}
  end;
  lpush:=before-after;

  if lpush<>4 then
    begin
      Writeln('Compiler does not push "pushl %gs" into 4 bytes');
      haserror:=true;
    end;
{$asmmode intel}
  asm
{$ifndef FPC_PIC}
    mov    before,esp
    push   es
    mov    after,esp
    pop    es
{$else not FPC_PIC}
    call   @@LPIC
@@LPIC:
    pop    ecx
{$ifdef darwin}
    mov    [before-@@LPIC+ecx],esp
    push   es
    mov    [after-@@LPIC+ecx],esp
    pop    es
{$else darwin}
    add    ecx,@_GLOBAL_OFFSET_TABLE_
    mov    [ecx].OFFSET before,esp
    push   es
    mov    [ecx].OFFSET after,esp
    pop    es
{$endif darwin}
{$endif not FPC_PIC}
  end;
  Writeln('Intel "push es" uses ',before-after,' bytes');
{$endif CPUI386}
  if haserror then
    Halt(1);
end.