forked from payne92/bare-metal-arm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
syscalls.c
executable file
·53 lines (45 loc) · 1.3 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
//
// syscalls.c -- Low level memory and I/O functions for newlib
//
// Nov, 2012
// <[email protected]>
//
#include <freedom.h>
#include <sys/stat.h>
#include "common.h"
int _close(int file) { return -1; }
int _isatty(int file) { return 1; }
int _open(const char *name, int flags, int mode) { return -1; }
int _fstat(int file, struct stat *st)
{
st->st_mode = S_IFCHR; // Character device
return 0;
}
int _write(int file, char *p, int len)
{
switch(file) {
case 1: return uart_write(p, len); // stdout
case 2: return uart_write_err(p,len); // stderr
default: return -1;
}
}
int _read(int file, char *p, int len)
{
return uart_read(p, len);
}
// ------------------------------------------------------------------------------------
// _sbrk(len) -- Allocate space on the heap
//
extern char __heap_start[]; // Defined by the linker script
static char *heap_end = __heap_start;
char *_sbrk(int incr)
{
heap_end += incr; // TODO: check for collisions with the stack
return (heap_end - incr);
}
// Signal handler (fault)
int _kill(int pid, int sig)
{
fault(0b11111110);
return -1; // Never gets here
}