From 426d21fbd177f759fe3108d513363bf884cae1ac Mon Sep 17 00:00:00 2001
From: pierre <pierre@freepascal.org>
Date: Thu, 12 Jul 2012 09:13:31 +0000
Subject: [PATCH]  Use need system macro FPC_LOCALS_ARE_STACK_REG_RELATIVE for
 mips support

git-svn-id: trunk@21897 -
---
 rtl/inc/objects.pp | 39 +++++++++++++++++++++++++++++++++------
 1 file changed, 33 insertions(+), 6 deletions(-)

diff --git a/rtl/inc/objects.pp b/rtl/inc/objects.pp
index 714a0bf13a..64f49df7c3 100644
--- a/rtl/inc/objects.pp
+++ b/rtl/inc/objects.pp
@@ -1906,8 +1906,17 @@ VAR I: LongInt;
 BEGIN
    For I := Count DownTo 1 Do
      Begin                   { Down from last item }
-       IF Boolean(Byte(ptruint(CallPointerLocal(Test,get_caller_frame(
-               get_frame,get_pc_addr),Items^[I-1])))) THEN
+       IF Boolean(Byte(ptruint(CallPointerLocal(Test,
+         { On most systems, locals are accessed relative to base pointer,
+           but for MIPS cpu, they are accessed relative to stack pointer.
+           This needs adaptation for so low level routines,
+           like MethodPointerLocal and related objects unit functions. }
+{$ifndef FPC_LOCALS_ARE_STACK_REG_RELATIVE}
+         get_caller_frame(get_frame,get_pc_addr)
+{$else}
+         get_frame
+{$endif}
+         ,Items^[I-1])))) THEN
        Begin          { Test each item }
          LastThat := Items^[I-1];                     { Return item }
          Exit;                                        { Now exit }
@@ -1924,8 +1933,17 @@ FUNCTION TCollection.FirstThat (Test: Pointer): Pointer;
 VAR I: LongInt;
 BEGIN
    For I := 1 To Count Do Begin                       { Up from first item }
-     IF Boolean(Byte(ptruint(CallPointerLocal(Test,get_caller_frame(
-             get_frame,get_pc_addr),Items^[I-1])))) THEN
+     IF Boolean(Byte(ptruint(CallPointerLocal(Test,
+         { On most systems, locals are accessed relative to base pointer,
+           but for MIPS cpu, they are accessed relative to stack pointer.
+           This needs adaptation for so low level routines,
+           like MethodPointerLocal and related objects unit functions. }
+{$ifndef FPC_LOCALS_ARE_STACK_REG_RELATIVE}
+         get_caller_frame(get_frame,get_pc_addr)
+{$else}
+         get_frame
+{$endif}
+         ,Items^[I-1])))) THEN
        Begin          { Test each item }
        FirstThat := Items^[I-1];                      { Return item }
        Exit;                                          { Now exit }
@@ -2044,8 +2062,17 @@ PROCEDURE TCollection.ForEach (Action: Pointer);
 VAR I: LongInt;
 BEGIN
    For I := 1 To Count Do                             { Up from first item }
-    CallPointerLocal(Action,get_caller_frame(
-            get_frame,get_pc_addr),Items^[I-1]);   { Call with each item }
+    CallPointerLocal(Action,
+      { On most systems, locals are accessed relative to base pointer,
+        but for MIPS cpu, they are accessed relative to stack pointer.
+        This needs adaptation for so low level routines,
+        like MethodPointerLocal and related objects unit functions. }
+{$ifndef FPC_LOCALS_ARE_STACK_REG_RELATIVE}
+      get_caller_frame(get_frame,get_pc_addr)
+{$else}
+      get_frame
+{$endif}
+      ,Items^[I-1]);   { Call with each item }
 END;
 {$POP}