]> code.bitgloo.com Git - clyne/stmos.git/commitdiff
fixed pdclib for arm, can make programs for stmos
authortcsullivan <tullivan99@gmail.com>
Sat, 17 Nov 2018 19:49:42 +0000 (14:49 -0500)
committertcsullivan <tullivan99@gmail.com>
Sat, 17 Nov 2018 19:49:42 +0000 (14:49 -0500)
18 files changed:
Makefile
initrd/Makefile [new file with mode: 0644]
initrd/test [new file with mode: 0755]
initrd/test.c [new file with mode: 0644]
src/kernel/clock.c
src/kernel/svc.c
src/kernel/vfs.c
src/kernel/vfs.h
src/pdclib/Makefile
src/pdclib/platform/stmos/functions/os/syscalls.c [new file with mode: 0644]
src/pdclib/platform/stmos/functions/stdio/remove.c
src/pdclib/platform/stmos/functions/stdio/tmpfile.c
src/pdclib/platform/stmos/functions/time/clock.c
src/pdclib/platform/stmos/functions/time/time.c
src/pdclib/platform/stmos/functions/time/timespec_get.c
src/pdclib/platform/stmos/include/syscalls.h [new file with mode: 0644]
src/user/syscalls.h [deleted file]
src/user/user.c

index 0d4d85c35c2271989aa1963480a13ed62d37f63b..d497420633f5a70899cbc937094162f5df6caf53 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -42,9 +42,11 @@ all:
        @$(MAKE) -C src/user
        @echo "  INITRD"
        @tools/rba initrd.img $$(find initrd/*)
-       @$(CROSS)$(OBJCOPY) -B arm -I binary -O elf32-littlearm initrd.img initrd.img.o
+       @$(CROSS)$(OBJCOPY) -B arm -I binary -O elf32-littlearm initrd.img \
+               initrd.img.o
        @echo "  LINK   " $(OUT)
-       @$(CROSS)$(CC) $(CFLAGS) $(LFLAGS) -o $(OUT) $$(find src/ -name "*.o") initrd.img.o
+       @$(CROSS)$(CC) $(CFLAGS) $(LFLAGS) -o $(OUT) \
+               $$(find src/fs src/kernel src/user -name "*.o") initrd.img.o
 
 
 clean:
diff --git a/initrd/Makefile b/initrd/Makefile
new file mode 100644 (file)
index 0000000..b2ca46f
--- /dev/null
@@ -0,0 +1,4 @@
+all:
+       @arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -fsigned-char -Os -nostdinc \
+               -I../src/pdclib/include -I../src/pdclib/platform/stmos/include \
+               test.c ../src/pdclib/pdclib.a -s -o test -pie
diff --git a/initrd/test b/initrd/test
new file mode 100755 (executable)
index 0000000..8b9d8a4
Binary files /dev/null and b/initrd/test differ
diff --git a/initrd/test.c b/initrd/test.c
new file mode 100644 (file)
index 0000000..f673ce0
--- /dev/null
@@ -0,0 +1,8 @@
+#include <stdio.h>
+
+int main(void)
+{
+       printf("Hello, world!\n");
+       return 0;
+}
+
index 5b80203a4e530166f3feaf58221ec5ad223af31a..950f4ca0f46e0ec84fa9a56c1fbba9884345b6de 100644 (file)
@@ -35,6 +35,8 @@ void clock_svc(uint32_t *args)
                task_sleep(args[1]);
        else if (args[0] == 1)
                udelay(args[1]);
+       else if (args[0] == 2)
+               *((unsigned int *)args[1]) = ticks;
 }
 
 void clock_init(void)
index 7d171c3e601884264e26a247cbdf60209f7711e7..cf1fbe22dff401d11d96ceb45222c8da61027925 100644 (file)
@@ -65,6 +65,7 @@ void SVC_Handler(void) {
        case 2: /* Clock-related calls
                 * 0 - delay
                 * 1 - udelay
+                * 2 - ticks
                 */
                clock_svc(args);
                break;
@@ -74,6 +75,7 @@ void SVC_Handler(void) {
                 * 1 - open
                 * 2 - close
                 * 3 - read
+                * 4 - write
                 */
                vfs_svc(args);
                break;
index d6f9e14546b56052261f1262464df124bf0435ad..da1d641eb7b253b599476a425f660daee47a1d84 100644 (file)
@@ -26,6 +26,9 @@ void vfs_svc(uint32_t *args)
        case 3:
                *((int *)args[4]) = vfs_read(args[1], args[2], (uint8_t *)args[3]);
                break;
+       case 4:
+               *((int *)args[4]) = vfs_write(args[1], args[2], (const uint8_t *)args[3]);
+               break;
        default:
                break;
        }
@@ -141,8 +144,30 @@ uint32_t vfs_read(int fd, uint32_t count, uint8_t *buffer)
                VFS_EOF))
                return 0;
 
