]> code.bitgloo.com Git - clyne/stmos.git/commitdiff
fs work, initrd/stdio
authorClyne Sullivan <tullivan99@gmail.com>
Tue, 20 Nov 2018 15:43:33 +0000 (10:43 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Tue, 20 Nov 2018 15:43:33 +0000 (10:43 -0500)
13 files changed:
Makefile
initrd/Makefile
initrd/test
initrd/test.c
link.ld
src/fs/initrd.c
src/kernel/gpio.c
src/kernel/startup_stm32l476xx.s
src/kernel/task.c
src/kernel/vfs.c
src/kernel/vfs.h
src/pdclib/platform/stmos/include/syscalls.h
src/user/user.c

index d497420633f5a70899cbc937094162f5df6caf53..488f95f31aeabf0d2fc6c96d7e9b13045f4fe592 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -25,11 +25,9 @@ OBJCOPY = objcopy
 
 MCUFLAGS = -mthumb -mcpu=cortex-m4 #-mfloat-abi=hard -mfpu=fpv4-sp-d16
 AFLAGS = $(MCUFLAGS) 
-CFLAGS = $(MCUFLAGS) -ggdb --specs=nosys.specs \
-       -I.. \
-       -fno-builtin -fsigned-char -ffreestanding \
-       -Wall -Werror -Wextra -pedantic \
-       -Wno-overlength-strings -Wno-discarded-qualifiers
+CFLAGS = $(MCUFLAGS) -ggdb -ffreestanding -nostdlib -fsigned-char -I.. \
+       -Wall -Werror -Wextra -pedantic
+       #-Wno-overlength-strings -Wno-discarded-qualifiers
 LFLAGS = -T link.ld
 
 OUT = main.elf
index b2ca46f8597490e562226ebab29102e1e2ef5dd7..705ac6cbea8ed1d585ef3bd02f4e4a6654837425 100644 (file)
@@ -1,4 +1,6 @@
 all:
-       @arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -fsigned-char -Os -nostdinc \
+       @arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -fsigned-char -Os \
+               -nostdinc -nostdlib \
+               -fdata-sections -ffunction-sections -Wl,--gc-sections \
                -I../src/pdclib/include -I../src/pdclib/platform/stmos/include \
-               test.c ../src/pdclib/pdclib.a -s -o test -pie
+               test.c ../src/pdclib/pdclib.a -s -o test
index 8b9d8a40dbfee1286e3021a2df2403bf06aab0d2..7bf8246d7cf1a393b86c12d860796678907245a4 100755 (executable)
Binary files a/initrd/test and b/initrd/test differ
index f673ce0974ea9c6408aedf8949040cce93820fd7..b79f315ba997419e30561a4d9a59fc51e7480b1e 100644 (file)
@@ -1,4 +1,12 @@
 #include <stdio.h>
+#include <stdlib.h>
+
+int main(void);
+
+void _start(void)
+{
+       exit(main());
+}
 
 int main(void)
 {
diff --git a/link.ld b/link.ld
index e00d450b0db719357e8854954cb073c39c52b52b..092032eb78b4f244a246a74663b9b254a6eb93fb 100644 (file)
--- a/link.ld
+++ b/link.ld
@@ -56,26 +56,6 @@ SECTIONS {
                . = ALIGN(8);
        } > FLASH
 
-       /* ARM stuff */
-       .ARM.exidx : {
-               *(.ARM.exidx)
-       } > FLASH
-
-       /* init_array/fini_array (TODO understand this) */
-       .init_array : {
-               __init_array_start = .;
-               KEEP(*(.init_array.*))
-               KEEP(*(.init_array*))
-               __init_array_end = .;
-       } > FLASH
-
-       .fini_array : {
-               __fini_array_start = .;
-               KEEP(*(.fini_array.*))
-               KEEP(*(.fini_array*))
-               __fini_array_end = .;
-       } > FLASH
-
        /* initialized data */
        _sidata = LOADADDR(.data);
        .data : {
index 5731ab51577a5f563fb0fb68ef26712c464cca9d..44e549307d5d3bb6ea088a3fa068e7d016287242 100644 (file)
@@ -1,5 +1,4 @@
 #include <stdint.h>
-#include <string.h>
 
 #include <kernel/heap.h>
 #include <kernel/vfs.h>
@@ -30,6 +29,16 @@ static const vfs_volume_funcs initrd_funcs = {
        0  // readdir
 };
 
+int initrd_strncmp(const char *a, const char *b, unsigned int n)
+{
+       for (unsigned int i = 0; i < n; i++) {
+               if (a[i] != b[i])
+                       return 1;
+       }
+
+       return 0;
+}
+
 void initrd_init(void)
 {
        vfs_mount(&initrd_funcs, VFS_READONLY);
@@ -40,7 +49,7 @@ void *initrd_open(const char *file)
        char *ptr;
        for (uint32_t i = 0; ptr = initrd_getfile(i), ptr != 0; i++) {
                uint32_t len = *((uint32_t *)ptr);
-               if (!strncmp(file, ptr + 4, len)) {
+               if (!initrd_strncmp(file, ptr + 4, len)) {
                        initrd_info *file = (initrd_info *)malloc(
                                sizeof(initrd_info));
                        file->address = ptr + len + 8;
index 1c81d115f024713473683531b9b29087e58220cf..0932e51609671effd7c7249d10bc040551c251ce 100644 (file)
@@ -20,7 +20,7 @@
 
 #include "gpio.h"
 
-static const GPIO_TypeDef *gpio_ports[8] = {
+static GPIO_TypeDef *gpio_ports[8] = {
        GPIOA, GPIOB, GPIOC, GPIOD,
        GPIOE, GPIOF, GPIOG, GPIOH
 };
index b26ced5cf1aacc3fc917be2c2af05f8d80f9f661..d60fa49906ad2529b1b7317f67a5e8ed73fda7c4 100644 (file)
@@ -105,7 +105,7 @@ LoopFillZerobss:
        bcc     FillZerobss\r
 \r
 /* Call static constructors */\r
-    bl __libc_init_array\r
+    //bl __libc_init_array\r
 /* Call the application's entry point.*/\r
        bl      main\r
 \r
index dfe50a7ced0720d01faf954206879bce2290fac1..c5e5e9634636651b00c765dae9f2af18a79c428d 100644 (file)
@@ -87,7 +87,7 @@ void task_sleep(uint32_t ms)
 
 pid_t task_getpid(void)
 {
-       return task_current->pid;
+       return task_current != 0 ? task_current->pid : 0;
 }
 
 pid_t task_waitpid(pid_t pid, int *wstatus, int options)
index da1d641eb7b253b599476a425f660daee47a1d84..62366915f2bf94d828b002dee5b3784ab1954015 100644 (file)
@@ -43,12 +43,12 @@ void vfs_init(void)
 
        vfs_mount(&stdio_funcs, 0);
        // order is crucial
-       vfs_open("in", VFS_FILE_READ);
-       vfs_open("out", VFS_FILE_WRITE);
-       vfs_open("err", VFS_FILE_WRITE);
+       vfs_open("   in", VFS_FILE_READ);
+       vfs_open("   out", VFS_FILE_WRITE);
+       vfs_open("   err", VFS_FILE_WRITE);
 }
 
-int vfs_mount(vfs_volume_funcs *funcs, uint32_t flags)
+int vfs_mount(const vfs_volume_funcs *funcs, uint32_t flags)
 {
        for (int i = 0; i < VFS_MAX_VOLS; i++) {
                if (!(vfs_volumes[i].flags && VFS_MOUNTED)) {
@@ -64,10 +64,14 @@ int vfs_mount(vfs_volume_funcs *funcs, uint32_t flags)
 int vfs_get_drive(const char *path)
 {
        // Validate parameters
-       if (path[0] == '\0' || path[1] == '\0' || path[1] != ':' ||
-               path[2] == '\0' || path[2] != '/')
+       if (path[0] == '\0')
                return -1;
 
+       // Default to 'A' if no drive specified (A gives stdio)
+       if (path[1] == '\0' || path[1] != ':' ||
+               path[2] == '\0' || path[2] != '/')
+               return 0;
+
        // Find chosen drive
        int drive = -1;
        for (int i = 0; i < VFS_MAX_VOLS; i++) {
@@ -103,11 +107,14 @@ int vfs_open(const char *path, uint32_t flags)
        if (file == -1)
                return -1;
 
+       void *fsinfo = vfs_volumes[drive].funcs->open(path + 3);
+       if (fsinfo == 0)
+               return -1;
+
        vfs_files[file].flags = VFS_FILE_OPEN | flags;
        vfs_files[file].vol = drive;
        vfs_files[file].pid = task_getpid();
-       vfs_files[file].fsinfo =
-               vfs_volumes[drive].funcs->open(path + 3);
+       vfs_files[file].fsinfo = fsinfo;
 
        return file;
 }
index 29763a5b8e4ce465542f37be4707dd85a2be44ab..89213f9ad3ce174e3d4b24540a98018db2e16c16 100644 (file)
@@ -22,7 +22,7 @@ typedef struct vfs_volume_funcs_t {
 
 typedef struct {
        uint32_t flags;
-       vfs_volume_funcs *funcs;
+       const vfs_volume_funcs *funcs;
 } vfs_volume;
 
 // Indicates an opened file
@@ -43,7 +43,7 @@ typedef struct {
 
 void vfs_init(void);
 
-int vfs_mount(vfs_volume_funcs *funcs, uint32_t flags);
+int vfs_mount(const 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);
index 2acb59ce896543ef6480d9495d865329c4b76925..b301b31b5a11d01d22ff1526721e376a3e839e0e 100644 (file)
@@ -6,6 +6,11 @@
 //
 // Task-related calls
 
+#define WEXITSTATUS(s) ((s) & 0xFF)
+#define WIFEXITED(s)   ((s) & (1 << 8))
+#define WIFSIGNALED(s) ((s) & (1 << 9))
+#define WTERMSIG(s)    ((s) & (1 << 10))
+
 void _exit(int code);
 
 int fork(void);
@@ -35,7 +40,9 @@ unsigned int ticks(void);
 // Set if EOF has been reached
 #define VFS_EOF        (1 << 3)
 
+#ifndef EOF
 #define EOF (-1)
+#endif // EOF
 
 struct dirent {
        char name[32];
index dd1aa54225ce259a6aff54bc0d75ca88d1be2eb6..b5ef789bfb1e2f224054348c839eadc95488dbec 100644 (file)
@@ -19,10 +19,11 @@ void user_main(void)
 {
        gpio(GPIO_MODE, 5, OUTPUT);
 
-       int test = vfs_open("A:/hello", VFS_FILE_READ);
+       int test = vfs_open("B:/hello", VFS_FILE_READ);
        char *buf = malloc(20);
        int count = vfs_read(test, 20, (uint8_t *)buf);
-       (void)count;
+       buf[count] = '\0';
+       vfs_close(test);
 
 //     if (fork() == 0) {
 //             while (1) {