2 * redboot-syscalls.c -- provide system call support for RedBoot
4 * Copyright (c) 1997, 2001, 2002 Red Hat, Inc.
6 * The authors hereby grant permission to use, copy, modify, distribute,
7 * and license this software and its documentation for any purpose, provided
8 * that existing copyright notices are retained in all copies and that this
9 * notice is included verbatim in any distributions. No written agreement,
10 * license, or royalty fee is required for any of the authorized uses.
11 * Modifications to this software may be copyrighted by their authors
12 * and need not follow the licensing terms described here, provided that
13 * the new terms are clearly indicated on the first page of each file where
20 #include <sys/times.h>
24 // Use "naked" attribute to suppress C prologue/epilogue
25 static int __attribute__ ((naked
)) __syscall(int func_no
, ...)
27 asm ("mov r12, lr\n");
31 asm ("swi 0x180001\n");
33 asm ("mov pc, r12\n");
40 err
= __syscall(SYS_close
, fd
);
54 __syscall(SYS_exit
, stat
);
59 _stat (const char *filename
, struct stat
*st
)
62 err
= __syscall(SYS_stat
, filename
, st
);
72 _fstat (int file
, struct stat
*st
)
75 err
= __syscall(SYS_fstat
, file
, st
);
92 _gettimeofday (void * tp
, void * tzp
)
95 err
= __syscall(SYS_gettimeofday
, tp
, tzp
);
109 err
= __syscall(SYS_isatty
, fd
);
120 _kill(int pid
, int sig
)
129 _lseek(int fd
, off_t offset
, int whence
)
132 err
= __syscall(SYS_lseek
, fd
, offset
, whence
);
143 _open(const char *buf
, int flags
, int mode
)
146 err
= __syscall(SYS_open
, buf
, flags
, mode
);
157 _write(int fd
, const char *buf
, int nbytes
)
161 err
= __syscall(SYS_write
, fd
, buf
, nbytes
);
179 _write (1, ptr
, p
-ptr
);
190 _read(int fd
, char *buf
, int nbytes
)
193 err
= __syscall(SYS_read
, fd
, buf
, nbytes
);
203 extern char end
[]; /* end is set in the linker command file */
213 heap_ptr
= (char *)&end
;
222 _times(struct tms
* tp
)
226 err
= __syscall(SYS_times
, &utime
);
231 tp
->tms_utime
= utime
;
241 _rename (const char *oldpath
, const char *newpath
)
244 err
= __syscall(SYS_rename
, oldpath
, newpath
);
254 _unlink (const char *pathname
)
257 err
= __syscall(SYS_unlink
, pathname
);
267 _system (const char *command
)
270 err
= __syscall(SYS_system
, command
);
274 #define SYS_meminfo 1001
279 unsigned long totmem
= 0, topmem
= 0;
282 __syscall(SYS_meminfo
, (unsigned long)&totmem
, (unsigned long)&topmem
, 0);
283 return (void*)topmem
;