summaryrefslogtreecommitdiffstats
path: root/rtemsbsd/src/rtems-bsd-panic.c
blob: 042f9f1d1e4c415f9d80322a8f2ec069be864207 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
 * @file
 *
 * @ingroup rtems_bsd_rtems
 *
 * @brief TODO.
 */

/*
 * Copyright (c) 2009, 2010 embedded brains GmbH.  All rights reserved.
 *
 *  embedded brains GmbH
 *  Obere Lagerstr. 30
 *  82178 Puchheim
 *  Germany
 *  <rtems@embedded-brains.de>
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rtems.com/license/LICENSE.
 */

#include <freebsd/machine/rtems-bsd-config.h>

#include <freebsd/sys/param.h>
#include <freebsd/sys/types.h>
#include <freebsd/sys/systm.h>
#include <freebsd/sys/kernel.h>
#include <freebsd/sys/lock.h>
#include <freebsd/sys/mutex.h>
#include <freebsd/sys/proc.h>

static void
suspend_all_threads(void)
{
	rtems_chain_control *chain = &rtems_bsd_thread_chain;
	rtems_chain_node *node = rtems_chain_first(chain);
	rtems_id self = rtems_task_self();

	while (!rtems_chain_is_tail(chain, node)) {
		struct thread *td = (struct thread *) node;

		if (td->td_id != self && td->td_id != RTEMS_SELF) {
			rtems_task_suspend(td->td_id);
		}

		node = rtems_chain_next(node);
	}

	rtems_task_suspend(RTEMS_SELF);
}

void
panic(const char *fmt, ...)
{
	va_list ap;

	printf("*** BSD PANIC *** ");

	va_start(ap, fmt);
	vprintf(fmt, ap);
	va_end(ap);

	printf("\n");

	suspend_all_threads();

	/* FIXME */
	rtems_fatal_error_occurred(0xdeadbeef);
}