14 #if !defined(OS_USE_SEMIHOSTING) 22 #include <sys/times.h> 43 static char name[] =
"";
49 static char* argv[2] =
72 kill(pid_t pid,
int sig);
81 #endif // !defined(OS_USE_SEMIHOSTING) 87 #if __STDC_HOSTED__ == 1 91 char** environ = __env;
93 #if !defined(OS_USE_SEMIHOSTING) 98 _chown(
const char* path, uid_t owner, gid_t group);
104 _execve(
char* name,
char** argv,
char** env);
110 _fstat(
int fildes,
struct stat* st);
116 _gettimeofday(
struct timeval* ptimeval,
void* ptimezone);
122 _kill(
int pid,
int sig);
125 _link(
char* existing,
char* _new);
128 _lseek(
int file,
int ptr,
int dir);
131 _open(
char* file,
int flags,
int mode);
134 _read(
int file,
char* ptr,
int len);
137 _readlink(
const char* path,
char* buf,
size_t bufsize);
140 _stat(
const char* file,
struct stat* st);
143 _symlink(
const char* path1,
const char* path2);
146 _times(
struct tms* buf);
155 _write(
int file,
char* ptr,
int len);
205 _gettimeofday(
struct timeval* ptimeval
__attribute__((unused)),
286 return ((clock_t) -1);
313 #else // defined(OS_USE_SEMIHOSTING) 324 #include <sys/stat.h> 325 #include <sys/fcntl.h> 329 #include <sys/time.h> 330 #include <sys/times.h> 334 #include <sys/wait.h> 340 int _kill (
int pid,
int sig);
345 int _system (
const char*);
346 int _rename (
const char*,
const char*);
348 clock_t _times (
struct tms*);
349 int _gettimeofday (
struct timeval *,
void*);
350 int _unlink (
const char*);
353 int _stat (
const char*,
struct stat*);
355 int _fstat (
int,
struct stat*);
356 int _swistat (
int fd,
struct stat* st);
359 clock_t _clock (
void);
361 int _open (
const char*,
int, ...);
362 int _swiopen (
const char*,
int);
363 int _write (
int,
char*,
int);
364 int _swiwrite (
int,
char*,
int);
365 int _lseek (
int,
int,
int);
366 int _swilseek (
int,
int,
int);
367 int _read (
int,
char*,
int);
368 int _swiread (
int,
char*,
int);
370 void initialise_monitor_handles (
void);
383 #define ARGS_BUF_ARRAY_SIZE 80 384 #define ARGV_BUF_ARRAY_SIZE 10 395 static char args_buf[ARGS_BUF_ARRAY_SIZE];
399 static char* argv_buf[ARGV_BUF_ARRAY_SIZE];
402 int isInArgument = 0;
404 CommandLineBlock cmdBlock;
405 cmdBlock.pCommandLine = args_buf;
406 cmdBlock.size =
sizeof(args_buf) - 1;
414 args_buf[ARGS_BUF_ARRAY_SIZE - 1] =
'\0';
417 char* p = cmdBlock.pCommandLine;
422 while ((ch = *p) !=
'\0')
424 if (isInArgument == 0)
428 if (argc >= (
int) ((
sizeof(argv_buf) /
sizeof(argv_buf[0])) - 1))
431 if (ch ==
'"' || ch ==
'\'')
440 argv_buf[argc++] = p;
444 else if (delim !=
'\0')
453 else if (isblank(ch))
467 argv_buf[0] = &args_buf[0];
472 argv_buf[argc] =
NULL;
475 *p_argv = &argv_buf[0];
478 initialise_monitor_handles ();
485 void _exit (
int status)
514 #define MAX_OPEN_FILES 20 531 static struct fdent openfiles[MAX_OPEN_FILES];
533 static struct fdent* findslot (
int);
534 static int newslot (
void);
537 register char* stack_ptr
asm (
"sp");
540 extern void __sinit(
struct _reent*);
541 #define CHECK_INIT(ptr) \ 544 if ((ptr) && !(ptr)->__sdidinit) \ 549 static int monitor_stdin;
550 static int monitor_stdout;
551 static int monitor_stderr;
561 if ((
unsigned int) fd >= MAX_OPEN_FILES)
567 if (openfiles[fd].handle == -1)
573 return &openfiles[fd];
583 for (i = 0; i < MAX_OPEN_FILES; i++)
585 if (openfiles[i].handle == -1)
591 if (i == MAX_OPEN_FILES)
600 initialise_monitor_handles (
void)
614 int volatile block[3];
616 block[0] = (int)
":tt";
621 block[0] = (int)
":tt";
626 block[0] = (int)
":tt";
632 if (monitor_stderr == -1)
634 monitor_stderr = monitor_stdout;
637 for (i = 0; i < MAX_OPEN_FILES; i++)
639 openfiles[i].handle = -1;
642 openfiles[0].handle = monitor_stdin;
643 openfiles[0].pos = 0;
644 openfiles[1].handle = monitor_stdout;
645 openfiles[1].pos = 0;
646 openfiles[2].handle = monitor_stderr;
647 openfiles[2].pos = 0;
660 errno = get_errno ();
666 checkerror (
int result)
681 _swiread (
int fh,
char* ptr,
int len)
686 block[1] = (int) ptr;
696 _read (
int fd,
char* ptr,
int len)
708 res = _swiread (pfd->handle, ptr, len);
715 pfd->pos += len - res;
723 int _swilseek (
int fd,
int ptr,
int dir)
737 if ((dir != SEEK_CUR) && (dir != SEEK_SET) && (dir != SEEK_END))
746 ptr = pfd->pos + ptr;
751 if ((pfd->pos > 0) && (ptr > 0))
763 block[0] = pfd->handle;
773 block[0] = pfd->handle;
789 int _lseek (
int fd,
int ptr,
int dir)
791 return _swilseek (fd, ptr, dir);
796 int _swiwrite (
int fh,
char* ptr,
int len)
801 block[1] = (int) ptr;
808 int _write (
int fd,
char* ptr,
int len)
820 res = _swiwrite (pfd->handle, ptr, len);
828 pfd->pos += len - res;
832 if ((len - res) == 0)
840 int _swiopen (
const char* path,
int flags)
854 if ((flags & O_CREAT) && (flags & O_EXCL))
858 res = _stat (path, &st);
868 if (flags & O_BINARY)
881 if ((flags & O_CREAT) || (flags & O_TRUNC) || (flags & O_WRONLY))
886 if (flags & O_APPEND)
893 block[0] = (uint32_t) path;
894 block[2] = strlen (path);
895 block[1] = (uint32_t) aflags;
902 openfiles[fd].handle = fh;
903 openfiles[fd].pos = 0;
912 int _open (
const char* path,
int flags, ...)
914 return _swiopen (path, flags);
918 int _swiclose (
int fh)
937 if ((fd == 1 || fd == 2) && (openfiles[1].handle == openfiles[2].handle))
944 res = _swiclose (pfd->handle);
962 _swistat (
int fd,
struct stat* st)
976 st->st_mode |= S_IFCHR;
977 st->st_blksize = 1024;
990 _fstat (
int fd,
struct stat* st)
992 memset (st, 0,
sizeof(*st));
993 return _swistat (fd, st);
997 _stat (
const char*fname,
struct stat *st)
1000 memset (st, 0,
sizeof(*st));
1003 if ((fd = _open (fname, O_RDONLY)) == -1)
1007 st->st_mode |= S_IFREG | S_IREAD;
1008 res = _swistat (fd, st);
1021 int _unlink (
const char* path)
1025 block[0] = (uint32_t) path;
1026 block[1] = strlen (path);
1036 int _gettimeofday (
struct timeval* tp,
void* tzvp)
1038 struct timezone* tzp = tzvp;
1049 tzp->tz_minuteswest = 0;
1050 tzp->tz_dsttime = 0;
1057 clock_t _clock (
void)
1067 _times (
struct tms* tp)
1069 clock_t timeval = _clock ();
1073 tp->tms_utime = timeval;
1082 int _isatty (
int fd)
1087 pfd = findslot (fd);
1101 errno = get_errno ();
1105 int _system (
const char* s)
1117 block[0] = (uint32_t) s;
1118 block[1] = strlen (s);
1120 if ((e >= 0) && (e < 256))
1127 for (exit_code = e; e && WEXITSTATUS (e) != exit_code; e <<= 1)
1135 int _rename (
const char* oldpath,
const char* newpath)
1138 block[0] = (uint32_t) oldpath;
1139 block[1] = strlen (oldpath);
1140 block[2] = (uint32_t) newpath;
1141 block[3] = strlen (newpath);
1159 char *getcwd (
char *buf,
size_t size)
1162 strncpy (buf,
"/tmp", size);
1166 #endif // defined OS_USE_SEMIHOSTING 1168 #endif // __STDC_HOSTED__ == 1
void __initialize_args(int *p_argc, char ***p_argv)
void *__dso_handle __attribute__((weak))
#define NULL
NULL pointer.
int kill(pid_t pid, int sig)