mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 23:03:27 +08:00
Progress toward clean SDCC compilation
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@18 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
+5
-2
@@ -47,7 +47,7 @@ COBJS = $(CSRCS:.c=.o)
|
||||
SRCS = $(ASRCS) $(CSRCS)
|
||||
OBJS = $(AOBJS) $(COBJS)
|
||||
|
||||
BIN = libmm.a
|
||||
BIN = libmm$(LIBEXT)
|
||||
|
||||
all: $(BIN)
|
||||
|
||||
@@ -58,7 +58,10 @@ $(COBJS): %.o: %.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
$(BIN): $(OBJS)
|
||||
$(AR) rcs $@ $(OBJS)
|
||||
( for obj in $(OBJS) ; do \
|
||||
$(AR) $@ $${obj} || \
|
||||
{ echo "$(AR) $@ $obj FAILED!" ; exit 1 ; } ; \
|
||||
done ; )
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
$(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||
|
||||
@@ -69,10 +69,6 @@
|
||||
|
||||
#ifdef MM_TEST
|
||||
|
||||
/* Standard types */
|
||||
|
||||
typedef unsigned int uint32;
|
||||
|
||||
/* Use the real system errno */
|
||||
|
||||
# define mm_errno errno
|
||||
|
||||
+3
-3
@@ -50,7 +50,7 @@
|
||||
|
||||
/* This is the size of the heap provided to mm */
|
||||
|
||||
uint32 g_heapsize;
|
||||
size_t g_heapsize;
|
||||
|
||||
/* This is the first and last nodes of the heap */
|
||||
|
||||
@@ -97,8 +97,8 @@ void mm_initialize(void *heapstart, size_t heapsize)
|
||||
* both aligned with the MM_MIN_CHUNK size.
|
||||
*/
|
||||
|
||||
uint32 heapbase = MM_ALIGN_UP((uint32)heapstart);
|
||||
uint32 heapend = MM_ALIGN_DOWN((uint32)heapstart + (uint32)heapsize);
|
||||
size_t heapbase = MM_ALIGN_UP((size_t)heapstart);
|
||||
size_t heapend = MM_ALIGN_DOWN((size_t)heapstart + (size_t)heapsize);
|
||||
|
||||
/* Save the size of the heap */
|
||||
|
||||
|
||||
+30
-12
@@ -61,8 +61,13 @@
|
||||
* losses.
|
||||
*/
|
||||
|
||||
#define MM_MIN_SHIFT 4 /* 16 bytes */
|
||||
#define MM_MAX_SHIFT 22 /* 4 Mb */
|
||||
#ifdef CONFIG_SMALL_MEMORY
|
||||
# define MM_MIN_SHIFT 4 /* 16 bytes */
|
||||
# define MM_MAX_SHIFT 15 /* 32 Kb */
|
||||
#else
|
||||
# define MM_MIN_SHIFT 4 /* 16 bytes */
|
||||
# define MM_MAX_SHIFT 22 /* 4 Mb */
|
||||
#endif
|
||||
|
||||
/* All other definitions derive from these two */
|
||||
|
||||
@@ -79,7 +84,11 @@
|
||||
* an allocated chunk.
|
||||
*/
|
||||
|
||||
#define MM_ALLOC_BIT 0x80000000
|
||||
#ifdef CONFIG_SMALL_MEMORY
|
||||
# define MM_ALLOC_BIT 0x8000
|
||||
#else
|
||||
# define MM_ALLOC_BIT 0x80000000
|
||||
#endif
|
||||
#define MM_IS_ALLOCATED(n) \
|
||||
((int)((struct mm_allocnode_s*)(n)->preceding) < 0))
|
||||
|
||||
@@ -94,11 +103,16 @@
|
||||
|
||||
struct mm_allocnode_s
|
||||
{
|
||||
uint32 size; /* Size of this chunk */
|
||||
uint32 preceding; /* Size of the preceding chunk */
|
||||
size_t size; /* Size of this chunk */
|
||||
size_t preceding; /* Size of the preceding chunk */
|
||||
};
|
||||
|
||||
#define SIZEOF_MM_ALLOCNODE 8
|
||||
#ifdef CONFIG_SMALL_MEMORY
|
||||
# define SIZEOF_MM_ALLOCNODE 4
|
||||
#else
|
||||
# define SIZEOF_MM_ALLOCNODE 8
|
||||
#endif
|
||||
|
||||
#define CHECK_ALLOCNODE_SIZE \
|
||||
DEBUGASSERT(sizeof(struct mm_allocnode_s) == SIZEOF_MM_ALLOCNODE)
|
||||
|
||||
@@ -106,13 +120,17 @@ struct mm_allocnode_s
|
||||
|
||||
struct mm_freenode_s
|
||||
{
|
||||
uint32 size; /* Size of this chunk */
|
||||
uint32 preceding; /* Size of the preceding chunk */
|
||||
size_t size; /* Size of this chunk */
|
||||
size_t preceding; /* Size of the preceding chunk */
|
||||
struct mm_freenode_s *flink; /* Supports a doubly linked list */
|
||||
struct mm_freenode_s *blink;
|
||||
};
|
||||
|
||||
#define SIZEOF_MM_FREENODE 16
|
||||
#ifdef CONFIG_SMALL_MEMORY
|
||||
# define SIZEOF_MM_FREENODE 10
|
||||
#else
|
||||
# define SIZEOF_MM_FREENODE 16
|
||||
#endif
|
||||
#define CHECK_FREENODE_SIZE \
|
||||
DEBUGASSERT(sizeof(struct mm_freenode_s) == SIZEOF_MM_FREENODE)
|
||||
|
||||
@@ -138,7 +156,7 @@ struct mallinfo
|
||||
|
||||
/* This is the size of the heap provided to mm */
|
||||
|
||||
extern uint32 g_heapsize;
|
||||
extern size_t g_heapsize;
|
||||
|
||||
/* This is the first and last nodes of the heap */
|
||||
|
||||
@@ -168,9 +186,9 @@ extern struct mm_freenode_s g_nodelist[MM_NNODES];
|
||||
extern struct mallinfo mallinfo(void);
|
||||
#endif
|
||||
|
||||
extern void mm_shrinkchunk(struct mm_allocnode_s *node, uint32 size);
|
||||
extern void mm_shrinkchunk(struct mm_allocnode_s *node, size_t size);
|
||||
extern void mm_addfreechunk(struct mm_freenode_s *node);
|
||||
extern int mm_size2ndx(uint32 size);
|
||||
extern int mm_size2ndx(size_t size);
|
||||
extern void mm_seminitialize(void);
|
||||
extern void mm_takesemaphore(void);
|
||||
extern void mm_givesemaphore(void);
|
||||
|
||||
+3
-3
@@ -69,10 +69,10 @@ struct mallinfo mallinfo(void)
|
||||
{
|
||||
static struct mallinfo stats;
|
||||
struct mm_allocnode_s *node;
|
||||
uint32 mxordblk = 0;
|
||||
size_t mxordblk = 0;
|
||||
int ordblks = 0; /* Number of non-inuse chunks */
|
||||
uint32 uordblks = 0; /* Total allocated space */
|
||||
uint32 fordblks = 0; /* Total non-inuse space */
|
||||
size_t uordblks = 0; /* Total allocated space */
|
||||
size_t fordblks = 0; /* Total non-inuse space */
|
||||
|
||||
/* Visit each node in physical memory */
|
||||
|
||||
|
||||
+1
-1
@@ -144,7 +144,7 @@ void *malloc(size_t size)
|
||||
{
|
||||
struct mm_freenode_s *remainder;
|
||||
struct mm_freenode_s *next;
|
||||
uint32 remaining;
|
||||
size_t remaining;
|
||||
|
||||
/* Remove the node. There must be a predecessor, but there may
|
||||
* not be a successor node.
|
||||
|
||||
+9
-9
@@ -66,10 +66,10 @@
|
||||
void *memalign(size_t alignment, size_t size)
|
||||
{
|
||||
struct mm_allocnode_s *node;
|
||||
uint32 rawchunk;
|
||||
uint32 alignedchunk;
|
||||
uint32 mask = (uint32)(alignment - 1);
|
||||
uint32 allocsize;
|
||||
size_t rawchunk;
|
||||
size_t alignedchunk;
|
||||
size_t mask = (size_t)(alignment - 1);
|
||||
size_t allocsize;
|
||||
|
||||
/* If this requested alignement less than or equal to the
|
||||
* natural alignment of malloc, then just let malloc do the
|
||||
@@ -99,7 +99,7 @@ void *memalign(size_t alignment, size_t size)
|
||||
|
||||
/* Then malloc that size */
|
||||
|
||||
rawchunk = (uint32)malloc(allocsize);
|
||||
rawchunk = (size_t)malloc(allocsize);
|
||||
if (!rawchunk)
|
||||
{
|
||||
return NULL;
|
||||
@@ -127,7 +127,7 @@ void *memalign(size_t alignment, size_t size)
|
||||
{
|
||||
struct mm_allocnode_s *newnode;
|
||||
struct mm_allocnode_s *next;
|
||||
uint32 precedingsize;
|
||||
size_t precedingsize;
|
||||
|
||||
/* Get the node the next node after the allocation. */
|
||||
|
||||
@@ -145,7 +145,7 @@ void *memalign(size_t alignment, size_t size)
|
||||
* SIZEOF_MM_ALLOCNODE
|
||||
*/
|
||||
|
||||
precedingsize = (uint32)newnode - (uint32)node;
|
||||
precedingsize = (size_t)newnode - (size_t)node;
|
||||
|
||||
/* If we were unlucky, then the alignedchunk can lie in such
|
||||
* a position that precedingsize < SIZEOF_NODE_FREENODE. We
|
||||
@@ -159,12 +159,12 @@ void *memalign(size_t alignment, size_t size)
|
||||
{
|
||||
alignedchunk += alignment;
|
||||
newnode = (struct mm_allocnode_s*)(alignedchunk - SIZEOF_MM_ALLOCNODE);
|
||||
precedingsize = (uint32)newnode - (uint32)node;
|
||||
precedingsize = (size_t)newnode - (size_t)node;
|
||||
}
|
||||
|
||||
/* Set up the size of the new node */
|
||||
|
||||
newnode->size = (uint32)next - (uint32)newnode;
|
||||
newnode->size = (size_t)next - (size_t)newnode;
|
||||
newnode->preceding = precedingsize | MM_ALLOC_BIT;
|
||||
|
||||
/* Reduce the size of the original chunk and mark it not allocated, */
|
||||
|
||||
+6
-6
@@ -78,9 +78,9 @@ void *realloc(void *oldmem, size_t size)
|
||||
struct mm_allocnode_s *oldnode;
|
||||
struct mm_freenode_s *prev;
|
||||
struct mm_freenode_s *next;
|
||||
uint32 oldsize;
|
||||
uint32 prevsize = 0;
|
||||
uint32 nextsize = 0;
|
||||
size_t oldsize;
|
||||
size_t prevsize = 0;
|
||||
size_t nextsize = 0;
|
||||
|
||||
/* If oldmem is NULL, then realloc is equivalent to malloc */
|
||||
|
||||
@@ -145,9 +145,9 @@ void *realloc(void *oldmem, size_t size)
|
||||
|
||||
if (nextsize + prevsize + oldsize >= size)
|
||||
{
|
||||
uint32 needed = size - oldsize;
|
||||
uint32 takeprev;
|
||||
uint32 takenext;
|
||||
size_t needed = size - oldsize;
|
||||
size_t takeprev;
|
||||
size_t takenext;
|
||||
|
||||
/* Check if we can extend into the previous chunk and if the
|
||||
* previous chunk is smaller than the next chunk.
|
||||
|
||||
+1
-1
@@ -64,7 +64,7 @@
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
void mm_shrinkchunk(struct mm_allocnode_s *node, uint32 size)
|
||||
void mm_shrinkchunk(struct mm_allocnode_s *node, size_t size)
|
||||
{
|
||||
struct mm_freenode_s *next;
|
||||
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@
|
||||
|
||||
/* Convert the size to a nodelist index */
|
||||
|
||||
int mm_size2ndx(uint32 size)
|
||||
int mm_size2ndx(size_t size)
|
||||
{
|
||||
int ndx = 0;
|
||||
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef unsigned int uint32;
|
||||
#include "mm_internal.h"
|
||||
|
||||
/* Definitions */
|
||||
|
||||
Reference in New Issue
Block a user