SYSLAB blog
PC版 SYSLAB blog http://syslab.asablo.jp/blog/......
<<前
次>>
SH2 SH7085 (10) printf (2) KPIT GNUSH Simulator
2011-09-04
禺画像]
#include #include #include "sys/syscall.h" #endif #include "syslab7086def.h" /* To use the simulator stdout (function printf()) */ int _write ( int file,char *ptr,int len) { #if SCI_printf //UARTx int i; for(i=0;iSimulator->System->System Call address. The default address is "H'0". If the "System Call Address" is "H'0" the program control will not jump to the reset vector, the simulator will intercept the call.*/ asm("mov #0, r3"); asm("jsr @r3"); return len; #endif } /* To use the simulator stdout (function scanf()) */ int _read (int file, char *ptr, int len) { #if SCI_printf //UARTx *ptr=charget(); return (1); #else //Simulator /*The function code for inputing one line from the standard input device is "H'23". The MSB should be set to "H'01".*/ /* Set the parameter block address to the R1 register */ asm("mov %0, r1"::"g"(&ptr):"r1"); /* Set the function code to the R0 register */ #if NEWLIB asm("mov %0, r0"::"r"(0x01230000):"r1"); #else //Optimized asm("mov %0, r0"::"r"(0x01210000):"r1"); #endif /* Jump to the "System Call Address". This address is set in Options->Simulator->System->System Call address. The default address is "H'0". If the "System Call Address" is "H'0" the program control will not jump to the reset vector, the simulator will intercept the call.*/ asm("mov #0, r3"); asm("jsr @r3"); return len; #endif } #if NEWLIB /* Changes: Please note all __trap34() functions are commented. This is to avoid calls to malloc() as __trap34() makes call to malloc() internally. Call to abort() is replaced by _exit() as abort() also calls malloc()*/ void _exit (n) { //return __trap34 (SYS_exit, n, 0, 0); } int errno; /* This is used by _sbrk. */ register char *stack_ptr asm ("r15"); int _lseek (int file, int ptr, int dir) { return 0; // return __trap34 (SYS_lseek, file, ptr, dir); } int _close (int file) { return 0; // return __trap34 (SYS_close, file, 0, 0); } int _link (char *old, char *new) { return -1; } caddr_t _sbrk (int incr) { extern char end; // Defined by the linker static char *heap_end; char *prev_heap_end; if (heap_end == 0) { heap_end = &end; } prev_heap_end = heap_end; if (heap_end + incr > stack_ptr) { _write (1, "Heap and stack collision\n", 25); _exit(1); // abort (); } heap_end += incr; return (caddr_t) prev_heap_end; } int _fstat (int file, struct stat *st) { st->st_mode = S_IFCHR; return 0; } int _open (const char *path, int flags) { return 0; //return __trap34 (SYS_open, path, flags, 0); } int _creat (const char *path, int mode) { return 0; //return __trap34 (SYS_creat, path, mode, 0); } int _unlink () { return -1; } int _isatty (fd) int fd; { return 1; } #if 0 _kill (n, m) { //return __trap34 (SYS_exit, 0xdead, 0, 0); } _getpid (n) { return 1; } _raise () { } #endif int _stat (const char *path, struct stat *st) { return 0; //return __trap34 (SYS_stat, path, st, 0); } int _chmod (const char *path, short mode) { return 0; //return __trap34 (SYS_chmod, path, mode); } int _chown (const char *path, short owner, short group) { return 0; //return __trap34 (SYS_chown, path, owner, group); } int _utime (path, times) const char *path; char *times; { return 0; //return __trap34 (SYS_utime, path, times); } int _fork () { return 0; //return __trap34 (SYS_fork); } int _wait (statusp) int *statusp; { return 0; //return __trap34 (SYS_wait); } int _execve (const char *path, char *const argv[], char *const envp[]) { return 0; //return __trap34 (SYS_execve, path, argv, envp); } int _execv (const char *path, char *const argv[]) { return 0; //return __trap34 (SYS_execv, path, argv); } int _pipe (int *fd) { return 0; //return __trap34 (SYS_pipe, fd); } #if 0 /* This is only provided because _gettimeofday_r and _times_r are defined in the same module, so we avoid a link error. */ clock_t _times (struct tms *tp) { return -1; } #endif int _gettimeofday (struct timeval *tv, struct timezone *tz) { tv->tv_usec = 0; //tv->tv_sec = __trap34 (SYS_time); return 0; } static inline int __setup_argv_for_main (int argc) { char **argv; int i = argc; argv = __builtin_alloca ((1 + argc) * sizeof (*argv)); argv[i] = NULL; while (i--) { // argv[i] = __builtin_alloca (1 + __trap34 (SYS_argnlen, i)); // __trap34 (SYS_argn, i, argv[i]); } return main (argc, argv); } int __setup_argv_and_call_main () { int argc ;//= __trap34 (SYS_argc); if (argc <= 0) return main (argc, NULL); else return __setup_argv_for_main (argc); } #endif
そして、 uart1.c これは 先日のサンプル SCI_UART を少し変更したものだ。
続きを読む
戻る
[SH2]
[マイコン]
コメント(全0件)
セ
コメントをする
<<前
次>>
トップ
上へ
下へ
セ
記事を書く
powered by ASAHIネット
セコメントをする