fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / newlib / libc / sys / z8ksim / glue.c
blobb3b0bab07fb31fd318c95a53f203700359d36c45
1 #include "sys/syscall.h"
2 #include <sys/types.h>
3 #include <sys/stat.h>
4 #include <_ansi.h>
5 #include <errno.h>
7 extern char _start_heap;
8 extern char _end_heap;
9 extern char _start_bss;
10 extern char _end_bss;
13 static int argl(long value)
15 asm("ld r0,%H0" : : "r" (value));
16 asm("ld r1,%I0" : : "r" (value));
17 asm("sc %0" : : "i" (SYS_ARG));
21 static int argw(value)
23 asm("ld r1,%H0" : : "r" ( value));
24 asm("ld r0,#0");
25 asm("sc %0" : : "i" (SYS_ARG));
28 static int argp(void *value)
30 #ifdef __Z8001__
31 asm("ld r0,%H0" : : "r" (value));
32 asm("ld r1,%I0" : : "r" (value));
33 #else
34 asm("ld r1,%H0" : : "r" ( value));
35 asm("ld r0,#0");
36 #endif
37 asm("sc %0" : : "i" (SYS_ARG));
43 #define ARGL(n, value) argl(value)
44 #define ARGW(n, value) argw(value)
45 #define ARGP(n, value) argp(value)
47 #define MACRO(n) asm("sc %0" : : "i" (n));
49 int _read (int fd, char *buf,size_t nbytes)
51 ARGW(0,fd);
52 ARGP(1,buf);
53 ARGP(2,(void *)(nbytes));
54 MACRO(SYS_read);
57 int _write (int fd, char *buf, size_t nbytes)
59 ARGW(0,fd);
60 ARGP(1,buf);
61 ARGP(2,(void *)(nbytes));
62 MACRO(SYS_write);
65 int _open (const char *buf, int flags, int mode)
67 ARGP(0, buf);
68 ARGW(1, flags);
69 ARGW(2, mode);
70 MACRO(SYS_open);
73 int _close (int fd)
75 ARGW(0,fd);
76 MACRO(SYS_close );
80 * sbrk -- changes heap size size. Get nbytes more
81 * RAM. We just increment a pointer in what's
82 * left of memory on the board.
84 caddr_t _sbrk (size_t nbytes)
86 static char* heap_ptr = NULL;
87 caddr_t base;
89 if (heap_ptr == NULL) {
90 heap_ptr = (caddr_t)&_start_heap;
93 if (heap_ptr + nbytes < &_end_heap) {
94 base = heap_ptr;
95 heap_ptr += nbytes;
96 return (heap_ptr);
97 } else {
98 errno = ENOMEM;
99 return ((caddr_t)-1);
103 int isatty (int fd)
105 ARGW(0,fd);
106 MACRO(SYS_isatty);
109 off_t _lseek (int fd, off_t offset, int whence)
111 ARGW(0,fd);
112 ARGL(1,offset);
113 ARGW(2, whence);
114 MACRO(SYS_lseek);
117 int _fstat (int fd, struct stat *buf)
119 ARGW(0,fd);
120 ARGP(1,buf);
121 MACRO(SYS_fstat);
128 _exit(int val)
130 ARGW(0,val);
131 MACRO(SYS_exit);
134 time_t _time(time_t *timer)
136 ARGP(0,timer);
137 MACRO(SYS_time);
141 _creat (const char *path, int mode)
143 ARGP(0, path);
144 ARGW(1, mode);
145 MACRO(SYS_creat);
148 _kill(int pid, int val)
150 _exit(val);
153 _getpid()
155 return 1;