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
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
#include <stdio.h>
+#include <stdlib.h>
+
+int main(void);
+
+void _start(void)
+{
+ exit(main());
+}
int main(void)
{
. = 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 : {
#include <stdint.h>
-#include <string.h>
#include <kernel/heap.h>
#include <kernel/vfs.h>
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);
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;
#include "gpio.h"
-static const GPIO_TypeDef *gpio_ports[8] = {
+static GPIO_TypeDef *gpio_ports[8] = {
GPIOA, GPIOB, GPIOC, GPIOD,
GPIOE, GPIOF, GPIOG, GPIOH
};
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
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)
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)) {
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++) {
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;
}
typedef struct {
uint32_t flags;
- vfs_volume_funcs *funcs;
+ const vfs_volume_funcs *funcs;
} vfs_volume;
// Indicates an opened file
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);
//
// 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);
// Set if EOF has been reached
#define VFS_EOF (1 << 3)
+#ifndef EOF
#define EOF (-1)
+#endif // EOF
struct dirent {
char name[32];
{
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) {