-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.c
52 lines (43 loc) · 1.39 KB
/
main.c
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
#include <msp430.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <sancus_support/sm_io.h>
#include <sancus_support/sm_control.h>
#include <sancus_support/global_symtab.h>
#include "global_callback.h"
#include "sm1.h"
void check_symbols(void)
{
size_t current_symbol;
for (current_symbol = 0; current_symbol < symtab_get_num_symbols(); current_symbol++) {
Symbol symbol;
int i, is_section;
ElfModule* module;
ASSERT(symtab_get_symbol(current_symbol, &symbol, &is_section, &module));
printf("\t%s:%d\n", symbol.name, strlen(symbol.name));
for (i=0; i < strlen(symbol.name); i++)
{
ASSERT(isprint(symbol.name[i]));
}
}
}
int main()
{
uint16_t id = 0, retval = 0;
uint16_t args[] = {100, 200};
msp430_io_init();
pr_info("Loading SM from buffer..");
id = sm_load((void *) SM_BINARY, SM_NAME, VENDOR_ID);
printf("Loaded SM id: %d\n", id);
ASSERT(id);
pr_info("Dumping and validating SM symbol table..");
check_symbols();
pr_info("Calling into dynamically loaded SM..");
sm_call_id(/*id=*/id, /*index=*/0, /*args=*/args, /*nargs=*/2, &retval);
pr_info1("SM returned %d", retval);
ASSERT(cb_fired);
ASSERT(retval == global_callback_func(args[0], args[1]));
sm_call_id(/*id=*/id, /*index=*/1, /*args=*/NULL, /*nargs=*/0, NULL);
ASSERT(0 && "should never reach here");
}