From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8194 invoked by alias); 23 May 2011 09:54:02 -0000 Received: (qmail 8171 invoked by uid 22791); 23 May 2011 09:54:00 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 23 May 2011 09:53:42 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p4N9rgb1018165 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 23 May 2011 05:53:42 -0400 Received: from Gift.redhat.com (vpn2-10-243.ams2.redhat.com [10.36.10.243]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p4N9rds8001905; Mon, 23 May 2011 05:53:40 -0400 From: Nick Clifton 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 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-IsSubscribed: yes Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2011-05/txt/msg00305.txt.bz2 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 * libc/sys/sysnecv850/sbrk.c (_sbrk): Tidy code. Base start of heap on the "heap_start" symbol. libgloss/ChangeLog 2011-05-23 Nick Clifton * 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 #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 #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) }