git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15375 27425a3e-05d8-49a3-a47f-9c15f0e5edd8

This commit is contained in:
Giovanni Di Sirio 2022-01-18 10:32:57 +00:00
parent 57b011ad0e
commit 33540de167
8 changed files with 156 additions and 39 deletions

View File

@ -1,5 +1,5 @@
/*
ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
ChibiOS - Copyright (C) 2006..2022 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.

View File

@ -0,0 +1,40 @@
/*
ChibiOS - Copyright (C) 2006..2022 Giovanni Di Sirio
Licensed 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.
*/
#include <unistd.h>
#include "sbuser.h"
#include "syscalls.h"
int runelf(const char *fname, char *argv[], char *envp[]) {
uint8_t *buf, *bufend;
size_t size;
msg_t ret;
buf = sbrk(0);
bufend = __sb_parameters.heap_end;
buf = (uint8_t *)((((uint32_t)buf - 1U) | 3U) + 1U);
if (buf >= bufend) {
return ENOMEM;
}
size = (size_t)(bufend - buf);
ret = sbLoadElf(fname, bufend, size);
if (CH_RET_IS_ERROR(ret)) {
return CH_DECODE_ERROR(ret);
}
}

107
os/sb/common/sbhdr.h Normal file
View File

@ -0,0 +1,107 @@
/*
ChibiOS - Copyright (C) 2006,2007,2008,2009,2010,2011,2012,2013,2014,
2015,2016,2017,2018,2019,2020,2021,2022 Giovanni Di Sirio.
This file is part of ChibiOS.
ChibiOS is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 3 of the License.
ChibiOS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file sb/host/sbhost.h
* @brief ARM SandBox host macros and structures.
*
* @addtogroup ARM_SANDBOX_HEADER
* @{
*/
#ifndef SBHDR_H
#define SBHDR_H
/*===========================================================================*/
/* Module constants. */
/*===========================================================================*/
/**
* @brief Magic numbers
* @{
*/
#define SB_HDR_MAGIC1 0xFE9154C0U
#define SB_HDR_MAGIC2 0x0C4519EFU
/** @} */
/*===========================================================================*/
/* Module pre-compile time settings. */
/*===========================================================================*/
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
/*===========================================================================*/
/* Module data structures and types. */
/*===========================================================================*/
/**
* @brief Type of a sandbox binary image header.
*/
typedef struct {
/**
* @brief Magic number 1.
*/
uint32_t hdr_magic1;
/**
* @brief Magic number 2.
*/
uint32_t hdr_magic2;
/**
* @brief Header size, inclusive of magic numbers.
*/
uint32_t hdr_size;
/**
* @brief Entry vector.
*/
uint32_t hdr_entry;
/**
* @brief Exit vector.
*/
uint32_t hdr_exit;
/**
* @brief Used-defined parameters, defaulted to zero.
*/
uint32_t user[3];
} sb_header_t;
/*===========================================================================*/
/* Module macros. */
/*===========================================================================*/
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
/*===========================================================================*/
/* Module inline functions. */
/*===========================================================================*/
#endif /* SBHDR_H */
/** @} */

View File

@ -1,6 +1,6 @@
/*
ChibiOS - Copyright (C) 2006,2007,2008,2009,2010,2011,2012,2013,2014,
2015,2016,2017,2018,2019,2020,2021 Giovanni Di Sirio.
2015,2016,2017,2018,2019,2020,2021,2022 Giovanni Di Sirio.
This file is part of ChibiOS.

View File

@ -306,6 +306,7 @@ extern "C" {
#include "sbelf.h"
#include "sbposix.h"
#include "sbapi.h"
#include "sbhdr.h"
#include "sbhost.h"
#endif /* SBHOST_H */

View File

@ -231,7 +231,8 @@ thread_t *sbStartThread(sb_class_t *sbp, const char *name,
sbhp = (const sb_header_t *)(void *)config->regions[config->code_region].area.base;
/* Checking header magic numbers.*/
if ((sbhp->hdr_magic1 != SB_MAGIC1) || (sbhp->hdr_magic2 != SB_MAGIC2)) {
if ((sbhp->hdr_magic1 != SB_HDR_MAGIC1) ||
(sbhp->hdr_magic2 != SB_HDR_MAGIC2)) {
return NULL;
}
@ -398,7 +399,8 @@ msg_t sbExec(sb_class_t *sbp, const char *pathname,
sbhp = (const sb_header_t *)(void *)ma.base;
/* Checking header magic numbers.*/
if ((sbhp->hdr_magic1 != SB_MAGIC1) || (sbhp->hdr_magic2 != SB_MAGIC2)) {
if ((sbhp->hdr_magic1 != SB_HDR_MAGIC1) ||
(sbhp->hdr_magic2 != SB_HDR_MAGIC2)) {
return CH_RET_ENOEXEC;
}

View File

@ -32,14 +32,6 @@
/* Module constants. */
/*===========================================================================*/
/**
* @brief Magic numbers
* @{
*/
#define SB_MAGIC1 0xFE9154C0U
#define SB_MAGIC2 0x0C4519EFU
/** @} */
/*===========================================================================*/
/* Module pre-compile time settings. */
/*===========================================================================*/
@ -52,32 +44,6 @@
/* Module data structures and types. */
/*===========================================================================*/
/**
* @brief Type of a sandbox binary image header.
*/
typedef struct {
/**
* @brief Magic number 1.
*/
uint32_t hdr_magic1;
/**
* @brief Magic number 2.
*/
uint32_t hdr_magic2;
/**
* @brief Header size, inclusive of magic numbers.
*/
uint32_t hdr_size;
/**
* @brief Entry point address.
*/
uint32_t hdr_entry;
/**
* @brief Used-defined parameters, defaulted to zero.
*/
uint32_t user[4];
} sb_header_t;
/*===========================================================================*/
/* Module macros. */
/*===========================================================================*/

View File

@ -6,7 +6,8 @@ SBUSERSRC = $(CHIBIOS)/os/sb/user/sbuser.c \
SBUSERASM =
SBUSERINC = $(CHIBIOS)/os/sb/common \
$(CHIBIOS)/os/sb/user
$(CHIBIOS)/os/sb/user \
$(CHIBIOS)/os/sb/user/lib
# Shared variables
ALLXASMSRC += $(SBUSERASM)