read write patch (not working yet)

This commit is contained in:
Marian Ohligs 2011-04-01 13:43:59 +02:00
parent bbc0bbe2c3
commit 04583e3982
13 changed files with 107 additions and 34 deletions

View file

@ -22,6 +22,7 @@
#include <metalsvm/stdio.h>
#include <metalsvm/errno.h>
#include <metalsvm/fs.h>
#include <metalsvm/spinlock.h>
/* Implementation of a simple null device */

View file

@ -21,6 +21,7 @@
#include <metalsvm/string.h>
#include <metalsvm/fs.h>
#include <metalsvm/errno.h>
#include <metalsvm/spinlock.h>
vfs_node_t* fs_root = NULL; // The root of the filesystem.

View file

@ -23,6 +23,7 @@
#include <metalsvm/fs.h>
#include <metalsvm/errno.h>
#include <asm/multiboot.h>
#include <metalsvm/spinlock.h>
static vfs_node_t initrd_root;

View file

@ -27,7 +27,7 @@
#define __FS_H__
#include <metalsvm/stddef.h>
#include <metalsvm/spinlock.h>
#include <metalsvm/spinlock_types.h>
#define FS_FILE 0x01
#define FS_DIRECTORY 0x02

View file

@ -0,0 +1,42 @@
/*
* Copyright 2011 Stefan Lankes, Chair for Operating Systems,
* RWTH Aachen University
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file is part of MetalSVM.
*/
#ifndef __FS_TYPES_H__
#define __FS_TYPES_H__
#include <metalsvm/stddef.h>
#include <metalsvm/fs.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct fildes {
vfs_node_t* node; /* */
off_t offset; /* */
} fildes_t;
#define MAX_FILDES 10
#define FS_INIT { [0 ... MAX_FILDES-1] = {NULL, 0} }
#ifdef __cplusplus
}
#endif
#endif

View file

