2014年6月11日 星期三

Newlib syscall


在porting Newlib for a new architecture 要注意事項,第六點
  1. Add a platform subdirectory to libgloss You need to add a bsp for your platform. This is the minimum set of syscalls needed by newlib and any linker scripts needed. This varies from board to board (it can also be a simulator). See the mn10300 or fr30 for examples. You will need to edit configure.in and regenerate configure so it will build your new files. By default you get libnosys which gives you a set of default syscall stubs. The majority of the stubs just return failure. You still need to supply an __exit routine. This can be as simple as generating an exception to stop the program.
意思是說要在libgross 下新增一個architecture directory
並且實作必要提供的最少syscall
以read system call 來說,_read_r 會需要底層平台支援(呼叫_read),
所以必須提供所謂BSP 也就是libgross,內含處理這些system call的實作。
reent/readr.c
_ssize_t
_DEFUN (_read_r, (ptr, fd, buf, cnt),
     struct _reent *ptr _AND
     int fd _AND
     _PTR buf _AND
     size_t cnt)
{
  _ssize_t ret;
  errno = 0;
  if ((ret = (_ssize_t)_read (fd, buf, cnt)) == -1 && errno != 0)
    ptr->_errno = errno;
  return ret;
}
libgloss/fr30/syscalls.c
int
_read (file, ptr, len)
     int    file;
     char * ptr;
     int    len;
{
  asm ("ldi:8 %0, r0" :: "i" (SYS_read) : "r0");
  asm ("int   #10");
  return;
}

僅是發system call,讓Vector Table 內的system call handler 去處理。



沒有留言:

張貼留言