8 #define SYS_ftruncate 3000
9 #define SYS_isatty 3001
11 /* Set to 1 if we are running on hardware. The config instruction is
12 * always emulated on the simulator. The emulation code pokes this
17 /* _cpu_config==0 => Abel
18 * _cpu_config==1 => Zeta
19 * _cpu_config==2 => Phi
21 extern int _cpu_config
;
26 extern int _syscall(int *foo
, int ID
, ...);
28 extern int main(int argc
, char **argv
);
30 static char *args
[]={"dummy.exe"};
32 extern void _init(void);
35 void __attribute__ ((weak
)) _premain()
38 /* we only use syscalls w/Zeta */
39 _use_syscall
=(_cpu_config
==1);
49 /* NOTE!!!! compiled with -fomit-frame-pointer to make sure that 'status' has the
50 * correct value when breakpointing at _exit
52 void __attribute__ ((weak
)) _exit (int status
)
54 /* end of the universe, cause memory fault */
59 void __attribute__ ((weak
)) _zpu_interrupt(void)
61 /* not implemented in libgloss */
67 int __attribute__ ((weak
))
68 _DEFUN (write
, (fd
, buf
, nbytes
),
77 result
=_syscall(&t
, SYS_write
, fd
, buf
, nbytes
);
84 for (i
= 0; i
< nbytes
; i
++) {
85 if (*(buf
+ i
) == '\n') {
96 * read -- read bytes from the serial port. Ignore fd, since
99 int __attribute__ ((weak
))
100 _DEFUN (read
, (fd
, buf
, nbytes
),
109 result
=_syscall(&t
, SYS_read
, fd
, buf
, nbytes
);
116 for (i
= 0; i
< nbytes
; i
++) {
119 if ((t
!='\r')&&(t
!='\n'))
125 // terminate the line in the way expected by the libraries
140 * open -- open a file descriptor. We don't have a filesystem, so
141 * we return an error.
143 int __attribute__ ((weak
)) open(const char *buf
,
152 result
=_syscall(&t
, SYS_open
, buf
, strlen(buf
)+1, flags
, mode
);
165 * close -- We don't need to do anything, but pretend we did.
167 int __attribute__ ((weak
))
175 result
=_syscall(&t
, SYS_close
, fd
);
187 int __attribute__ ((weak
))
188 ftruncate (int file
, off_t length
)
195 result=_syscall(&t, SYS_ftruncate, file, length);
207 * unlink -- since we have no file system,
208 * we just return an error.
210 int __attribute__ ((weak
))
211 _DEFUN (unlink
, (path
),
218 result
=_syscall(&t
, SYS_unlink
, path
, strlen(path
)+1);
230 * lseek -- Since a serial port is non-seekable, we return an error.
232 off_t
__attribute__ ((weak
))
233 _DEFUN (lseek
, (fd
, offset
, whence
),
242 result
=_syscall(&t
, SYS_lseek
, fd
, offset
, whence
);
252 /* we convert from bigendian to smallendian*/
253 static long conv(char *a
, int len
)
257 for (i
=0; i
<len
; i
++)
259 t
|=(((int)a
[i
])&0xff)<<((len
-1-i
)*8);
264 static void convert(struct fio_stat
*gdb_stat
, struct stat
*buf
)
266 memset(buf
, 0, sizeof(*buf
));
267 buf
->st_dev
=conv(gdb_stat
->fst_dev
, sizeof(gdb_stat
->fst_dev
));
268 buf
->st_ino
=conv(gdb_stat
->fst_ino
, sizeof(gdb_stat
->fst_ino
));
269 buf
->st_mode
=conv(gdb_stat
->fst_mode
, sizeof(gdb_stat
->fst_mode
));
270 buf
->st_nlink
=conv(gdb_stat
->fst_nlink
, sizeof(gdb_stat
->fst_nlink
));
271 buf
->st_uid
=conv(gdb_stat
->fst_uid
, sizeof(gdb_stat
->fst_uid
));
272 buf
->st_gid
=conv(gdb_stat
->fst_gid
, sizeof(gdb_stat
->fst_gid
));
273 buf
->st_rdev
=conv(gdb_stat
->fst_rdev
, sizeof(gdb_stat
->fst_rdev
));
274 buf
->st_size
=conv(gdb_stat
->fst_size
, sizeof(gdb_stat
->fst_size
));
276 conv_64(fio_ulong_t
, &gdb_stat
->fst_blksize
);
277 conv_64(fio_ulong_t
, &gdb_stat
->fst_blocks
);
286 int __attribute__ ((weak
))
287 _DEFUN (fstat
, (fd
, buf
),
295 struct fio_stat gdb_stat
;
296 result
=_syscall(&t
, SYS_fstat
, fd
, &gdb_stat
);
297 convert(&gdb_stat
, buf
);
303 * fstat -- Since we have no file system, we just return an error.
305 buf
->st_mode
= S_IFCHR
; /* Always pretend to be a tty */
313 int __attribute__ ((weak
))
314 _DEFUN (stat
, (path
, buf
),
315 const char *path _AND
322 struct fio_stat gdb_stat
;
323 result
=_syscall(&t
, SYS_stat
, path
, strlen(path
)+1, &gdb_stat
);
324 convert(&gdb_stat
, buf
);
336 int __attribute__ ((weak
))
337 _DEFUN (isatty
, (fd
),
344 result
=_syscall(&t
, SYS_isatty
, fd
);
350 * isatty -- returns 1 if connected to a terminal device,
351 * returns 0 if not. Since we're hooked up to a
352 * serial port, we'll say yes _AND return a 1.