Welcome to mirror list, hosted at ThFree Co, Russian Federation.

glue.c « z8ksim « sys « libc « newlib - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b3b0bab07fb31fd318c95a53f203700359d36c45 (plain)
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include "sys/syscall.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <_ansi.h>
#include <errno.h>

extern char _start_heap;
extern char _end_heap;
extern char _start_bss;
extern char _end_bss;


static int argl(long value)
{
  asm("ld r0,%H0" : : "r" (value));
  asm("ld r1,%I0" : : "r" (value));
  asm("sc %0" : : "i" (SYS_ARG)); 
}


static int argw(value)
{
  asm("ld r1,%H0" : : "r" ( value));
  asm("ld  r0,#0");
  asm("sc %0" : : "i" (SYS_ARG)); 
}

static int argp(void *value)
{
#ifdef __Z8001__  
  asm("ld r0,%H0" : : "r" (value));
  asm("ld r1,%I0" : : "r" (value));
#else
  asm("ld r1,%H0" : : "r" ( value));
  asm("ld  r0,#0");
#endif
  asm("sc %0" : : "i" (SYS_ARG)); 

}



#define ARGL(n, value)  argl(value)
#define ARGW(n, value)  argw(value)
#define ARGP(n, value) argp(value)

#define MACRO(n) asm("sc %0" : : "i" (n));

int _read (int fd, char *buf,size_t nbytes)
{
  ARGW(0,fd);
  ARGP(1,buf);
  ARGP(2,(void *)(nbytes));
  MACRO(SYS_read);
}

int _write (int fd, char *buf, size_t nbytes)
{
  ARGW(0,fd);
  ARGP(1,buf);
  ARGP(2,(void *)(nbytes));
  MACRO(SYS_write);
}

int _open (const char *buf, int flags, int mode)
{
  ARGP(0, buf);
  ARGW(1, flags);
  ARGW(2, mode);
  MACRO(SYS_open);
}

int _close (int fd)
{
  ARGW(0,fd);
  MACRO(SYS_close );
}

/*
 * 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 (size_t nbytes)
{
  static char* heap_ptr = NULL;
  caddr_t        base;

  if (heap_ptr == NULL) {
    heap_ptr = (caddr_t)&_start_heap;
  }

  if (heap_ptr + nbytes < &_end_heap) {
    base = heap_ptr;
    heap_ptr += nbytes;
    return (heap_ptr);
  } else {
    errno = ENOMEM;
    return ((caddr_t)-1);
  }
}

int isatty (int fd)
{
  ARGW(0,fd);
  MACRO(SYS_isatty);
}

off_t _lseek (int fd,  off_t offset, int whence)
{
  ARGW(0,fd);
  ARGL(1,offset);
  ARGW(2, whence);
  MACRO(SYS_lseek);
}

int _fstat (int fd, struct stat *buf)
{
  ARGW(0,fd);
  ARGP(1,buf);
  MACRO(SYS_fstat);
}




int
_exit(int val)
{
  ARGW(0,val);
  MACRO(SYS_exit);
}

time_t _time(time_t *timer)
{
  ARGP(0,timer);
  MACRO(SYS_time);
}

int
_creat (const char *path, int mode)
{
  ARGP(0, path);
  ARGW(1, mode);
  MACRO(SYS_creat);
}

_kill(int pid, int val)
{
  _exit(val);
}

_getpid() 
{
  return 1;
}