With these fixes, the kernel build is basically functional (but there is more to be done)

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5722 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2013-03-09 01:27:42 +00:00
parent 0db8dc83ee
commit feca2c077e
14 changed files with 336 additions and 35 deletions

View file

@ -4287,7 +4287,12 @@
(2013-03-08).
* mm/ and include/nuttx/mm.h: Implement support for multiple heaps.
(2013-03-08).
* arch/*/src: xyz_addregion() needs to call kmm_addregion, not mm_addretion.
* arch/*/src: xyz_addregion() needs to call kmm_addregion, not mm_addregion.
(2013-03-08).
* sched/kmm*.c: Move this garbage kmm*.c file to mm/. until I decide what
to do with them (which is probably to just delete them). (2013-03-08).
* mm/mm_test.c and Makefile.test: Deleted the memory test. This was
a good test and helped me a lot when I wrote the memory manager, but
now it is in the way and paralyzing other efforts. So the memory unit
test was deleted. (2013-03-08)

View file

@ -520,7 +520,7 @@ lib/libuc$(LIBEXT): libc/libuc$(LIBEXT)
$(Q) install libc/libuc$(LIBEXT) lib/libuc$(LIBEXT)
mm/libumm$(LIBEXT): context
$(Q) $(MAKE) -C mm TOPDIR="$(TOPDIR)" libumm$(LIBEXT) EXTRADEFINES=$(KDEFINE)
$(Q) $(MAKE) -C mm TOPDIR="$(TOPDIR)" libumm$(LIBEXT)
lib/libumm$(LIBEXT): mm/libumm$(LIBEXT)
$(Q) install mm/libumm$(LIBEXT) lib/libumm$(LIBEXT)
@ -552,7 +552,7 @@ lib/libc$(LIBEXT): libc/libc$(LIBEXT)
$(Q) install libc/libc$(LIBEXT) lib/libc$(LIBEXT)
mm/libmm$(LIBEXT): context
$(Q) $(MAKE) -C mm TOPDIR="$(TOPDIR)" libmm$(LIBEXT) EXTRADEFINES=$(KDEFINE)
$(Q) $(MAKE) -C mm TOPDIR="$(TOPDIR)" libmm$(LIBEXT)
lib/libmm$(LIBEXT): mm/libmm$(LIBEXT)
$(Q) install mm/libmm$(LIBEXT) lib/libmm$(LIBEXT)

View file

@ -536,7 +536,7 @@ lib\libuc$(LIBEXT): libc\libuc$(LIBEXT)
$(Q) install libc\libuc$(LIBEXT) lib\libuc$(LIBEXT)
mm\libumm$(LIBEXT): context
$(Q) $(MAKE) -C mm TOPDIR="$(TOPDIR)" libumm$(LIBEXT) EXTRADEFINES=$(KDEFINE)
$(Q) $(MAKE) -C mm TOPDIR="$(TOPDIR)" libumm$(LIBEXT)
lib\libumm$(LIBEXT): mm\libumm$(LIBEXT)
$(Q) install mm\libumm$(LIBEXT) lib\libumm$(LIBEXT)
@ -568,7 +568,7 @@ lib\libc$(LIBEXT): libc\libc$(LIBEXT)
$(Q) install libc\libc$(LIBEXT) lib\libc$(LIBEXT)
mm\libmm$(LIBEXT): context
$(Q) $(MAKE) -C mm TOPDIR="$(TOPDIR)" libmm$(LIBEXT) EXTRADEFINES=$(KDEFINE)
$(Q) $(MAKE) -C mm TOPDIR="$(TOPDIR)" libmm$(LIBEXT)
lib\libmm$(LIBEXT): mm\libmm$(LIBEXT)
$(Q) install mm\libmm$(LIBEXT) lib\libmm$(LIBEXT)

View file

