arch/qemu: cortex-r5 PROTECTED support

This adds MPU and userspace handling in QEMU chips so that to
boot PROTECTED target qemu-armv7r:pnsh.

Signed-off-by: Yanfeng Liu <p-liuyanfeng9@xiaomi.com>
This commit is contained in:
Yanfeng Liu 2025-01-29 13:32:24 +08:00 committed by archer
parent 1cecf6791d
commit b7fc3aa034
5 changed files with 200 additions and 0 deletions

View file

@ -38,4 +38,8 @@ if(CONFIG_BUILD_KERNEL)
list(APPEND SRCS qemu_pgalloc.c)
endif()
if(CONFIG_BUILD_PROTECTED)
list(APPEND SRCS qemu_userspace.c)
endif()
target_sources(arch PRIVATE ${SRCS})

View file

@ -42,3 +42,7 @@ endif
ifeq ($(CONFIG_ARCH_IDLE_CUSTOM),y)
CHIP_CSRCS += qemu_idle.c
endif
ifeq ($(CONFIG_BUILD_PROTECTED),y)
CHIP_CSRCS += qemu_userspace.c
endif

View file

@ -34,6 +34,7 @@
#include "qemu_irq.h"
#include "qemu_memorymap.h"
#include "qemu_userspace.h"
#include "smp.h"
#include "gic.h"
@ -108,6 +109,10 @@ void arm_boot(void)
syslog_rpmsg_init_early(g_syslog_rpmsg_buf, sizeof(g_syslog_rpmsg_buf));
#endif
#ifdef CONFIG_BUILD_PROTECTED
qemu_userspace();
#endif
#ifdef CONFIG_ARCH_ARMV7R
/* dont return per armv7-r/arm_head.S design */

View file

@ -0,0 +1,109 @@
/****************************************************************************
* arch/arm/src/qemu/qemu_userspace.c
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <assert.h>
#include <sys/param.h>
#include <nuttx/userspace.h>
#include <arch/barriers.h>
#include <arch/board/board_memorymap.h>
#include "mpu.h"
#include "qemu_userspace.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: qemu_userspace
*
* Description:
* For the case of the separate user-/kernel-space build, perform whatever
* platform specific initialization of the user memory is required.
* Normally this just means initializing the user space .data and .bss
* segments.
*
* Assumptions:
* The D-Cache has not yet been enabled.
*
****************************************************************************/
void qemu_userspace(void)
{
uint8_t *src;
uint8_t *dest;
uint8_t *end;
uintptr_t datastart;
uintptr_t dataend;
/* Clear all of user-space .bss */
DEBUGASSERT(USERSPACE->us_bssstart != 0 &&
USERSPACE->us_bssend != 0 &&
USERSPACE->us_bssstart <= USERSPACE->us_bssend);
dest = (uint8_t *)USERSPACE->us_bssstart;
end = (uint8_t *)USERSPACE->us_bssend;
while (dest != end)
{
*dest++ = 0;
}
/* Initialize all of user-space .data */
DEBUGASSERT(USERSPACE->us_datasource != 0 &&
USERSPACE->us_datastart != 0 &&
USERSPACE->us_dataend != 0 &&
USERSPACE->us_datastart <= USERSPACE->us_dataend);
src = (uint8_t *)USERSPACE->us_datasource;
dest = (uint8_t *)USERSPACE->us_datastart;
end = (uint8_t *)USERSPACE->us_dataend;
while (dest != end)
{
*dest++ = *src++;
}
DEBUGASSERT(USERSPACE->us_textend >= USERSPACE->us_textstart);
datastart = MIN(USERSPACE->us_datastart, USERSPACE->us_bssstart);
dataend = MAX(USERSPACE->us_dataend, USERSPACE->us_bssend);
DEBUGASSERT(dataend >= datastart);
/* Configure user FLASH and SRAM spaces */
mpu_showtype();
mpu_user_flash(UFLASH_START, UFLASH_SIZE);
mpu_user_intsram(USRAM_START, USRAM_SIZE);
mpu_control(true);
}

View file

@ -0,0 +1,78 @@
/****************************************************************************
* arch/arm/src/qemu/qemu_userspace.h
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __ARCH_ARM_SRC_QEMU_QEMU_USERSPACE_H
#define __ARCH_ARM_SRC_QEMU_QEMU_USERSPACE_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/compiler.h>
#include <sys/types.h>
#include <stdint.h>
#include <stdbool.h>
#include "arm_internal.h"
#include "chip.h"
/****************************************************************************
* Public Data
****************************************************************************/
#ifndef __ASSEMBLY__
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: qemu_userspace
*
* Description:
* For the case of the separate user-/kernel-space build, perform whatever
* platform specific initialization of the user memory is required.
* Normally this just means initializing the user space .data and .bss
* segments.
*
****************************************************************************/
void qemu_userspace(void);
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __ARCH_ARM_SRC_QEMU_QEMU_USERSPACE_H */