More MPU-related fixes
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5746 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
6239b70352
commit
8bba3440a3
7
Kconfig
7
Kconfig
@ -383,6 +383,13 @@ config DEBUG_GRAPHICS
|
|||||||
---help---
|
---help---
|
||||||
Enable NX graphics debug SYSLOG output (disabled by default)
|
Enable NX graphics debug SYSLOG output (disabled by default)
|
||||||
|
|
||||||
|
config DEBUG_SYSCALL
|
||||||
|
bool "Enable SYSCALL Debug Output"
|
||||||
|
default n
|
||||||
|
depends on NUTTX_KERNEL
|
||||||
|
---help---
|
||||||
|
Enable very low level output related to system calls
|
||||||
|
|
||||||
comment "Driver Debug Options"
|
comment "Driver Debug Options"
|
||||||
|
|
||||||
config DEBUG_LCD
|
config DEBUG_LCD
|
||||||
|
@ -164,8 +164,11 @@ struct xcptcontext
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_NUTTX_KERNEL
|
#ifdef CONFIG_NUTTX_KERNEL
|
||||||
/* The following holds the return address from a system call */
|
/* The following holds the return address and the exc_return value needed
|
||||||
|
* to return from a system call.
|
||||||
|
*/
|
||||||
|
|
||||||
|
uint32_t excreturn;
|
||||||
uint32_t sysreturn;
|
uint32_t sysreturn;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ struct xcptcontext
|
|||||||
|
|
||||||
#ifdef CONFIG_NUTTX_KERNEL
|
#ifdef CONFIG_NUTTX_KERNEL
|
||||||
/* The following holds the return address and the exc_return value needed
|
/* The following holds the return address and the exc_return value needed
|
||||||
* return from a system call.
|
* to return from a system call.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
uint32_t excreturn;
|
uint32_t excreturn;
|
||||||
|
@ -65,10 +65,11 @@
|
|||||||
/* Debug output from this file may interfere with context switching! To get
|
/* Debug output from this file may interfere with context switching! To get
|
||||||
* debug output you must enabled the following in your NuttX configuration:
|
* debug output you must enabled the following in your NuttX configuration:
|
||||||
*
|
*
|
||||||
* CONFIG_DEBUG and CONFIG_DEBUG_SYSCALL
|
* - CONFIG_DEBUG and CONFIG_DEBUG_SYSCALL (shows only syscalls)
|
||||||
|
* - CONFIG_DEBUG and CONFIG_DEBUG_SVCALL (shows everything)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef CONFIG_DEBUG_SYSCALL
|
#if defined(CONFIG_DEBUG_SYSCALL) || defined(CONFIG_DEBUG_SVCALL)
|
||||||
# define svcdbg(format, arg...) lldbg(format, ##arg)
|
# define svcdbg(format, arg...) lldbg(format, ##arg)
|
||||||
#else
|
#else
|
||||||
# define svcdbg(x...)
|
# define svcdbg(x...)
|
||||||
@ -140,31 +141,40 @@ static void dispatch_syscall(void)
|
|||||||
int up_svcall(int irq, FAR void *context)
|
int up_svcall(int irq, FAR void *context)
|
||||||
{
|
{
|
||||||
uint32_t *regs = (uint32_t*)context;
|
uint32_t *regs = (uint32_t*)context;
|
||||||
|
uint32_t cmd;
|
||||||
|
|
||||||
DEBUGASSERT(regs && regs == current_regs);
|
DEBUGASSERT(regs && regs == current_regs);
|
||||||
|
cmd = regs[REG_R0];
|
||||||
|
|
||||||
/* The SVCall software interrupt is called with R0 = system call command
|
/* The SVCall software interrupt is called with R0 = system call command
|
||||||
* and R1..R7 = variable number of arguments depending on the system call.
|
* and R1..R7 = variable number of arguments depending on the system call.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
svcdbg("SVCALL Entry: regs: %p cmd: %d\n", regs, regs[REG_R0]);
|
#if defined(CONFIG_DEBUG_SYSCALL) || defined(CONFIG_DEBUG_SVCALL)
|
||||||
svcdbg(" R0: %08x %08x %08x %08x %08x %08x %08x %08x\n",
|
# ifndef CONFIG_DEBUG_SVCALL
|
||||||
regs[REG_R0], regs[REG_R1], regs[REG_R2], regs[REG_R3],
|
if (cmd > SYS_switch_context)
|
||||||
regs[REG_R4], regs[REG_R5], regs[REG_R6], regs[REG_R7]);
|
# endif
|
||||||
svcdbg(" R8: %08x %08x %08x %08x %08x %08x %08x %08x\n",
|
{
|
||||||
regs[REG_R8], regs[REG_R9], regs[REG_R10], regs[REG_R11],
|
svcdbg("SVCALL Entry: regs: %p cmd: %d\n", regs, cmd);
|
||||||
regs[REG_R12], regs[REG_R13], regs[REG_R14], regs[REG_R15]);
|
svcdbg(" R0: %08x %08x %08x %08x %08x %08x %08x %08x\n",
|
||||||
#ifdef CONFIG_NUTTX_KERNEL
|
regs[REG_R0], regs[REG_R1], regs[REG_R2], regs[REG_R3],
|
||||||
svcdbg("xPSR: %08x BASEPRI: %08x EXEC_RETURN: %08x\n",
|
regs[REG_R4], regs[REG_R5], regs[REG_R6], regs[REG_R7]);
|
||||||
regs[REG_XPSR], regs[REG_BASEPRI], regs[REG_EXC_RETURN]);
|
svcdbg(" R8: %08x %08x %08x %08x %08x %08x %08x %08x\n",
|
||||||
#else
|
regs[REG_R8], regs[REG_R9], regs[REG_R10], regs[REG_R11],
|
||||||
svcdbg("xPSR: %08x BASEPRI: %08x\n",
|
regs[REG_R12], regs[REG_R13], regs[REG_R14], regs[REG_R15]);
|
||||||
regs[REG_XPSR], regs[REG_BASEPRI]);
|
# ifdef CONFIG_NUTTX_KERNEL
|
||||||
|
svcdbg(" PSR: %08x BASEPRI: %08x EXC_RETURN: %08x\n",
|
||||||
|
regs[REG_XPSR], regs[REG_BASEPRI], regs[REG_EXC_RETURN]);
|
||||||
|
# else
|
||||||
|
svcdbg(" PSR: %08x BASEPRI: %08x\n",
|
||||||
|
regs[REG_XPSR], regs[REG_BASEPRI]);
|
||||||
|
# endif
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Handle the SVCall according to the command in R0 */
|
/* Handle the SVCall according to the command in R0 */
|
||||||
|
|
||||||
switch (regs[REG_R0])
|
switch (cmd)
|
||||||
{
|
{
|
||||||
/* R0=SYS_save_context: This is a save context command:
|
/* R0=SYS_save_context: This is a save context command:
|
||||||
*
|
*
|
||||||
@ -249,23 +259,20 @@ int up_svcall(int irq, FAR void *context)
|
|||||||
{
|
{
|
||||||
struct tcb_s *rtcb = sched_self();
|
struct tcb_s *rtcb = sched_self();
|
||||||
|
|
||||||
/* Make sure that we got here from a privileged thread and
|
/* Make sure that there is a saved syscall return address. */
|
||||||
* that there is a saved syscall return address.
|
|
||||||
*/
|
|
||||||
|
|
||||||
DEBUGASSERT(rtcb->xcp.sysreturn != 0 &&
|
DEBUGASSERT(rtcb->xcp.sysreturn != 0);
|
||||||
regs[REG_EXC_RETURN] == EXC_RETURN_PRIVTHR);
|
|
||||||
|
|
||||||
/* Setup to return to the saved syscall return address in
|
/* Setup to return to the saved syscall return address in
|
||||||
* unprivileged mode.
|
* the original mode.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
regs[REG_PC] = rtcb->xcp.sysreturn;
|
regs[REG_PC] = rtcb->xcp.sysreturn;
|
||||||
regs[REG_EXC_RETURN] = EXC_RETURN_UNPRIVTHR;
|
regs[REG_EXC_RETURN] = rtcb->xcp.excreturn;
|
||||||
rtcb->xcp.sysreturn = 0;
|
rtcb->xcp.sysreturn = 0;
|
||||||
|
|
||||||
/* The return value must be in R0-R1. dispatch_syscall() temporarily
|
/* The return value must be in R0-R1. dispatch_syscall() temporarily
|
||||||
* moved the value to R2.
|
* moved the value for R0 into R2.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
regs[REG_R0] = regs[REG_R2];
|
regs[REG_R0] = regs[REG_R2];
|
||||||
@ -295,7 +302,7 @@ int up_svcall(int irq, FAR void *context)
|
|||||||
regs[REG_PC] = (uint32_t)USERSPACE->task_startup;
|
regs[REG_PC] = (uint32_t)USERSPACE->task_startup;
|
||||||
regs[REG_EXC_RETURN] = EXC_RETURN_UNPRIVTHR;
|
regs[REG_EXC_RETURN] = EXC_RETURN_UNPRIVTHR;
|
||||||
|
|
||||||
/* Change the paramter ordering to match the expection of struct
|
/* Change the parameter ordering to match the expectation of struct
|
||||||
* userpace_s task_startup:
|
* userpace_s task_startup:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -316,20 +323,21 @@ int up_svcall(int irq, FAR void *context)
|
|||||||
#ifdef CONFIG_NUTTX_KERNEL
|
#ifdef CONFIG_NUTTX_KERNEL
|
||||||
FAR struct tcb_s *rtcb = sched_self();
|
FAR struct tcb_s *rtcb = sched_self();
|
||||||
|
|
||||||
/* Verify the the SYS call number is within range */
|
/* Verify that the SYS call number is within range */
|
||||||
|
|
||||||
DEBUGASSERT(regs[REG_R0] < SYS_maxsyscall);
|
DEBUGASSERT(cmd < SYS_maxsyscall);
|
||||||
|
|
||||||
/* Make sure that we got here from an unprivileged thread and that
|
/* Make sure that there is a no saved syscall return address. We
|
||||||
* there is a no saved syscall return address.
|
* cannot yet handle nested system calls.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
DEBUGASSERT(rtcb->xcp.sysreturn == 0 &&
|
DEBUGASSERT(rtcb->xcp.sysreturn == 0);
|
||||||
regs[REG_EXC_RETURN] == EXC_RETURN_UNPRIVTHR);
|
|
||||||
|
|
||||||
/* Setup to return to dispatch_syscall in privileged mode. */
|
/* Setup to return to dispatch_syscall in privileged mode. */
|
||||||
|
|
||||||
rtcb->xcp.sysreturn = regs[REG_PC];
|
rtcb->xcp.sysreturn = regs[REG_PC];
|
||||||
|
rtcb->xcp.excreturn = regs[REG_EXC_RETURN];
|
||||||
|
|
||||||
regs[REG_PC] = (uint32_t)dispatch_syscall;
|
regs[REG_PC] = (uint32_t)dispatch_syscall;
|
||||||
regs[REG_EXC_RETURN] = EXC_RETURN_PRIVTHR;
|
regs[REG_EXC_RETURN] = EXC_RETURN_PRIVTHR;
|
||||||
|
|
||||||
@ -345,9 +353,14 @@ int up_svcall(int irq, FAR void *context)
|
|||||||
|
|
||||||
/* Report what happened. That might difficult in the case of a context switch */
|
/* Report what happened. That might difficult in the case of a context switch */
|
||||||
|
|
||||||
|
#if defined(CONFIG_DEBUG_SYSCALL) || defined(CONFIG_DEBUG_SVCALL)
|
||||||
|
# ifndef CONFIG_DEBUG_SVCALL
|
||||||
|
if (cmd > SYS_switch_context)
|
||||||
|
# elif
|
||||||
if (regs != current_regs)
|
if (regs != current_regs)
|
||||||
|
# endif
|
||||||
{
|
{
|
||||||
svcdbg("SVCall Return: Context switch!\n");
|
svcdbg("SVCall Return:\n");
|
||||||
svcdbg(" R0: %08x %08x %08x %08x %08x %08x %08x %08x\n",
|
svcdbg(" R0: %08x %08x %08x %08x %08x %08x %08x %08x\n",
|
||||||
current_regs[REG_R0], current_regs[REG_R1], current_regs[REG_R2], current_regs[REG_R3],
|
current_regs[REG_R0], current_regs[REG_R1], current_regs[REG_R2], current_regs[REG_R3],
|
||||||
current_regs[REG_R4], current_regs[REG_R5], current_regs[REG_R6], current_regs[REG_R7]);
|
current_regs[REG_R4], current_regs[REG_R5], current_regs[REG_R6], current_regs[REG_R7]);
|
||||||
@ -355,18 +368,21 @@ int up_svcall(int irq, FAR void *context)
|
|||||||
current_regs[REG_R8], current_regs[REG_R9], current_regs[REG_R10], current_regs[REG_R11],
|
current_regs[REG_R8], current_regs[REG_R9], current_regs[REG_R10], current_regs[REG_R11],
|
||||||
current_regs[REG_R12], current_regs[REG_R13], current_regs[REG_R14], current_regs[REG_R15]);
|
current_regs[REG_R12], current_regs[REG_R13], current_regs[REG_R14], current_regs[REG_R15]);
|
||||||
#ifdef CONFIG_NUTTX_KERNEL
|
#ifdef CONFIG_NUTTX_KERNEL
|
||||||
svcdbg("xPSR: %08x BASEPRI: %08x EXEC_RETURN: %08x\n",
|
svcdbg(" PSR: %08x BASEPRI: %08x EXC_RETURN: %08x\n",
|
||||||
current_regs[REG_XPSR], current_regs[REG_BASEPRI],
|
current_regs[REG_XPSR], current_regs[REG_BASEPRI],
|
||||||
current_regs[REG_EXC_RETURN]);
|
current_regs[REG_EXC_RETURN]);
|
||||||
#else
|
#else
|
||||||
svcdbg("xPSR: %08x BASEPRI: %08x\n",
|
svcdbg(" PSR: %08x BASEPRI: %08x\n",
|
||||||
current_regs[REG_XPSR], current_regs[REG_BASEPRI]);
|
current_regs[REG_XPSR], current_regs[REG_BASEPRI]);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
# ifdef CONFIG_DEBUG_SVCALL
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
svcdbg("SVCall Return: %d\n", regs[REG_R0]);
|
svcdbg("SVCall Return: %d\n", regs[REG_R0]);
|
||||||
}
|
}
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/************************************************************************************
|
/************************************************************************************
|
||||||
* arch/arm/src/armv7-m/mpu.h
|
* arch/arm/src/armv7-m/mpu.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -173,9 +173,9 @@ uint8_t mpu_log2regionfloor(size_t size);
|
|||||||
* Name: mpu_subregion
|
* Name: mpu_subregion
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Given the size of the (1) memory to be mapped and (2) the log2 size
|
* Given (1) the offset to the beginning of valid data, (2) the size of the
|
||||||
* of the mapping to use, determine the minimal sub-region set to span
|
* memory to be mapped and (2) the log2 size of the mapping to use, determine
|
||||||
* that memory region.
|
* the minimal sub-region set to span that memory region.
|
||||||
*
|
*
|
||||||
* Assumption:
|
* Assumption:
|
||||||
* l2size has the same properties as the return value from
|
* l2size has the same properties as the return value from
|
||||||
@ -183,7 +183,7 @@ uint8_t mpu_log2regionfloor(size_t size);
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
uint32_t mpu_subregion(size_t size, uint8_t l2size);
|
uint32_t mpu_subregion(uintptr_t base, size_t size, uint8_t l2size);
|
||||||
|
|
||||||
/************************************************************************************
|
/************************************************************************************
|
||||||
* Inline Functions
|
* Inline Functions
|
||||||
@ -264,7 +264,7 @@ static inline void mpu_userflash(uintptr_t base, size_t size)
|
|||||||
/* Select the region size and the sub-region map */
|
/* Select the region size and the sub-region map */
|
||||||
|
|
||||||
l2size = mpu_log2regionceil(size);
|
l2size = mpu_log2regionceil(size);
|
||||||
subregions = mpu_subregion(size, l2size);
|
subregions = mpu_subregion(base, size, l2size);
|
||||||
|
|
||||||
/* The configure the region */
|
/* The configure the region */
|
||||||
|
|
||||||
@ -302,7 +302,7 @@ static inline void mpu_privflash(uintptr_t base, size_t size)
|
|||||||
/* Select the region size and the sub-region map */
|
/* Select the region size and the sub-region map */
|
||||||
|
|
||||||
l2size = mpu_log2regionceil(size);
|
l2size = mpu_log2regionceil(size);
|
||||||
subregions = mpu_subregion(size, l2size);
|
subregions = mpu_subregion(base, size, l2size);
|
||||||
|
|
||||||
/* The configure the region */
|
/* The configure the region */
|
||||||
|
|
||||||
@ -340,7 +340,7 @@ static inline void mpu_userintsram(uintptr_t base, size_t size)
|
|||||||
/* Select the region size and the sub-region map */
|
/* Select the region size and the sub-region map */
|
||||||
|
|
||||||
l2size = mpu_log2regionceil(size);
|
l2size = mpu_log2regionceil(size);
|
||||||
subregions = mpu_subregion(size, l2size);
|
subregions = mpu_subregion(base, size, l2size);
|
||||||
|
|
||||||
/* The configure the region */
|
/* The configure the region */
|
||||||
|
|
||||||
@ -379,7 +379,7 @@ static inline void mpu_privintsram(uintptr_t base, size_t size)
|
|||||||
/* Select the region size and the sub-region map */
|
/* Select the region size and the sub-region map */
|
||||||
|
|
||||||
l2size = mpu_log2regionceil(size);
|
l2size = mpu_log2regionceil(size);
|
||||||
subregions = mpu_subregion(size, l2size);
|
subregions = mpu_subregion(base, size, l2size);
|
||||||
|
|
||||||
/* The configure the region */
|
/* The configure the region */
|
||||||
|
|
||||||
@ -418,7 +418,7 @@ static inline void mpu_userextsram(uintptr_t base, size_t size)
|
|||||||
/* Select the region size and the sub-region map */
|
/* Select the region size and the sub-region map */
|
||||||
|
|
||||||
l2size = mpu_log2regionceil(size);
|
l2size = mpu_log2regionceil(size);
|
||||||
subregions = mpu_subregion(size, l2size);
|
subregions = mpu_subregion(base, size, l2size);
|
||||||
|
|
||||||
/* The configure the region */
|
/* The configure the region */
|
||||||
|
|
||||||
@ -458,7 +458,7 @@ static inline void mpu_privextsram(uintptr_t base, size_t size)
|
|||||||
/* Select the region size and the sub-region map */
|
/* Select the region size and the sub-region map */
|
||||||
|
|
||||||
l2size = mpu_log2regionceil(size);
|
l2size = mpu_log2regionceil(size);
|
||||||
subregions = mpu_subregion(size, l2size);
|
subregions = mpu_subregion(base, size, l2size);
|
||||||
|
|
||||||
/* The configure the region */
|
/* The configure the region */
|
||||||
|
|
||||||
@ -498,7 +498,7 @@ static inline void mpu_peripheral(uintptr_t base, size_t size)
|
|||||||
/* Select the region size and the sub-region map */
|
/* Select the region size and the sub-region map */
|
||||||
|
|
||||||
l2size = mpu_log2regionceil(size);
|
l2size = mpu_log2regionceil(size);
|
||||||
subregions = mpu_subregion(size, l2size);
|
subregions = mpu_subregion(base, size, l2size);
|
||||||
|
|
||||||
/* The configure the region */
|
/* The configure the region */
|
||||||
|
|
||||||
|
@ -103,7 +103,12 @@ int up_memfault(int irq, FAR void *context)
|
|||||||
mfdbg(" R8: %08x %08x %08x %08x %08x %08x %08x %08x\n",
|
mfdbg(" R8: %08x %08x %08x %08x %08x %08x %08x %08x\n",
|
||||||
regs[REG_R8], regs[REG_R9], regs[REG_R10], regs[REG_R11],
|
regs[REG_R8], regs[REG_R9], regs[REG_R10], regs[REG_R11],
|
||||||
regs[REG_R12], regs[REG_R13], regs[REG_R14], regs[REG_R15]);
|
regs[REG_R12], regs[REG_R13], regs[REG_R14], regs[REG_R15]);
|
||||||
mfdbg(" PSR=%08x\n", regs[REG_XPSR]);
|
#ifdef REG_EXC_RETURN
|
||||||
|
mfdbg(" PSR: %08x EXC_RETURN: %08x\n",
|
||||||
|
regs[REG_XPSR], regs[REG_EXC_RETURN]);
|
||||||
|
#else
|
||||||
|
mfdbg(" PSR: %08x\n", regs[REG_XPSR]);
|
||||||
|
#endif
|
||||||
|
|
||||||
PANIC(OSERR_UNEXPECTEDISR);
|
PANIC(OSERR_UNEXPECTEDISR);
|
||||||
return OK;
|
return OK;
|
||||||
|
@ -58,15 +58,28 @@
|
|||||||
* Private Data
|
* Private Data
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* This set represents the set of disabled memory sub-regions. A bit set
|
/* These sets represent the set of disabled memory sub-regions. A bit set
|
||||||
* corresponds to a disabled sub-region; the LS bit corresponds to the first
|
* corresponds to a disabled sub-region; the LS bit corresponds to the first
|
||||||
* region. The array is indexed by the number of subregions: 0 means no sub-
|
* region.
|
||||||
* regions (0xff), and 0 means all subregions but one (0x00).
|
*
|
||||||
|
* The g_ms_regionmask array is indexed by the number of subregions at the
|
||||||
|
* end of the region: 0 means no sub-regions are available(0xff) and 8 means
|
||||||
|
* all subregions are available (0x00).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static const uint8_t g_regionmap[9] =
|
static const uint8_t g_ms_regionmask[9] =
|
||||||
{
|
{
|
||||||
0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01, 0x00
|
0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00
|
||||||
|
};
|
||||||
|
|
||||||
|
/* The g_ls_regionmask array is indexed by the number of subregions at the
|
||||||
|
* beginning of the region: 0 means no sub-regions need be disabled (0x00)
|
||||||
|
* and 8 means all subregions must be disabled (0xff).
|
||||||
|
*/
|
||||||
|
|
||||||
|
static const uint8_t g_ls_regionmask[9] =
|
||||||
|
{
|
||||||
|
0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff
|
||||||
};
|
};
|
||||||
|
|
||||||
/* The next available region number */
|
/* The next available region number */
|
||||||
@ -77,6 +90,107 @@ static uint8_t g_region;
|
|||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: mpu_subregion_ms
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Given (1) the size of the memory to be mapped and (2) the log2 size
|
||||||
|
* of the mapping to use, determine the minimal sub-region set at the
|
||||||
|
* to be disabled at the higher end of the region.
|
||||||
|
*
|
||||||
|
* Assumption:
|
||||||
|
* l2size has the same properties as the return value from
|
||||||
|
* mpu_log2regionceil()
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static inline uint32_t mpu_subregion_ms(size_t size, uint8_t l2size)
|
||||||
|
{
|
||||||
|
unsigned int nsrs;
|
||||||
|
uint32_t asize;
|
||||||
|
uint32_t mask;
|
||||||
|
|
||||||
|
/* Examples with l2size = 12:
|
||||||
|
*
|
||||||
|
* Shifted Adjusted Number Sub-Region
|
||||||
|
* Size Mask Size Shift Sub-Regions Bitset
|
||||||
|
* 0x1000 0x01ff 0x1000 9 8 0x00
|
||||||
|
* 0x0c00 0x01ff 0x0c00 9 6 0xc0
|
||||||
|
* 0x0c40 0x01ff 0x0e00 9 7 0x80
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (l2size < 32)
|
||||||
|
{
|
||||||
|
mask = ((1 << l2size)-1) >> 3; /* Shifted mask */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The 4Gb region size is a special case */
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* NOTE: There is no way to represent a 4Gb region size in the 32-bit
|
||||||
|
* input.
|
||||||
|
*/
|
||||||
|
|
||||||
|
mask = 0x1fffffff; /* Shifted mask */
|
||||||
|
}
|
||||||
|
|
||||||
|
asize = (size + mask) & ~mask; /* Adjusted size */
|
||||||
|
nsrs = asize >> (l2size-3); /* Number of subregions */
|
||||||
|
return g_ms_regionmask[nsrs];
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: mpu_subregion_ls
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Given (1) the offset to the beginning of data in the region and (2) the
|
||||||
|
* log2 size of the mapping to use, determine the minimal sub-region set
|
||||||
|
* to span that memory region sub-region set at the to be disabled at the
|
||||||
|
* higher end of the region
|
||||||
|
*
|
||||||
|
* Assumption:
|
||||||
|
* l2size has the same properties as the return value from
|
||||||
|
* mpu_log2regionceil()
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static inline uint32_t mpu_subregion_ls(size_t offset, uint8_t l2size)
|
||||||
|
{
|
||||||
|
unsigned int nsrs;
|
||||||
|
uint32_t aoffset;
|
||||||
|
uint32_t mask;
|
||||||
|
|
||||||
|
/* Examples with l2size = 12:
|
||||||
|
*
|
||||||
|
* Shifted Adjusted Number Sub-Region
|
||||||
|
* Offset Mask Offset Shift Sub-Regions Bitset
|
||||||
|
* 0x0000 0x01ff 0x0000 9 8 0x00
|
||||||
|
* 0x0400 0x01ff 0x0400 9 6 0x03
|
||||||
|
* 0x02c0 0x01ff 0x0200 9 7 0x01
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (l2size < 32)
|
||||||
|
{
|
||||||
|
mask = ((1 << l2size)-1) >> 3; /* Shifted mask */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The 4Gb region size is a special case */
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* NOTE: There is no way to represent a 4Gb region size in the 32-bit
|
||||||
|
* input.
|
||||||
|
*/
|
||||||
|
|
||||||
|
mask = 0x1fffffff; /* Shifted mask */
|
||||||
|
}
|
||||||
|
|
||||||
|
aoffset = offset & ~mask; /* Adjusted offset */
|
||||||
|
nsrs = aoffset >> (l2size-3); /* Number of subregions */
|
||||||
|
return g_ls_regionmask[nsrs];
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -115,9 +229,9 @@ uint8_t mpu_log2regionceil(size_t size)
|
|||||||
{
|
{
|
||||||
uint8_t l2size;
|
uint8_t l2size;
|
||||||
|
|
||||||
/* The minimum permitted region size is 16 bytes (log2(16) = 4. */
|
/* The minimum permitted region size is 32 bytes (log2(32) = 5. */
|
||||||
|
|
||||||
for (l2size = 4; l2size < 32 && size > (1 << l2size); l2size++);
|
for (l2size = 5; l2size < 32 && size > (1 << l2size); l2size++);
|
||||||
return l2size;
|
return l2size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,47 +272,45 @@ uint8_t mpu_log2regionfloor(size_t size)
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
uint32_t mpu_subregion(size_t size, uint8_t l2size)
|
uint32_t mpu_subregion(uintptr_t base, size_t size, uint8_t l2size)
|
||||||
{
|
{
|
||||||
unsigned int nsrs;
|
uint32_t mask;
|
||||||
uint32_t asize;
|
size_t offset;
|
||||||
uint32_t mask;
|
uint32_t ret;
|
||||||
|
|
||||||
/* Eight subregions are support. The representation is as an 8-bit
|
/* Eight subregions are supported. The representation is as an 8-bit
|
||||||
* value with the LS bit corresponding to subregion 0. A bit is set
|
* value with the LS bit corresponding to subregion 0. A bit is set
|
||||||
* to disable the sub-region.
|
* to disable the sub-region.
|
||||||
*
|
*
|
||||||
* l2size: Log2 of the actual region size is <= (1 << l2size);
|
* l2size: Log2 of the actual region size is <= (1 << l2size);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
DEBUGASSERT(l2size > 3 && size <= (1 << l2size));
|
DEBUGASSERT(l2size > 4 && size <= (1 << l2size));
|
||||||
|
|
||||||
/* Examples with l2size = 12:
|
/* For region sizes of 32, 64, and 128 bytes, the effect of setting
|
||||||
*
|
* one or more bits of the SRD field to 1 is UNPREDICTABLE.
|
||||||
* Shifted Adjusted Number Sub-Region
|
|
||||||
* Size Mask Size Shift Sub-Regions Bitset
|
|
||||||
* 0x1000 0x01ff 0x1000 9 8 0x00
|
|
||||||
* 0x0c00 0x01ff 0x0c00 9 6 0x03
|
|
||||||
* 0x0c40 0x01ff 0x0e00 9 7 0x01
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (l2size < 32)
|
if (l2size < 8)
|
||||||
{
|
{
|
||||||
mask = ((1 << l2size)-1) >> 3; /* Shifted mask */
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The 4Gb region size is a special case */
|
/* Calculate the offset of the base address into the aligned region. */
|
||||||
|
|
||||||
else
|
mask = (1 << l2size) - 1;
|
||||||
{
|
offset = base & mask;
|
||||||
/* NOTE: There is no way to represent a 4Gb region size in the 32-bit
|
|
||||||
* input.
|
|
||||||
*/
|
|
||||||
|
|
||||||
mask = 0x1fffffff; /* Shifted mask */
|
/* Calculate the mask need to handle disabled subregions at the end of the
|
||||||
}
|
* region
|
||||||
|
*/
|
||||||
|
|
||||||
asize = (size + mask) & ~mask; /* Adjusted size */
|
ret = mpu_subregion_ms(size + offset, l2size);
|
||||||
nsrs = asize >> (l2size-3); /* Number of subregions */
|
|
||||||
return g_regionmap[nsrs];
|
/* Then OR in the mask need to handle disabled subretinos at the beginning
|
||||||
|
* of the region.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ret |= mpu_subregion_ls(offset, l2size);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -65,10 +65,11 @@
|
|||||||
/* Debug output from this file may interfere with context switching! To get
|
/* Debug output from this file may interfere with context switching! To get
|
||||||
* debug output you must enabled the following in your NuttX configuration:
|
* debug output you must enabled the following in your NuttX configuration:
|
||||||
*
|
*
|
||||||
* CONFIG_DEBUG and CONFIG_DEBUG_SYSCALL
|
* - CONFIG_DEBUG and CONFIG_DEBUG_SYSCALL (shows only syscalls)
|
||||||
|
* - CONFIG_DEBUG and CONFIG_DEBUG_SVCALL (shows everything)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef CONFIG_DEBUG_SYSCALL
|
#if defined(CONFIG_DEBUG_SYSCALL) || defined(CONFIG_DEBUG_SVCALL)
|
||||||
# define svcdbg(format, arg...) lldbg(format, ##arg)
|
# define svcdbg(format, arg...) lldbg(format, ##arg)
|
||||||
#else
|
#else
|
||||||
# define svcdbg(x...)
|
# define svcdbg(x...)
|
||||||
@ -92,8 +93,6 @@
|
|||||||
* Description:
|
* Description:
|
||||||
* Call the stub function corresponding to the system call.
|
* Call the stub function corresponding to the system call.
|
||||||
*
|
*
|
||||||
* Here we need to preserve registers:
|
|
||||||
*
|
|
||||||
* R0 - Need not be preserved until after the stub is called.
|
* R0 - Need not be preserved until after the stub is called.
|
||||||
* R1-R3 - Need to be preserved until the stub is called. The values of
|
* R1-R3 - Need to be preserved until the stub is called. The values of
|
||||||
* R0 and R1 returned by the stub must be preserved.
|
* R0 and R1 returned by the stub must be preserved.
|
||||||
@ -141,29 +140,39 @@ static void dispatch_syscall(void)
|
|||||||
int up_svcall(int irq, FAR void *context)
|
int up_svcall(int irq, FAR void *context)
|
||||||
{
|
{
|
||||||
uint32_t *regs = (uint32_t*)context;
|
uint32_t *regs = (uint32_t*)context;
|
||||||
|
uint32_t cmd;
|
||||||
|
|
||||||
DEBUGASSERT(regs && regs == current_regs);
|
DEBUGASSERT(regs && regs == current_regs);
|
||||||
|
cmd = regs[REG_R0];
|
||||||
|
|
||||||
/* The SVCall software interrupt is called with R0 = system call command
|
/* The SVCall software interrupt is called with R0 = system call command
|
||||||
* and R1..R7 = variable number of arguments depending on the system call.
|
* and R1..R7 = variable number of arguments depending on the system call.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
svcdbg("SVCALL Entry: regs: %p cmd: %d\n", regs, regs[REG_R0]);
|
#if defined(CONFIG_DEBUG_SYSCALL) || defined(CONFIG_DEBUG_SVCALL)
|
||||||
svcdbg(" R0: %08x %08x %08x %08x %08x %08x %08x %08x\n",
|
# ifndef CONFIG_DEBUG_SVCALL
|
||||||
regs[REG_R0], regs[REG_R1], regs[REG_R2], regs[REG_R3],
|
if (cmd > SYS_switch_context)
|
||||||
regs[REG_R4], regs[REG_R5], regs[REG_R6], regs[REG_R7]);
|
# endif
|
||||||
svcdbg(" R8: %08x %08x %08x %08x %08x %08x %08x %08x\n",
|
{
|
||||||
regs[REG_R8], regs[REG_R9], regs[REG_R10], regs[REG_R11],
|
svcdbg("SVCALL Entry: regs: %p cmd: %d\n", regs, cmd);
|
||||||
regs[REG_R12], regs[REG_R13], regs[REG_R14], regs[REG_R15]);
|
svcdbg(" R0: %08x %08x %08x %08x %08x %08x %08x %08x\n",
|
||||||
#ifdef REG_EXC_RETURN
|
regs[REG_R0], regs[REG_R1], regs[REG_R2], regs[REG_R3],
|
||||||
svcdbg(" PSR: %08x LR: %08x\n", regs[REG_XPSR], regs[REG_EXC_RETURN]);
|
regs[REG_R4], regs[REG_R5], regs[REG_R6], regs[REG_R7]);
|
||||||
#else
|
svcdbg(" R8: %08x %08x %08x %08x %08x %08x %08x %08x\n",
|
||||||
svcdbg(" PSR: %08x\n", regs[REG_XPSR]);
|
regs[REG_R8], regs[REG_R9], regs[REG_R10], regs[REG_R11],
|
||||||
|
regs[REG_R12], regs[REG_R13], regs[REG_R14], regs[REG_R15]);
|
||||||
|
# ifdef REG_EXC_RETURN
|
||||||
|
svcdbg(" PSR: %08x EXC_RETURN: %08x\n",
|
||||||
|
regs[REG_XPSR], regs[REG_EXC_RETURN]);
|
||||||
|
# else
|
||||||
|
svcdbg(" PSR: %08x\n", regs[REG_XPSR]);
|
||||||
|
# endif
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Handle the SVCall according to the command in R0 */
|
/* Handle the SVCall according to the command in R0 */
|
||||||
|
|
||||||
switch (regs[REG_R0])
|
switch (cmd)
|
||||||
{
|
{
|
||||||
/* R0=SYS_save_context: This is a save context command:
|
/* R0=SYS_save_context: This is a save context command:
|
||||||
*
|
*
|
||||||
@ -216,7 +225,7 @@ int up_svcall(int irq, FAR void *context)
|
|||||||
*
|
*
|
||||||
* At this point, the following values are saved in context:
|
* At this point, the following values are saved in context:
|
||||||
*
|
*
|
||||||
* R0 = 1
|
* R0 = SYS_switch_context
|
||||||
* R1 = saveregs
|
* R1 = saveregs
|
||||||
* R2 = restoreregs
|
* R2 = restoreregs
|
||||||
*
|
*
|
||||||
@ -297,7 +306,7 @@ int up_svcall(int irq, FAR void *context)
|
|||||||
regs[REG_PC] = (uint32_t)USERSPACE->task_startup;
|
regs[REG_PC] = (uint32_t)USERSPACE->task_startup;
|
||||||
regs[REG_EXC_RETURN] = EXC_RETURN_UNPRIVTHR;
|
regs[REG_EXC_RETURN] = EXC_RETURN_UNPRIVTHR;
|
||||||
|
|
||||||
/* Change the paramter ordering to match the expection of struct
|
/* Change the parameter ordering to match the expectation of struct
|
||||||
* userpace_s task_startup:
|
* userpace_s task_startup:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -320,10 +329,10 @@ int up_svcall(int irq, FAR void *context)
|
|||||||
|
|
||||||
/* Verify that the SYS call number is within range */
|
/* Verify that the SYS call number is within range */
|
||||||
|
|
||||||
DEBUGASSERT(regs[REG_R0] < SYS_maxsyscall);
|
DEBUGASSERT(cmd < SYS_maxsyscall);
|
||||||
|
|
||||||
/* Make sure that we got here that there is a no saved syscall
|
/* Make sure that there is a no saved syscall return address. We
|
||||||
* return address. We cannot yet handle nested system calls.
|
* cannot yet handle nested system calls.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
DEBUGASSERT(rtcb->xcp.sysreturn == 0);
|
DEBUGASSERT(rtcb->xcp.sysreturn == 0);
|
||||||
@ -348,26 +357,34 @@ int up_svcall(int irq, FAR void *context)
|
|||||||
|
|
||||||
/* Report what happened. That might difficult in the case of a context switch */
|
/* Report what happened. That might difficult in the case of a context switch */
|
||||||
|
|
||||||
|
#if defined(CONFIG_DEBUG_SYSCALL) || defined(CONFIG_DEBUG_SVCALL)
|
||||||
|
# ifndef CONFIG_DEBUG_SVCALL
|
||||||
|
if (cmd > SYS_switch_context)
|
||||||
|
# elif
|
||||||
if (regs != current_regs)
|
if (regs != current_regs)
|
||||||
|
# endif
|
||||||
{
|
{
|
||||||
svcdbg("SVCall Return: Context switch!\n");
|
svcdbg("SVCall Return:\n");
|
||||||
svcdbg(" R0: %08x %08x %08x %08x %08x %08x %08x %08x\n",
|
svcdbg(" R0: %08x %08x %08x %08x %08x %08x %08x %08x\n",
|
||||||
current_regs[REG_R0], current_regs[REG_R1], current_regs[REG_R2], current_regs[REG_R3],
|
current_regs[REG_R0], current_regs[REG_R1], current_regs[REG_R2], current_regs[REG_R3],
|
||||||
current_regs[REG_R4], current_regs[REG_R5], current_regs[REG_R6], current_regs[REG_R7]);
|
current_regs[REG_R4], current_regs[REG_R5], current_regs[REG_R6], current_regs[REG_R7]);
|
||||||
svcdbg(" R8: %08x %08x %08x %08x %08x %08x %08x %08x\n",
|
svcdbg(" R8: %08x %08x %08x %08x %08x %08x %08x %08x\n",
|
||||||
current_regs[REG_R8], current_regs[REG_R9], current_regs[REG_R10], current_regs[REG_R11],
|
current_regs[REG_R8], current_regs[REG_R9], current_regs[REG_R10], current_regs[REG_R11],
|
||||||
current_regs[REG_R12], current_regs[REG_R13], current_regs[REG_R14], current_regs[REG_R15]);
|
current_regs[REG_R12], current_regs[REG_R13], current_regs[REG_R14], current_regs[REG_R15]);
|
||||||
#ifdef REG_EXC_RETURN
|
# ifdef REG_EXC_RETURN
|
||||||
svcdbg(" PSR: %08x LR: %08x\n",
|
svcdbg(" PSR: %08x EXC_RETURN: %08x\n",
|
||||||
current_regs[REG_XPSR], current_regs[REG_EXC_RETURN]);
|
current_regs[REG_XPSR], current_regs[REG_EXC_RETURN]);
|
||||||
#else
|
# else
|
||||||
svcdbg(" PSR: %08x\n", current_regs[REG_XPSR]);
|
svcdbg(" PSR: %08x\n", current_regs[REG_XPSR]);
|
||||||
#endif
|
# endif
|
||||||
}
|
}
|
||||||
|
# ifdef CONFIG_DEBUG_SVCALL
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
svcdbg("SVCall Return: %d\n", regs[REG_R0]);
|
svcdbg("SVCall Return: %d\n", regs[REG_R0]);
|
||||||
}
|
}
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user