1 /*
2 		    Low Level Interface Library
3            Copyright 1983-2000 Green Hills Software,Inc.
4 
5  *  This program is the property of Green Hills Software, Inc,
6  *  its contents are proprietary information and no part of it
7  *  is to be disclosed to anyone except employees of Green Hills
8  *  Software, Inc., or as agreed in writing signed by the President
9  *  of Green Hills Software, Inc.
10 */
11 /* ind_heap.c: Machine Independent low-level heap growth facilities. */
12 
13 #include "indos.h"
14 #include <string.h>		/* for memset() */
15 #include "ind_thrd.h"
16 #include <stdint.h>
17 
18 #if defined(EMBEDDED)
19 
20 #if 1 // CAFE MOD
21 void *__ghs_alloc (int size, int align);
22 #endif // CAFE MOD
23 
24 #if 0 // CAFE GHS ORIG
25 /******************************************************************************/
26 /* void *__ghs_alloc (int size, int align);				      */
27 /*  Return a pointer to at least size bytes of contiguous read/write memory,  */
28 /*  at an address that is aligned to at least a multiple of align. This is a  */
29 /*  front end to sbrk(), mainly for internal use by the Low-Level Libraries.  */
30 /*									      */
31 /*  NOTE: 'align' MUST BE A POSITIVE POWER OF TWO. We also return differently.*/
32 /*									      */
33 /*  Return 0 on an error and set errno = ENOMEM.			      */
34 /******************************************************************************/
35 void *__ghs_alloc (int size, int align)
36 {
37     /* cast to short for v850e with 16bit data pointers. harmless elsewhere. */
38     char *m1 = (char *)(short)-1;
39     char *ret;
40 
41     __ghsLock();
42     ret = sbrk(0);
43     if (ret == m1)
44 	ret = 0;
45     else {
46 	ret = sbrk((-(intptr_t)ret) & (align-1));	/* align our pointer */
47 	if (ret == m1 || sbrk(size) == m1)	/* do the real allocation */
48 	    ret = 0;
49     }
50     __ghsUnlock();
51     return ret;
52 }
53 #endif // CAFE GHS ORIG
54 
55 /******************************************************************************/
56 /* void *__ghs_calloc (int size, int align);				      */
57 /*  Allocate some memory by passing our arguments to __ghs_alloc(), then use  */
58 /*  memset() to clear the memory to 0 if the allocation was successful.	      */
59 /*									      */
60 /*  NOTE: 'align' MUST BE A POSITIVE POWER OF TWO.			      */
61 /******************************************************************************/
__ghs_calloc(int size,int align)62 void *__ghs_calloc (int size, int align)
63 {
64     void *p = __ghs_alloc(size, align);
65     if (!p)
66 	return p;
67     return memset(p, '\0', size);
68 }
69 
70 #endif
71