-
Notifications
You must be signed in to change notification settings - Fork 1
/
syscall.c
45 lines (43 loc) · 1.16 KB
/
syscall.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
#include "syscall.h"
#include "sim.h"
#include "helper.h"
#include <stdlib.h>
#include <stdint.h>
int syscall(int callnum)
{
switch (callnum) {
case SYS_putint:
printf("%d\n", R(0));
break;
case SYS_exit:
printf("SYS_exit: retval = %d\n", R(0));
halted = 1;
// exit(0);
break;
case SYS_udiv:
return (uint32_t)R(0) / (uint32_t)R(1);
case SYS_div:
return (int)R(0) / (int)R(1);
case SYS_mod:
return (int)R(0) % (int)R(1);
case SYS_umod:
return (uint32_t)R(0) % (uint32_t)R(1);
case SYS_state:
{
#ifdef BENCH
printf("%d %d %d %d %d %d %d %d %d %d %d\n", inst_cnt, ncycle, nstall, nbubble, nforward, misspred,
dcache.nmiss, dcache.nhit, icache.nmiss, icache.nhit, dcache.ndirty);
printf("ALU: %d\n", icnt[0] + icnt[1] + icnt[2] + icnt[3]);
printf("Load/Store: %d\n", icnt[5] + icnt[6] + icnt[7] + icnt[8]);
printf("Cond. Jump: %d\n", icnt[10]);
printf("ST: %d\n", icnt[9]);
printf("Jump: %d\n", icnt[4]);
#endif
return 0;
}
default:
printf("unimplemented syscall\n");
return -1;
}
return 0;
}