From: Nick Clifton <nickc@redhat.com>
To: newlib@sourceware.org
Cc: binutils@sourceware.org
Subject: RFA: V850: Separate DATA and HEAP memory areas
Date: Mon, 23 May 2011 09:54:00 -0000 [thread overview]
Message-ID: <m3ipt1bv39.fsf@redhat.com> (raw)
Hi Jeff,
I would like permission to apply the patch below to the V850 version
of the sbrk() function in newlib and libgloss. It does two things.
Firstly it tidies up the code. Secondly it changes the start of the
heap to be based on the symbol "heap_start" rather than the symbol
"end". The importance of the second change is that it allows the heap
to be placed somewhere other than at the end of data. This means that
on a V850 board with two separate banks of memory, for example, the
stack and heap can be in one bank and the data in another. Eg:
MEMORY
{
ROM : ORIGIN = 0x00001000, LENGTH = 0x001ff000 /* 2Mb */
RAM2 (w) : ORIGIN = 0xfebf0000, LENGTH = 0x00010000 /* 64k */
STACK (w) : ORIGIN = 0xfebffff0, LENGTH = 16 /* Top of RAM2 */
RAM (w) : ORIGIN = 0xfedf0000, LENGTH = 0x00010000 /* 64k */
}
SECTIONS
{
.text :
{
*(.text)
} >ROM =0
.data :
{
PROVIDE (__datastart = .);
*(.data)
} >RAM AT>ROM
.bss :
{
*(.bss)
PROVIDE (end = .);
} >RAM
.heap :
{
KEEP (*(.heap))
PROVIDE (_heap_start = .);
} >RAM2
.stack :
{
__stack = .;
KEEP ( *(.stack) )
} > STACK
}
Ok to apply ?
Cheers
Nick
newlib/ChangeLog
2011-05-23 Nick Clifton <nickc@redhat.com>
* libc/sys/sysnecv850/sbrk.c (_sbrk): Tidy code.
Base start of heap on the "heap_start" symbol.
libgloss/ChangeLog
2011-05-23 Nick Clifton <nickc@redhat.com>
* v8500/sbrk.c (_sbrk): Tidy code.
Base start of heap on the "heap_start" symbol.
Index: newlib/libc/sys/sysnecv850/sbrk.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/sys/sysnecv850/sbrk.c,v
retrieving revision 1.1.1.1
diff -u -3 -p -r1.1.1.1 sbrk.c
--- newlib/libc/sys/sysnecv850/sbrk.c 17 Feb 2000 19:39:50 -0000 1.1.1.1
+++ newlib/libc/sys/sysnecv850/sbrk.c 23 May 2011 09:38:00 -0000
@@ -3,34 +3,27 @@
#include <sys/stat.h>
#include "sys/syscall.h"
-int errno;
-
-int __trap0 (int function, int p1, int p2, int p3);
-
-#define TRAP0(f, p1, p2, p3) __trap0(f, (int)(p1), (int)(p2), (int)(p3))
-
caddr_t
_sbrk (int incr)
{
- extern char end; /* Defined by the linker */
- static char *heap_end;
- char *prev_heap_end;
-#if 0
- char *sp = (char *)stack_ptr;
-#else
- char *sp = (char *)&sp;
-#endif
+ extern char heap_start; /* Defined by the linker script. */
+ static char * heap_end = NULL;
+ char * prev_heap_end;
+ char * sp = (char *) & sp;
+
+ if (heap_end == NULL)
+ heap_end = & heap_start;
- if (heap_end == 0)
- {
- heap_end = &end;
- }
prev_heap_end = heap_end;
+
if (heap_end + incr > sp)
{
- _write (1, "Heap and stack collision\n", 25);
+#define MESSAGE "Heap and stack collision\n"
+ _write (1, MESSAGE, sizeof MESSAGE);
abort ();
}
+
heap_end += incr;
+
return (caddr_t) prev_heap_end;
}
Index: libgloss/v850/sbrk.c
===================================================================
RCS file: /cvs/src/src/libgloss/v850/sbrk.c,v
retrieving revision 1.1
diff -u -3 -p -r1.1 sbrk.c
--- libgloss/v850/sbrk.c 23 Jul 2010 17:52:37 -0000 1.1
+++ libgloss/v850/sbrk.c 23 May 2011 09:38:00 -0000
@@ -3,34 +3,27 @@
#include <sys/stat.h>
#include "sys/syscall.h"
-int errno;
-
-int __trap0 (int function, int p1, int p2, int p3);
-
-#define TRAP0(f, p1, p2, p3) __trap0(f, (int)(p1), (int)(p2), (int)(p3))
-
caddr_t
_sbrk (int incr)
{
- extern char end; /* Defined by the linker */
- static char *heap_end;
- char *prev_heap_end;
-#if 0
- char *sp = (char *)stack_ptr;
-#else
- char *sp = (char *)&sp;
-#endif
+ extern char heap_start; /* Defined by the linker script. */
+ static char * heap_end = NULL;
+ char * prev_heap_end;
+ char * sp = (char *) & sp;
+
+ if (heap_end == NULL)
+ heap_end = & heap_start;
- if (heap_end == 0)
- {
- heap_end = &end;
- }
prev_heap_end = heap_end;
+
if (heap_end + incr > sp)
{
- _write (1, "Heap and stack collision\n", 25);
+#define MESSAGE "Heap and stack collision\n"
+ _write (1, MESSAGE, sizeof MESSAGE);
abort ();
}
+
heap_end += incr;
+
return (caddr_t) prev_heap_end;
}
PPS. Assuming that you approve the newlib/libgloss patch, I will apply
this patch to the linker sources:
Index: ld/scripttempl/v850.sc
===================================================================
RCS file: /cvs/src/src/ld/scripttempl/v850.sc,v
retrieving revision 1.10
diff -u -3 -p -r1.10 v850.sc
--- ld/scripttempl/v850.sc 10 Feb 2011 08:18:58 -0000 1.10
+++ ld/scripttempl/v850.sc 23 May 2011 09:38:00 -0000
@@ -180,6 +180,7 @@ SECTIONS
${RELOCATING+_end = . ;}
${RELOCATING+PROVIDE (end = .);}
+ ${RELOCATING+PROVIDE (_heap_start = .);}
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
next reply other threads:[~2011-05-23 9:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-23 9:54 Nick Clifton [this message]
2011-05-24 15:54 ` Jeff Johnston
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3ipt1bv39.fsf@redhat.com \
--to=nickc@redhat.com \
--cc=binutils@sourceware.org \
--cc=newlib@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).