Oberon Community Platform Forum
November 22, 2019, 06:49:29 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Assembler Code Which Never Trapped Before Now Does  (Read 2573 times)
soren renner
Global Moderator
Full Member
*****
Posts: 216



« on: February 26, 2011, 02:46:44 AM »

sr@aptosidbox:~/dev/xenopus$ cat trap.text

UnixAos (0.94/r3849) for Linux

Trap   11 (Segmentation violation)
SP = 00000000H, FP = D925B00CH, PC = ED2806F7H

XNPSE.E:8 pc=15 [0000000FH] = 7 + 8
  p=Rec@00000004H
  ijk=Rec@00000008H
  in=  0.000000E+000,   0.000000E+000,   0.000000E+000
  out=
UnixAos (0.94/r3849) for Linux

==== recursive Trap  11 (Segmentation violation)


----------------------------------------------------
sr@aptosidbox:~/dev/xenopus$





MODULE XNPSE;
IMPORT SYSTEM, XNPSBase;

(* procedure for casting real array to integer array. From Patrik Reali ETHZ 2000*)

PROCEDURE E*(VAR p: XNPSBase.PT; VAR ijk: XNPSBase.IPT);
VAR
   in: ARRAY 3 OF REAL;
   out: ARRAY 3 OF INTEGER;
BEGIN
   in[0]:=p.x;in[1]:=p.y; in[2]:=p.z;
   Eprime(in,out);
   ijk.i:=out[0]; ijk.j:=out[1]; ijk.k:=out[2];
END E;

PROCEDURE Eprime(VAR in:ARRAY OF REAL; VAR out: ARRAY OF INTEGER);
CODE {SYSTEM.i386, SYSTEM.FPU}
   MOV   EDI, [EBP+8]         ; dest   = ADR(out)
   MOV   ECX, [EBP+12]       ; count  = LEN(out)
   MOV   ESI, [EBP+16]        ; source = ADR(in)
   CMP   ECX, [EBP+20]
   JGE   Ok
   PUSH  99                  ; LEN(in) > LEN(out)  then TRAP(99)
   INT   3
Ok:
   SUB   ESP, 8              ; change FPU rounding to "chop"
   FSTCW [ESP]
   FWAIT
   MOV   EBX, [ESP]
   OR    EBX, 0400H          ; clear bit 10,11 (chop/truncate toward zero)
   MOV   [ESP+4], EBX
   FLDCW [ESP+4]
   JMP   Check
Loop:
   DEC   ECX
   FLD   DWORD [ESI+ECX*4]  ; in: REAL
   FISTP WORD [EDI+ECX*2]   ; out: INTEGER
   FWAIT
Check:
   CMP   ECX, 0
   JG    Loop
   FLDCW [ESP]               ; restore original FPU configuration
   ADD   ESP, 8
END Eprime;

PROCEDURE E2*(in: XNPSBase.PT; VAR out: XNPSBase.IPT);
(*
BEGIN
   ROUND(in[0], out[0]);
   ROUND(in[1], out[1]);
   ROUND(in[2], out[2]); *)
END E2;

(* PROCEDURE ROUND(x: REAL; VAR y: LONGINT);
CODE {SYSTEM.i386, SYSTEM.FPU}
       FLD x[EBP]
       MOV EAX, y[EBP]
       FISTP DWORD 0[EAX]
END ROUND;

PROCEDURE ROUND(x: LONGREAL; VAR y: LONGINT);
CODE {SYSTEM.i386, SYSTEM.FPU}
       FLD [EBP+x]
       MOV EAX, [EBP+y]
       FISTP DWORD [EAX]
END ROUND; *)

PROCEDURE -ROUND*(x: REAL; VAR y: LONGINT);
CODE {SYSTEM.i386, SYSTEM.FPU}
       POP EAX
       FLD DWORD [EBP]
       ADD ESP, 4
       FISTP DWORD [EAX]
END ROUND;

(* PROCEDURE -ROUND(x: LONGREAL; VAR y: LONGINT);
CODE {SYSTEM.i386, SYSTEM.FPU}
       POP EAX
       FLD QWORD [EBP]
       ADD ESP, 8
       FISTP DWORD [EAX]
END ROUND;
*)

END XNPSE.

Logged
soren renner
Global Moderator
Full Member
*****
Posts: 216



« Reply #1 on: February 26, 2011, 03:22:12 AM »

It might be a new kind of stack overflow trap.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!