adds newlib-nano settings
This commit is contained in:
79
newlib-nano/syscalls.c
Normal file
79
newlib-nano/syscalls.c
Normal file
@@ -0,0 +1,79 @@
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
extern int _end;
|
||||
void* _sbrk(int incr);
|
||||
int _close(int file);
|
||||
int _fstat(int file, struct stat *st);
|
||||
int _isatty(int fd);
|
||||
int _lseek(int file, int ptr, int dir);
|
||||
|
||||
void _kill(int pid, int sig);
|
||||
int _getpid(void);
|
||||
void write_hex(int fd, unsigned long int hex);
|
||||
|
||||
void *_sbrk(int incr) {
|
||||
static unsigned char *heap = NULL;
|
||||
unsigned char *prev_heap;
|
||||
if (heap == NULL) {
|
||||
heap = (unsigned char *)&_end;
|
||||
}
|
||||
prev_heap = heap;
|
||||
heap += incr;
|
||||
return prev_heap;
|
||||
}
|
||||
|
||||
int _close(int file) {
|
||||
(void)file;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _fstat(int file, struct stat *st) {
|
||||
(void)file;
|
||||
st->st_mode = S_IFCHR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _isatty(int fd) {
|
||||
if (fd == STDOUT_FILENO || fd == STDERR_FILENO)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _lseek(int file, int ptr, int dir) {
|
||||
(void)file;
|
||||
(void)ptr;
|
||||
(void)dir;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void _exit(int status) {
|
||||
const char message[] = "\nProgam has exited with code:";
|
||||
write(STDERR_FILENO, message, sizeof(message) - 1);
|
||||
write_hex(STDERR_FILENO, status);
|
||||
write(STDERR_FILENO, "\n", 1);
|
||||
for (;;);
|
||||
}
|
||||
|
||||
void _kill(int pid, int sig) {
|
||||
(void)pid;
|
||||
(void)sig;
|
||||
return;
|
||||
}
|
||||
|
||||
int _getpid(void) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
void write_hex(int fd, unsigned long int hex){
|
||||
uint8_t ii;
|
||||
uint8_t jj;
|
||||
char towrite;
|
||||
write(fd , "0x", 2);
|
||||
for (ii = sizeof(unsigned long int) * 2 ; ii > 0; ii--) {
|
||||
jj = ii - 1;
|
||||
uint8_t digit = ((hex & (0xF << (jj*4))) >> (jj*4));
|
||||
towrite = digit < 0xA ? ('0' + digit) : ('A' + (digit - 0xA));
|
||||
write(fd, &towrite, 1);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user