forked from wilkie/buildtools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
syscalls.c
116 lines (81 loc) · 1.78 KB
/
syscalls.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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/fcntl.h>
#include <sys/times.h>
#include <sys/errno.h>
#include <sys/time.h>
#include <stdio.h>
#include <stdbool.h>
//#include <_ansi.h>
#include <errno.h>
// first, the 13 required calls
/*
* kill -- go out via exit...
*/
/*
* isatty -- returns 1 if connected to a terminal device,
* returns 0 if not. Since we're hooked up to a
* serial port, we'll say yes and return a 1.
*/
unsigned long long initHeap();
// --- Memory ---
#define PAGE_SIZE 4096ULL
#define PAGE_MASK 0xFFFFFFFFFFFFF000ULL
/*
* sbrk -- changes heap size size. Get nbytes more
* RAM. We just increment a pointer in what's
* left of memory on the board.
*/
caddr_t
sbrk(int nbytes){
static unsigned long long heap_ptr = 0;
caddr_t base;
int temp;
if(heap_ptr == 0){
heap_ptr = initHeap();
}
base = (caddr_t)heap_ptr;
if(nbytes < 0){
heap_ptr -= nbytes;
return base;
}
if( (heap_ptr & ~PAGE_MASK) != 0ULL){
temp = (PAGE_SIZE - (heap_ptr & ~PAGE_MASK));
if( nbytes < temp ){
heap_ptr += nbytes;
nbytes = 0;
}else{
heap_ptr += temp;
nbytes -= temp;
}
}
while(nbytes > PAGE_SIZE){
nbytes -= (int) PAGE_SIZE;
heap_ptr = heap_ptr + PAGE_SIZE;
}
if( nbytes > 0){
heap_ptr += nbytes;
}
return base;
}
// --- Other ---
int gettimeofday(struct timeval *p, void *z){
return -1;
}
static int fail();
int utime(const char *filename, const struct utimbuf *times){
// I ain't tellin'
errno = EPERM;
return -1;
}
int getdents(unsigned int fd, struct linux_dirent *dirp,
unsigned int count){
return fail();
}
int getrusage(int who, struct rusage *usage){
return fail();
}
/*int fail(){
errno = ENOSYS;
return -1;
}*/