/kernel/trunk/generic/src/console/console.c |
---|
0,0 → 1,88 |
/* |
* Copyright (C) 2003 Josef Cejka |
* Copyright (C) 2005 Jakub Jermar |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#include <console/console.h> |
#include <console/chardev.h> |
#include <synch/waitq.h> |
#include <synch/spinlock.h> |
#include <arch/types.h> |
#include <typedefs.h> |
#include <arch.h> |
/** Standard input character device. */ |
chardev_t *stdin = NULL; |
/** Get string from character device. |
* |
* Read characters from character device until first occurrence |
* of newline character. |
* |
* @param chardev Character device. |
* @param string Buffer where to store string terminated by '\0'. |
* @param len Size of the buffer. |
*/ |
void gets(chardev_t *chardev, __u8 *string, size_t buflen) |
{ |
index_t index = 0; |
char ch; |
while (index < buflen) { |
ch = getc(chardev); |
if (ch == '\n') { /* end of string => write 0, return */ |
string[index] = '\0'; |
return; |
} |
string[index++] = ch; |
} |
return; |
} |
/** Get character from character device. |
* |
* @param chardev Character device. |
* |
* @return Character read. |
*/ |
__u8 getc(chardev_t *chardev) |
{ |
__u8 ch; |
ipl_t ipl; |
waitq_sleep(&chardev->wq); |
ipl = interrupts_disable(); |
spinlock_lock(&chardev->lock); |
ch = chardev->buffer[(chardev->index - chardev->counter) % CHARDEV_BUFLEN]; |
chardev->counter--; |
spinlock_unlock(&chardev->lock); |
interrupts_restore(ipl); |
chardev->ready_func(); |
return ch; |
} |
/kernel/trunk/generic/src/console/chardev.c |
---|
0,0 → 1,41 |
/* |
* Copyright (C) 2005 Jakub Jermar |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#include <console/chardev.h> |
#include <synch/waitq.h> |
#include <synch/spinlock.h> |
/** Initialize character device. */ |
void chardev_initialize(chardev_t *chardev, ready_func_t r) |
{ |
waitq_initialize(&chardev->wq); |
spinlock_initialize(&chardev->lock); |
chardev->counter = 0; |
chardev->index = 0; |
chardev->ready_func = r; |
} |
/kernel/trunk/generic/src/main/kinit.c |
---|
26,10 → 26,11 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#include <main/kinit.h> |
#include <main/kconsole.h> |
#include <main/uinit.h> |
#include <config.h> |
#include <arch.h> |
#include <main/kinit.h> |
#include <main/uinit.h> |
#include <proc/scheduler.h> |
#include <proc/task.h> |
#include <proc/thread.h> |
82,7 → 83,7 |
thread_ready(t); |
waitq_sleep(&kmp_completion_wq); |
} |
else panic("thread_create/kmp"); |
else panic("thread_create/kmp\n"); |
} |
#endif /* CONFIG_SMP */ |
/* |
109,12 → 110,19 |
spinlock_unlock(&t->lock); |
thread_ready(t); |
} |
else panic("thread_create/kcpulb"); |
else panic("thread_create/kcpulb\n"); |
} |
} |
#endif /* CONFIG_SMP */ |
/* |
* Create kernel console. |
*/ |
if (t = thread_create(kconsole, NULL, TASK, 0)) |
thread_ready(t); |
else panic("thread_create/kconsole\n"); |
interrupts_enable(); |
#ifdef CONFIG_USERSPACE |
123,13 → 131,13 |
*/ |
m = vm_create(NULL); |
if (!m) |
panic("vm_create"); |
panic("vm_create\n"); |
u = task_create(m); |
if (!u) |
panic("task_create"); |
panic("task_create\n"); |
t = thread_create(uinit, NULL, u, THREAD_USER_STACK); |
if (!t) |
panic("thread_create"); |
panic("thread_create\n"); |
/* |
* Create the text vm_area and copy the userspace code there. |
136,7 → 144,7 |
*/ |
a = vm_area_create(m, VMA_TEXT, 1, UTEXT_ADDRESS); |
if (!a) |
panic("vm_area_create: vm_text"); |
panic("vm_area_create: vm_text\n"); |
vm_area_map(a, m); |
memcpy((void *) PA2KA(a->mapping[0]), (void *) utext, utext_size < PAGE_SIZE ? utext_size : PAGE_SIZE); |
145,7 → 153,7 |
*/ |
a = vm_area_create(m, VMA_STACK, 1, USTACK_ADDRESS); |
if (!a) |
panic("vm_area_create: vm_stack"); |
panic("vm_area_create: vm_stack\n"); |
vm_area_map(a, m); |
thread_ready(t); |
155,7 → 163,6 |
test(); |
#endif /* CONFIG_TEST */ |
while (1) { |
thread_sleep(60); |
printf("kinit... "); |
/kernel/trunk/generic/src/main/main.c |
---|
70,7 → 70,7 |
char *rr_delimiter = ""; |
char *revision = ""; |
#endif |
char *copyright = "Copyright (C) 2001-2005 Jakub Jermar\nCopyright (C) 2005 HelenOS project"; |
char *copyright = "Copyright (C) 2001-2005 HelenOS project"; |
config_t config; |
context_t ctx; |
/kernel/trunk/generic/src/main/kconsole.c |
---|
0,0 → 1,53 |
/* |
* Copyright (C) 2005 Jakub Jermar |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#include <main/kconsole.h> |
#include <console/console.h> |
#include <console/chardev.h> |
#include <print.h> |
#include <typedefs.h> |
#include <arch/types.h> |
/** Kernel console managing thread. |
* |
* @param arg Not used. |
*/ |
void kconsole(void *arg) |
{ |
__u8 buf[CHARDEV_BUFLEN]; |
if (!stdin) { |
printf("%s: no stdin\n", __FUNCTION__); |
return; |
} |
while (true) { |
printf("%s> ", __FUNCTION__); |
gets(stdin, buf, sizeof(buf)); |
} |
} |