-
Notifications
You must be signed in to change notification settings - Fork 0
/
clib.cpp
98 lines (78 loc) · 1.27 KB
/
clib.cpp
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <sys/stat.h>
#include "uart.h"
#include "system.h"
//Needed for Clib
extern "C"
caddr_t _sbrk( int incr )
{
extern char __end;
static char* heap_end = 0;
char* prev_heap_end;
if( heap_end == 0 )
heap_end = &__end;
prev_heap_end = heap_end;
heap_end += incr;
return (caddr_t)prev_heap_end;
}
extern "C"
int _write( int file, char *ptr, int len )
{
System::uart().write(ptr, len);
return len;
}
extern "C"
int _close( int file )
{
return -1;
}
extern "C"
int _fstat( int file, struct stat *st )
{
st->st_mode = S_IFCHR;
return 0;
}
extern "C"
int _isatty(int file)
{
return 1;
}
extern "C"
int _lseek(int file, int ptr, int dir)
{
return 0;
}
extern "C"
int _read( int file, char *ptr, int len )
{
return 0;
}
//Needed for libstdc++
#include <errno.h>
#undef errno
extern int errno;
void _exit( int status )
{
/* Stop the compiler complaining about unused variables by "using" it */
(void)status;
while(1)
{
/* TRAP HERE */
}
}
extern "C"
int _kill( int pid, int sig )
{
errno = EINVAL;
return -1;
}
extern "C"
int _getpid( void )
{
return 1;
}
//For global objects
extern "C"
int _open( const char *name, int flags, int mode )
{
return -1;
}