@ -116,10 +116,10 @@ $(BOARD_INCLUDE)$(DELIM)user_map.h: $(TOPDIR)$(DELIM)User.map
$(Q) echo "" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
$(Q) echo "/* Memory manager entry points */" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
$(Q) echo "" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
$(Q) echo "#define CONFIG_USER_MMINIT 0x`grep \" mm_initialize$\" $(TOPDIR)$(DELIM)User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
$(Q) echo "#define CONFIG_USER_MMADDREGION 0x`grep \" mm_addregion$\" $(TOPDIR)$(DELIM)User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
$(Q) echo "#define CONFIG_USER_MMTRYSEM 0x`grep \" mm_trysemaphore$\" $(TOPDIR)$(DELIM)User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
$(Q) echo "#define CONFIG_USER_MMGIVESEM 0x`grep \" mm_givesemaphore$\" $(TOPDIR)$(DELIM)User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
$(Q) echo "#define CONFIG_USER_MMINIT 0x`grep \" umm_initialize$\" $(TOPDIR)$(DELIM)User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
$(Q) echo "#define CONFIG_USER_MMADDREGION 0x`grep \" umm_addregion$\" $(TOPDIR)$(DELIM)User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
$(Q) echo "#define CONFIG_USER_MMTRYSEM 0x`grep \" umm_trysemaphore$\" $(TOPDIR)$(DELIM)User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
$(Q) echo "#define CONFIG_USER_MMGIVESEM 0x`grep \" umm_givesemaphore$\" $(TOPDIR)$(DELIM)User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
$(Q) echo "" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
$(Q) echo "#define CONFIG_USER_MALLOC 0x`grep \" malloc$\" $(TOPDIR)$(DELIM)User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
$(Q) echo "#define CONFIG_USER_REALLOC 0x`grep \" realloc$\" $(TOPDIR)$(DELIM)User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)$(DELIM)user_map.h

View file

@ -67,10 +67,10 @@ MEMORY
* but be usable both by kernel- and user-space code
*/
EXTERN(mm_initialize)
EXTERN(mm_addregion)
EXTERN(mm_trysemaphore)
EXTERN(mm_givesemaphore)
EXTERN(umm_initialize)
EXTERN(umm_addregion)
EXTERN(umm_trysemaphore)
EXTERN(umm_givesemaphore)
EXTERN(malloc)
EXTERN(realloc)

View file

@ -43,11 +43,9 @@
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdlib.h>
#ifndef CONFIG_NUTTX_KERNEL
# include <stdlib.h>
# include <nuttx/mm.h>
#endif
#include <nuttx/mm.h>
/****************************************************************************
* Public Types
@ -77,10 +75,10 @@ extern "C"
#ifndef CONFIG_NUTTX_KERNEL
# define kmm_initialize(h,s) mm_initialize(&g_mmheap,h,s)
# define kmm_addregion(h,s) mm_addregion(&g_mmheap,h,s)
# define kmm_trysemaphore() mm_trysemaphore(&g_mmheap)
# define kmm_givesemaphore() mm_givesemaphore(&g_mmheap)
# define kmm_initialize(h,s) umm_initialize(h,s)
# define kmm_addregion(h,s) umm_addregion(h,s)
# define kmm_trysemaphore() umm_trysemaphore()
# define kmm_givesemaphore() umm_givesemaphore()
# define kmalloc(s) malloc(s)
# define kzalloc(s) zalloc(s)

View file

@ -238,6 +238,18 @@ void mm_initialize(FAR struct mm_heap_s *heap, FAR void *heap_start,
void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart,
size_t heapsize);
/* Functions contained in umm_initialize.c **********************************/
#if !defined(CONFIG_NUTTX_KERNEL) || !defined(__KERNEL__)
void umm_initialize(FAR void *heap_start, size_t heap_size);
#endif
/* Functions contained in umm_addregion.c ***********************************/
#if !defined(CONFIG_NUTTX_KERNEL) || !defined(__KERNEL__)
void umm_addregion(FAR void *heapstart, size_t heapsize);
#endif
/* Functions contained in mm_sem.c ******************************************/
void mm_seminitialize(FAR struct mm_heap_s *heap);
@ -245,6 +257,13 @@ void mm_takesemaphore(FAR struct mm_heap_s *heap);
int mm_trysemaphore(FAR struct mm_heap_s *heap);
void mm_givesemaphore(FAR struct mm_heap_s *heap);
/* Functions contained in umm_semaphore.c ***********************************/
#if !defined(CONFIG_NUTTX_KERNEL) || !defined(__KERNEL__)
int umm_trysemaphore(void);
void umm_givesemaphore(void);
#endif
/* Functions contained in mm_malloc.c ***************************************/
#ifdef CONFIG_MM_MULTIHEAP

