-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstart.c
executable file
·66 lines (54 loc) · 1.15 KB
/
start.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
57
58
59
60
61
62
63
64
65
66
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
extern int main(void);
/* Static functions and constant data */
const int SYS_WRITE0 = 0x04;
void semihost(int sys_id, const void *arg)
{
register int r0 __asm__ ("r0") = sys_id;
register const void *r1 __asm__ ("r1") = arg;
__asm__ volatile ("bkpt 0xab");
(void) r0;
(void) r1;
}
void logPrint(const char* format, ...)
{
char buffer[256] = {'\0'};
int bufferPos = 0;
unsigned int hex;
va_list arg;
va_start(arg, format);
for(const char* nextChar = format; *nextChar != '\0'; nextChar++)
{
while ((*nextChar != '%') && (*nextChar != '\0'))
{
sprintf(buffer + bufferPos, "%c", *nextChar);
bufferPos++;
nextChar++;
}
if (*nextChar == '\0')
{
break;
}
nextChar++;
switch (*nextChar)
{
case 'x':
hex = va_arg(arg, unsigned int);
int written = 0;
written = sprintf(buffer + bufferPos, "%x", hex);
bufferPos = bufferPos + written;
break;
}
}
buffer[bufferPos] = '\0';
va_end(arg);
semihost(SYS_WRITE0, buffer);
}
void _start(void)
{
main();
exit(0);
while (1){};
}