summaryrefslogtreecommitdiff
path: root/os
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2011-02-02 08:35:38 -0800
committerPixel <pixel@nobis-crew.org>2011-02-02 08:35:38 -0800
commit3ca9b28c5b04220565c206bd73d9ebb48b64db3b (patch)
tree86ffbb085f2c255de44321c858780c77dc7583d8 /os
parent29dc401e5ba2c3f5676d426c4c1b10f1fc475fcd (diff)
Making a sample code for the 'romfs' thingy.
Diffstat (limited to 'os')
-rw-r--r--os/Makefile4
-rw-r--r--os/src/close.c3
-rw-r--r--os/src/fclose.c3
-rw-r--r--os/src/fflush.c2
-rw-r--r--os/src/filesystem.c2
-rw-r--r--os/src/fio.c7
-rw-r--r--os/src/fopen.c2
-rw-r--r--os/src/fprintf.c4
-rw-r--r--os/src/fread.c2
-rw-r--r--os/src/free.c4
-rw-r--r--os/src/fstat.c2
-rw-r--r--os/src/fwrite.c2
-rw-r--r--os/src/isatty.c2
-rw-r--r--os/src/lseek.c2
-rw-r--r--os/src/malloc.c2
-rw-r--r--os/src/open.c2
-rw-r--r--os/src/printf.c1
-rw-r--r--os/src/read.c2
-rw-r--r--os/src/romfs.c2
-rw-r--r--os/src/sprintf.c2
-rw-r--r--os/src/write.c2
21 files changed, 46 insertions, 8 deletions
diff --git a/os/Makefile b/os/Makefile
index cfc6e33..d7d0419 100644
--- a/os/Makefile
+++ b/os/Makefile
@@ -36,6 +36,10 @@ src/malloc.c \
src/printf.c \
src/sprintf.c \
+ifeq ($(CPU),arm)
+TARGET_SRCS += src/semifs.c
+endif
+
include $(ROOTDIR)/target-rules.mk
clean: clean-generic
diff --git a/os/src/close.c b/os/src/close.c
index 90b22ed..5da8b2c 100644
--- a/os/src/close.c
+++ b/os/src/close.c
@@ -1,9 +1,10 @@
#include <reent.h>
-#include <osdebug.h>
#include <errno.h>
#include "fio.h"
+#include "osdebug.h"
int _close_r(struct _reent * reent, int fd) {
+// DBGOUT("_close_r(%p, %i)\r\n", reent, fd);
if (!fio_is_open(fd)) {
reent->_errno = EBADF;
return -1;
diff --git a/os/src/fclose.c b/os/src/fclose.c
index 76cf51d..4c4c3fc 100644
--- a/os/src/fclose.c
+++ b/os/src/fclose.c
@@ -1,7 +1,8 @@
#include <stdio.h>
#include <reent.h>
-#include <osdebug.h>
+#include "osdebug.h"
int fclose(FILE * fp) {
+// DBGOUT("fclose(%p)\r\n", fp);
return _fclose_r(_impure_ptr, fp);
}
diff --git a/os/src/fflush.c b/os/src/fflush.c
index fc1bf63..84e2c67 100644
--- a/os/src/fflush.c
+++ b/os/src/fflush.c
@@ -1,5 +1,7 @@
#include <stdio.h>
+#include "osdebug.h"
int fflush(FILE * file) {
+// DBGOUT("fflush(%p)\r\n", file);
return _fflush_r(_impure_ptr, file);
}
diff --git a/os/src/filesystem.c b/os/src/filesystem.c
index 64d7e0d..dda47bd 100644
--- a/os/src/filesystem.c
+++ b/os/src/filesystem.c
@@ -22,6 +22,7 @@ __attribute__((constructor)) void fs_init() {
int register_fs(const char * mountpoint, fs_open_t callback, void * opaque) {
int i;
+ DBGOUT("register_fs(\"%s\", %p, %p)\r\n", mountpoint, callback, opaque);
for (i = 0; i < MAX_FS; i++) {
if (!fss[i].cb) {
@@ -39,6 +40,7 @@ int fs_open(const char * path, int flags, int mode) {
const char * slash;
uint32_t hash;
int i;
+// DBGOUT("fs_open(\"%s\", %i, %i)\r\n", path, flags, mode);
while (path[0] == '/')
path++;
diff --git a/os/src/fio.c b/os/src/fio.c
index 9fe5038..432f7e2 100644
--- a/os/src/fio.c
+++ b/os/src/fio.c
@@ -75,6 +75,7 @@ int fio_is_open(int fd) {
int fio_open(fdread_t fdread, fdwrite_t fdwrite, fdseek_t fdseek, fdclose_t fdclose, void * opaque) {
int fd;
+// DBGOUT("fio_open(%p, %p, %p, %p, %p)\r\n", fdread, fdwrite, fdseek, fdclose, opaque);
xSemaphoreTake(fio_sem, portMAX_DELAY);
fd = fio_findfd();
@@ -92,6 +93,7 @@ int fio_open(fdread_t fdread, fdwrite_t fdwrite, fdseek_t fdseek, fdclose_t fdcl
ssize_t fio_read(int fd, void * buf, size_t count) {
ssize_t r = 0;
+// DBGOUT("fio_read(%i, %p, %i)\r\n", fd, buf, count);
if (fio_is_open_int(fd)) {
if (fio_fds[fd].fdread) {
r = fio_fds[fd].fdread(fio_fds[fd].opaque, buf, count);
@@ -106,6 +108,7 @@ ssize_t fio_read(int fd, void * buf, size_t count) {
ssize_t fio_write(int fd, const void * buf, size_t count) {
ssize_t r = 0;
+// DBGOUT("fio_write(%i, %p, %i)\r\n", fd, buf, count);
if (fio_is_open_int(fd)) {
if (fio_fds[fd].fdwrite) {
r = fio_fds[fd].fdwrite(fio_fds[fd].opaque, buf, count);
@@ -120,6 +123,7 @@ ssize_t fio_write(int fd, const void * buf, size_t count) {
off_t fio_seek(int fd, off_t offset, int whence) {
off_t r = 0;
+// DBGOUT("fio_seek(%i, %i, %i)\r\n", fd, offset, whence);
if (fio_is_open_int(fd)) {
if (fio_fds[fd].fdseek) {
r = fio_fds[fd].fdseek(fio_fds[fd].opaque, offset, whence);
@@ -134,6 +138,7 @@ off_t fio_seek(int fd, off_t offset, int whence) {
int fio_close(int fd) {
int r = 0;
+// DBGOUT("fio_close(%i)\r\n", fd);
if (fio_is_open_int(fd)) {
if (fio_fds[fd].fdclose)
r = fio_fds[fd].fdclose(fio_fds[fd].opaque);
@@ -157,6 +162,7 @@ void fio_set_opaque(int fd, void * opaque) {
static int devfs_open(void * opaque, const char * path, int flags, int mode) {
uint32_t h = hash_djb2((const uint8_t *) path, -1);
+// DBGOUT("devfs_open(%p, \"%s\", %i, %i)\r\n", opaque, path, flags, mode);
switch (h) {
case stdin_hash:
if (flags & (O_WRONLY | O_RDWR))
@@ -178,5 +184,6 @@ static int devfs_open(void * opaque, const char * path, int flags, int mode) {
}
void register_devfs() {
+ DBGOUT("Registering devfs.\r\n");
register_fs("dev", devfs_open, NULL);
}
diff --git a/os/src/fopen.c b/os/src/fopen.c
index e8b4246..22ac269 100644
--- a/os/src/fopen.c
+++ b/os/src/fopen.c
@@ -1,6 +1,8 @@
#include <stdio.h>
#include <reent.h>
+#include "osdebug.h"
FILE * fopen(const char * path, const char * mode) {
+// DBGOUT("fopen(\"%s\", \"%s\")\r\n", path, mode);
return _fopen_r(_impure_ptr, path, mode);
}
diff --git a/os/src/fprintf.c b/os/src/fprintf.c
index 10d34e7..a56ed33 100644
--- a/os/src/fprintf.c
+++ b/os/src/fprintf.c
@@ -1,12 +1,12 @@
#include <reent.h>
#include <stdio.h>
#include <stdarg.h>
-#include <osdebug.h>
+#include "osdebug.h"
int fprintf(FILE * file, const char * fmt, ...) {
int r;
va_list ap;
- DBGOUT("fprintf(%p, %p, ...)\r\n", file, fmt);
+// DBGOUT("fprintf(%p, %p, ...)\r\n", file, fmt);
va_start(ap, fmt);
r = _vfprintf_r(_impure_ptr, file, fmt, ap);
va_end(ap);
diff --git a/os/src/fread.c b/os/src/fread.c
index b003d33..3f39c1e 100644
--- a/os/src/fread.c
+++ b/os/src/fread.c
@@ -1,5 +1,7 @@
#include <stdio.h>
+#include "osdebug.h"
size_t fread(void * ptr, size_t size, size_t nmemb, FILE * file) {
+// DBGOUT("fread(%p, %i, %i, %p)\r\n", ptr, size, nmemb, file);
return _fread_r(_impure_ptr, ptr, size, nmemb, file);
}
diff --git a/os/src/free.c b/os/src/free.c
index 0091d56..a011077 100644
--- a/os/src/free.c
+++ b/os/src/free.c
@@ -1,8 +1,8 @@
#include <reent.h>
#include <malloc.h>
-#include <osdebug.h>
+#include "osdebug.h"
void free(void * ptr) {
- DBGOUT("free(%p)\r\n", ptr);
+// DBGOUT("free(%p)\r\n", ptr);
_free_r(_impure_ptr, ptr);
}
diff --git a/os/src/fstat.c b/os/src/fstat.c
index b10194c..a7c251f 100644
--- a/os/src/fstat.c
+++ b/os/src/fstat.c
@@ -3,9 +3,11 @@
#include <string.h>
#include <errno.h>
#include "fio.h"
+#include "osdebug.h"
int _fstat_r(struct _reent * reent, int fd, struct stat * buf) {
off_t c;
+// DBGOUT("_fstat_r(%p, %i, %p)\r\n", reent, fd, buf);
memset(buf, 0, sizeof(struct stat));
if (!fio_is_open(fd)) {
diff --git a/os/src/fwrite.c b/os/src/fwrite.c
index c6890dc..6a10db0 100644
--- a/os/src/fwrite.c
+++ b/os/src/fwrite.c
@@ -1,5 +1,7 @@
#include <stdio.h>
+#include "osdebug.h"
size_t fwrite(const void * ptr, size_t size, size_t nmemb, FILE * file) {
+// DBGOUT("fwrite(%p, %i, %i, %p)\r\n", ptr, size, nmemb, file);
return _fwrite_r(_impure_ptr, ptr, size, nmemb, file);
}
diff --git a/os/src/isatty.c b/os/src/isatty.c
index 051284f..b37a9dc 100644
--- a/os/src/isatty.c
+++ b/os/src/isatty.c
@@ -2,8 +2,10 @@
#include <reent.h>
#include <errno.h>
#include "fio.h"
+#include "osdebug.h"
int _isatty_r(struct _reent * reent, int fd) {
+// DBGOUT("_isatty_r(%p, %i)\r\n", reent, fd);
if (!fio_is_open(fd)) {
reent->_errno = EBADF;
return 0;
diff --git a/os/src/lseek.c b/os/src/lseek.c
index 1cb0234..1e904a5 100644
--- a/os/src/lseek.c
+++ b/os/src/lseek.c
@@ -2,9 +2,11 @@
#include <osdebug.h>
#include <errno.h>
#include "fio.h"
+#include "osdebug.h"
_off_t _lseek_r(struct _reent * reent, int fd, _off_t seek, int wheel) {
off_t r;
+// DBGOUT("_lseek_r(%p, %i, %i, %i)\r\n", reent, fd, seek, wheel);
if ((wheel != SEEK_SET) && (wheel != SEEK_CUR) && (wheel != SEEK_END)) {
reent->_errno = EINVAL;
diff --git a/os/src/malloc.c b/os/src/malloc.c
index 281a75b..3d867d0 100644
--- a/os/src/malloc.c
+++ b/os/src/malloc.c
@@ -2,6 +2,7 @@
#include <malloc.h>
#include <FreeRTOS.h>
#include <semphr.h>
+#include "osdebug.h"
static xSemaphoreHandle malloc_sem = NULL;
@@ -11,6 +12,7 @@ __attribute__((constructor)) static void malloc_init() {
void * malloc(size_t size) {
void * ptr;
+// DBGOUT("malloc(%i)\r\n", size);
if (malloc_sem)
xSemaphoreTake(malloc_sem, portMAX_DELAY);
diff --git a/os/src/open.c b/os/src/open.c
index 7a2c147..5298fd8 100644
--- a/os/src/open.c
+++ b/os/src/open.c
@@ -3,8 +3,10 @@
#include <errno.h>
#include "fio.h"
#include "filesystem.h"
+#include "osdebug.h"
int _open_r(struct _reent * reent, const char * path, int flags, int mode) {
+// DBGOUT("_open_r(%p, \"%s\", flags, mode)\r\n", reent, path, flags, mode);
int r = fs_open(path, flags, mode);
if (r >= 0)
diff --git a/os/src/printf.c b/os/src/printf.c
index 83f7539..80b6b94 100644
--- a/os/src/printf.c
+++ b/os/src/printf.c
@@ -6,6 +6,7 @@
int printf(const char * fmt, ...) {
int r;
va_list ap;
+// DBGOUT("printf(\"%p\", ...)\r\n", fmt);
va_start(ap, fmt);
r = _vprintf_r(_impure_ptr, fmt, ap);
va_end(ap);
diff --git a/os/src/read.c b/os/src/read.c
index f848812..845092b 100644
--- a/os/src/read.c
+++ b/os/src/read.c
@@ -6,6 +6,8 @@
_ssize_t _read_r(struct _reent * reent, int fd, void * buf, size_t size) {
_ssize_t r;
+// DBGOUT("_read_r(%p, %i, %p, %i)\r\n", reent, fd, buf, size);
+
if (!fio_is_open(fd)) {
reent->_errno = EBADF;
return -1;
diff --git a/os/src/romfs.c b/os/src/romfs.c
index 270fb54..2d11d96 100644
--- a/os/src/romfs.c
+++ b/os/src/romfs.c
@@ -90,6 +90,6 @@ static int romfs_open(void * opaque, const char * path, int flags, int mode) {
}
void register_romfs(const char * mountpoint, const uint8_t * romfs) {
- DBGOUT("Registering romfs `%s' @ %p\r\n", mountpoint, romfs);
+// DBGOUT("Registering romfs `%s' @ %p\r\n", mountpoint, romfs);
register_fs(mountpoint, romfs_open, (void *) romfs);
}
diff --git a/os/src/sprintf.c b/os/src/sprintf.c
index 9027623..755d780 100644
--- a/os/src/sprintf.c
+++ b/os/src/sprintf.c
@@ -6,7 +6,7 @@
int sprintf(char * str, const char * fmt, ...) {
int r;
va_list ap;
- DBGOUT("sprintf(%p, %p, ...)\r\n", str, fmt);
+// DBGOUT("sprintf(%p, %p, ...)\r\n", str, fmt);
va_start(ap, fmt);
r = _vsprintf_r(_impure_ptr, str, fmt, ap);
va_end(ap);
diff --git a/os/src/write.c b/os/src/write.c
index 14e26d6..c54e304 100644
--- a/os/src/write.c
+++ b/os/src/write.c
@@ -6,6 +6,8 @@
_ssize_t _write_r(struct _reent * reent, int fd, const void * buf, size_t size) {
_ssize_t r;
+// DBGOUT("_write_r(%p, %i, %p, %i)\r\n", reent, fd, buf, size);
+
if (!fio_is_open(fd)) {
reent->_errno = EBADF;
return -1;