-       uint32_t ret = vfs_volumes[vfs_files[fd].vol].funcs->read(vfs_files[fd].fsinfo,
-               count, buffer);
+       uint32_t ret = vfs_volumes[vfs_files[fd].vol].funcs->read(
+               vfs_files[fd].fsinfo, count, buffer);
+
+       if (ret < count)
+               vfs_files[fd].flags |= VFS_EOF;
+
+       return ret;
+}
+
+uint32_t vfs_write(int fd, uint32_t count, const uint8_t *buffer)
+{
+       if (fd < 0 || fd > VFS_MAX_FILES || count == 0 || buffer == 0)
+               return 0;
+       if (vfs_volumes[vfs_files[fd].vol].funcs->write == 0)
+               return -1;
+       if (vfs_files[fd].pid != task_getpid())
+               return 0;
+       // TODO append?
+       if ((!(vfs_files[fd].flags & VFS_FILE_WRITE)) || (vfs_files[fd].flags &
+               VFS_EOF))
+               return 0;
+
+       uint32_t ret = vfs_volumes[vfs_files[fd].vol].funcs->write(
+               vfs_files[fd].fsinfo, count, buffer);
 
        if (ret < count)
                vfs_files[fd].flags |= VFS_EOF;
index c9c91799bb527971683913be6d5717e988e0e02b..29763a5b8e4ce465542f37be4707dd85a2be44ab 100644 (file)
@@ -47,5 +47,6 @@ int vfs_mount(vfs_volume_funcs *funcs, uint32_t flags);
 int vfs_open(const char *path, uint32_t flags);
 int vfs_close(int fd);
 uint32_t vfs_read(int fd, uint32_t count, uint8_t *buffer);
+uint32_t vfs_write(int fd, uint32_t count, const uint8_t *buffer);
 
 #endif // VFS_H_
index ebb0ad4f3e44ee8e9ecc3176f1dc13fc2428f88c..bef1e1927cf0b68517d923740b63e5f2838f391b 100644 (file)
@@ -24,8 +24,10 @@ REGDEPFILES := $(patsubst %,$(BUILDDIR)/%.d,$(REGFILES))
 # All files belonging to the source distribution
 ALLFILES := $(SRCFILES) $(HDRFILES) $(AUXFILES)
 
+CC = arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -fsigned-char --specs=nosys.specs
+
 WARNINGS := -Wall -Wextra -pedantic -Wno-unused-parameter -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -Wno-long-long -Wuninitialized -Wstrict-prototypes -Wdeclaration-after-statement
-CFLAGS := -fno-builtin -g -std=c99 -I./testing -I../user -I./platform/stmos/include $(WARNINGS) $(USERFLAGS)
+CFLAGS := -fno-builtin -g -std=c99 -I./testing -I./platform/stmos/include $(WARNINGS) $(USERFLAGS)
 
 .PHONY: all clean srcdist tests testdrivers regtests regtestdrivers todos fixmes help
 
@@ -58,7 +60,7 @@ all: $(BUILDDIR)/pdclib.a #testdrivers regtestdrivers
 
 $(BUILDDIR)/pdclib.a: $(OBJFILES)
        @echo " AR      $@"
-       @ar rc $(BUILDDIR)/pdclib.a $?
+       @arm-none-eabi-ar rc $(BUILDDIR)/pdclib.a $?
        @echo
 
 tests: testdrivers
diff --git a/src/pdclib/platform/stmos/functions/os/syscalls.c b/src/pdclib/platform/stmos/functions/os/syscalls.c
new file mode 100644 (file)
index 0000000..a58dc50
--- /dev/null
@@ -0,0 +1,163 @@
+#include "syscalls.h"
+
+//
+// Task-related calls
+
+void _exit(int code)
+{
+       register uint32_t r1 __asm("r1") = code;
+       __asm("\
+               mov r0, 0; \
+               mov r1, %0; \
+               svc 0; \
+       " :: "r" (r1));
+}
+
+int fork(void)
+{
+       int ret = 0;
+       register uint32_t r1 __asm("r1") = (uint32_t)&ret;
+       __asm("\
+               mov r0, 1; \
+               mov r1, %0; \
+               svc 0; \
+       " :: "r" (r1));
+       return ret;
+}
+
+int getpid(void)
+{
+       int ret = 0;
+       register uint32_t r1 __asm("r1") = (uint32_t)&ret;
+       __asm("\
+               mov r0, 2; \
+               mov r1, %0; \
+               svc 0; \
+       " :: "r" (r1));
+       return ret;
+}
+
+void *sbrk(unsigned int bytes)
+{
+       void *ret = 0;
+       register uint32_t r1 __asm("r1") = bytes;
+       register uint32_t r2 __asm("r2") = (uint32_t)&ret;
+       __asm("\
+               mov r0, 4; \
+               mov r1, %0; \
+               mov r2, %1; \
+               svc 0; \
+       " :: "r" (r1), "r" (r2));
+       return ret;
+}
+
+//
+// Clock-related calls
+
+void delay(unsigned int ms)
+{
+       register uint32_t r1 __asm("r1") = ms;
+       __asm("\
+               mov r0, 0; \
+               mov r1, %0; \
+               svc 2; \
+       " :: "r" (r1));
+}
+
+unsigned int ticks(void)
+{
+       unsigned int ret = 0;
+       register uint32_t r1 __asm("r1") = (uint32_t)&ret;
+       __asm("\
+               mov r0, 2; \
+               mov r1, %0; \
+               svc 2; \
+       " :: "r" (r1));
+       return ret;
+}
+
+//
+// File-related calls
+
+int mount(vfs_volume_funcs *funcs, uint32_t flags)
+{
+       int ret = 0;
+       register uint32_t r1 __asm("r1") = (uint32_t)funcs;
+       register uint32_t r2 __asm("r2") = flags;
+       register uint32_t r3 __asm("r3") = (uint32_t)&ret;
+       __asm("\
+               mov r0, 0; \
+               mov r1, %0; \
+               mov r2, %1; \
+               mov r3, %2; \
+               svc 3; \
+       " :: "r" (r1), "r" (r2), "r" (r3));
+       return ret;
+}
+
+int open(const char *path, uint32_t flags)
+{
+       int ret = 0;
+       register uint32_t r1 __asm("r1") = (uint32_t)path;
+       register uint32_t r2 __asm("r2") = flags;
+       register uint32_t r3 __asm("r3") = (uint32_t)&ret;
+       __asm("\
+               mov r0, 1; \
+               mov r1, %0; \
+               mov r2, %1; \
+               mov r3, %2; \
+               svc 3; \
+       " :: "r" (r1), "r" (r2), "r" (r3));
+       return ret;
+}
+
+int close(int fd)
+{
+       int ret = 0;
+       register uint32_t r1 __asm("r1") = fd;
+       register uint32_t r2 __asm("r2") = (uint32_t)&ret;
+       __asm("\
+               mov r0, 2; \
+               mov r1, %0; \
+               mov r2, %1; \
+               svc 3; \
+       " :: "r" (r1), "r" (r2));
+       return ret;
+}
+
+int read(int fd, uint32_t count, uint8_t *buffer)
+{
+       int ret = 0;
+       register uint32_t r1 __asm("r1") = fd;
+       register uint32_t r2 __asm("r2") = count;
+       register uint32_t r3 __asm("r3") = (uint32_t)buffer;
+       register uint32_t r4 __asm("r4") = (uint32_t)&ret;
+       __asm("\
+               mov r0, 3; \
+               mov r1, %0; \
+               mov r2, %1; \
+               mov r3, %2; \
+               mov r4, %3; \
+               svc 3; \
+       " :: "r" (r1), "r" (r2), "r" (r3), "r" (r4));
+       return ret;
+}
+
+int write(int fd, uint32_t count, const uint8_t *buffer)
+{
+       int ret = 0;
+       register uint32_t r1 __asm("r1") = fd;
+       register uint32_t r2 __asm("r2") = count;
+       register uint32_t r3 __asm("r3") = (uint32_t)buffer;
+       register uint32_t r4 __asm("r4") = (uint32_t)&ret;
+       __asm("\
+               mov r0, 4; \
+               mov r1, %0; \
+               mov r2, %1; \
+               mov r3, %2; \
+               mov r4, %3; \
+               svc 3; \
+       " :: "r" (r1), "r" (r2), "r" (r3), "r" (r4));
+       return ret;
+}
+
index aca3eaf98f31e6d562ad4bf1fa699bc11981cc1e..c1ed6a00fa960b40eb53cb137129c273e098a8d1 100644 (file)
@@ -7,57 +7,58 @@
 /* This is an example implementation of remove() fit for use with POSIX kernels.
 */
 
-#include <stdio.h>
+#include <syscalls.h>
 
 #ifndef REGTEST
 
-#include <string.h>
+//#include <string.h>
 
-#include "/usr/include/errno.h"
+//#include "/usr/include/errno.h"
 
 extern struct _PDCLIB_file_t * _PDCLIB_filelist;
 
-extern int unlink( const char * pathname );
+//extern int unlink( const char * pathname );
 
 int remove( const char * pathname )
 {
-    int rc;
-    struct _PDCLIB_file_t * current = _PDCLIB_filelist;
-    while ( current != NULL )
-    {
-        if ( ( current->filename != NULL ) && ( strcmp( current->filename, pathname ) == 0 ) )
-        {
-            return EOF;
-        }
-        current = current->next;
-    }
-    if ( ( rc = unlink( pathname ) ) == -1 )
-    {
-        switch ( errno )
-        {
-            /* See the comments on implementation-defined errno values in
-               <_PDCLIB_config.h>.
-            */
-            case EACCES:
-            case EFAULT:
-            case EIO:
-            case EISDIR:
-            case ELOOP:
-            case ENAMETOOLONG:
-            case ENOENT:
-            case ENOMEM:
-            case ENOTDIR:
-            case EPERM:
-            case EROFS:
-                _PDCLIB_errno = _PDCLIB_ERROR;
-                break;
-            default:
+//    int rc;
+//    struct _PDCLIB_file_t * current = _PDCLIB_filelist;
+//    while ( current != NULL )
+//    {
+//        if ( ( current->filename != NULL ) && ( strcmp( current->filename, pathname ) == 0 ) )
+//        {
+//            return EOF;
+//        }
+//        current = current->next;
+//    }
+//    if ( ( rc = unlink( pathname ) ) == -1 )
+//    {
+//        switch ( errno )
+//        {
+//            /* See the comments on implementation-defined errno values in
+//               <_PDCLIB_config.h>.
+//            */
+//            case EACCES:
+//            case EFAULT:
+//            case EIO:
+//            case EISDIR:
+//            case ELOOP:
+//            case ENAMETOOLONG:
+//            case ENOENT:
+//            case ENOMEM:
+//            case ENOTDIR:
+//            case EPERM:
+//            case EROFS:
+//                _PDCLIB_errno = _PDCLIB_ERROR;
+//                break;
+//            default:
                 /* This should be something like EUNKNOWN. */
                 _PDCLIB_errno = _PDCLIB_ERROR;
-                break;
-        }
-    }
-    return rc;
+//                break;
+//        }
+//    }
+//    return rc;
+    return EOF;
 }
 
 #endif
index 585a61d4d44847046406c76d89ab5fffeb71d112..f8a697bf57fcdae1020c1530478d803cb38e2198 100644 (file)
@@ -4,20 +4,20 @@
    Permission is granted to use, modify, and / or redistribute at will.
 */
 
-#include <stdio.h>
+//#include <stdio.h>
 
 #ifndef REGTEST
 
 #include "pdclib/_PDCLIB_glue.h"
 
-#include <inttypes.h>
+//#include <inttypes.h>
 #include <stdlib.h>
-#include <string.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
+//#include <string.h>
+//
+//#include <sys/types.h>
+//#include <sys/stat.h>
+//#include <fcntl.h>
+//#include <unistd.h>
 
 extern struct _PDCLIB_file_t * _PDCLIB_filelist;
 
@@ -26,61 +26,61 @@ extern struct _PDCLIB_file_t * _PDCLIB_filelist;
 */
 struct _PDCLIB_file_t * tmpfile( void )
 {
-    FILE * rc;
-    /* This is the chosen way to get high-quality randomness. Replace as
-       appropriate.
-    */
-    FILE * randomsource = fopen( "/proc/sys/kernel/random/uuid", "rb" );
-    char filename[ L_tmpnam ];
-    _PDCLIB_fd_t fd;
-    if ( randomsource == NULL )
-    {
-        return NULL;
-    }
-    for ( ;; )
-    {
-        /* Get a filename candidate. What constitutes a valid filename and
-           where temporary files are usually located is platform-dependent,
-           which is one reason why this function is located in the platform
-           overlay. The other reason is that a *good* implementation should
-           use high-quality randomness instead of a pseudo-random sequence to
-           generate the filename candidate, which is *also* platform-dependent.
-        */
-        unsigned int random;
-        fscanf( randomsource, "%u", &random );
-        sprintf( filename, "/tmp/%u.tmp", random );
-        /* Check if file of this name exists. Note that fopen() is a very weak
-           check, which does not take e.g. access permissions into account
-           (file might exist but not readable). Replace with something more
-           appropriate.
-        */
-        fd = open( filename, O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR );
-        if ( fd != -1 )
-        {
-            break;
-        }
-        close( fd );
-    }
-    fclose( randomsource );
-    /* See fopen(). */
-    if ( ( rc = calloc( 1, sizeof( struct _PDCLIB_file_t ) + _PDCLIB_UNGETCBUFSIZE + L_tmpnam + BUFSIZ ) ) == NULL )
-    {
-        /* No memory to set up FILE structure */
-        close( fd );
+//    FILE * rc;
+//    /* This is the chosen way to get high-quality randomness. Replace as
+//       appropriate.
+//    */
+//    FILE * randomsource = fopen( "/proc/sys/kernel/random/uuid", "rb" );
+//    char filename[ L_tmpnam ];
+//    _PDCLIB_fd_t fd;
+//    if ( randomsource == NULL )
+//    {
         return NULL;
-    }
-    rc->status = _PDCLIB_filemode( "wb+" ) | _IOLBF | _PDCLIB_DELONCLOSE;
-    rc->handle = fd;
-    rc->ungetbuf = (unsigned char *)rc + sizeof( struct _PDCLIB_file_t );
-    rc->filename = (char *)rc->ungetbuf + _PDCLIB_UNGETCBUFSIZE;
-    rc->buffer   = rc->filename + L_tmpnam;
-    strcpy( rc->filename, filename );
-    rc->bufsize = BUFSIZ;
-    rc->bufidx = 0;
-    rc->ungetidx = 0;
-    rc->next = _PDCLIB_filelist;
-    _PDCLIB_filelist = rc;
-    return rc;
+//    }
+//    for ( ;; )
+//    {
+//        /* Get a filename candidate. What constitutes a valid filename and
+//           where temporary files are usually located is platform-dependent,
+//           which is one reason why this function is located in the platform
+//           overlay. The other reason is that a *good* implementation should
+//           use high-quality randomness instead of a pseudo-random sequence to
+//           generate the filename candidate, which is *also* platform-dependent.
+//        */
+//        unsigned int random;
+//        fscanf( randomsource, "%u", &random );
+//        sprintf( filename, "/tmp/%u.tmp", random );
+//        /* Check if file of this name exists. Note that fopen() is a very weak
+//           check, which does not take e.g. access permissions into account
+//           (file might exist but not readable). Replace with something more
+//           appropriate.
+//        */
+//        fd = open( filename, O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR );
+//        if ( fd != -1 )
+//        {
+//            break;
+//        }
+//        close( fd );
+//    }
+//    fclose( randomsource );
+//    /* See fopen(). */
+//    if ( ( rc = calloc( 1, sizeof( struct _PDCLIB_file_t ) + _PDCLIB_UNGETCBUFSIZE + L_tmpnam + BUFSIZ ) ) == NULL )
+//    {
+//        /* No memory to set up FILE structure */
+//        close( fd );
+//        return NULL;
+//    }
+//    rc->status = _PDCLIB_filemode( "wb+" ) | _IOLBF | _PDCLIB_DELONCLOSE;
+//    rc->handle = fd;
+//    rc->ungetbuf = (unsigned char *)rc + sizeof( struct _PDCLIB_file_t );
+//    rc->filename = (char *)rc->ungetbuf + _PDCLIB_UNGETCBUFSIZE;
+//    rc->buffer   = rc->filename + L_tmpnam;
+//    strcpy( rc->filename, filename );
+//    rc->bufsize = BUFSIZ;
+//    rc->bufidx = 0;
+//    rc->ungetidx = 0;
+//    rc->next = _PDCLIB_filelist;
+//    _PDCLIB_filelist = rc;
+//    return rc;
 }
 
 #endif
index 825e040e9e62ffaad8585972f9b4df508918f35a..b7880afa1f9aa9f386a725edebece0d442efa75c 100644 (file)
@@ -8,16 +8,17 @@
 
 #ifndef REGTEST
 
-#include <sys/times.h>
+#include <syscalls.h>
 
 clock_t clock( void )
 {
-    struct tms buf;
-    if ( times( &buf ) != (clock_t)-1 )
-    {
-        return buf.tms_utime + buf.tms_stime;
-    }
-    return -1;
+      return ticks();
+//    struct tms buf;
+//    if ( times( &buf ) != (clock_t)-1 )
+//    {
+//        return buf.tms_utime + buf.tms_stime;
+//    }
+//    return -1;
 }
 
 #endif
index cbb29e1fe21953a24e1b96ad6107a6804c447785..814c9251c28888f1ee81b67a7c5ed2fea1c1c631 100644 (file)
@@ -8,22 +8,16 @@
 
 #ifndef REGTEST
 
-#include <sys/time.h>
+#include <syscalls.h>
 
 /* See comments in time.h on the semantics of time_t. */
 
 time_t time( time_t * timer )
 {
-    struct timeval tv;
-    if ( gettimeofday( &tv, NULL ) == 0 )
-    {
-        if ( timer != NULL )
-        {
-            *timer = tv.tv_sec;
-        }
-        return tv.tv_sec;
-    }
-    return -1;
+    if ( timer != NULL )
+        *timer = ticks();
+
+    return ticks();
 }
 
 #endif
index d8cbab748e5cf95b00eb6a1f8d22bf2f0f80b68f..df17f1abadacb2dcf4949ec0c00344a59aa0bee6 100644 (file)
@@ -8,21 +8,18 @@
 
 #ifndef REGTEST
 
-#include <sys/time.h>
+#include <syscalls.h>
 
 int timespec_get( struct timespec * ts, int base )
 {
     if ( base == TIME_UTC )
     {
-        /* We can make do with a really thin wrapper here. */
-        struct timeval tv;
-        if ( gettimeofday( &tv, NULL ) == 0 )
-        {
-            ts->tv_sec = tv.tv_sec;
-            ts->tv_nsec = tv.tv_usec * 1000;
-            return base;
-        }
+       unsigned int t = ticks();
+        ts->tv_sec = t / 1000;
+       ts->tv_nsec = t * 1000000;
+        return base;
     }
+
     /* Not supporting any other time base than TIME_UTC for now. */
     return 0;
 }
diff --git a/src/pdclib/platform/stmos/include/syscalls.h b/src/pdclib/platform/stmos/include/syscalls.h
new file mode 100644 (file)
index 0000000..2acb59c
--- /dev/null
@@ -0,0 +1,53 @@
+#ifndef SYSCALLS_H_
+#define SYSCALLS_H_
+
+#include <stdint.h>
+
+//
+// Task-related calls
+
+void _exit(int code);
+
+int fork(void);
+int getpid(void);
+void *sbrk(unsigned int bytes);
+
+//
+// Clock-related calls
+
+void delay(unsigned int ms);
+unsigned int ticks(void);
+
+//
+// File-related calls
+
+// Indicates mounted volume
+#define VFS_MOUNTED  (1 << 0)
+// Set if filesystem is read-only
+#define VFS_READONLY (1 << 1)
+
+// Indicates an opened file
+#define VFS_FILE_OPEN  (1 << 0)
+// Indicates read permission on file
+#define VFS_FILE_READ  (1 << 1)
+// Indicates write permission on file
+#define VFS_FILE_WRITE (1 << 2)
+// Set if EOF has been reached
+#define VFS_EOF        (1 << 3)
+
+#define EOF (-1)
+
+struct dirent {
+       char name[32];
+};
+
+struct vfs_volume_funcs_t;
+typedef struct vfs_volume_funcs_t vfs_volume_funcs;
+
+int mount(vfs_volume_funcs *funcs, uint32_t flags);
+int open(const char *path, uint32_t flags);
+int close(int fd);
+int read(int fd, uint32_t count, uint8_t *buffer);
+int write(int fd, uint32_t count, const uint8_t *buffer);
+
+#endif // SYSCALLS_H_
diff --git a/src/user/syscalls.h b/src/user/syscalls.h
deleted file mode 100644 (file)
index c6a0c61..0000000
+++ /dev/null
@@ -1,146 +0,0 @@
-#ifndef SYSCALLS_H_
-#define SYSCALLS_H_
-
-#include <stdint.h>
-
-//
-// Task-related calls
-
-inline void _exit(int code)
-{
-       register uint32_t r1 __asm("r1") = code;
-       __asm("\
-               mov r0, 0; \
-               mov r1, %0; \
-               svc 0; \
-       " :: "r" (r1));
-}
-
-inline int fork(void)
-{
-       int ret = 0;
-       register uint32_t r1 __asm("r1") = (uint32_t)&ret;
-       __asm("\
-               mov r0, 1; \
-               mov r1, %0; \
-               svc 0; \
-       " :: "r" (r1));
-       return ret;
-}
-
-inline int getpid(void)
-{
-       int ret = 0;
-       register uint32_t r1 __asm("r1") = (uint32_t)&ret;
-       __asm("\
-               mov r0, 2; \
-               mov r1, %0; \
-               svc 0; \
-       " :: "r" (r1));
-       return ret;
-}
-
-inline void *sbrk(unsigned int bytes)
-{
-       void *ret = 0;
-       register uint32_t r1 __asm("r1") = bytes;
-       register uint32_t r2 __asm("r2") = (uint32_t)&ret;
-       __asm("\
-               mov r0, 4; \
-               mov r1, %0; \
-               mov r2, %1; \
-               svc 0; \
-       " :: "r" (r1), "r" (r2));
-       return ret;
-}
-
-//
-// File-related calls
-
-// Indicates mounted volume
-#define VFS_MOUNTED  (1 << 0)
-// Set if filesystem is read-only
-#define VFS_READONLY (1 << 1)
-
-// Indicates an opened file
-#define VFS_FILE_OPEN  (1 << 0)
-// Indicates read permission on file
-#define VFS_FILE_READ  (1 << 1)
-// Indicates write permission on file
-#define VFS_FILE_WRITE (1 << 2)
-// Set if EOF has been reached
-#define VFS_EOF        (1 << 3)
-
-#define EOF (-1)
-
-struct dirent {
-       char name[32];
-};
-
-struct vfs_volume_funcs_t;
-typedef struct vfs_volume_funcs_t vfs_volume_funcs;
-
-inline int mount(vfs_volume_funcs *funcs, uint32_t flags)
-{
-       int ret = 0;
-       register uint32_t r1 __asm("r1") = (uint32_t)funcs;
-       register uint32_t r2 __asm("r2") = flags;
-       register uint32_t r3 __asm("r3") = (uint32_t)&ret;
-       __asm("\
-               mov r0, 0; \
-               mov r1, %0; \
-               mov r2, %1; \
-               mov r3, %2; \
-               svc 3; \
-       " :: "r" (r1), "r" (r2), "r" (r3));
-       return ret;
-}
-
-inline int open(const char *path, uint32_t flags)
-{
-       int ret = 0;
-       register uint32_t r1 __asm("r1") = (uint32_t)path;
-       register uint32_t r2 __asm("r2") = flags;
-       register uint32_t r3 __asm("r3") = (uint32_t)&ret;
-       __asm("\
-               mov r0, 1; \
-               mov r1, %0; \
-               mov r2, %1; \
-               mov r3, %2; \
-               svc 3; \
-       " :: "r" (r1), "r" (r2), "r" (r3));
-       return ret;
-}
-
-inline int close(int fd)
-{
-       int ret = 0;
-       register uint32_t r1 __asm("r1") = fd;
-       register uint32_t r2 __asm("r2") = (uint32_t)&ret;
-       __asm("\
-               mov r0, 2; \
-               mov r1, %0; \
-               mov r2, %1; \
-               svc 3; \
-       " :: "r" (r1), "r" (r2));
-}
-
-inline int read(int fd, uint32_t count, uint8_t *buffer)
-{
-       int ret = 0;
-       register uint32_t r1 __asm("r1") = fd;
-       register uint32_t r2 __asm("r2") = count;
-       register uint32_t r3 __asm("r3") = (uint32_t)buffer;
-       register uint32_t r4 __asm("r4") = (uint32_t)&ret;
-       __asm("\
-               mov r0, 3; \
-               mov r1, %0; \
-               mov r2, %1; \
-               mov r3, %2; \
-               mov r4, %3; \
-               svc 3; \
-       " :: "r" (r1), "r" (r2), "r" (r3), "r" (r4));
-       return ret;
-}
-
-#endif // SYSCALLS_H_
index 218ac97a0d6718cc2856b6fd9f82db931be02aa9..dd1aa54225ce259a6aff54bc0d75ca88d1be2eb6 100644 (file)
@@ -4,8 +4,6 @@
 #include <kernel/heap.h>
 #include <kernel/vfs.h>
 
-#include "syscalls.h"
-
 void user_delay(uint32_t ms)
 {
        register uint32_t r1 asm("r1") = ms;
@@ -26,17 +24,17 @@ void user_main(void)
        int count = vfs_read(test, 20, (uint8_t *)buf);
        (void)count;
 
-       if (fork() == 0) {
-               while (1) {
-                       gpio(GPIO_OUT, 5, 1);
-                       user_delay(2000);
-               }
-       } else {
-               while (1) {
-                       user_delay(1000);
-                       gpio(GPIO_OUT, 5, 0);
-                       user_delay(1000);
-               }
-       }
+//     if (fork() == 0) {
+//             while (1) {
+//                     gpio(GPIO_OUT, 5, 1);
+//                     user_delay(2000);
+//             }
+//     } else {
+//             while (1) {
+//                     user_delay(1000);
+//                     gpio(GPIO_OUT, 5, 0);
+//                     user_delay(1000);
+//             }
+//     }
 }