-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjelvmtest.c
50 lines (43 loc) · 1.04 KB
/
jelvmtest.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
/*
* File: jelvmtest.c
* Implements:
*
* Copyright: Jens Låås, 2011
* Copyright license: According to GPL, see file COPYING in this directory.
*
*/
#include <arpa/inet.h>
#include <unistd.h>
#include <errno.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "jelvm.h"
uint64_t extcall(uint64_t *regs)
{
printf("External call! %llu %llu\n", regs[0], regs[1]);
return 0;
}
void infofn(const char *s)
{
printf("info from jelvm: '%s'\n", s);
}
int main(int argc, char **argv)
{
uint64_t iv[1];
iv[0] = extcall;
uint8_t code[] = {
'J', 'E', 'L', 'V', 0, 0,
OP_SET, 8, 0, 1, 0, 0, 0, 0, 0, 0, 0, 111,
OP_CALL, 0, 0, 0,
OP_SYSCALL, 0, 0, SYSCALL_getpid,
OP_SET, 8, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1,
OP_SET, 8, 0, 4, 0, 0, 0, 0, 0, 0, 0, 4,
OP_ADDROF, 8, 0, 3, 0, 0, 0, 0, 0, 0, 0, 24,
OP_SYSCALL, 3, (SYSCALL_write & 0xff00) >> 8, SYSCALL_write & 0xff,
OP_EXIT, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
'H', 'E', 'J', '\n', 0
};
return jelvm_exec(code, iv, 1, JELVM_TRACE|JELVM_DEBUG, infofn);
}