@ -32,6 +32,7 @@
#include <metalsvm/stddef.h>
#include <metalsvm/vma.h>
#include <metalsvm/spinlock_types.h>
#include <metalsvm/fs_types.h>
#include <metalsvm/mailbox_types.h>
#include <asm/atomic.h>
@ -65,6 +66,8 @@ typedef struct task {
spinlock_t vma_lock;
/// List of VMAs
vma_t* vma_list;
/// Filedescriptor table
fildes_t fildes_table[MAX_FILDES];
/// Mail inbox
mailbox_wait_msg_t inbox;
/// Mail outbox array

View file

@ -21,9 +21,10 @@
#include <metalsvm/stdio.h>
#include <metalsvm/syscall.h>
#include <metalsvm/tasks.h>
#include <metalsvm/string.h>
#include <metalsvm/errno.h>
static int sys_write(int fildes, const char *buf, size_t len)
static int sys_write(int fd, const char *buf, size_t len)
{
int i;
@ -50,20 +51,47 @@ int syscall_handler(uint32_t sys_nr, ...)
sys_exit(va_arg(vl, uint32_t));
ret = 0;
break;
case __NR_write: {
int fildes = va_arg(vl, int);
const char* buf = va_arg(vl, const char*);
size_t len = va_arg(vl, size_t);
ret = sys_write(fildes, buf, len);
case __NR_read: {
int fd = va_arg(vl, int);
uint8_t* buf = va_arg(vl, uint8_t*);
size_t len = va_arg(vl, size_t);
ret = read_fs(per_core(current_task)->fildes_table[fd].node, buf, len, per_core(current_task)->fildes_table[fd].offset);
kprintf("%p, hmmmm...", ret);
break;
}
case __NR_write: {
int fd = va_arg(vl, int);
uint8_t* buf = va_arg(vl, uint8_t*);
size_t len = va_arg(vl, size_t);
ret = write_fs(per_core(current_task)->fildes_table[fd].node, buf, len, per_core(current_task)->fildes_table[fd].offset);
break;
}
case __NR_open: {
const char* file = va_arg(vl, const char*);
int flags = va_arg(vl, int);
int mode = va_arg(vl, int);
int fd = 0;
for (fd = 0; fd < MAX_FILDES; fd++) {
if (per_core(current_task)->fildes_table[fd].node == NULL) {
per_core(current_task)->fildes_table[fd].node = findnode_fs((char*) file);
ret = fd;
break;
}
}
if (fd >= MAX_FILDES) {
kprintf("Unable to create filedescriptor");
ret = -EINVAL;
}
break;
}
case __NR_close: {
int fd = va_arg(vl, int);
close_fs(per_core(current_task)->fildes_table[fd].node);
per_core(current_task)->fildes_table[fd].node = NULL;
per_core(current_task)->fildes_table[fd].offset = 0;
ret = 0;
break;
}
case __NR_open:
ret = 1;
break;
case __NR_close:
ret = 0;
break;
case __NR_getpid:
ret = per_core(current_task)->id;
break;

View file

@ -46,9 +46,8 @@ DEFINE_PER_CORE(task_t*, current_task, NULL);
*
* A task's id will be its position in this array.
*/
static task_t task_table[MAX_TASKS] = {[0 ... MAX_TASKS-1] = \
{0, TASK_INVALID, ATOMIC_INIT(0), \
SPINLOCK_INIT, NULL, SPINLOCK_INIT, NULL}};
static task_t task_table[MAX_TASKS] = {[0 ... MAX_TASKS-1] = {0, TASK_INVALID, ATOMIC_INIT(0), \
SPINLOCK_INIT, NULL, SPINLOCK_INIT, NULL, FS_INIT}};
static spinlock_t table_lock = SPINLOCK_INIT;
/** @brief helper function for the assembly code to determine the current task

View file

@ -104,16 +104,16 @@ int test_init(void)
{
char* argv[] = {"/bin/tests", NULL};
sem_init(&producing, 1);
sem_init(&consuming, 0);
mailbox_int32_init(&mbox);
//sem_init(&producing, 1);
//sem_init(&consuming, 0);
//mailbox_int32_init(&mbox);
create_kernel_task(NULL, foo, "Hello from foo1\n");
//create_kernel_task(NULL, foo, "Hello from foo1\n");
//create_kernel_task(NULL, join_test, NULL);
//create_kernel_task(NULL, producer, NULL);
//create_kernel_task(NULL, consumer, NULL);
//create_user_task(NULL, "/bin/hello", argv);
create_user_task(NULL, "/bin/tests", argv);
create_user_task(NULL, "/bin/hello", argv);
//create_user_task(NULL, "/bin/tests", argv);
return 0;
}

View file

@ -28,16 +28,13 @@ extern int errno;
int main(int argc, char** argv)
{
int i;
const char str[] = "Hello World!!!\n";
char* str;
FILE* testfile;
testfile = fopen("/bin/test\n", "rw\n");
str = fgets(str, 5, testfile);
for(i=0; environ[i]; i++)
printf("environ[%d] = %s\n", i, environ[i]);
for(i=0; i<argc; i++)
printf("argv[%d] = %s\n", i, argv[i]);
write(1, str, strlen(str));
printf("Hello from printf!!!\n");
printf("%s", str);
printf("Hello from printf2!!!\n");
return errno;
}

1
newlib/examples/test Normal file
View file

@ -0,0 +1 @@
HalloXA!

View file

@ -34,7 +34,7 @@ _DEFUN (_open, (file, flags, mode),
{
int ret;
ret = SYSCALL2(__NR_open, flags, mode);
ret = SYSCALL3(__NR_open, file, flags, mode);
if (ret < 0) {
errno = -ret;
ret = -1;

View file

@ -7,7 +7,7 @@ LDFLGAS =
DEFINES=
NASM = nasm
NASMFLAGS = -fbin
EXECFILES = $(shell find ../newlib/examples -perm -u+r+x -type f)
EXECFILES = $(shell find ../newlib/examples -perm -u+r+x -type f) ../newlib/examples/test
# other implicit rules
%.o : %.c