summaryrefslogtreecommitdiff
path: root/410user/progs/swexn_dispatch.c
blob: 50764e97e1dbe9258328180fb1a0d88324aefe5a (plain)
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
/**
 * @file swexn_dispatch.c
 * @author bblum
 * @brief Tests swexn basic function dispatch
 * @public yes
 * @for p4
 */

#include <stddef.h>
#include <stdlib.h>
#include <syscall.h>
#include "410_tests.h"

DEF_TEST_NAME("swexn_dispatch:");

#define STAQ_SIZE (4096)
char exn_staq[STAQ_SIZE];
#define EXN_STAQ_TOP ((void *)(&exn_staq[STAQ_SIZE-4]))

#define COOKIE ((void *)0x0dd0ad9b)

void handler(void *arg, ureg_t *uregs)
{
	REPORT_MISC("Hello from a handler");

	if (arg != COOKIE) {
		/* this fight is not worth fighting */
		REPORT_MISC("C is for cookie; it's not good enough for me...");
		REPORT_END_FAIL;
		exit(-1);
	}

	REPORT_END_SUCCESS;
	exit(42);
}

int main()
{
	int ret;

	REPORT_START_CMPLT;

	ret = swexn(EXN_STAQ_TOP, handler, COOKIE, NULL);
	if (ret < 0) {
		REPORT_MISC("swexn call rejected");
		REPORT_END_FAIL;
		exit(-1);
	}

	/* Invoke handler */
	ret = *(volatile int *)NULL;
	REPORT_MISC("should not get here!");
	REPORT_END_FAIL;
	exit(ret);
}