View file

@ -73,6 +73,7 @@ KBIN = libkc$(LIBEXT)
BIN = libc$(LIBEXT)
all: $(BIN)
.PHONY: kclean uclean clean distclean
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
@ -84,19 +85,15 @@ $(BIN): $(OBJS)
$(call ARCHIVE, $@, $(OBJS))
ifneq ($(BIN),$(UBIN))
.userlib:
$(UBIN): kclean
$(Q) $(MAKE) $(UBIN) BIN=$(UBIN) TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES)
$(Q) touch .userlib
$(UBIN): kclean .userlib
endif
ifneq ($(BIN),$(KBIN))
.kernlib:
$(KBIN): uclean
$(Q) $(MAKE) $(KBIN) BIN=$(KBIN) TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES)
$(Q) touch .kernlib
$(KBIN): uclean .kernlib
endif
.depend: Makefile $(SRCS)

View file

@ -11,10 +11,32 @@ config MM_MULTIHEAP
confused with memory regions. One heap may be composed of multiple,
non-contiguous memory regions. The fact that the heap is composed
of such multiple regions is invisible to the end-user (other than
the heap comes pre-fragemented). Multiple heaps, on the other hand,
the heap comes pre-fragmented). Multiple heaps, on the other hand,
supports a separate set of allocators that operate on a separate set
of memory regions.
config MM_KERNEL_HEAP
bool "Support a protected, kernel heap"
default y
depends on NUTTX_KERNEL && MM_MULTIHEAP
---help---
Partition heap memory into two parts: (1) a protected, kernel-mode
heap accessible only by the NuttX kernel, and (2) an unprotected
user-mode heap for use by applications. If you are only interested
in protected the kernel from read access, then this option is not
necessary. If you wish to secure the kernel data as well, then
this option should be selected.
config MM_KERNEL_HEAPSIZE
int "Kernal heap size"
default 8192
depends on MM_KERNEL_HEAP
---help---
This is the size of the a protected, kernel-mode heap (in bytes).
The remaining of available memory is given to the unprotected
user-mode heap. This value may need to be aligned to units of the
size of the smallest memory protection region.
config MM_SMALL
bool "Small memory model"
default n

View file

@ -40,6 +40,8 @@ CSRCS = mm_initialize.c mm_sem.c mm_addfreechunk.c mm_size2ndx.c
CSRCS += mm_shrinkchunk.c mm_malloc.c mm_zalloc.c mm_calloc.c mm_realloc.c
CSRCS += mm_memalign.c mm_free.c mm_mallinfo.c
CSRCS += umm_initialize.c umm_addregion.c umm_semaphore.c
ifeq ($(CONFIG_NUTTX_KERNEL),y)
CSRCS += kmm_initialize.c kmm_addregion.c kmm_semaphore.c
CSRCS += kmm_kmalloc.c kmm_kzalloc.c kmm_krealloc.c kmm_kfree.c
@ -60,6 +62,7 @@ KBIN = libkmm$(LIBEXT)
BIN = libmm$(LIBEXT)
all: $(BIN)
.PHONY: kclean uclean clean distclean
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
@ -71,19 +74,15 @@ $(BIN): $(OBJS)
$(call ARCHIVE, $@, $(OBJS))
ifneq ($(BIN),$(UBIN))
.userlib:
$(UBIN): kclean
$(Q) $(MAKE) $(UBIN) BIN=$(UBIN) TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES)
$(Q) touch .userlib
$(UBIN): kclean .userlib
endif
ifneq ($(BIN),$(KBIN))
.kernlib:
$(KBIN): uclean
$(Q) $(MAKE) $(KBIN) BIN=$(KBIN) TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES)
$(Q) touch .kernlib
$(KBIN): uclean .kernlib
endif
.depend: Makefile $(SRCS)

View file

