forked from jimparis/fernly
-
Notifications
You must be signed in to change notification settings - Fork 8
/
cmd-load.c
56 lines (43 loc) · 960 Bytes
/
cmd-load.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
53
54
55
56
#include <string.h>
#include "bionic.h"
#include "serial.h"
#include "printf.h"
#include "memio.h"
int cmd_load(int argc, char **argv)
{
uint32_t offset;
uint32_t total;
uint32_t left;
if (argc != 2) {
printf("Usage: load [offset] [size]\n"
"Loads [size] bytes to address [offset]\n");
return 1;
}
offset = strtoul(argv[0], NULL, 0);
total = strtoul(argv[1], NULL, 0);
left = total;
while (left--)
writeb(serial_getc(), offset++);
return 0;
}
int cmd_loadjump(int argc, char **argv)
{
uint32_t offset;
uint32_t total;
uint32_t left;
void (*jumpaddr)(void);
if (argc != 2) {
printf("Usage: loadjmp [offset] [size]\n"
"Loads [size] bytes to address [offset], and "
"jumps to [offset] afterwards.\n");
return 1;
}
offset = strtoul(argv[0], NULL, 0);
total = strtoul(argv[1], NULL, 0);
jumpaddr = (void (*)(void))offset;
left = total;
while (left--)
writeb(serial_getc(), offset++);
jumpaddr();
return 0;
}