/branches/network/kernel/generic/src/console/console.c |
---|
39,7 → 39,6 |
#include <synch/waitq.h> |
#include <synch/spinlock.h> |
#include <arch/types.h> |
#include <ddi/device.h> |
#include <ddi/irq.h> |
#include <ddi/ddi.h> |
#include <ipc/irq.h> |
47,71 → 46,45 |
#include <func.h> |
#include <print.h> |
#include <atomic.h> |
#include <syscall/copy.h> |
#include <errno.h> |
#define KLOG_SIZE PAGE_SIZE |
#define KLOG_LATENCY 8 |
/**< Kernel log cyclic buffer */ |
/** Kernel log cyclic buffer */ |
static char klog[KLOG_SIZE] __attribute__ ((aligned (PAGE_SIZE))); |
/**< Kernel log initialized */ |
/** Kernel log initialized */ |
static bool klog_inited = false; |
/**< First kernel log characters */ |
/** First kernel log characters */ |
static index_t klog_start = 0; |
/**< Number of valid kernel log characters */ |
/** Number of valid kernel log characters */ |
static size_t klog_len = 0; |
/**< Number of stored (not printed) kernel log characters */ |
/** Number of stored (not printed) kernel log characters */ |
static size_t klog_stored = 0; |
/**< Number of stored kernel log characters for uspace */ |
/** Number of stored kernel log characters for uspace */ |
static size_t klog_uspace = 0; |
/**< Kernel log spinlock */ |
/** Silence output */ |
bool silent = false; |
/** Kernel log spinlock */ |
SPINLOCK_INITIALIZE(klog_lock); |
/** Physical memory area used for klog buffer */ |
static parea_t klog_parea; |
/* |
* For now, we use 0 as INR. |
* However, it is therefore desirable to have architecture specific |
* definition of KLOG_VIRT_INR in the future. |
*/ |
#define KLOG_VIRT_INR 0 |
static irq_t klog_irq; |
/** Standard input and output character devices */ |
indev_t *stdin = NULL; |
outdev_t *stdout = NULL; |
static chardev_operations_t null_stdout_ops = { |
.suspend = NULL, |
.resume = NULL, |
.write = NULL, |
.read = NULL |
}; |
chardev_t null_stdout = { |
.name = "null", |
.op = &null_stdout_ops |
}; |
/** Allways refuse IRQ ownership. |
* |
* This is not a real IRQ, so we always decline. |
* |
* @return Always returns IRQ_DECLINE. |
*/ |
static irq_ownership_t klog_claim(void) |
{ |
return IRQ_DECLINE; |
} |
/** Standard input character device */ |
chardev_t *stdin = NULL; |
chardev_t *stdout = &null_stdout; |
/** Initialize kernel logging facility |
* |
* The shared area contains kernel cyclic buffer. Userspace application may |
* be notified on new data with indication of position and size |
* of the data within the circular buffer. |
* |
*/ |
void klog_init(void) |
{ |
119,89 → 92,122 |
ASSERT((uintptr_t) faddr % FRAME_SIZE == 0); |
ASSERT(KLOG_SIZE % FRAME_SIZE == 0); |
devno_t devno = device_assign_devno(); |
klog_parea.pbase = (uintptr_t) faddr; |
klog_parea.vbase = (uintptr_t) klog; |
klog_parea.frames = SIZE2FRAMES(KLOG_SIZE); |
klog_parea.cacheable = true; |
ddi_parea_register(&klog_parea); |
sysinfo_set_item_val("klog.faddr", NULL, (unative_t) faddr); |
sysinfo_set_item_val("klog.pages", NULL, SIZE2FRAMES(KLOG_SIZE)); |
sysinfo_set_item_val("klog.devno", NULL, devno); |
sysinfo_set_item_val("klog.inr", NULL, KLOG_VIRT_INR); |
irq_initialize(&klog_irq); |
klog_irq.devno = devno; |
klog_irq.inr = KLOG_VIRT_INR; |
klog_irq.claim = klog_claim; |
irq_register(&klog_irq); |
//irq_initialize(&klog_irq); |
//klog_irq.devno = devno; |
//klog_irq.inr = KLOG_VIRT_INR; |
//klog_irq.claim = klog_claim; |
//irq_register(&klog_irq); |
spinlock_lock(&klog_lock); |
klog_inited = true; |
spinlock_unlock(&klog_lock); |
} |
/** Get character from character device. Do not echo character. |
void grab_console(void) |
{ |
silent = false; |
arch_grab_console(); |
} |
void release_console(void) |
{ |
silent = true; |
arch_release_console(); |
} |
/** Tell kernel to get keyboard/console access again */ |
unative_t sys_debug_enable_console(void) |
{ |
#ifdef CONFIG_KCONSOLE |
grab_console(); |
return true; |
#else |
return false; |
#endif |
} |
/** Tell kernel to relinquish keyboard/console access */ |
unative_t sys_debug_disable_console(void) |
{ |
release_console(); |
return true; |
} |
bool check_poll(indev_t *indev) |
{ |
if (indev == NULL) |
return false; |
if (indev->op == NULL) |
return false; |
return (indev->op->poll != NULL); |
} |
/** Get character from input character device. Do not echo character. |
* |
* @param chardev Character device. |
* @param indev Input character device. |
* @return Character read. |
* |
* @return Character read. |
*/ |
uint8_t _getc(chardev_t *chardev) |
uint8_t _getc(indev_t *indev) |
{ |
uint8_t ch; |
ipl_t ipl; |
if (atomic_get(&haltstate)) { |
/* If we are here, we are hopefully on the processor, that |
/* If we are here, we are hopefully on the processor that |
* issued the 'halt' command, so proceed to read the character |
* directly from input |
*/ |
if (chardev->op->read) |
return chardev->op->read(chardev); |
/* no other way of interacting with user, halt */ |
if (check_poll(indev)) |
return indev->op->poll(indev); |
/* No other way of interacting with user */ |
interrupts_disable(); |
if (CPU) |
printf("cpu%u: ", CPU->id); |
else |
printf("cpu: "); |
printf("halted - no kconsole\n"); |
printf("halted (no polling input)\n"); |
cpu_halt(); |
} |
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); |
waitq_sleep(&indev->wq); |
ipl_t ipl = interrupts_disable(); |
spinlock_lock(&indev->lock); |
uint8_t ch = indev->buffer[(indev->index - indev->counter) % INDEV_BUFLEN]; |
indev->counter--; |
spinlock_unlock(&indev->lock); |
interrupts_restore(ipl); |
chardev->op->resume(chardev); |
return ch; |
} |
/** Get string from character device. |
/** Get string from input character device. |
* |
* Read characters from character device until first occurrence |
* Read characters from input character device until first occurrence |
* of newline character. |
* |
* @param chardev Character device. |
* @param buf Buffer where to store string terminated by '\0'. |
* @param indev Input character device. |
* @param buf Buffer where to store string terminated by '\0'. |
* @param buflen Size of the buffer. |
* |
* @return Number of characters read. |
* |
*/ |
count_t gets(chardev_t *chardev, char *buf, size_t buflen) |
count_t gets(indev_t *indev, char *buf, size_t buflen) |
{ |
index_t index = 0; |
char ch; |
while (index < buflen) { |
ch = _getc(chardev); |
char ch = _getc(indev); |
if (ch == '\b') { |
if (index > 0) { |
index--; |
213,7 → 219,7 |
continue; |
} |
putchar(ch); |
if (ch == '\n') { /* end of string => write 0, return */ |
buf[index] = '\0'; |
return (count_t) index; |
220,15 → 226,14 |
} |
buf[index++] = ch; |
} |
return (count_t) index; |
} |
/** Get character from device & echo it to screen */ |
uint8_t getc(chardev_t *chardev) |
/** Get character from input device & echo it to screen */ |
uint8_t getc(indev_t *indev) |
{ |
uint8_t ch; |
ch = _getc(chardev); |
uint8_t ch = _getc(indev); |
putchar(ch); |
return ch; |
} |
237,10 → 242,10 |
{ |
spinlock_lock(&klog_lock); |
if ((klog_inited) && (klog_irq.notif_cfg.notify) && (klog_uspace > 0)) { |
ipc_irq_send_msg_3(&klog_irq, klog_start, klog_len, klog_uspace); |
klog_uspace = 0; |
} |
// if ((klog_inited) && (klog_irq.notif_cfg.notify) && (klog_uspace > 0)) { |
// ipc_irq_send_msg_3(&klog_irq, klog_start, klog_len, klog_uspace); |
// klog_uspace = 0; |
// } |
spinlock_unlock(&klog_lock); |
} |
249,11 → 254,11 |
{ |
spinlock_lock(&klog_lock); |
if ((klog_stored > 0) && (stdout->op->write)) { |
if ((klog_stored > 0) && (stdout) && (stdout->op->write)) { |
/* Print charaters stored in kernel log */ |
index_t i; |
for (i = klog_len - klog_stored; i < klog_len; i++) |
stdout->op->write(stdout, klog[(klog_start + i) % KLOG_SIZE]); |
stdout->op->write(stdout, klog[(klog_start + i) % KLOG_SIZE], silent); |
klog_stored = 0; |
} |
264,8 → 269,8 |
else |
klog_start = (klog_start + 1) % KLOG_SIZE; |
if (stdout->op->write) |
stdout->op->write(stdout, c); |
if ((stdout) && (stdout->op->write)) |
stdout->op->write(stdout, c, silent); |
else { |
/* The character is just in the kernel log */ |
if (klog_stored < klog_len) |
289,5 → 294,38 |
klog_update(); |
} |
/** Print using kernel facility |
* |
* Print to kernel log. |
* |
*/ |
unative_t sys_klog(int fd, const void * buf, size_t count) |
{ |
char *data; |
int rc; |
if (count > PAGE_SIZE) |
return ELIMIT; |
if (count > 0) { |
data = (char *) malloc(count + 1, 0); |
if (!data) |
return ENOMEM; |
rc = copy_from_uspace(data, buf, count); |
if (rc) { |
free(data); |
return rc; |
} |
data[count] = 0; |
printf("%s", data); |
free(data); |
} else |
klog_update(); |
return count; |
} |
/** @} |
*/ |
/branches/network/kernel/generic/src/console/cmd.c |
---|
50,9 → 50,9 |
#include <arch.h> |
#include <config.h> |
#include <func.h> |
#include <string.h> |
#include <macros.h> |
#include <debug.h> |
#include <symtab.h> |
#include <cpu.h> |
#include <mm/tlb.h> |
#include <arch/mm/tlb.h> |
64,6 → 64,8 |
#include <proc/task.h> |
#include <ipc/ipc.h> |
#include <ipc/irq.h> |
#include <symtab.h> |
#include <errno.h> |
#ifdef CONFIG_TEST |
#include <test.h> |
78,12 → 80,6 |
.argc = 0 |
}; |
static cmd_info_t exit_info = { |
.name = "exit", |
.description = "Exit kconsole.", |
.argc = 0 |
}; |
static int cmd_reboot(cmd_arg_t *argv); |
static cmd_info_t reboot_info = { |
.name = "reboot", |
398,17 → 394,17 |
.argc = 0 |
}; |
/* Data and methods for 'ipc_task' command */ |
static int cmd_ipc_task(cmd_arg_t *argv); |
static cmd_arg_t ipc_task_argv = { |
/* Data and methods for 'ipc' command */ |
static int cmd_ipc(cmd_arg_t *argv); |
static cmd_arg_t ipc_argv = { |
.type = ARG_TYPE_INT, |
}; |
static cmd_info_t ipc_task_info = { |
.name = "ipc_task", |
.description = "ipc_task <taskid> Show IPC information of given task.", |
.func = cmd_ipc_task, |
static cmd_info_t ipc_info = { |
.name = "ipc", |
.description = "ipc <taskid> Show IPC information of given task.", |
.func = cmd_ipc, |
.argc = 1, |
.argv = &ipc_task_argv |
.argv = &ipc_argv |
}; |
/* Data and methods for 'zone' command */ |
456,12 → 452,11 |
&continue_info, |
&cpus_info, |
&desc_info, |
&exit_info, |
&reboot_info, |
&uptime_info, |
&halt_info, |
&help_info, |
&ipc_task_info, |
&ipc_info, |
&set4_info, |
&slabs_info, |
&symaddr_info, |
501,7 → 496,7 |
for (i = 0; basic_commands[i]; i++) { |
cmd_initialize(basic_commands[i]); |
if (!cmd_register(basic_commands[i])) |
panic("could not register command %s\n", basic_commands[i]->name); |
printf("Cannot register command %s\n", basic_commands[i]->name); |
} |
} |
514,23 → 509,31 |
*/ |
int cmd_help(cmd_arg_t *argv) |
{ |
link_t *cur; |
spinlock_lock(&cmd_lock); |
link_t *cur; |
size_t len = 0; |
for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) { |
cmd_info_t *hlp; |
hlp = list_get_instance(cur, cmd_info_t, link); |
spinlock_lock(&hlp->lock); |
if (strlen(hlp->name) > len) |
len = strlen(hlp->name); |
spinlock_unlock(&hlp->lock); |
} |
for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) { |
cmd_info_t *hlp; |
hlp = list_get_instance(cur, cmd_info_t, link); |
spinlock_lock(&hlp->lock); |
printf("%s - %s\n", hlp->name, hlp->description); |
printf("%-*s %s\n", len, hlp->name, hlp->description); |
spinlock_unlock(&hlp->lock); |
} |
spinlock_unlock(&cmd_lock); |
spinlock_unlock(&cmd_lock); |
return 1; |
} |
616,33 → 619,26 |
{ |
uintptr_t symaddr; |
char *symbol; |
unative_t (*f)(void); |
#ifdef ia64 |
struct { |
unative_t f; |
unative_t gp; |
} fptr; |
#endif |
unative_t (*fnc)(void); |
fncptr_t fptr; |
int rc; |
symaddr = get_symbol_addr((char *) argv->buffer); |
if (!symaddr) |
printf("Symbol %s not found.\n", argv->buffer); |
else if (symaddr == (uintptr_t) -1) { |
symtab_print_search((char *) argv->buffer); |
symbol = (char *) argv->buffer; |
rc = symtab_addr_lookup(symbol, &symaddr); |
if (rc == ENOENT) |
printf("Symbol %s not found.\n", symbol); |
else if (rc == EOVERFLOW) { |
symtab_print_search(symbol); |
printf("Duplicate symbol, be more specific.\n"); |
} else if (rc == EOK) { |
fnc = (unative_t (*)(void)) arch_construct_function(&fptr, |
(void *) symaddr, (void *) cmd_call0); |
printf("Calling %s() (%p)\n", symbol, symaddr); |
printf("Result: %#" PRIxn "\n", fnc()); |
} else { |
symbol = get_symtab_entry(symaddr); |
printf("Calling %s() (%p)\n", symbol, symaddr); |
#ifdef ia64 |
fptr.f = symaddr; |
fptr.gp = ((unative_t *)cmd_call2)[1]; |
f = (unative_t (*)(void)) &fptr; |
#else |
f = (unative_t (*)(void)) symaddr; |
#endif |
printf("Result: %#" PRIxn "\n", f()); |
printf("No symbol information available.\n"); |
} |
return 1; |
} |
680,35 → 676,27 |
{ |
uintptr_t symaddr; |
char *symbol; |
unative_t (*f)(unative_t,...); |
unative_t (*fnc)(unative_t, ...); |
unative_t arg1 = argv[1].intval; |
#ifdef ia64 |
struct { |
unative_t f; |
unative_t gp; |
} fptr; |
#endif |
fncptr_t fptr; |
int rc; |
symaddr = get_symbol_addr((char *) argv->buffer); |
if (!symaddr) |
printf("Symbol %s not found.\n", argv->buffer); |
else if (symaddr == (uintptr_t) -1) { |
symtab_print_search((char *) argv->buffer); |
symbol = (char *) argv->buffer; |
rc = symtab_addr_lookup(symbol, &symaddr); |
if (rc == ENOENT) { |
printf("Symbol %s not found.\n", symbol); |
} else if (rc == EOVERFLOW) { |
symtab_print_search(symbol); |
printf("Duplicate symbol, be more specific.\n"); |
} else if (rc == EOK) { |
fnc = (unative_t (*)(unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call1); |
printf("Calling f(%#" PRIxn "): %p: %s\n", arg1, symaddr, symbol); |
printf("Result: %#" PRIxn "\n", fnc(arg1)); |
} else { |
symbol = get_symtab_entry(symaddr); |
printf("No symbol information available.\n"); |
} |
printf("Calling f(%#" PRIxn "): %p: %s\n", arg1, symaddr, symbol); |
#ifdef ia64 |
fptr.f = symaddr; |
fptr.gp = ((unative_t *)cmd_call2)[1]; |
f = (unative_t (*)(unative_t,...)) &fptr; |
#else |
f = (unative_t (*)(unative_t,...)) symaddr; |
#endif |
printf("Result: %#" PRIxn "\n", f(arg1)); |
} |
return 1; |
} |
717,36 → 705,28 |
{ |
uintptr_t symaddr; |
char *symbol; |
unative_t (*f)(unative_t,unative_t,...); |
unative_t (*fnc)(unative_t, unative_t, ...); |
unative_t arg1 = argv[1].intval; |
unative_t arg2 = argv[2].intval; |
#ifdef ia64 |
struct { |
unative_t f; |
unative_t gp; |
}fptr; |
#endif |
fncptr_t fptr; |
int rc; |
symaddr = get_symbol_addr((char *) argv->buffer); |
if (!symaddr) |
printf("Symbol %s not found.\n", argv->buffer); |
else if (symaddr == (uintptr_t) -1) { |
symtab_print_search((char *) argv->buffer); |
symbol = (char *) argv->buffer; |
rc = symtab_addr_lookup(symbol, &symaddr); |
if (rc == ENOENT) { |
printf("Symbol %s not found.\n", symbol); |
} else if (rc == EOVERFLOW) { |
symtab_print_search(symbol); |
printf("Duplicate symbol, be more specific.\n"); |
} else { |
symbol = get_symtab_entry(symaddr); |
} else if (rc == EOK) { |
fnc = (unative_t (*)(unative_t, unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call2); |
printf("Calling f(%#" PRIxn ", %#" PRIxn "): %p: %s\n", |
arg1, arg2, symaddr, symbol); |
#ifdef ia64 |
fptr.f = symaddr; |
fptr.gp = ((unative_t *)cmd_call2)[1]; |
f = (unative_t (*)(unative_t,unative_t,...)) &fptr; |
#else |
f = (unative_t (*)(unative_t,unative_t,...)) symaddr; |
#endif |
printf("Result: %#" PRIxn "\n", f(arg1, arg2)); |
printf("Result: %#" PRIxn "\n", fnc(arg1, arg2)); |
} else { |
printf("No symbol information available.\n"); |
} |
return 1; |
} |
755,37 → 735,29 |
{ |
uintptr_t symaddr; |
char *symbol; |
unative_t (*f)(unative_t,unative_t,unative_t,...); |
unative_t (*fnc)(unative_t, unative_t, unative_t, ...); |
unative_t arg1 = argv[1].intval; |
unative_t arg2 = argv[2].intval; |
unative_t arg3 = argv[3].intval; |
#ifdef ia64 |
struct { |
unative_t f; |
unative_t gp; |
}fptr; |
#endif |
fncptr_t fptr; |
int rc; |
symbol = (char *) argv->buffer; |
rc = symtab_addr_lookup(symbol, &symaddr); |
symaddr = get_symbol_addr((char *) argv->buffer); |
if (!symaddr) |
printf("Symbol %s not found.\n", argv->buffer); |
else if (symaddr == (uintptr_t) -1) { |
symtab_print_search((char *) argv->buffer); |
if (rc == ENOENT) { |
printf("Symbol %s not found.\n", symbol); |
} else if (rc == EOVERFLOW) { |
symtab_print_search(symbol); |
printf("Duplicate symbol, be more specific.\n"); |
} else { |
symbol = get_symtab_entry(symaddr); |
} else if (rc == EOK) { |
fnc = (unative_t (*)(unative_t, unative_t, unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call3); |
printf("Calling f(%#" PRIxn ",%#" PRIxn ", %#" PRIxn "): %p: %s\n", |
arg1, arg2, arg3, symaddr, symbol); |
#ifdef ia64 |
fptr.f = symaddr; |
fptr.gp = ((unative_t *)cmd_call2)[1]; |
f = (unative_t (*)(unative_t,unative_t,unative_t,...)) &fptr; |
#else |
f = (unative_t (*)(unative_t,unative_t,unative_t,...)) symaddr; |
#endif |
printf("Result: %#" PRIxn "\n", f(arg1, arg2, arg3)); |
printf("Result: %#" PRIxn "\n", fnc(arg1, arg2, arg3)); |
} else { |
printf("No symbol information available.\n"); |
} |
return 1; |
} |
835,30 → 807,34 |
/** Write 4 byte value to address */ |
int cmd_set4(cmd_arg_t *argv) |
{ |
uint32_t *addr; |
uintptr_t addr; |
uint32_t arg1 = argv[1].intval; |
bool pointer = false; |
int rc; |
if (((char *)argv->buffer)[0] == '*') { |
addr = (uint32_t *) get_symbol_addr((char *) argv->buffer + 1); |
rc = symtab_addr_lookup((char *) argv->buffer + 1, &addr); |
pointer = true; |
} else if (((char *) argv->buffer)[0] >= '0' && |
((char *)argv->buffer)[0] <= '9') |
addr = (uint32_t *)atoi((char *)argv->buffer); |
else |
addr = (uint32_t *)get_symbol_addr((char *) argv->buffer); |
((char *)argv->buffer)[0] <= '9') { |
rc = EOK; |
addr = atoi((char *)argv->buffer); |
} else { |
rc = symtab_addr_lookup((char *) argv->buffer, &addr); |
} |
if (!addr) |
if (rc == ENOENT) |
printf("Symbol %s not found.\n", argv->buffer); |
else if (addr == (uint32_t *) -1) { |
else if (rc == EOVERFLOW) { |
symtab_print_search((char *) argv->buffer); |
printf("Duplicate symbol, be more specific.\n"); |
} else { |
} else if (rc == EOK) { |
if (pointer) |
addr = (uint32_t *)(*(unative_t *)addr); |
addr = *(uintptr_t *) addr; |
printf("Writing %#" PRIx64 " -> %p\n", arg1, addr); |
*addr = arg1; |
*(uint32_t *) addr = arg1; |
} else { |
printf("No symbol information available.\n"); |
} |
return 1; |
937,7 → 913,7 |
* |
* return Always 1 |
*/ |
int cmd_ipc_task(cmd_arg_t * argv) { |
int cmd_ipc(cmd_arg_t * argv) { |
ipc_print_task(argv[0].intval); |
return 1; |
} |
976,8 → 952,11 |
int cmd_continue(cmd_arg_t *argv) |
{ |
printf("The kernel will now relinquish the console.\n"); |
printf("Use userspace controls to redraw the screen.\n"); |
arch_release_console(); |
release_console(); |
if ((kconsole_notify) && (kconsole_irq.notif_cfg.notify)) |
ipc_irq_send_msg_0(&kconsole_irq); |
return 1; |
} |
990,18 → 969,23 |
*/ |
int cmd_tests(cmd_arg_t *argv) |
{ |
size_t len = 0; |
test_t *test; |
for (test = tests; test->name != NULL; test++) { |
if (strlen(test->name) > len) |
len = strlen(test->name); |
} |
for (test = tests; test->name != NULL; test++) |
printf("%s\t\t%s%s\n", test->name, test->desc, (test->safe ? "" : " (unsafe)")); |
printf("%-*s %s%s\n", len, test->name, test->desc, (test->safe ? "" : " (unsafe)")); |
printf("*\t\tRun all safe tests\n"); |
printf("%-*s Run all safe tests\n", len, "*"); |
return 1; |
} |
static bool run_test(const test_t *test) |
{ |
printf("%s\t\t%s\n", test->name, test->desc); |
printf("%s (%s)\n", test->name, test->desc); |
/* Update and read thread accounting |
for benchmarking */ |
/branches/network/kernel/generic/src/console/chardev.c |
---|
37,42 → 37,62 |
#include <synch/waitq.h> |
#include <synch/spinlock.h> |
/** Initialize character device. |
/** Initialize input character device. |
* |
* @param chardev Character device. |
* @param op Implementation of character device operations. |
* @param indev Input character device. |
* @param op Implementation of input character device operations. |
* |
*/ |
void chardev_initialize(char *name, chardev_t *chardev, |
chardev_operations_t *op) |
void indev_initialize(char *name, indev_t *indev, |
indev_operations_t *op) |
{ |
chardev->name = name; |
waitq_initialize(&chardev->wq); |
spinlock_initialize(&chardev->lock, "chardev"); |
chardev->counter = 0; |
chardev->index = 0; |
chardev->op = op; |
indev->name = name; |
waitq_initialize(&indev->wq); |
spinlock_initialize(&indev->lock, "indev"); |
indev->counter = 0; |
indev->index = 0; |
indev->op = op; |
} |
/** Push character read from input character device. |
* |
* @param chardev Character device. |
* @param ch Character being pushed. |
* @param indev Input character device. |
* @param ch Character being pushed. |
* |
*/ |
void chardev_push_character(chardev_t *chardev, uint8_t ch) |
void indev_push_character(indev_t *indev, uint8_t ch) |
{ |
spinlock_lock(&chardev->lock); |
chardev->counter++; |
if (chardev->counter == CHARDEV_BUFLEN - 1) { |
/* buffer full => disable device interrupt */ |
chardev->op->suspend(chardev); |
ASSERT(indev); |
spinlock_lock(&indev->lock); |
if (indev->counter == INDEV_BUFLEN - 1) { |
/* Buffer full */ |
spinlock_unlock(&indev->lock); |
return; |
} |
chardev->buffer[chardev->index++] = ch; |
chardev->index = chardev->index % CHARDEV_BUFLEN; /* index modulo size of buffer */ |
waitq_wakeup(&chardev->wq, WAKEUP_FIRST); |
spinlock_unlock(&chardev->lock); |
indev->counter++; |
indev->buffer[indev->index++] = ch; |
/* Index modulo size of buffer */ |
indev->index = indev->index % INDEV_BUFLEN; |
waitq_wakeup(&indev->wq, WAKEUP_FIRST); |
spinlock_unlock(&indev->lock); |
} |
/** Initialize output character device. |
* |
* @param outdev Output character device. |
* @param op Implementation of output character device operations. |
* |
*/ |
void outdev_initialize(char *name, outdev_t *outdev, |
outdev_operations_t *op) |
{ |
outdev->name = name; |
spinlock_initialize(&outdev->lock, "outdev"); |
outdev->op = op; |
} |
/** @} |
*/ |
/branches/network/kernel/generic/src/console/kconsole.c |
---|
49,8 → 49,12 |
#include <macros.h> |
#include <debug.h> |
#include <func.h> |
#include <string.h> |
#include <macros.h> |
#include <sysinfo/sysinfo.h> |
#include <ddi/device.h> |
#include <symtab.h> |
#include <macros.h> |
#include <errno.h> |
/** Simple kernel console. |
* |
83,10 → 87,39 |
index_t *end); |
static char history[KCONSOLE_HISTORY][MAX_CMDLINE] = {}; |
/** Initialize kconsole data structures. */ |
/* |
* For now, we use 0 as INR. |
* However, it is therefore desirable to have architecture specific |
* definition of KCONSOLE_VIRT_INR in the future. |
*/ |
#define KCONSOLE_VIRT_INR 0 |
bool kconsole_notify = false; |
irq_t kconsole_irq; |
/** Allways refuse IRQ ownership. |
* |
* This is not a real IRQ, so we always decline. |
* |
* @return Always returns IRQ_DECLINE. |
* |
*/ |
static irq_ownership_t kconsole_claim(irq_t *irq) |
{ |
return IRQ_DECLINE; |
} |
/** Initialize kconsole data structures |
* |
* This is the most basic initialization, almost no |
* other kernel subsystem is ready yet. |
* |
*/ |
void kconsole_init(void) |
{ |
int i; |
unsigned int i; |
cmd_init(); |
for (i = 0; i < KCONSOLE_HISTORY; i++) |
94,6 → 127,26 |
} |
/** Initialize kconsole notification mechanism |
* |
* Initialize the virtual IRQ notification mechanism. |
* |
*/ |
void kconsole_notify_init(void) |
{ |
sysinfo_set_item_val("kconsole.present", NULL, true); |
sysinfo_set_item_val("kconsole.inr", NULL, KCONSOLE_VIRT_INR); |
irq_initialize(&kconsole_irq); |
kconsole_irq.devno = device_assign_devno(); |
kconsole_irq.inr = KCONSOLE_VIRT_INR; |
kconsole_irq.claim = kconsole_claim; |
irq_register(&kconsole_irq); |
kconsole_notify = true; |
} |
/** Register kconsole command. |
* |
* @param cmd Structure describing the command. |
203,7 → 256,7 |
*/ |
static int cmdtab_compl(char *name) |
{ |
static char output[MAX_SYMBOL_NAME + 1]; |
static char output[/*MAX_SYMBOL_NAME*/128 + 1]; |
link_t *startpos = NULL; |
const char *foundtxt; |
int found = 0; |
235,12 → 288,11 |
startpos = startpos->next; |
} |
} |
strncpy(name, output, MAX_SYMBOL_NAME); |
strncpy(name, output, 128/*MAX_SYMBOL_NAME*/); |
return found; |
} |
static char *clever_readline(const char *prompt, chardev_t *input) |
static char *clever_readline(const char *prompt, indev_t *input) |
{ |
static int histposition = 0; |
401,42 → 453,71 |
return current; |
} |
/** Kernel console managing thread. |
bool kconsole_check_poll(void) |
{ |
return check_poll(stdin); |
} |
/** Kernel console prompt. |
* |
* @param prompt Kernel console prompt (e.g kconsole/panic). |
* @param msg Message to display in the beginning. |
* @param kcon Wait for keypress to show the prompt |
* and never exit. |
* |
*/ |
void kconsole(void *prompt) |
void kconsole(char *prompt, char *msg, bool kcon) |
{ |
cmd_info_t *cmd_info; |
count_t len; |
char *cmdline; |
if (!stdin) { |
printf("%s: no stdin\n", __func__); |
LOG("No stdin for kernel console"); |
return; |
} |
if (msg) |
printf("%s", msg); |
if (kcon) |
_getc(stdin); |
else |
printf("Type \"exit\" to leave the console.\n"); |
while (true) { |
cmdline = clever_readline((char *) prompt, stdin); |
len = strlen(cmdline); |
if (!len) |
continue; |
if ((!kcon) && (len == 4) && (strncmp(cmdline, "exit", 4) == 0)) |
break; |
cmd_info = parse_cmdline(cmdline, len); |
if (!cmd_info) |
continue; |
if (strncmp(cmd_info->name, "exit", |
min(strlen(cmd_info->name), 5)) == 0) |
break; |
(void) cmd_info->func(cmd_info->argv); |
} |
} |
/** Kernel console managing thread. |
* |
*/ |
void kconsole_thread(void *data) |
{ |
kconsole("kconsole", "Kernel console ready (press any key to activate)\n", true); |
} |
static int parse_int_arg(char *text, size_t len, unative_t *result) |
{ |
static char symname[MAX_SYMBOL_NAME]; |
uintptr_t symaddr; |
bool isaddr = false; |
bool isptr = false; |
int rc; |
static char symname[MAX_SYMBOL_NAME]; |
/* If we get a name, try to find it in symbol table */ |
if (text[0] == '&') { |
450,16 → 531,20 |
} |
if (text[0] < '0' || text[0] > '9') { |
strncpy(symname, text, min(len + 1, MAX_SYMBOL_NAME)); |
symaddr = get_symbol_addr(symname); |
if (!symaddr) { |
rc = symtab_addr_lookup(symname, &symaddr); |
switch (rc) { |
case ENOENT: |
printf("Symbol %s not found.\n", symname); |
return -1; |
} |
if (symaddr == (uintptr_t) -1) { |
case EOVERFLOW: |
printf("Duplicate symbol %s.\n", symname); |
symtab_print_search(symname); |
return -1; |
default: |
printf("No symbol information available.\n"); |
return -1; |
} |
if (isaddr) |
*result = (unative_t)symaddr; |
else if (isptr) |