-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhrtrt.h
105 lines (89 loc) · 2.8 KB
/
hrtrt.h
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#ifndef __HRT_RUNTIME_H__
#define __HRT_RUNTIME_H__
#include <libelf/libelf.h>
#if DEBUG_ENABLE==1
#define DEBUG(fmt, args...) printf("DEBUG: " fmt, ##args)
#else
#define DEBUG(fmt, args...)
#endif
#define SIG_STACK_SIZE 8192
struct thread_data {
int is_exited;
void * nk_thread_id; // nautilus thread id
void * stack; // stack that is allocated in ROS
int hrt_thread_started;
void (*call_addr)(void); // address of nk_thread_create
uint64_t nk_func; // function that nautilus thread should execute
uint64_t type; // is it a top-level HRT thread or a child?
char * ak_func; // nautilus name of function
};
int hrt_runtime_init(int argc, char * argv[]);
void hrt_runtime_deinit(void);
void * find_aerokernel_addr (Elf * elf, const char * symname);
struct v3_ros_event {
enum { ROS_NONE=0, ROS_PAGE_FAULT=1, ROS_SYSCALL=2, HRT_EXCEPTION=3, HRT_THREAD_EXIT=4} event_type;
uint64_t last_ros_event_result; // valid when ROS_NONE
union {
struct { // valid when ROS_PAGE_FAULT
uint64_t rip;
uint64_t cr2;
enum {ROS_READ, ROS_WRITE} action;
} page_fault;
struct { // valid when ROS_SYSCALL
uint64_t args[8];
} syscall;
struct { // valid when HRT_THREAD_EXIT
uint64_t nktid;
} thread_exit;
};
};
#define HCALL64(rc,id,a,b,c,d,e,f,g,h) \
asm volatile ("movq %1, %%rax; " \
"pushq %%rbx; " \
"movq $0x6464646464646464, %%rbx; " \
"movq %2, %%rcx; " \
"movq %3, %%rdx; " \
"movq %4, %%rsi; " \
"movq %5, %%rdi; " \
"movq %6, %%r8 ; " \
"movq %7, %%r9 ; " \
"movq %8, %%r10; " \
"movq %9, %%r11; " \
"vmmcall ; " \
"movq %%rax, %0; " \
"popq %%rbx; " \
: "=m"(rc) \
: "m"(id), \
"m"(a), "m"(b), "m"(c), "m"(d), \
"m"(e), "m"(f), "m"(g), "m"(h) \
: "%rax","%rcx","%rdx","%rsi","%rdi", \
"%r8","%r9","%r10","%r11" \
)
#define HCALL32(rc,id,a,b,c,d,e,f,g,h) \
asm volatile ("movl %1, %%eax; " \
"pushl %%ebx; " \
"movl $0x32323232, %%ebx; " \
"pushl %9;" \
"pushl %8;" \
"pushl %7;" \
"pushl %6;" \
"pushl %5;" \
"pushl %4;" \
"pushl %3;" \
"pushl %2;" \
"vmmcall ; " \
"movl %%eax, %0; " \
"addl $32, %%esp; " \
"popl %%ebx; " \
: "=r"(rc) \
: "m"(id), \
"m"(a), "m"(b), "m"(c), "m"(d), \
"m"(e), "m"(f), "m"(g), "m"(h) \
: "%eax" \
)
#ifdef __x86_64__
#define HCALL(rc,id,a,b,c,d,e,f,g,h) HCALL64(rc,id,a,b,c,d,e,f,g,h)
#else
#define HCALL(rc,id,a,b,c,d,e,f,g,h) HCALL32(rc,id,a,b,c,d,e,f,g,h)
#endif
#endif