Browse Source

Modify test to take into account the specific prologue for Huge model

git-svn-id: trunk@34016 -
pierre 9 years ago
parent
commit
dfeadf89e9
1 changed files with 48 additions and 6 deletions
  1. 48 6
      tests/test/cpu16/i8086/tfarcal1.pp

+ 48 - 6
tests/test/cpu16/i8086/tfarcal1.pp

@@ -15,6 +15,7 @@
   {$endif}
   {$ifdef FPC_MM_HUGE}
     {$define TEST_ENABLED}
+    {$define NEED_POP_DS}
   {$endif}
 {$ELSE FPC}
   {$define TEST_ENABLED}
@@ -33,12 +34,12 @@ var
   SavedSP: Word;
   Bug: Boolean;
 
-procedure CheckBug;
+procedure CheckBug(i : byte);
 begin
   if Bug then
   begin
     Writeln('FAIL!!!');
-    halt(1);
+    halt(i);
   end
   else
     Writeln('OK');
@@ -46,14 +47,31 @@ end;
 
 procedure farretproc; assembler;
 asm
+  { Huge mode generates:
+    push  ds
+    mov   ax,TFARCAL1_DATA
+    mov   ds,ax
+    sequence }
+{$ifdef NEED_POP_DS}
+    pop ds
+{$endif def NEED_POP_DS}
   { hardcode it with db, because the compiler could generate a near ret, due
     to some bug }
   db $CB  { RETF }
 end;
 
+procedure farretproc2; assembler; {$ifdef FPC} nostackframe;{$endif FPC}
+asm
+  { hardcode it with db, because the compiler could generate a near ret, due
+    to some bug }
+  { For huge mode, the sequence described above
+    is not generated here }
+  db $CB  { RETF }
+end;
+
 procedure testfarcall;
 label
-  NoBug;
+  NoBug1, NoBug2;
 begin
   Write('Testing call farretproc...');
   asm
@@ -70,15 +88,39 @@ begin
 
     xor ax, ax
     cmp SavedSP, sp
-    je NoBug
+    je NoBug1
+    mov sp, SavedSP  { restore the broken SP }
+    inc ax
+NoBug1:
+    mov Bug, al
+    pop bx  { pop the saved CS }
+    sti
+  end;
+  CheckBug(1);
+  Write('Testing call farretproc2 with nostackframe modifier ...');
+  asm
+    cli
+
+    { in case of a near call, the retf will pop this word and we'll detect the
+      bug without crashing }
+    push cs
+
+    mov SavedSP, sp
+
+    { this should emit a far call }
+    call farretproc2
+
+    xor ax, ax
+    cmp SavedSP, sp
+    je NoBug2
     mov sp, SavedSP  { restore the broken SP }
     inc ax
-NoBug:
+NoBug2:
     mov Bug, al
     pop bx  { pop the saved CS }
     sti
   end;
-  CheckBug;
+  CheckBug(2);
 end;
 
 begin