2008-06-01 15:18:51 +02:00
|
|
|
/****************************************************************************
|
2014-09-30 18:44:32 +02:00
|
|
|
* arch/sim/src/up_head.c
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2016-02-10 21:58:21 +01:00
|
|
|
* Copyright (C) 2007-2009, 2011-2013, 2016 Gregory Nutt. All rights reserved.
|
2012-01-22 17:42:49 +01:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* 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.
|
2008-06-01 15:18:51 +02:00
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
2007-02-18 00:21:28 +01:00
|
|
|
* 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.
|
|
|
|
*
|
2008-06-01 15:18:51 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-06-01 15:18:51 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2008-06-01 15:18:51 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2009-12-16 15:52:56 +01:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <setjmp.h>
|
|
|
|
#include <assert.h>
|
2009-12-16 15:52:56 +01:00
|
|
|
|
2007-09-09 13:58:50 +02:00
|
|
|
#include <nuttx/init.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <nuttx/arch.h>
|
2015-07-04 15:22:38 +02:00
|
|
|
#include <nuttx/board.h>
|
2012-01-22 17:42:49 +01:00
|
|
|
#include <nuttx/power/pm.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2015-07-04 16:43:10 +02:00
|
|
|
#include "up_internal.h"
|
|
|
|
|
2008-06-01 15:18:51 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Private Data
|
2008-06-01 15:18:51 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2015-07-04 18:39:24 +02:00
|
|
|
static jmp_buf g_simabort;
|
|
|
|
static int g_exitcode = EXIT_SUCCESS;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-06-01 15:18:51 +02:00
|
|
|
/****************************************************************************
|
2015-10-03 01:42:29 +02:00
|
|
|
* Public Functions
|
2008-06-01 15:18:51 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2015-07-04 15:22:38 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: main
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This is the main entry point into the simulation.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
int main(int argc, char **argv, char **envp)
|
|
|
|
{
|
2016-02-10 21:58:21 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* In the SMP case, configure the main thread as CPU 0 */
|
|
|
|
|
2016-02-17 20:35:23 +01:00
|
|
|
sim_cpu0_initialize();
|
2016-02-10 21:58:21 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
2011-09-04 21:24:27 +02:00
|
|
|
/* Power management should be initialized early in the (simulated) boot
|
|
|
|
* sequence.
|
|
|
|
*/
|
|
|
|
|
|
|
|
pm_initialize();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Then start NuttX */
|
|
|
|
|
2015-07-04 18:39:24 +02:00
|
|
|
if (setjmp(g_simabort) == 0)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2016-02-18 21:54:48 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* Start the CPU0 emulation. This should not return. */
|
|
|
|
|
|
|
|
sim_cpu0_start();
|
|
|
|
#else
|
|
|
|
/* Start the Nuttx emulation. This should not return. */
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
os_start();
|
2016-02-18 21:54:48 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
2015-07-04 15:22:38 +02:00
|
|
|
|
2015-07-04 16:43:10 +02:00
|
|
|
/* Restore the original terminal mode and return the exit code */
|
|
|
|
|
2016-02-16 14:24:28 +01:00
|
|
|
simuart_terminate();
|
2015-07-04 18:39:24 +02:00
|
|
|
return g_exitcode;
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
|
2015-07-04 15:22:38 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: up_assert
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Called to terminate the simulation abnormally in the event of a failed
|
|
|
|
* assertion.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2009-12-16 15:52:56 +01:00
|
|
|
void up_assert(const uint8_t *filename, int line)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2015-07-04 15:22:38 +02:00
|
|
|
/* Show the location of the failed assertion */
|
|
|
|
|
2016-02-15 20:47:05 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
fprintf(stderr, "CPU%d: Assertion failed at file:%s line: %d\n",
|
2016-02-17 20:35:23 +01:00
|
|
|
up_cpu_index(), filename, line);
|
2016-02-15 20:47:05 +01:00
|
|
|
#else
|
|
|
|
fprintf(stderr, "Assertion failed at file:%s line: %d\n",
|
|
|
|
filename, line);
|
|
|
|
#endif
|
2015-03-04 14:00:29 +01:00
|
|
|
|
2015-07-04 15:22:38 +02:00
|
|
|
/* Allow for any board/configuration specific crash information */
|
|
|
|
|
2015-03-04 14:00:29 +01:00
|
|
|
#ifdef CONFIG_BOARD_CRASHDUMP
|
2016-02-07 00:05:55 +01:00
|
|
|
board_crashdump(up_getsp(), this_task(), filename, line);
|
2015-03-04 14:00:29 +01:00
|
|
|
#endif
|
|
|
|
|
2015-07-04 15:22:38 +02:00
|
|
|
/* Exit the simulation */
|
|
|
|
|
2015-07-04 18:39:24 +02:00
|
|
|
g_exitcode = EXIT_FAILURE;
|
|
|
|
longjmp(g_simabort, 1);
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
2015-07-04 15:22:38 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: board_power_off
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Power off the board. This function may or may not be supported by a
|
|
|
|
* particular board architecture.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* status - Status information provided with the power off event.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* If this function returns, then it was not possible to power-off the
|
|
|
|
* board due to some constraints. The return value int this case is a
|
|
|
|
* board-specific reason for the failure to shutdown.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_BOARDCTL_POWEROFF
|
|
|
|
int board_power_off(int status)
|
|
|
|
{
|
|
|
|
/* Save the return code and exit the simulation */
|
|
|
|
|
2015-07-04 18:39:24 +02:00
|
|
|
g_exitcode = status;
|
|
|
|
longjmp(g_simabort, 1);
|
2015-07-04 15:22:38 +02:00
|
|
|
}
|
|
|
|
#endif
|