-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_example.c
More file actions
68 lines (58 loc) · 1.4 KB
/
user_example.c
File metadata and controls
68 lines (58 loc) · 1.4 KB
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
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/ioctl.h>
typedef struct write_struct {
uint64_t address;
uint64_t value;
uint32_t size;
uint8_t use_phys_to_virt;
} IOCTL_WRITE;
typedef struct read_struct {
uint64_t address;
uint32_t size;
uint8_t use_phys_to_virt;
} IOCTL_READ;
typedef struct alloc_struct {
uint32_t size;
} IOCTL_ALLOC;
int32_t fd = 0;
void sleep_ms(int milliseconds) {
usleep(milliseconds * 1000);
}
uint64_t alloc(uint32_t size) {
IOCTL_ALLOC s;
s.size = size;
uint64_t addr = ioctl(fd, 0x1339, &s);
printf("alloc: addr %p\n", (void*)addr);
return addr;
}
void write_val(uint64_t address, uint64_t value, uint32_t size, uint32_t sleep_val, char phys_to_virt) {
IOCTL_WRITE s;
s.address = address;
s.value = value;
s.size = size;
s.use_phys_to_virt = phys_to_virt;
fflush(stdout);
sleep_ms(sleep_val);
ioctl(fd, 0x1337, &s);
}
uint32_t read_val(uint64_t address, uint32_t size, uint32_t sleep_val) {
IOCTL_READ s;
s.address = address;
s.size = size;
s.use_phys_to_virt = 0;
fflush(stdout);
sleep_ms(sleep_val);
uint32_t res = ioctl(fd, 0x1338, &s);
return res;
}
int main(int argc, char** argv) {
fd = open("/dev/phyzone", O_RDWR);
write_val(0xffcdf118, 0x4141, 2, 0, 0);
printf("%x\n", read_val(0xffccf000, 2, 0));
printf("%x\n", read_val(0xffccf002, 4, 0));
printf("%x\n", read_val(0xffccf006, 8, 0));
}