_sbrk for Hitachi H8/300 and H8/300H
Giovanni Caterina
giova@idtech.be
Wed Sep 9 05:12:00 GMT 1998
Hello,
First of all, I'm not one of your customers.
I use the gcc cross compiler with your newlib 1.8.1.
May I suggest you the following correction to your module sbrk.c for
the Hitachi H8/300(H) :
---------------------------------------------------------------------
#include <_ansi.h>
#include <sys/types.h>
#include <sys/stat.h>
register char *stack_ptr asm ("sp");
caddr_t
_sbrk(incr)
int incr;
{
extern char end; /* Defined by the linker */
static char *heap_end;
char *prev_heap_end;
if (heap_end == 0)
{
heap_end = &end;
}
/* Correction */
if((short)heap_end & 1) ++heap_end;
/*
This ensures that the allocated space always begins
at an even address. We need this because it can contain
any type of data and the processor can access words
(and long words for 300H) ONLY ON EVEN addresses and since
we can allocate an odd number of bytes ... !!!
*/
/* end of correction */
prev_heap_end = heap_end;
if (heap_end + incr > stack_ptr)
{
_write (1, "Heap and stack collision\n", 25);
abort ();
}
heap_end += incr;
return (caddr_t)prev_heap_end;
}
---------------------------------------------------------------------
Best regards,
Giovanni Caterina
--------------------------------------------------------------------------
e-mail : Giova@idtech.be
___ ____ _ _ IDtech S.A.
|_ _| _ \| |_ ___ ___| |__ 62, rue Saucin
| || | | | __/ _ \/ __| '_ \ B-5032 Gembloux Tel : (32) 81/55.46.10
| || |_| | || __/ (__| | | | Belgium Fax : (32) 81/55.46.58
|___|____/ \__\___|\___|_| |_|
Access Control, Time Attendance, Alarm Monitoring... info@idtech.be
--------------------------------------------------------------------------
More information about the Newlib
mailing list