@ -107,7 +107,7 @@ typedef void (*kmaddregion_t)(FAR void*, size_t);
void kmm_addregion(FAR void *heap_start, size_t heap_size)
{
return KADDREGION(&g_kmmheap, heap_start, heap_size);
return KADDREGION(heap_start, heap_size);
}
#endif /* CONFIG_NUTTX_KERNEL && __KERNEL__ */

81
mm/umm_addregion.c Normal file
View file

@ -0,0 +1,81 @@
/************************************************************************
* mm/umm_addregion.c
*
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
************************************************************************/
/************************************************************************
* Included Files
************************************************************************/
#include <nuttx/config.h>
#include <nuttx/mm.h>
#if !defined(CONFIG_NUTTX_KERNEL) || !defined(__KERNEL__)
/************************************************************************
* Pre-processor definition
************************************************************************/
/************************************************************************
* Private Types
************************************************************************/
/************************************************************************
* Private Functions
************************************************************************/
/************************************************************************
* Public Functions
************************************************************************/
/************************************************************************
* Name: umm_addregion
*
* Description:
* This is a simple wrapper for the mm_addregion() function.
*
* Parameters:
* heap_start - Address of the beginning of the memory region
* heap_size - The size (in bytes) if the memory region.
*
* Return Value:
* None
*
************************************************************************/
void umm_addregion(FAR void *heap_start, size_t heap_size)
{
mm_addregion(&g_mmheap, heap_start, heap_size);
}
#endif /* !CONFIG_NUTTX_KERNEL || !__KERNEL__ */

81
mm/umm_initialize.c Normal file
View file

@ -0,0 +1,81 @@
/************************************************************************
* mm/umm_initialize.c
*
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
************************************************************************/
/************************************************************************
* Included Files
************************************************************************/
#include <nuttx/config.h>
#include <nuttx/mm.h>
#if !defined(CONFIG_NUTTX_KERNEL) || !defined(__KERNEL__)
/************************************************************************
* Pre-processor definition
************************************************************************/
/************************************************************************
* Private Types
************************************************************************/
/************************************************************************
* Private Functions
************************************************************************/
/************************************************************************
* Public Functions
************************************************************************/
/************************************************************************
* Name: umm_initialize
*
* Description:
* This is a simple wrapper for the mm_initialize() function.
*
* Parameters:
* heap_start - Address of the beginning of the (initial) memory region
* heap_size - The size (in bytes) if the (initial) memory region.
*
* Return Value:
* None
*
************************************************************************/
void umm_initialize(FAR void *heap_start, size_t heap_size)
{
mm_initialize(&g_mmheap, heap_start, heap_size);
}
#endif /* !CONFIG_NUTTX_KERNEL || !__KERNEL__ */

99
mm/umm_semaphore.c Normal file
View file

@ -0,0 +1,99 @@
/************************************************************************
* mm/umm_semaphore.c
*
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
************************************************************************/
/************************************************************************
* Included Files
************************************************************************/
#include <nuttx/config.h>
#include <nuttx/mm.h>
#if !defined(CONFIG_NUTTX_KERNEL) || !defined(__KERNEL__)
/************************************************************************
* Pre-processor definition
************************************************************************/
/************************************************************************
* Private Types
************************************************************************/
/************************************************************************
* Private Functions
************************************************************************/
/************************************************************************
* Public Functions
************************************************************************/
/************************************************************************
* Name: umm_trysemaphore
*
* Description:
* This is a simple wrapper for the mm_trysemaphore() function.
*
* Parameters:
* None
*
* Return Value:
* OK on success; a negated errno on failure
*
************************************************************************/
int umm_trysemaphore(void)
{
return mm_trysemaphore(&g_mmheap);
}
/************************************************************************
* Name: umm_givesemaphore
*
* Description:
* This is a simple wrapper for the mm_givesemaphore() function.
*
* Parameters:
* None
*
* Return Value:
* OK on success; a negated errno on failure
*
************************************************************************/
void umm_givesemaphore(void)
{
mm_givesemaphore(&g_mmheap);
}
#endif /* !CONFIG_NUTTX_KERNEL || __KERNEL__ */