mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 05:08:41 +08:00
Remove user_map.h; replace with a header at the beginning of the user-space blob. User work queue no started by os_brinup() on behalf of the application
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5727 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
18ca1965b6
commit
2433c1461b
18 changed files with 430 additions and 434 deletions
|
@ -4302,4 +4302,12 @@
|
|||
so configured. (2013-03-10)
|
||||
* configs/sam3u-ek/knsh: This configuration was converted to use the
|
||||
kconfigs-frontends build tool. (2013-03-10)
|
||||
* configs/*/include/user_map.h and include/nuttx/userspace.h: Remove
|
||||
the very kludgy user_map.h file and replace it with a header that
|
||||
is expected at the beginning of the user-space blob. (2013-03-10)
|
||||
* configs/sam3u-ek/kernel/up_userspace.c: This is the header for
|
||||
the SAM3U-EK's user space. (2013-03-10)
|
||||
* sched/os_bringup.c: In the kernel build, os_bringup() now uses the
|
||||
user-space header to automatically start the user-space work queue,
|
||||
if so configured. (2013-03-10)
|
||||
|
||||
|
|
11
Kconfig
11
Kconfig
|
@ -180,6 +180,17 @@ config NUTTX_KERNEL
|
|||
default n
|
||||
---help---
|
||||
Builds NuttX as a separately compiled kernel.
|
||||
|
||||
config NUTTX_USERSPACE
|
||||
hex "Beginning of user-space blob"
|
||||
default 0x0
|
||||
depends on NUTTX_KERNEL
|
||||
---help---
|
||||
In the kernel build, the NuttX kernel and the user-space blob are
|
||||
built separately linked objects. NUTTX_USERSPACE provides the
|
||||
address where the user-space blob is loaded into memory. NuttX will
|
||||
expect to find and instance of struct userspace_s at this location.
|
||||
|
||||
endif
|
||||
endmenu
|
||||
|
||||
|
|
|
@ -223,10 +223,6 @@ void up_allocate_kheap(FAR void **heap_start, size_t *heap_size)
|
|||
|
||||
*heap_start = (FAR void*)kbase;
|
||||
*heap_size = KHEAP_SIZE;
|
||||
|
||||
/* Prohibit user access to the kernel heap memory */
|
||||
|
||||
sam3u_mpu_kheap((uintptr_t)kbase, KHEAP_SIZE);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -477,10 +477,10 @@ void sam3u_mpuinitialize(void);
|
|||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: sam3u_mpu_uheap and sam3u_mpu_uheap
|
||||
* Name: sam3u_mpu_uheap
|
||||
*
|
||||
* Description:
|
||||
* Map a user- or kernel-heap region.
|
||||
* Map the user heap region.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
@ -490,12 +490,6 @@ void sam3u_mpu_uheap(uintptr_t start, size_t size);
|
|||
# define sam3u_mpu_uheap(start,size)
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP)
|
||||
void sam3u_mpu_kheap(uintptr_t start, size_t size);
|
||||
#else
|
||||
# define sam3u_mpu_kheap(start,size)
|
||||
#endif
|
||||
|
||||
/************************************************************************************
|
||||
* Name: sam3u_gpioirqinitialize
|
||||
*
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
|
||||
#include <assert.h>
|
||||
|
||||
#include <arch/board/user_map.h>
|
||||
#include <nuttx/userspace.h>
|
||||
|
||||
#include "mpu.h"
|
||||
|
||||
|
@ -82,10 +82,11 @@
|
|||
|
||||
void sam3u_mpuinitialize(void)
|
||||
{
|
||||
uintptr_t datastart = MIN(CONFIG_USER_DATADESTSTART, CONFIG_USER_BSSSTART);
|
||||
uintptr_t dataend = MAX(CONFIG_USER_DATADESTEND, CONFIG_USER_BSSEND);
|
||||
uintptr_t datastart = MIN(USERSPACE->us_datastart, USERSPACE->us_bssstart);
|
||||
uintptr_t dataend = MAX(USERSPACE->us_dataend, USERSPACE->us_bssend);
|
||||
|
||||
DEBUGASSERT(CONFIG_USER_TEXTEND >= CONFIG_USER_TEXTSTART && dataend >= datastart);
|
||||
DEBUGASSERT(USERSPACE->us_textend >= USERSPACE->us_textstart &&
|
||||
dataend >= datastart);
|
||||
|
||||
/* Show MPU information */
|
||||
|
||||
|
@ -93,7 +94,9 @@ void sam3u_mpuinitialize(void)
|
|||
|
||||
/* Configure user flash and SRAM space */
|
||||
|
||||
mpu_userflash(CONFIG_USER_TEXTSTART, CONFIG_USER_TEXTEND - CONFIG_USER_TEXTSTART);
|
||||
mpu_userflash(USERSPACE->us_textstart,
|
||||
USERSPACE->us_textend - USERSPACE->us_textstart);
|
||||
|
||||
mpu_userintsram(datastart, dataend - datastart);
|
||||
|
||||
/* Then enable the MPU */
|
||||
|
@ -116,12 +119,5 @@ void sam3u_mpu_uheap(uintptr_t start, size_t size)
|
|||
mpu_userintsram(start, size);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_MM_KERNEL_HEAP
|
||||
void sam3u_mpu_kheap(uintptr_t start, size_t size)
|
||||
{
|
||||
mpu_privintsram(start, size);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_NUTTX_KERNEL */
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
* arch/arm/src/common/sam3u_userspace.c
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -42,7 +42,9 @@
|
|||
#include <stdint.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <arch/board/user_map.h>
|
||||
#include <nuttx/userspace.h>
|
||||
|
||||
#include "sam3u_internal.h"
|
||||
|
||||
#ifdef CONFIG_NUTTX_KERNEL
|
||||
|
||||
|
@ -81,10 +83,11 @@ void sam3u_userspace(void)
|
|||
|
||||
/* Clear all of user-space .bss */
|
||||
|
||||
DEBUGASSERT((uintptr_t)CONFIG_USER_DATADESTSTART <= CONFIG_USER_DATADESTEND);
|
||||
DEBUGASSERT(USERSPACE->us_bssstart != 0 && USERSPACE->us_bssend != 0 &&
|
||||
USERSPACE->us_bssstart <= USERSPACE->us_bssend);
|
||||
|
||||
dest = (uint8_t*)CONFIG_USER_BSSSTART;
|
||||
end = (uint8_t*)CONFIG_USER_BSSEND;
|
||||
dest = (uint8_t*)USERSPACE->us_bssstart;
|
||||
end = (uint8_t*)USERSPACE->us_bssend;
|
||||
|
||||
while (dest != end)
|
||||
{
|
||||
|
@ -93,16 +96,22 @@ void sam3u_userspace(void)
|
|||
|
||||
/* Initialize all of user-space .data */
|
||||
|
||||
DEBUGASSERT((uintptr_t)CONFIG_USER_DATADESTSTART <= CONFIG_USER_DATADESTEND);
|
||||
DEBUGASSERT(USERSPACE->us_datasource != 0 &&
|
||||
USERSPACE->us_datastart != 0 && USERSPACE->us_dataend != 0 &&
|
||||
USERSPACE->us_datastart <= USERSPACE->us_dataend);
|
||||
|
||||
src = (uint8_t*)CONFIG_USER_DATASOURCE;
|
||||
dest = (uint8_t*)CONFIG_USER_DATADESTSTART;
|
||||
end = (uint8_t*)CONFIG_USER_DATADESTEND;
|
||||
src = (uint8_t*)USERSPACE->us_datasource;
|
||||
dest = (uint8_t*)USERSPACE->us_datastart;
|
||||
end = (uint8_t*)USERSPACE->us_dataend;
|
||||
|
||||
while (dest != end)
|
||||
{
|
||||
*dest++ = *src++;
|
||||
}
|
||||
|
||||
/* Configure the MPU to permit user-space access to its FLASH and RAM */
|
||||
|
||||
sam3u_mpuinitialize();
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NUTTX_KERNEL */
|
||||
|
|
|
@ -61,16 +61,24 @@ USER_LDFLAGS = --undefined=$(ENTRYPT) --entry=$(ENTRYPT) $(USER_LDSCRIPT)
|
|||
USER_LDLIBS = $(patsubst lib%,-l%,$(basename $(notdir $(USERLIBS))))
|
||||
USER_LIBGCC = "${shell $(CC) -print-libgcc-file-name}"
|
||||
|
||||
# Source files
|
||||
|
||||
CSRCS = up_userspace.c
|
||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||
OBJS = $(COBJS)
|
||||
|
||||
# Targets:
|
||||
|
||||
all: $(TOPDIR)$(DELIM)nuttx_user.elf $(TOPDIR)$(DELIM)User.map $(BOARD_INCLUDE)$(DELIM)user_map.h
|
||||
|
||||
all: $(TOPDIR)$(DELIM)nuttx_user.elf $(TOPDIR)$(DELIM)User.map
|
||||
.PHONY: depend clean distclean
|
||||
|
||||
$(COBJS): %$(OBJEXT): %.c
|
||||
$(call COMPILE, $<, $@)
|
||||
|
||||
# Create the nuttx_user.elf file containing all of the user-mode code
|
||||
|
||||
nuttx_user.elf:
|
||||
$(Q) $(LD) -o $@ $(USER_LDFLAGS) $(USER_LIBPATHS) --start-group $(USER_LDLIBS) --end-group $(USER_LIBGCC)
|
||||
nuttx_user.elf: $(OBJS)
|
||||
$(Q) $(LD) -o $@ $(USER_LDFLAGS) $(USER_LIBPATHS) $(OBJS) --start-group $(USER_LDLIBS) --end-group $(USER_LIBGCC)
|
||||
|
||||
$(TOPDIR)$(DELIM)nuttx_user.elf: nuttx_user.elf
|
||||
@echo "LD: nuttx_user.elf"
|
||||
|
@ -93,41 +101,6 @@ $(TOPDIR)$(DELIM)User.map: nuttx_user.elf
|
|||
$(Q) $(NM) nuttx_user.elf >$(TOPDIR)$(DELIM)User.map
|
||||
$(Q) $(CROSSDEV)size nuttx_user.elf
|
||||
|
||||
$(BOARD_INCLUDE)$(DELIM)user_map.h: $(TOPDIR)$(DELIM)User.map
|
||||
@echo "MK: user_map.h"
|
||||
$(Q) echo "/* configs$(DELIM)$(CONFIG_ARCH_BOARD)$(DELIM)include$(DELIM)user_map.h" > $(BOARD_INCLUDE)$(DELIM)user_map.h
|
||||
$(Q) echo " *" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
|
||||
$(Q) echo " * This is an auto-generated file.. Do not edit this file!" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
|
||||
$(Q) echo " */" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
|
||||
$(Q) echo "" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
|
||||
$(Q) echo "#ifndef __ARCH_BOARD_USER_MAP_H" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
|
||||
$(Q) echo "#define __ARCH_BOARD_USER_MAP_H" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
|
||||
$(Q) echo "" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
|
||||
$(Q) echo "/* General memory map */" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
|
||||
$(Q) echo "" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
|
||||
$(Q) echo "#define CONFIG_USER_ENTRYPOINT 0x`grep \" $(ENTRYPT)\" $(TOPDIR)$(DELIM)User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
|
||||
$(Q) echo "#define CONFIG_USER_TEXTSTART 0x`grep \" _stext\" $(TOPDIR)$(DELIM)User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
|
||||
$(Q) echo "#define CONFIG_USER_TEXTEND 0x`grep \" _etext$\" $(TOPDIR)$(DELIM)User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
|
||||
$(Q) echo "#define CONFIG_USER_DATASOURCE 0x`grep \" _eronly$\" $(TOPDIR)$(DELIM)User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
|
||||
$(Q) echo "#define CONFIG_USER_DATADESTSTART 0x`grep \" _sdata$\" $(TOPDIR)$(DELIM)User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
|
||||
$(Q) echo "#define CONFIG_USER_DATADESTEND 0x`grep \" _edata$\" $(TOPDIR)$(DELIM)User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
|
||||
$(Q) echo "#define CONFIG_USER_BSSSTART 0x`grep \" _sbss\" $(TOPDIR)$(DELIM)User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
|
||||
$(Q) echo "#define CONFIG_USER_BSSEND 0x`grep \" _ebss$\" $(TOPDIR)$(DELIM)User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
|
||||
$(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 \" 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
|
||||
$(Q) echo "#define CONFIG_USER_ZALLOC 0x`grep \" zalloc$\" $(TOPDIR)$(DELIM)User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
|
||||
$(Q) echo "#define CONFIG_USER_FREE 0x`grep \" free$\" $(TOPDIR)$(DELIM)User.map | cut -d' ' -f1`" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
|
||||
$(Q) echo "" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
|
||||
$(Q) echo "#endif /* __ARCH_BOARD_USER_MAP_H */" >> $(BOARD_INCLUDE)$(DELIM)user_map.h
|
||||
|
||||
.depend:
|
||||
|
||||
depend: .depend
|
||||
|
@ -139,4 +112,3 @@ clean:
|
|||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
|
||||
|
|
|
@ -81,6 +81,10 @@ OUTPUT_ARCH(arm)
|
|||
|
||||
SECTIONS
|
||||
{
|
||||
.userspace : {
|
||||
*(.userspace)
|
||||
} > uflash
|
||||
|
||||
.text : {
|
||||
_stext = ABSOLUTE(.);
|
||||
*(.vectors)
|
||||
|
|
129
configs/sam3u-ek/kernel/up_userspace.c
Normal file
129
configs/sam3u-ek/kernel/up_userspace.c
Normal file
|
@ -0,0 +1,129 @@
|
|||
/****************************************************************************
|
||||
* configs/sam3u-ek/kernel/up_userspace.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 <stdlib.h>
|
||||
|
||||
#include <nuttx/userspace.h>
|
||||
#include <nuttx/wqueue.h>
|
||||
#include <nuttx/mm.h>
|
||||
|
||||
#if defined(CONFIG_NUTTX_KERNEL) && !defined(__KERNEL__)
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
#ifndef CONFIG_NUTTX_USERSPACE
|
||||
# error "CONFIG_NUTTX_USERSPACE not defined"
|
||||
#endif
|
||||
|
||||
#if CONFIG_NUTTX_USERSPACE != 0x00090000
|
||||
# error "CONFIG_NUTTX_USERSPACE must be 0x00090000 to match kernel.ld"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/* These 'addresses' of these values are setup by the linker script. They are
|
||||
* not actual uint32_t storage locations! They are only used meaningfully in the
|
||||
* following way:
|
||||
*
|
||||
* - The linker script defines, for example, the symbol_sdata.
|
||||
* - The declareion extern uint32_t _sdata; makes C happy. C will believe
|
||||
* that the value _sdata is the address of a uint32_t variable _data (it is
|
||||
* not!).
|
||||
* - We can recoved the linker value then by simply taking the address of
|
||||
* of _data. like: uint32_t *pdata = &_sdata;
|
||||
*/
|
||||
|
||||
extern uint32_t _stext; /* Start of .text */
|
||||
extern uint32_t _etext; /* End_1 of .text + .rodata */
|
||||
extern const uint32_t _eronly; /* End+1 of read only section (.text + .rodata) */
|
||||
extern uint32_t _sdata; /* Start of .data */
|
||||
extern uint32_t _edata; /* End+1 of .data */
|
||||
extern uint32_t _sbss; /* Start of .bss */
|
||||
extern uint32_t _ebss; /* End+1 of .bss */
|
||||
|
||||
/* This is the user space entry point */
|
||||
|
||||
int CONFIG_USER_ENTRYPOINT(int argc, char *argv[]);
|
||||
|
||||
const struct userspace_s userspace __attribute__ ((section (".userspace"))) =
|
||||
{
|
||||
/* General memory map */
|
||||
|
||||
.us_entrypoint = (main_t)CONFIG_USER_ENTRYPOINT,
|
||||
.us_textstart = (uintptr_t)&_stext,
|
||||
.us_textend = (uintptr_t)&_etext,
|
||||
.us_datasource = (uintptr_t)&_eronly,
|
||||
.us_datastart = (uintptr_t)&_sdata,
|
||||
.us_dataend = (uintptr_t)&_edata,
|
||||
.us_bssstart = (uintptr_t)&_sbss,
|
||||
.us_bssend = (uintptr_t)&_ebss,
|
||||
|
||||
/* Memory manager entry points (declared in include/nuttx/mm.h) */
|
||||
|
||||
.mm_initialize = umm_initialize,
|
||||
.mm_addregion = umm_addregion,
|
||||
.mm_trysemaphore = umm_trysemaphore,
|
||||
.mm_givesemaphore = umm_givesemaphore,
|
||||
|
||||
/* Memory manager entry points (declared in include/stdlib.h) */
|
||||
|
||||
.mm_malloc = malloc,
|
||||
.mm_realloc = realloc,
|
||||
.mm_zalloc = zalloc,
|
||||
.mm_free = free,
|
||||
|
||||
/* User-space work queue support (declared in include/nuttx/wqueue.h) */
|
||||
|
||||
#if defined(CONFIG_SCHED_WORKQUEUE) && defined(CONFIG_SCHED_USRWORK)
|
||||
.work_usrstart = work_usrstart;
|
||||
#endif
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#endif /* CONFIG_NUTTX_KERNEL && !__KERNEL__ */
|
|
@ -16,18 +16,19 @@ CONFIG_HOST_LINUX=y
|
|||
#
|
||||
# Build Configuration
|
||||
#
|
||||
CONFIG_APPS_DIR="../apps"
|
||||
# CONFIG_APPS_DIR="../apps"
|
||||
CONFIG_BUILD_2PASS=y
|
||||
CONFIG_PASS1_TARGET="all"
|
||||
CONFIG_PASS1_BUILDIR="configs/sam3u-ek/kernel"
|
||||
CONFIG_PASS1_OBJECT=""
|
||||
CONFIG_NUTTX_KERNEL=y
|
||||
CONFIG_NUTTX_USERSPACE=0x00090000
|
||||
|
||||
#
|
||||
# Binary Output Formats
|
||||
#
|
||||
# CONFIG_RRLOAD_BINARY is not set
|
||||
# CONFIG_INTELHEX_BINARY=y
|
||||
# CONFIG_INTELHEX_BINARY is not set
|
||||
# CONFIG_MOTOROLA_SREC is not set
|
||||
# CONFIG_RAW_BINARY is not set
|
||||
|
||||
|
@ -350,7 +351,9 @@ CONFIG_FS_FAT=y
|
|||
#
|
||||
# Memory Management
|
||||
#
|
||||
# CONFIG_MM_MULTIHEAP is not set
|
||||
CONFIG_MM_MULTIHEAP=y
|
||||
CONFIG_MM_KERNEL_HEAP=y
|
||||
CONFIG_MM_KERNEL_HEAPSIZE=8192
|
||||
# CONFIG_MM_SMALL is not set
|
||||
CONFIG_MM_REGIONS=3
|
||||
# CONFIG_GRAN is not set
|
||||
|
|
|
@ -94,7 +94,6 @@
|
|||
|
||||
static const uint8_t g_ledon[8] =
|
||||
{
|
||||
|
||||
(LED0_OFF |LED1_OFF |LED2_OFF), /* LED_STARTED */
|
||||
(LED0_ON |LED1_OFF |LED2_ON), /* LED_HEAPALLOCATE */
|
||||
(LED0_OFF |LED1_ON |LED2_OFF), /* LED_IRQSENABLED */
|
||||
|
@ -108,7 +107,6 @@ static const uint8_t g_ledon[8] =
|
|||
|
||||
static const uint8_t g_ledoff[8] =
|
||||
{
|
||||
|
||||
(LED0_OFF |LED1_OFF |LED2_OFF), /* LED_STARTED (does not happen) */
|
||||
(LED0_ON |LED1_OFF |LED2_ON), /* LED_HEAPALLOCATE (does not happen) */
|
||||
(LED0_OFF |LED1_ON |LED2_OFF), /* LED_IRQSENABLED (does not happen) */
|
||||
|
@ -145,6 +143,7 @@ static void up_setled(uint16_t pinset, uint8_t state)
|
|||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
sam3u_gpiowrite(pinset, polarity);
|
||||
}
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include <nuttx/mm.h>
|
||||
#include <nuttx/userspace.h>
|
||||
|
||||
#if !defined(CONFIG_NUTTX_KERNEL) || defined(__KERNEL__)
|
||||
|
||||
|
@ -76,15 +77,21 @@ extern "C"
|
|||
*/
|
||||
|
||||
/* This familiy of allocators is used to manage user-accessible memory
|
||||
* from the kernel.
|
||||
* from the kernel. In the flat build, the following are declared in
|
||||
* stdlib.h and are directly callable. In the kernel-phase of the kernel
|
||||
* build, the following are defined in userspace.h as macros that call
|
||||
* into user-space via a header at the begining of the user-space blob.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_NUTTX_KERNEL
|
||||
#define kumm_initialize(h,s) umm_initialize(h,s)
|
||||
#define kumm_addregion(h,s) umm_addregion(h,s)
|
||||
#define kumm_trysemaphore() umm_trysemaphore()
|
||||
#define kumm_givesemaphore() umm_givesemaphore()
|
||||
|
||||
# define kumm_initialize(h,s) umm_initialize(h,s)
|
||||
# define kumm_addregion(h,s) umm_addregion(h,s)
|
||||
# define kumm_trysemaphore() umm_trysemaphore()
|
||||
# define kumm_givesemaphore() umm_givesemaphore()
|
||||
#ifndef CONFIG_NUTTX_KERNEL
|
||||
/* In the flat build, the following are declared in stdlib.h and are
|
||||
* directly callable.
|
||||
*/
|
||||
|
||||
# define kumalloc(s) malloc(s)
|
||||
# define kuzalloc(s) zalloc(s)
|
||||
|
@ -92,24 +99,24 @@ extern "C"
|
|||
# define kufree(p) free(p)
|
||||
|
||||
#else
|
||||
/* In the kernel-phase of the kernel build, the following are defined
|
||||
* in userspace.h as macros that call into user-space via a header at
|
||||
* the begining of the user-space blob.
|
||||
*/
|
||||
|
||||
/* This familiy of allocators is used to manage kernel protected memory */
|
||||
|
||||
void kumm_initialize(FAR void *heap_start, size_t heap_size);
|
||||
void kumm_addregion(FAR void *heapstart, size_t heapsize);
|
||||
int kumm_trysemaphore(void);
|
||||
void kumm_givesemaphore(void);
|
||||
|
||||
FAR void *kumalloc(size_t size);
|
||||
FAR void *kuzalloc(size_t size);
|
||||
FAR void *kurealloc(FAR void *oldmem, size_t newsize);
|
||||
void kufree(FAR void *mem);
|
||||
# define kumalloc(s) umm_malloc(s)
|
||||
# define kuzalloc(s) umm_zalloc(s)
|
||||
# define kurealloc(p,s) umm_realloc(p,s)
|
||||
# define kufree(p) umm_free(p)
|
||||
|
||||
#endif
|
||||
|
||||
/* This familiy of allocators is used to manage kernel protected memory */
|
||||
|
||||
#ifndef CONFIG_NUTTX_KERNEL
|
||||
/* If this is not a kernel build, then these map to the same interfaces
|
||||
* as were used for the user-mode function.
|
||||
*/
|
||||
|
||||
# define kmm_initialize(h,s) /* Initialization done by kumm_initialize */
|
||||
# define kmm_addregion(h,s) umm_addregion(h,s)
|
||||
|
@ -122,18 +129,25 @@ void kufree(FAR void *mem);
|
|||
# define kfree(p) free(p)
|
||||
|
||||
#elif !defined(CONFIG_MM_KERNEL_HEAP)
|
||||
/* If this the kernel phase of a kernel build, and there are only user-space
|
||||
* allocators, then the following are defined in userspace.h as macros that
|
||||
* call into user-space via a header at the begining of the user-space blob.
|
||||
*/
|
||||
|
||||
# define kmm_initialize(h,s) /* Initialization done by kumm_initialize */
|
||||
# define kmm_addregion(h,s) kumm_addregion(h,s)
|
||||
# define kmm_trysemaphore() kumm_trysemaphore()
|
||||
# define kmm_givesemaphore() kumm_givesemaphore()
|
||||
# define kmm_addregion(h,s) umm_addregion(h,s)
|
||||
# define kmm_trysemaphore() umm_trysemaphore()
|
||||
# define kmm_givesemaphore() umm_givesemaphore()
|
||||
|
||||
# define kmalloc(s) kumalloc(s)
|
||||
# define kzalloc(s) kuzalloc(s)
|
||||
# define krealloc(p,s) kurealloc(p,s)
|
||||
# define kfree(p) kufree(p)
|
||||
# define kmalloc(s) umm_malloc(s)
|
||||
# define kzalloc(s) umm_zalloc(s)
|
||||
# define krealloc(p,s) umm_realloc(p,s)
|
||||
# define kfree(p) umm_free(p)
|
||||
|
||||
#else
|
||||
/* Otherwise, the kernel-space allocators are declared here and we can call
|
||||
* them directly.
|
||||
*/
|
||||
|
||||
void kmm_initialize(FAR void *heap_start, size_t heap_size);
|
||||
void kmm_addregion(FAR void *heapstart, size_t heapsize);
|
||||
|
|
155
include/nuttx/userspace.h
Normal file
155
include/nuttx/userspace.h
Normal file
|
@ -0,0 +1,155 @@
|
|||
/****************************************************************************
|
||||
* include/nuttx/userspace.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_USERSPACE_H
|
||||
#define __INCLUDE_NUTTX_USERSPACE_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef CONFIG_NUTTX_KERNEL
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
/* Configuration ************************************************************/
|
||||
/* If CONFIG_NUTTX_KERNEL, then CONFIG_NUTTX_USERSPACE must be defined to
|
||||
* provide the address where the user-space header can be found in memory.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_NUTTX_USERSPACE
|
||||
# error "CONFIG_NUTTX_USERSPACE is not defined"
|
||||
#endif
|
||||
|
||||
/* Let's insist on 4-byte alignment. This alignment may not be required
|
||||
* technically for all platforms. However, neither is it an unreasonable
|
||||
* requirement for any platform.
|
||||
*/
|
||||
|
||||
#if (CONFIG_NUTTX_USERSPACE & 3) != 0
|
||||
# warning "CONFIG_NUTTX_USERSPACE is not aligned to a 4-byte boundary"
|
||||
#endif
|
||||
|
||||
/* Helper Macros ************************************************************/
|
||||
/* This macro is used to access the struct userpace_s header that can be
|
||||
* found at the beginning of the user-space blob.
|
||||
*/
|
||||
|
||||
#define USERSPACE ((FAR struct userspace_s *)CONFIG_NUTTX_USERSPACE)
|
||||
|
||||
/* In user space, these functions are directly callable. In kernel space,
|
||||
* they can be called through the userspace structure.
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_NUTTX_KERNEL) && defined(__KERNEL__)
|
||||
# define umm_initialize(b,s) USERSPACE->mm_initialize(b,s)
|
||||
# define umm_addregion(b,s) USERSPACE->mm_addregion(b,s)
|
||||
# define umm_trysemaphore() USERSPACE->mm_trysemaphore()
|
||||
# define umm_givesemaphore() USERSPACE->mm_givesemaphore()
|
||||
# define umm_malloc(s) USERSPACE->mm_malloc(s)
|
||||
# define umm_zalloc(s) USERSPACE->mm_zalloc(s)
|
||||
# define umm_realloc(p,s) USERSPACE->mm_realloc(p,s)
|
||||
# define umm_free(p) USERSPACE->mm_free(p)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Type Definitions
|
||||
****************************************************************************/
|
||||
/* Every user-space blob starts with a header that provides information about
|
||||
* the blob. The form of that header is provided by struct userspace_s. An
|
||||
* instance of this structure is expected to reside at CONFIG_NUTTX_USERSPACE.
|
||||
*/
|
||||
|
||||
struct userspace_s
|
||||
{
|
||||
/* General memory map */
|
||||
|
||||
main_t us_entrypoint;
|
||||
uintptr_t us_textstart;
|
||||
uintptr_t us_textend;
|
||||
uintptr_t us_datasource;
|
||||
uintptr_t us_datastart;
|
||||
uintptr_t us_dataend;
|
||||
uintptr_t us_bssstart;
|
||||
uintptr_t us_bssend;
|
||||
|
||||
/* Memory manager entry points */
|
||||
|
||||
void (*mm_initialize)(FAR void *heap_start, size_t heap_size);
|
||||
void (*mm_addregion)(FAR void *heap_start, size_t heap_size);
|
||||
int (*mm_trysemaphore)(void);
|
||||
void (*mm_givesemaphore)(void);
|
||||
|
||||
FAR void *(*mm_malloc)(size_t size);
|
||||
FAR void *(*mm_realloc)(FAR void *oldmem, size_t newsize);
|
||||
FAR void *(*mm_zalloc)(size_t size);
|
||||
void (*mm_free)(FAR void *mem);
|
||||
|
||||
/* User-space work queue support */
|
||||
|
||||
#if defined(CONFIG_SCHED_WORKQUEUE) && defined(CONFIG_SCHED_USRWORK)
|
||||
int (*work_usrstart)(void);
|
||||
#endif
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_NUTTX_KERNEL */
|
||||
#endif /* __INCLUDE_NUTTX_USERSPACE_H */
|
|
@ -214,8 +214,11 @@ static void work_process(FAR struct wqueue_s *wqueue)
|
|||
*
|
||||
* These worker threads are started by the OS during normal bringup.
|
||||
*
|
||||
* work_usrthread: This is a user mode work queue. It must be started
|
||||
* by application code by calling work_usrstart().
|
||||
* work_usrthread: This is a user mode work queue. It must be built into
|
||||
* the applicatino blob during the user phase of a kernel build. The
|
||||
* user work thread will then automatically be started when the system
|
||||
* boots by calling through the pointer found in the header on the user
|
||||
* space blob.
|
||||
*
|
||||
* All of these entrypoints are referenced by OS internally and should not
|
||||
* not be accessed by application logic.
|
||||
|
|
|
@ -92,9 +92,7 @@ int work_usrstart(void)
|
|||
|
||||
DEBUGASSERT(g_usrwork[USRWORK] == NULL);
|
||||
|
||||
/* Start a lower priority worker thread for other, non-critical continuation
|
||||
* tasks
|
||||
*/
|
||||
/* Start a user-mode worker thread for use by applications. */
|
||||
|
||||
svdbg("Starting user-mode worker thread\n");
|
||||
|
||||
|
|
|
@ -46,8 +46,7 @@ CSRCS += mm_memalign.c mm_free.c mm_mallinfo.c
|
|||
|
||||
CSRCS += mm_user.c
|
||||
ifeq ($(CONFIG_NUTTX_KERNEL),y)
|
||||
CSRCS += mm_kerneluser.c
|
||||
ifeq ($(CONFIG_NUTTX_KERNEL),y)
|
||||
ifeq ($(CONFIG_MM_KERNEL_HEAP),y)
|
||||
CSRCS += mm_kernel.c
|
||||
endif
|
||||
endif
|
||||
|
|
|
@ -1,309 +0,0 @@
|
|||
/************************************************************************
|
||||
* mm/mm_kerneluser.c
|
||||
*
|
||||
* Copyright (C) 2011, 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 <assert.h>
|
||||
|
||||
#include <nuttx/kmalloc.h>
|
||||
|
||||
#if defined(CONFIG_NUTTX_KERNEL) && defined(__KERNEL__)
|
||||
|
||||
/* This logic is all tentatively and, hopefully, will grow in usability.
|
||||
* For now, the kernel-mode build uses the memory manager that is
|
||||
* provided in the user-space build. That is awkward but reasonable for
|
||||
* the current level of support: At present, only memory protection is
|
||||
* provided. Kernel-mode code may call into user-mode code, but not
|
||||
* vice-versa. So hosting the memory manager in user-space allows the
|
||||
* memory manager to be shared in both kernel- and user-mode spaces.
|
||||
*
|
||||
* In the longer run, if an MMU is support that can provide virtualized
|
||||
* memory, then some SLAB memory manager will be required in kernel-space
|
||||
* with some kind of brk() system call to obtain mapped heap space.
|
||||
*
|
||||
* In the current build model, the user-space module is built first. The
|
||||
* file user_map.h is generated in the first pass and contains the
|
||||
* addresses of the memory manager needed in this file:
|
||||
*/
|
||||
|
||||
#include <arch/board/user_map.h>
|
||||
|
||||
/************************************************************************
|
||||
* Pre-processor definition
|
||||
************************************************************************/
|
||||
|
||||
/* These values are obtained from user_map.h */
|
||||
|
||||
#define KINITIALIZE(h,s) ((kminitialize_t)CONFIG_USER_MMINIT)(h,s)
|
||||
#define KADDREGION(h,s) ((kmaddregion_t)CONFIG_USER_MMADDREGION)(h,s)
|
||||
#define KMALLOC(s) ((kmalloc_t)CONFIG_USER_MALLOC)(s)
|
||||
#define KZALLOC(s) ((kzalloc_t)CONFIG_USER_ZALLOC)(s)
|
||||
#define KREALLOC(p,s) ((krealloc_t)CONFIG_USER_REALLOC)(p,s)
|
||||
#define KFREE(p) ((kfree_t)CONFIG_USER_FREE)(p)
|
||||
#define KTRYSEMAPHORE() ((kmtrysemaphore_t) CONFIG_USER_MMTRYSEM )()
|
||||
#define KGIVESEMAPHORE() ((kmgivesemaphore_t)CONFIG_USER_MMGIVESEM)()
|
||||
|
||||
/************************************************************************
|
||||
* Private Types
|
||||
************************************************************************/
|
||||
|
||||
typedef void (*kminitialize_t)(FAR void*, size_t);
|
||||
typedef void (*kmaddregion_t)(FAR void*, size_t);
|
||||
typedef FAR void *(*kmalloc_t)(size_t);
|
||||
typedef FAR void *(*kzalloc_t)(size_t);
|
||||
typedef FAR void *(*krealloc_t)(FAR void*, size_t);
|
||||
typedef void (*kfree_t)(FAR void *);
|
||||
typedef int (*kmtrysemaphore_t)(void);
|
||||
typedef void (*kmgivesemaphore_t)(void);
|
||||
|
||||
/************************************************************************
|
||||
* Private Functions
|
||||
************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
* Name: kumm_initialize
|
||||
*
|
||||
* Description:
|
||||
* This is a simple redirection to the user-space 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
|
||||
*
|
||||
* Assumptions:
|
||||
* 1. mm_initialize() resides in user-space
|
||||
* 2. The address of the user space mm_initialize() is provided in
|
||||
* user_map.h
|
||||
* 3. The user-space mm_initialize() is callable from kernel-space.
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
void kumm_initialize(FAR void *heap_start, size_t heap_size)
|
||||
{
|
||||
return KINITIALIZE(heap_start, heap_size);
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Name: kumm_addregion
|
||||
*
|
||||
* Description:
|
||||
* This is a simple redirection to the user-space 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
|
||||
*
|
||||
* Assumptions:
|
||||
* 1. mm_addregion() resides in user-space
|
||||
* 2. The address of the user space mm_addregion() is provided in
|
||||
* user_map.h
|
||||
* 3. The user-space mm_addregion() is callable from kernel-space.
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
void kumm_addregion(FAR void *heap_start, size_t heap_size)
|
||||
{
|
||||
return KADDREGION(heap_start, heap_size);
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Name: kumalloc
|
||||
*
|
||||
* Description:
|
||||
* This is a simple redirection to the user-space malloc() function.
|
||||
*
|
||||
* Parameters:
|
||||
* size - Size (in bytes) of the memory region to be allocated.
|
||||
*
|
||||
* Return Value:
|
||||
* The address of the allocated memory (NULL on failure to allocate)
|
||||
*
|
||||
* Assumptions:
|
||||
* 1. malloc() resides in user-space
|
||||
* 2. The address of the user space malloc() is provided in user_map.h
|
||||
* 3. The user-space malloc() is callable from kernel-space.
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
FAR void *kumalloc(size_t size)
|
||||
{
|
||||
return KMALLOC(size);
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Name: kuzalloc
|
||||
*
|
||||
* Description:
|
||||
* This is a simple redirection to the user-space zalloc() function.
|
||||
*
|
||||
* Parameters:
|
||||
* size - Size (in bytes) of the memory region to be allocated.
|
||||
*
|
||||
* Return Value:
|
||||
* The address of the allocated memory (NULL on failure to allocate)
|
||||
*
|
||||
* Assumptions:
|
||||
* 1. zalloc() resides in user-space
|
||||
* 2. The address of the user space zalloc() is provided in user_map.h
|
||||
* 3. The user-space zalloc() is callable from kernel-space.
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
FAR void *kuzalloc(size_t size)
|
||||
{
|
||||
return KZALLOC(size);
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Name: kurealloc
|
||||
*
|
||||
* Description:
|
||||
* This is a simple redirection to the user-space realloc() function.
|
||||
*
|
||||
* Parameters:
|
||||
* oldmem - The old memory allocated
|
||||
* newsize - Size (in bytes) of the new memory region to be re-allocated.
|
||||
*
|
||||
* Return Value:
|
||||
* The address of the re-allocated memory (NULL on failure to re-allocate)
|
||||
*
|
||||
* Assumptions:
|
||||
* 1. realloc() resides in user-space
|
||||
* 2. The address of the user space realloc() is provided in user_map.h
|
||||
* 3. The user-space realloc() is callable from kernel-space.
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
FAR void *kurealloc(FAR void *oldmem, size_t newsize)
|
||||
{
|
||||
return KREALLOC(oldmem, newsize);
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Name: kufree
|
||||
*
|
||||
* Description:
|
||||
* This is a simple redirection to the user-space free() function.
|
||||
*
|
||||
* Parameters:
|
||||
* None
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Assumptions:
|
||||
* 1. free() resides in user-space
|
||||
* 2. The address of the user space free() is provided in user_map.h
|
||||
* 3. The user-space free() is callable from kernel-space.
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
void kufree(FAR void *mem)
|
||||
{
|
||||
#if defined(CONFIG_MM_KERNEL_HEAP) && defined(CONFIG_DEBUG)
|
||||
DEBUGASSERT(!kmm_heapmember(mem));
|
||||
#endif
|
||||
return KFREE(mem);
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Name: kumm_trysemaphore
|
||||
*
|
||||
* Description:
|
||||
* This is a simple redirection to the user-space mm_trysemaphore()
|
||||
* function.
|
||||
*
|
||||
* Parameters:
|
||||
* None
|
||||
*
|
||||
* Return Value:
|
||||
* OK on success; a negated errno on failure
|
||||
*
|
||||
* Assumptions:
|
||||
* 1. mm_trysemaphore() resides in user-space
|
||||
* 2. The address of the user space mm_trysemaphore() is provided in
|
||||
* user_map.h
|
||||
* 3. The user-space mm_semaphore() is callable from kernel-space.
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
int kumm_trysemaphore(void)
|
||||
{
|
||||
return KTRYSEMAPHORE();
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
* Name: kumm_givesemaphore
|
||||
*
|
||||
* Description:
|
||||
* This is a simple redirection to the user-space mm_givesemaphore()
|
||||
* function.
|
||||
*
|
||||
* Parameters:
|
||||
* None
|
||||
*
|
||||
* Return Value:
|
||||
* OK on success; a negated errno on failure
|
||||
*
|
||||
* Assumptions:
|
||||
* 1. mm_givesemaphore() resides in user-space
|
||||
* 2. The address of the user space mm_givesemaphore() is provided in
|
||||
* user_map.h
|
||||
* 3. The user-space mm_semaphore() is callable from kernel-space.
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
void kumm_givesemaphore(void)
|
||||
{
|
||||
KGIVESEMAPHORE();
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NUTTX_KERNEL && __KERNEL__ */
|
|
@ -49,14 +49,12 @@
|
|||
|
||||
#include <nuttx/init.h>
|
||||
#include <nuttx/wqueue.h>
|
||||
#include <nuttx/userspace.h>
|
||||
|
||||
#include "os_internal.h"
|
||||
#ifdef CONFIG_PAGING
|
||||
# include "pg_internal.h"
|
||||
#endif
|
||||
#ifdef CONFIG_NUTTX_KERNEL
|
||||
# include "arch/board/user_map.h"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
|
@ -130,7 +128,7 @@
|
|||
|
||||
int os_bringup(void)
|
||||
{
|
||||
int init_taskid;
|
||||
int taskid;
|
||||
|
||||
/* Setup up the initial environment for the idle task. At present, this
|
||||
* may consist of only the initial PATH variable. The PATH variable is
|
||||
|
@ -154,7 +152,7 @@ int os_bringup(void)
|
|||
g_pgworker = KERNEL_THREAD("pgfill", CONFIG_PAGING_DEFPRIO,
|
||||
CONFIG_PAGING_STACKSIZE,
|
||||
(main_t)pg_worker, (FAR char * const *)NULL);
|
||||
ASSERT(g_pgworker > 0);
|
||||
DEBUGASSERT(g_pgworker > 0);
|
||||
#endif
|
||||
|
||||
/* Start the worker thread that will serve as the device driver "bottom-
|
||||
|
@ -173,7 +171,7 @@ int os_bringup(void)
|
|||
g_work[HPWORK].pid = KERNEL_THREAD(HPWORKNAME, CONFIG_SCHED_WORKPRIORITY,
|
||||
CONFIG_SCHED_WORKSTACKSIZE,
|
||||
(main_t)work_hpthread, (FAR char * const *)NULL);
|
||||
ASSERT(g_work[HPWORK].pid > 0);
|
||||
DEBUGASSERT(g_work[HPWORK].pid > 0);
|
||||
|
||||
/* Start a lower priority worker thread for other, non-critical continuation
|
||||
* tasks
|
||||
|
@ -186,29 +184,46 @@ int os_bringup(void)
|
|||
g_work[LPWORK].pid = KERNEL_THREAD(LPWORKNAME, CONFIG_SCHED_LPWORKPRIORITY,
|
||||
CONFIG_SCHED_LPWORKSTACKSIZE,
|
||||
(main_t)work_lpthread, (FAR char * const *)NULL);
|
||||
ASSERT(g_work[LPWORK].pid > 0);
|
||||
DEBUGASSERT(g_work[LPWORK].pid > 0);
|
||||
|
||||
#endif /* CONFIG_SCHED_LPWORK */
|
||||
#endif /* CONFIG_SCHED_HPWORK */
|
||||
|
||||
#if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_SCHED_USRWORK)
|
||||
/* Start the user-space work queue */
|
||||
|
||||
DEBUGASSERT(USERSPACE->work_usrstart != NULL);
|
||||
taskid = USERSPACE->work_usrstart();
|
||||
DEBUGASSERT(taskid > 0);
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_SCHED_WORKQUEUE */
|
||||
|
||||
/* Once the operating system has been initialized, the system must be
|
||||
* started by spawning the user init thread of execution. This is the
|
||||
* first user-mode thead.
|
||||
*
|
||||
* In a kernel build (CONFIG_NUTTX_KERNEL), it is expected that this user
|
||||
* initialization function will call work_usrstart() to start the user
|
||||
* work thread (if so configured).
|
||||
*/
|
||||
|
||||
svdbg("Starting init thread\n");
|
||||
|
||||
/* Start the default application at CONFIG_USER_ENTRYPOINT() */
|
||||
/* Start the default application. In a flat build, this is entrypoint
|
||||
* is given by the definitions, CONFIG_USER_ENTRYPOINT. In the kernel
|
||||
* build, however, we must get the address of the entrypoint from the
|
||||
* header at the beginning of the user-space blob.
|
||||
*/
|
||||
|
||||
init_taskid = TASK_CREATE("init", SCHED_PRIORITY_DEFAULT,
|
||||
CONFIG_USERMAIN_STACKSIZE,
|
||||
(main_t)CONFIG_USER_ENTRYPOINT, (FAR char * const *)NULL);
|
||||
ASSERT(init_taskid > 0);
|
||||
#ifdef CONFIG_NUTTX_KERNEL
|
||||
DEBUGASSERT(USERSPACE->us_entrypoint != NULL);
|
||||
taskid = TASK_CREATE("init", SCHED_PRIORITY_DEFAULT,
|
||||
CONFIG_USERMAIN_STACKSIZE, USERSPACE->us_entrypoint,
|
||||
(FAR char * const *)NULL);
|
||||
#else
|
||||
taskid = TASK_CREATE("init", SCHED_PRIORITY_DEFAULT,
|
||||
CONFIG_USERMAIN_STACKSIZE,
|
||||
(main_t)CONFIG_USER_ENTRYPOINT,
|
||||
(FAR char * const *)NULL);
|
||||
#endif
|
||||
DEBUGASSERT(taskid > 0);
|
||||
|
||||
/* We an save a few bytes by discarding the IDLE thread's environment. */
|
||||
|
||||
|
|
Loading…
Reference in a new issue