This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Committed, MMIX: mark dynamically allocated memory.


I just committed the static-allocation part to the gcc repo,
cf. <http://gcc.gnu.org/ml/gcc-patches/2012-10/msg01871.html>.  Here's
the part for dynamic allocation.  Right, there's no un-marking for
deallocation; I'm keeping this as simple as possible (but not simpler).

	* libc/sys/mmixware/sbrk.c (_sbrk): Drop unused extern declaration
	of "end".  Mark allocated memory by applying PRELD.

Index: sbrk.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/sys/mmixware/sbrk.c,v
retrieving revision 1.3
diff -p -u -r1.3 sbrk.c
--- sbrk.c	18 Nov 2001 23:47:59 -0000	1.3
+++ sbrk.c	21 Oct 2012 03:40:08 -0000
@@ -1,6 +1,6 @@
 /* sbrk for MMIXware.

-   Copyright (C) 2001 Hans-Peter Nilsson
+   Copyright (C) 2001, 2012 Hans-Peter Nilsson

    Permission to use, copy, modify, and distribute this software is
    freely granted, provided that the above copyright notice, this notice
@@ -34,10 +34,26 @@ __asm__ (" .global _Sbrk_high\n"
 caddr_t
 _sbrk (size_t incr)
 {
-  extern char end;		/* Defined by the linker */
   char *prev_heap_end;

   prev_heap_end = _Sbrk_high;
+
+  /* A simulator that requires explicit memory allocation is expected
+     to hook that to the PRELD data prefetch insn, which is otherwise
+     typically a nop.  */
+  if ((long) incr > 0)
+    {
+      size_t n = incr;
+      char *p = prev_heap_end;
+#define A(N) __asm__ ("preld " #N ",%0,0" : : "r" (p))
+#define PRELDOWNTO(N) while (n >= N + 1) { A(N); n -= N + 1; p += N + 1; }
+
+      PRELDOWNTO (255);
+      PRELDOWNTO (31);
+      PRELDOWNTO (3);
+      PRELDOWNTO (0);
+    }
+
   _Sbrk_high += incr;
   return (caddr_t) prev_heap_end;
 }

brgds, H-P


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]