diff --git a/Makefile.example b/Makefile.example index 131b4e8d..0ac25df0 100644 --- a/Makefile.example +++ b/Makefile.example @@ -2,7 +2,7 @@ TOPDIR = $(shell pwd) ARCH = x86 NAME = metalsvm LWIPDIRS = lwip/src/arch lwip/src/api lwip/src/core lwip/src/core/ipv4 lwip/src/netif -DRIVERDIRS = drivers/net drivers/char drivers/stdin drivers/stdout drivers/stderr drivers/netchar +DRIVERDIRS = drivers/net drivers/char KERNDIRS = libkern kernel mm fs arch/$(ARCH)/kernel arch/$(ARCH)/mm arch/$(ARCH)/scc $(LWIPDIRS) $(DRIVERDIRS) SUBDIRS = $(KERNDIRS) diff --git a/drivers/char/Makefile b/drivers/char/Makefile index f76488cf..ba5e2f20 100644 --- a/drivers/char/Makefile +++ b/drivers/char/Makefile @@ -1,4 +1,4 @@ -C_source := null.c +C_source := stdio.c netio.c MODULE := drivers_char diff --git a/drivers/netchar/netchar.c b/drivers/char/netio.c similarity index 100% rename from drivers/netchar/netchar.c rename to drivers/char/netio.c diff --git a/drivers/char/null.c b/drivers/char/null.c deleted file mode 100644 index 771a8a18..00000000 --- a/drivers/char/null.c +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2010 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. - */ - -#include -#include -#include -#include -#include -#include - -/* Implementation of a simple null device */ - -static ssize_t null_read(fildes_t* file, uint8_t* buffer, size_t size) -{ - memset(buffer, 0x00, size); - - file->offset += size; - return size; -} - -static ssize_t null_write(fildes_t* file, uint8_t* buffer, size_t size) -{ - return size; -} - -static int null_open(fildes_t* file, const char* name) -{ - return 0; -} - -static int null_close(fildes_t* file) -{ - return 0; -} - -int null_init(vfs_node_t* node, const char* name) -{ - uint32_t i, j; - vfs_node_t* new_node; - dir_block_t* blockdir; - dirent_t* dirent; - block_list_t* blist; - - if (BUILTIN_EXPECT(!node || !name, 0)) - return -EINVAL; - - if (BUILTIN_EXPECT(node->type != FS_DIRECTORY, 0)) - return -EINVAL; - - if (finddir_fs(node, name)) - return -EINVAL; - - new_node = kmalloc(sizeof(vfs_node_t)); - if (BUILTIN_EXPECT(!new_node, 0)) - return -ENOMEM; - - memset(new_node, 0x00, sizeof(vfs_node_t)); - new_node->type = FS_CHARDEVICE; - new_node->open = &null_open; - new_node->close = &null_close; - new_node->read = &null_read; - new_node->write = &null_write; - spinlock_init(&new_node->lock); - - blist= &node->block_list; - do { - for(i=0; idata[i]) { - blockdir = (dir_block_t*) blist->data[i]; - for(j=0; jentries[j]; - if (!dirent->vfs_node) { - dirent->vfs_node = new_node; - strncpy(dirent->name, name, MAX_FNAME); - return 0; - } - } - } - } - - if (!blist->next) { - blist->next = (block_list_t*) kmalloc(sizeof(block_list_t)); - if (blist->next) - memset(blist->next, 0x00, sizeof(block_list_t)); - } - - } while(blist); - - kfree(new_node, sizeof(vfs_node_t)); - - return -ENOMEM; -} diff --git a/drivers/char/stdio.c b/drivers/char/stdio.c new file mode 100644 index 00000000..69fc9852 --- /dev/null +++ b/drivers/char/stdio.c @@ -0,0 +1,325 @@ +/* + * Copyright 2010 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. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/* Functions of a simple null device */ + +static ssize_t null_read(fildes_t* file, uint8_t* buffer, size_t size) +{ + memset(buffer, 0x00, size); + + file->offset += size; + return size; +} + +static ssize_t null_write(fildes_t* file, uint8_t* buffer, size_t size) +{ + return size; +} + +static int null_open(fildes_t* file, const char* name) +{ + return 0; +} + +static int null_close(fildes_t* file) +{ + return 0; +} + +/* Read Function of a stdio device */ + +static ssize_t stdio_read(fildes_t* file, uint8_t* buffer, size_t size) +{ + kb_buffer.buffer = kmalloc(size * sizeof(char)); + kb_buffer.maxsize = size; + kb_buffer.size = 0; + kb_buffer.tid = per_core(current_task)->id; + block_current_task(); + //per_core(current_task)->status = TASK_BLOCKED; + reschedule(); + + size = kb_buffer.size; + memcpy(buffer, kb_buffer.buffer, size); + + /*cleaning up */ + kb_flush(); + + //kprintf("Size: %i, offset: %i, buffer: %s", size, buffer, offset); + file->offset += size; + return size; +} + +/* Write Function of a stdio device */ + +static ssize_t stdio_write(fildes_t* file, uint8_t* buffer, size_t size) +{ + int i; + for (i = 0; ioffset += size; + return size; +} + +/* Init Functions */ + +int null_init(vfs_node_t* node, const char* name) +{ + uint32_t i, j; + vfs_node_t* new_node; + dir_block_t* blockdir; + dirent_t* dirent; + block_list_t* blist; + + if (BUILTIN_EXPECT(!node || !name, 0)) + return -EINVAL; + + if (BUILTIN_EXPECT(node->type != FS_DIRECTORY, 0)) + return -EINVAL; + + if (finddir_fs(node, name)) + return -EINVAL; + + new_node = kmalloc(sizeof(vfs_node_t)); + if (BUILTIN_EXPECT(!new_node, 0)) + return -ENOMEM; + + memset(new_node, 0x00, sizeof(vfs_node_t)); + new_node->type = FS_CHARDEVICE; + new_node->open = &null_open; + new_node->close = &null_close; + new_node->read = &null_read; + new_node->write = &null_write; + spinlock_init(&new_node->lock); + + blist= &node->block_list; + do { + for(i=0; idata[i]) { + blockdir = (dir_block_t*) blist->data[i]; + for(j=0; jentries[j]; + if (!dirent->vfs_node) { + dirent->vfs_node = new_node; + strncpy(dirent->name, name, MAX_FNAME); + return 0; + } + } + } + } + + if (!blist->next) { + blist->next = (block_list_t*) kmalloc(sizeof(block_list_t)); + if (blist->next) + memset(blist->next, 0x00, sizeof(block_list_t)); + } + + } while(blist); + + kfree(new_node, sizeof(vfs_node_t)); + + return -ENOMEM; +} + + +int stdin_init(vfs_node_t* node, const char* name) +{ + uint32_t i, j; + vfs_node_t* new_node; + dir_block_t* blockdir; + dirent_t* dirent; + block_list_t* blist; + + if (BUILTIN_EXPECT(!node || !name, 0)) + return -EINVAL; + + if (BUILTIN_EXPECT(node->type != FS_DIRECTORY, 0)) + return -EINVAL; + + if (finddir_fs(node, name)) + return -EINVAL; + + new_node = kmalloc(sizeof(vfs_node_t)); + if (BUILTIN_EXPECT(!new_node, 0)) + return -ENOMEM; + + memset(new_node, 0x00, sizeof(vfs_node_t)); + new_node->type = FS_CHARDEVICE; + new_node->open = &null_open; + new_node->close = &null_close; + new_node->read = &stdio_read; + new_node->write = &null_write; + spinlock_init(&new_node->lock); + + blist= &node->block_list; + do { + for(i=0; idata[i]) { + blockdir = (dir_block_t*) blist->data[i]; + for(j=0; jentries[j]; + if (!dirent->vfs_node) { + dirent->vfs_node = new_node; + strncpy(dirent->name, name, MAX_FNAME); + return 0; + } + } + } + } + + if (!blist->next) { + blist->next = (block_list_t*) kmalloc(sizeof(block_list_t)); + if (blist->next) + memset(blist->next, 0x00, sizeof(block_list_t)); + } + + } while(blist); + + kfree(new_node, sizeof(vfs_node_t)); + + return -ENOMEM; +} + + +int stdout_init(vfs_node_t* node, const char* name) +{ + uint32_t i, j; + vfs_node_t* new_node; + dir_block_t* blockdir; + dirent_t* dirent; + block_list_t* blist; + + if (BUILTIN_EXPECT(!node || !name, 0)) + return -EINVAL; + + if (BUILTIN_EXPECT(node->type != FS_DIRECTORY, 0)) + return -EINVAL; + + if (finddir_fs(node, name)) + return -EINVAL; + + new_node = kmalloc(sizeof(vfs_node_t)); + if (BUILTIN_EXPECT(!new_node, 0)) + return -ENOMEM; + + memset(new_node, 0x00, sizeof(vfs_node_t)); + new_node->type = FS_CHARDEVICE; + new_node->open = &null_open; + new_node->close = &null_close; + new_node->read = &null_read; + new_node->write = &stdio_write; + spinlock_init(&new_node->lock); + + blist= &node->block_list; + do { + for(i=0; idata[i]) { + blockdir = (dir_block_t*) blist->data[i]; + for(j=0; jentries[j]; + if (!dirent->vfs_node) { + dirent->vfs_node = new_node; + strncpy(dirent->name, name, MAX_FNAME); + return 0; + } + } + } + } + + if (!blist->next) { + blist->next = (block_list_t*) kmalloc(sizeof(block_list_t)); + if (blist->next) + memset(blist->next, 0x00, sizeof(block_list_t)); + } + + } while(blist); + + kfree(new_node, sizeof(vfs_node_t)); + + return -ENOMEM; +} + + +int stderr_init(vfs_node_t* node, const char* name) +{ + uint32_t i, j; + vfs_node_t* new_node; + dir_block_t* blockdir; + dirent_t* dirent; + block_list_t* blist; + + if (BUILTIN_EXPECT(!node || !name, 0)) + return -EINVAL; + + if (BUILTIN_EXPECT(node->type != FS_DIRECTORY, 0)) + return -EINVAL; + + if (finddir_fs(node, name)) + return -EINVAL; + + new_node = kmalloc(sizeof(vfs_node_t)); + if (BUILTIN_EXPECT(!new_node, 0)) + return -ENOMEM; + + memset(new_node, 0x00, sizeof(vfs_node_t)); + new_node->type = FS_CHARDEVICE; + new_node->open = &null_open; + new_node->close = &null_close; + new_node->read = &null_read; + new_node->write = &stdio_write; + spinlock_init(&new_node->lock); + + blist= &node->block_list; + do { + for(i=0; idata[i]) { + blockdir = (dir_block_t*) blist->data[i]; + for(j=0; jentries[j]; + if (!dirent->vfs_node) { + dirent->vfs_node = new_node; + strncpy(dirent->name, name, MAX_FNAME); + return 0; + } + } + } + } + + if (!blist->next) { + blist->next = (block_list_t*) kmalloc(sizeof(block_list_t)); + if (blist->next) + memset(blist->next, 0x00, sizeof(block_list_t)); + } + + } while(blist); + + kfree(new_node, sizeof(vfs_node_t)); + + return -ENOMEM; +} diff --git a/drivers/stderr/Makefile b/drivers/stderr/Makefile deleted file mode 100644 index 05d06d5c..00000000 --- a/drivers/stderr/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -C_source := stderr.c -MODULE := drivers_stderr - -include $(TOPDIR)/Makefile.inc diff --git a/drivers/stderr/stderr.c b/drivers/stderr/stderr.c deleted file mode 100644 index aab7473e..00000000 --- a/drivers/stderr/stderr.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright 2010 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. - */ - -#include -#include -#include -#include -#include -#include - -/* Implementation of a simple stderr device */ - -static ssize_t stderr_read(fildes_t* file, uint8_t* buffer, size_t size) -{ - return size; -} - -static ssize_t stderr_write(fildes_t* file, uint8_t* buffer, size_t size) -{ - kprintf("\nError: "); - int i; - for (i = 0; ioffset += size; - return size; -} - -static int stderr_open(fildes_t* file, const char* name) -{ - return 0; -} - -static int stderr_close(fildes_t* file) -{ - return 0; -} - -int stderr_init(vfs_node_t* node, const char* name) -{ - uint32_t i, j; - vfs_node_t* new_node; - dir_block_t* blockdir; - dirent_t* dirent; - block_list_t* blist; - - if (BUILTIN_EXPECT(!node || !name, 0)) - return -EINVAL; - - if (BUILTIN_EXPECT(node->type != FS_DIRECTORY, 0)) - return -EINVAL; - - if (finddir_fs(node, name)) - return -EINVAL; - - new_node = kmalloc(sizeof(vfs_node_t)); - if (BUILTIN_EXPECT(!new_node, 0)) - return -ENOMEM; - - memset(new_node, 0x00, sizeof(vfs_node_t)); - new_node->type = FS_CHARDEVICE; - new_node->open = &stderr_open; - new_node->close = &stderr_close; - new_node->read = &stderr_read; - new_node->write = &stderr_write; - spinlock_init(&new_node->lock); - - blist= &node->block_list; - do { - for(i=0; idata[i]) { - blockdir = (dir_block_t*) blist->data[i]; - for(j=0; jentries[j]; - if (!dirent->vfs_node) { - dirent->vfs_node = new_node; - strncpy(dirent->name, name, MAX_FNAME); - return 0; - } - } - } - } - - if (!blist->next) { - blist->next = (block_list_t*) kmalloc(sizeof(block_list_t)); - if (blist->next) - memset(blist->next, 0x00, sizeof(block_list_t)); - } - - } while(blist); - - kfree(new_node, sizeof(vfs_node_t)); - - return -ENOMEM; -} diff --git a/drivers/stdin/Makefile b/drivers/stdin/Makefile deleted file mode 100644 index f2429096..00000000 --- a/drivers/stdin/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -C_source := stdin.c -MODULE := drivers_stdin - -include $(TOPDIR)/Makefile.inc diff --git a/drivers/stdin/stdin.c b/drivers/stdin/stdin.c deleted file mode 100644 index 27119b6e..00000000 --- a/drivers/stdin/stdin.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright 2010 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. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - - -/* Implementation of a simple stdin device */ - -static ssize_t stdin_read(fildes_t* file, uint8_t* buffer, size_t size) -{ - kb_buffer.buffer = kmalloc(size * sizeof(char)); - kb_buffer.maxsize = size; - kb_buffer.size = 0; - kb_buffer.tid = per_core(current_task)->id; - block_current_task(); - //per_core(current_task)->status = TASK_BLOCKED; - reschedule(); - - size = kb_buffer.size; - memcpy(buffer, kb_buffer.buffer, size); - - /*cleaning up */ - kb_flush(); - - //kprintf("Size: %i, offset: %i, buffer: %s", size, buffer, offset); - file->offset += size; - return size; -} - -static ssize_t stdin_write(fildes_t* file, uint8_t* buffer, size_t size) -{ - return size; -} - -static int stdin_open(fildes_t* file, const char* name) -{ - return 0; -} - -static int stdin_close(fildes_t* file) -{ - return 0; -} - -int stdin_init(vfs_node_t* node, const char* name) -{ - uint32_t i, j; - vfs_node_t* new_node; - dir_block_t* blockdir; - dirent_t* dirent; - block_list_t* blist; - - if (BUILTIN_EXPECT(!node || !name, 0)) - return -EINVAL; - - if (BUILTIN_EXPECT(node->type != FS_DIRECTORY, 0)) - return -EINVAL; - - if (finddir_fs(node, name)) - return -EINVAL; - - new_node = kmalloc(sizeof(vfs_node_t)); - if (BUILTIN_EXPECT(!new_node, 0)) - return -ENOMEM; - - memset(new_node, 0x00, sizeof(vfs_node_t)); - new_node->type = FS_CHARDEVICE; - new_node->open = &stdin_open; - new_node->close = &stdin_close; - new_node->read = &stdin_read; - new_node->write = &stdin_write; - spinlock_init(&new_node->lock); - - blist= &node->block_list; - do { - for(i=0; idata[i]) { - blockdir = (dir_block_t*) blist->data[i]; - for(j=0; jentries[j]; - if (!dirent->vfs_node) { - dirent->vfs_node = new_node; - strncpy(dirent->name, name, MAX_FNAME); - return 0; - } - } - } - } - - if (!blist->next) { - blist->next = (block_list_t*) kmalloc(sizeof(block_list_t)); - if (blist->next) - memset(blist->next, 0x00, sizeof(block_list_t)); - } - - } while(blist); - - kfree(new_node, sizeof(vfs_node_t)); - - return -ENOMEM; -} diff --git a/drivers/stdout/Makefile b/drivers/stdout/Makefile deleted file mode 100644 index a7053f06..00000000 --- a/drivers/stdout/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -C_source := stdout.c -MODULE := drivers_stdout - -include $(TOPDIR)/Makefile.inc diff --git a/drivers/stdout/stdout.c b/drivers/stdout/stdout.c deleted file mode 100755 index 563220d3..00000000 --- a/drivers/stdout/stdout.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2010 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. - */ - -#include -#include -#include -#include -#include -#include - -/* Implementation of a simple stdout device */ - -static ssize_t stdout_read(fildes_t* file, uint8_t* buffer, size_t size) -{ - return size; -} - -static ssize_t stdout_write(fildes_t* file, uint8_t* buffer, size_t size) -{ - int i; - for (i = 0; ioffset += size; - return size; -} - -static int stdout_open(fildes_t* file, const char* name) -{ - return 0; -} - -static int stdout_close(fildes_t* file) -{ - return 0; -} - -int stdout_init(vfs_node_t* node, const char* name) -{ - uint32_t i, j; - vfs_node_t* new_node; - dir_block_t* blockdir; - dirent_t* dirent; - block_list_t* blist; - - if (BUILTIN_EXPECT(!node || !name, 0)) - return -EINVAL; - - if (BUILTIN_EXPECT(node->type != FS_DIRECTORY, 0)) - return -EINVAL; - - if (finddir_fs(node, name)) - return -EINVAL; - - new_node = kmalloc(sizeof(vfs_node_t)); - if (BUILTIN_EXPECT(!new_node, 0)) - return -ENOMEM; - - memset(new_node, 0x00, sizeof(vfs_node_t)); - new_node->type = FS_CHARDEVICE; - new_node->open = &stdout_open; - new_node->close = &stdout_close; - new_node->read = &stdout_read; - new_node->write = &stdout_write; - spinlock_init(&new_node->lock); - - blist= &node->block_list; - do { - for(i=0; idata[i]) { - blockdir = (dir_block_t*) blist->data[i]; - for(j=0; jentries[j]; - if (!dirent->vfs_node) { - dirent->vfs_node = new_node; - strncpy(dirent->name, name, MAX_FNAME); - return 0; - } - } - } - } - - if (!blist->next) { - blist->next = (block_list_t*) kmalloc(sizeof(block_list_t)); - if (blist->next) - memset(blist->next, 0x00, sizeof(block_list_t)); - } - - } while(blist); - - kfree(new_node, sizeof(vfs_node_t)); - - return -ENOMEM; -}