Changeset 46c20c8 in mainline for kernel/generic/src/console


Ignore:
Timestamp:
2010-11-26T20:08:10Z (15 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
45df59a
Parents:
fb150d78 (diff), ffdd2b9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

Location:
kernel/generic/src/console
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/console/chardev.c

    rfb150d78 r46c20c8  
    4747 *
    4848 */
    49 void indev_initialize(char *name, indev_t *indev,
     49void indev_initialize(const char *name, indev_t *indev,
    5050    indev_operations_t *op)
    5151{
    5252        indev->name = name;
    5353        waitq_initialize(&indev->wq);
    54         spinlock_initialize(&indev->lock, "indev");
     54        irq_spinlock_initialize(&indev->lock, "chardev.indev.lock");
    5555        indev->counter = 0;
    5656        indev->index = 0;
     
    6868        ASSERT(indev);
    6969       
    70         spinlock_lock(&indev->lock);
     70        irq_spinlock_lock(&indev->lock, true);
    7171        if (indev->counter == INDEV_BUFLEN - 1) {
    7272                /* Buffer full */
    73                 spinlock_unlock(&indev->lock);
     73                irq_spinlock_unlock(&indev->lock, true);
    7474                return;
    7575        }
     
    8181        indev->index = indev->index % INDEV_BUFLEN;
    8282        waitq_wakeup(&indev->wq, WAKEUP_FIRST);
    83         spinlock_unlock(&indev->lock);
     83        irq_spinlock_unlock(&indev->lock, true);
    8484}
    8585
     
    114114       
    115115        waitq_sleep(&indev->wq);
    116         ipl_t ipl = interrupts_disable();
    117         spinlock_lock(&indev->lock);
     116        irq_spinlock_lock(&indev->lock, true);
    118117        wchar_t ch = indev->buffer[(indev->index - indev->counter) % INDEV_BUFLEN];
    119118        indev->counter--;
    120         spinlock_unlock(&indev->lock);
    121         interrupts_restore(ipl);
     119        irq_spinlock_unlock(&indev->lock, true);
    122120       
    123121        return ch;
     
    130128 *
    131129 */
    132 void outdev_initialize(char *name, outdev_t *outdev,
     130void outdev_initialize(const char *name, outdev_t *outdev,
    133131    outdev_operations_t *op)
    134132{
    135133        outdev->name = name;
    136         spinlock_initialize(&outdev->lock, "outdev");
     134        spinlock_initialize(&outdev->lock, "chardev.outdev.lock");
    137135        link_initialize(&outdev->link);
    138136        list_initialize(&outdev->list);
  • kernel/generic/src/console/cmd.c

    rfb150d78 r46c20c8  
    4646#include <print.h>
    4747#include <panic.h>
    48 #include <arch/types.h>
     48#include <typedefs.h>
    4949#include <adt/list.h>
    5050#include <arch.h>
    5151#include <config.h>
    5252#include <func.h>
    53 #include <string.h>
     53#include <str.h>
    5454#include <macros.h>
    5555#include <debug.h>
     
    6666#include <ipc/irq.h>
    6767#include <ipc/event.h>
     68#include <sysinfo/sysinfo.h>
    6869#include <symtab.h>
    6970#include <errno.h>
     
    107108
    108109#ifdef CONFIG_TEST
    109 static int cmd_tests(cmd_arg_t *argv);
    110 static cmd_info_t tests_info = {
    111         .name = "tests",
    112         .description = "Print available kernel tests.",
    113         .func = cmd_tests,
    114         .argc = 0
    115 };
    116 
    117110static char test_buf[MAX_CMDLINE + 1];
    118111static int cmd_test(cmd_arg_t *argv);
    119112static cmd_arg_t test_argv[] = {
    120113        {
    121                 .type = ARG_TYPE_STRING,
     114                .type = ARG_TYPE_STRING_OPTIONAL,
    122115                .buffer = test_buf,
    123116                .len = sizeof(test_buf)
     
    126119static cmd_info_t test_info = {
    127120        .name = "test",
    128         .description = "Run kernel test.",
     121        .description = "Print list of kernel tests or run a test.",
    129122        .func = cmd_test,
    130123        .argc = 1,
     
    206199};
    207200
    208 /* Data and methods for 'call0' command. */
     201/* Data and methods for 'call0' and 'mcall0' command. */
    209202static char call0_buf[MAX_CMDLINE + 1];
    210203static char carg1_buf[MAX_CMDLINE + 1];
     
    354347};
    355348
     349static char flag_buf[MAX_CMDLINE + 1];
     350
    356351static int cmd_threads(cmd_arg_t *argv);
     352static cmd_arg_t threads_argv = {
     353        .type = ARG_TYPE_STRING_OPTIONAL,
     354        .buffer = flag_buf,
     355        .len = sizeof(flag_buf)
     356};
    357357static cmd_info_t threads_info = {
    358358        .name = "threads",
    359         .description = "List all threads.",
     359        .description = "List all threads (use -a for additional information).",
    360360        .func = cmd_threads,
    361         .argc = 0
     361        .argc = 1,
     362        .argv = &threads_argv
    362363};
    363364
    364365static int cmd_tasks(cmd_arg_t *argv);
     366static cmd_arg_t tasks_argv = {
     367        .type = ARG_TYPE_STRING_OPTIONAL,
     368        .buffer = flag_buf,
     369        .len = sizeof(flag_buf)
     370};
    365371static cmd_info_t tasks_info = {
    366372        .name = "tasks",
    367         .description = "List all tasks.",
     373        .description = "List all tasks (use -a for additional information).",
    368374        .func = cmd_tasks,
    369         .argc = 0
     375        .argc = 1,
     376        .argv = &tasks_argv
    370377};
    371378
     
    384391        .description = "List slab caches.",
    385392        .func = cmd_slabs,
     393        .argc = 0
     394};
     395
     396static int cmd_sysinfo(cmd_arg_t *argv);
     397static cmd_info_t sysinfo_info = {
     398        .name = "sysinfo",
     399        .description = "Dump sysinfo.",
     400        .func = cmd_sysinfo,
    386401        .argc = 0
    387402};
     
    475490        &set4_info,
    476491        &slabs_info,
     492        &sysinfo_info,
    477493        &symaddr_info,
    478494        &sched_info,
     
    485501        &zone_info,
    486502#ifdef CONFIG_TEST
    487         &tests_info,
    488503        &test_info,
    489504        &bench_info,
     
    500515void cmd_initialize(cmd_info_t *cmd)
    501516{
    502         spinlock_initialize(&cmd->lock, "cmd");
     517        spinlock_initialize(&cmd->lock, "cmd.lock");
    503518        link_initialize(&cmd->link);
    504519}
     
    539554        }
    540555       
     556        unsigned int _len = (unsigned int) len;
     557        if ((_len != len) || (((int) _len) < 0)) {
     558                printf("Command length overflow\n");
     559                return 1;
     560        }
     561       
    541562        for (cur = cmd_head.next; cur != &cmd_head; cur = cur->next) {
    542563                cmd_info_t *hlp;
     
    544565               
    545566                spinlock_lock(&hlp->lock);
    546                 printf("%-*s %s\n", len, hlp->name, hlp->description);
     567                printf("%-*s %s\n", _len, hlp->name, hlp->description);
    547568                spinlock_unlock(&hlp->lock);
    548569        }
     
    648669                printf("Duplicate symbol, be more specific.\n");
    649670        } else if (rc == EOK) {
     671                ipl_t ipl;
     672
     673                ipl = interrupts_disable();
    650674                fnc = (unative_t (*)(void)) arch_construct_function(&fptr,
    651675                    (void *) symaddr, (void *) cmd_call0);
    652                 printf("Calling %s() (%p)\n", symbol, symaddr);
     676                printf("Calling %s() (%p)\n", symbol, (void *) symaddr);
    653677                printf("Result: %#" PRIxn "\n", fnc());
     678                interrupts_restore(ipl);
    654679        } else {
    655680                printf("No symbol information available.\n");
     
    666691         */
    667692       
    668         size_t i;
     693        unsigned int i;
    669694        for (i = 0; i < config.cpu_count; i++) {
    670695                if (!cpus[i].active)
    671696                        continue;
    672697               
    673                 thread_t *t;
    674                 if ((t = thread_create((void (*)(void *)) cmd_call0, (void *) argv, TASK, THREAD_FLAG_WIRED, "call0", false))) {
    675                         spinlock_lock(&t->lock);
    676                         t->cpu = &cpus[i];
    677                         spinlock_unlock(&t->lock);
     698                thread_t *thread;
     699                if ((thread = thread_create((void (*)(void *)) cmd_call0,
     700                    (void *) argv, TASK, THREAD_FLAG_WIRED, "call0", false))) {
     701                        irq_spinlock_lock(&thread->lock, true);
     702                        thread->cpu = &cpus[i];
     703                        irq_spinlock_unlock(&thread->lock, true);
     704                       
    678705                        printf("cpu%u: ", i);
    679                         thread_ready(t);
    680                         thread_join(t);
    681                         thread_detach(t);
     706                       
     707                        thread_ready(thread);
     708                        thread_join(thread);
     709                        thread_detach(thread);
    682710                } else
    683711                        printf("Unable to create thread for cpu%u\n", i);
     
    706734                printf("Duplicate symbol, be more specific.\n");
    707735        } else if (rc == EOK) {
    708                 fnc = (unative_t (*)(unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call1);
    709                 printf("Calling f(%#" PRIxn "): %p: %s\n", arg1, symaddr, symbol);
     736                ipl_t ipl;
     737
     738                ipl = interrupts_disable();
     739                fnc = (unative_t (*)(unative_t, ...))
     740                    arch_construct_function(&fptr, (void *) symaddr,
     741                    (void *) cmd_call1);
     742                printf("Calling f(%#" PRIxn "): %p: %s\n", arg1,
     743                    (void *) symaddr, symbol);
    710744                printf("Result: %#" PRIxn "\n", fnc(arg1));
     745                interrupts_restore(ipl);
    711746        } else {
    712747                printf("No symbol information available.\n");
     
    736771                printf("Duplicate symbol, be more specific.\n");
    737772        } else if (rc == EOK) {
    738                 fnc = (unative_t (*)(unative_t, unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call2);
     773                ipl_t ipl;
     774
     775                ipl = interrupts_disable();
     776                fnc = (unative_t (*)(unative_t, unative_t, ...))
     777                    arch_construct_function(&fptr, (void *) symaddr,
     778                    (void *) cmd_call2);
    739779                printf("Calling f(%#" PRIxn ", %#" PRIxn "): %p: %s\n",
    740                        arg1, arg2, symaddr, symbol);
     780                       arg1, arg2, (void *) symaddr, symbol);
    741781                printf("Result: %#" PRIxn "\n", fnc(arg1, arg2));
     782                interrupts_restore(ipl);
    742783        } else {
    743784                printf("No symbol information available.\n");
     
    767808                printf("Duplicate symbol, be more specific.\n");
    768809        } else if (rc == EOK) {
    769                 fnc = (unative_t (*)(unative_t, unative_t, unative_t, ...)) arch_construct_function(&fptr, (void *) symaddr, (void *) cmd_call3);
    770                 printf("Calling f(%#" PRIxn ",%#" PRIxn ", %#" PRIxn "): %p: %s\n",
    771                        arg1, arg2, arg3, symaddr, symbol);
     810                ipl_t ipl;
     811
     812                ipl = interrupts_disable();
     813                fnc = (unative_t (*)(unative_t, unative_t, unative_t, ...))
     814                    arch_construct_function(&fptr, (void *) symaddr,
     815                    (void *) cmd_call3);
     816                printf("Calling f(%#" PRIxn ",%#" PRIxn ", %#" PRIxn "): %p: %s\n",
     817                       arg1, arg2, arg3, (void *) symaddr, symbol);
    772818                printf("Result: %#" PRIxn "\n", fnc(arg1, arg2, arg3));
     819                interrupts_restore(ipl);
    773820        } else {
    774821                printf("No symbol information available.\n");
     
    827874        bool pointer = false;
    828875        int rc;
    829 
    830         if (((char *)argv->buffer)[0] == '*') {
     876       
     877        if (((char *) argv->buffer)[0] == '*') {
    831878                rc = symtab_addr_lookup((char *) argv->buffer + 1, &addr);
    832879                pointer = true;
    833         } else if (((char *) argv->buffer)[0] >= '0' &&
    834                    ((char *)argv->buffer)[0] <= '9') {
    835                 rc = EOK;
    836                 addr = atoi((char *)argv->buffer);
    837         } else {
     880        } else if (((char *) argv->buffer)[0] >= '0' &&
     881                   ((char *) argv->buffer)[0] <= '9') {
     882                uint64_t value;
     883                rc = str_uint64((char *) argv->buffer, NULL, 0, true, &value);
     884                if (rc == EOK)
     885                        addr = (uintptr_t) value;
     886        } else
    838887                rc = symtab_addr_lookup((char *) argv->buffer, &addr);
    839         }
    840 
     888       
    841889        if (rc == ENOENT)
    842                 printf("Symbol %s not found.\n", argv->buffer);
     890                printf("Symbol %s not found.\n", (char *) argv->buffer);
     891        else if (rc == EINVAL)
     892                printf("Invalid address.\n");
    843893        else if (rc == EOVERFLOW) {
    844894                symtab_print_search((char *) argv->buffer);
    845                 printf("Duplicate symbol, be more specific.\n");
     895                printf("Duplicate symbol (be more specific) or address overflow.\n");
    846896        } else if (rc == EOK) {
    847897                if (pointer)
    848898                        addr = *(uintptr_t *) addr;
    849                 printf("Writing %#" PRIx64 " -> %p\n", arg1, addr);
     899                printf("Writing %#" PRIx32" -> %p\n", arg1, (void *) addr);
    850900                *(uint32_t *) addr = arg1;
    851         } else {
     901        } else
    852902                printf("No symbol information available.\n");
    853         }
    854903       
    855904        return 1;
     
    868917}
    869918
     919/** Command for dumping sysinfo
     920 *
     921 * @param argv Ignores
     922 *
     923 * @return Always 1
     924 */
     925int cmd_sysinfo(cmd_arg_t * argv)
     926{
     927        sysinfo_dump(NULL);
     928        return 1;
     929}
     930
    870931
    871932/** Command for listings Thread information
    872933 *
     934 * @param argv Ignored
     935 *
     936 * @return Always 1
     937 */
     938int cmd_threads(cmd_arg_t *argv)
     939{
     940        if (str_cmp(flag_buf, "-a") == 0)
     941                thread_print_list(true);
     942        else if (str_cmp(flag_buf, "") == 0)
     943                thread_print_list(false);
     944        else
     945                printf("Unknown argument \"%s\".\n", flag_buf);
     946       
     947        return 1;
     948}
     949
     950/** Command for listings Task information
     951 *
     952 * @param argv Ignored
     953 *
     954 * @return Always 1
     955 */
     956int cmd_tasks(cmd_arg_t *argv)
     957{
     958        if (str_cmp(flag_buf, "-a") == 0)
     959                task_print_list(true);
     960        else if (str_cmp(flag_buf, "") == 0)
     961                task_print_list(false);
     962        else
     963                printf("Unknown argument \"%s\".\n", flag_buf);
     964       
     965        return 1;
     966}
     967
     968/** Command for listings Thread information
     969 *
    873970 * @param argv Ignores
    874971 *
    875972 * @return Always 1
    876973 */
    877 int cmd_threads(cmd_arg_t * argv)
    878 {
    879         thread_print_list();
    880         return 1;
    881 }
    882 
    883 /** Command for listings Task information
    884  *
    885  * @param argv Ignores
    886  *
    887  * @return Always 1
    888  */
    889 int cmd_tasks(cmd_arg_t * argv)
    890 {
    891         task_print_list();
    892         return 1;
    893 }
    894 
    895 /** Command for listings Thread information
    896  *
    897  * @param argv Ignores
    898  *
    899  * @return Always 1
    900  */
    901974int cmd_sched(cmd_arg_t * argv)
    902975{
     
    913986int cmd_zones(cmd_arg_t * argv)
    914987{
    915         zone_print_list();
     988        zones_print_list();
    916989        return 1;
    917990}
     
    9971070
    9981071#ifdef CONFIG_TEST
    999 /** Command for printing kernel tests list.
    1000  *
    1001  * @param argv Ignored.
    1002  *
    1003  * return Always 1.
    1004  */
    1005 int cmd_tests(cmd_arg_t *argv)
    1006 {
    1007         size_t len = 0;
    1008         test_t *test;
    1009         for (test = tests; test->name != NULL; test++) {
    1010                 if (str_length(test->name) > len)
    1011                         len = str_length(test->name);
    1012         }
    1013        
    1014         for (test = tests; test->name != NULL; test++)
    1015                 printf("%-*s %s%s\n", len, test->name, test->desc, (test->safe ? "" : " (unsafe)"));
    1016        
    1017         printf("%-*s Run all safe tests\n", len, "*");
    1018         return 1;
    1019 }
    1020 
    10211072static bool run_test(const test_t *test)
    10221073{
     
    10251076        /* Update and read thread accounting
    10261077           for benchmarking */
    1027         ipl_t ipl = interrupts_disable();
    1028         spinlock_lock(&TASK->lock);
    1029         uint64_t t0 = task_get_accounting(TASK);
    1030         spinlock_unlock(&TASK->lock);
    1031         interrupts_restore(ipl);
     1078        irq_spinlock_lock(&TASK->lock, true);
     1079        uint64_t ucycles0, kcycles0;
     1080        task_get_accounting(TASK, &ucycles0, &kcycles0);
     1081        irq_spinlock_unlock(&TASK->lock, true);
    10321082       
    10331083        /* Execute the test */
    10341084        test_quiet = false;
    1035         char *ret = test->entry();
     1085        const char *ret = test->entry();
    10361086       
    10371087        /* Update and read thread accounting */
    1038         ipl = interrupts_disable();
    1039         spinlock_lock(&TASK->lock);
    1040         uint64_t dt = task_get_accounting(TASK) - t0;
    1041         spinlock_unlock(&TASK->lock);
    1042         interrupts_restore(ipl);
    1043        
    1044         uint64_t cycles;
    1045         char suffix;
    1046         order(dt, &cycles, &suffix);
    1047                
    1048         printf("Time: %" PRIu64 "%c cycles\n", cycles, suffix);
     1088        uint64_t ucycles1, kcycles1;
     1089        irq_spinlock_lock(&TASK->lock, true);
     1090        task_get_accounting(TASK, &ucycles1, &kcycles1);
     1091        irq_spinlock_unlock(&TASK->lock, true);
     1092       
     1093        uint64_t ucycles, kcycles;
     1094        char usuffix, ksuffix;
     1095        order_suffix(ucycles1 - ucycles0, &ucycles, &usuffix);
     1096        order_suffix(kcycles1 - kcycles0, &kcycles, &ksuffix);
     1097       
     1098        printf("Time: %" PRIu64 "%c user cycles, %" PRIu64 "%c kernel cycles\n",
     1099            ucycles, usuffix, kcycles, ksuffix);
    10491100       
    10501101        if (ret == NULL) {
     
    10521103                return true;
    10531104        }
    1054 
     1105       
    10551106        printf("%s\n", ret);
    10561107        return false;
     
    10611112        uint32_t i;
    10621113        bool ret = true;
    1063         uint64_t cycles;
    1064         char suffix;
     1114        uint64_t ucycles, kcycles;
     1115        char usuffix, ksuffix;
    10651116       
    10661117        if (cnt < 1)
     
    10781129                /* Update and read thread accounting
    10791130                   for benchmarking */
    1080                 ipl_t ipl = interrupts_disable();
    1081                 spinlock_lock(&TASK->lock);
    1082                 uint64_t t0 = task_get_accounting(TASK);
    1083                 spinlock_unlock(&TASK->lock);
    1084                 interrupts_restore(ipl);
     1131                irq_spinlock_lock(&TASK->lock, true);
     1132                uint64_t ucycles0, kcycles0;
     1133                task_get_accounting(TASK, &ucycles0, &kcycles0);
     1134                irq_spinlock_unlock(&TASK->lock, true);
    10851135               
    10861136                /* Execute the test */
    10871137                test_quiet = true;
    1088                 char * ret = test->entry();
     1138                const char *ret = test->entry();
    10891139               
    10901140                /* Update and read thread accounting */
    1091                 ipl = interrupts_disable();
    1092                 spinlock_lock(&TASK->lock);
    1093                 uint64_t dt = task_get_accounting(TASK) - t0;
    1094                 spinlock_unlock(&TASK->lock);
    1095                 interrupts_restore(ipl);
     1141                irq_spinlock_lock(&TASK->lock, true);
     1142                uint64_t ucycles1, kcycles1;
     1143                task_get_accounting(TASK, &ucycles1, &kcycles1);
     1144                irq_spinlock_unlock(&TASK->lock, true);
    10961145               
    10971146                if (ret != NULL) {
     
    11011150                }
    11021151               
    1103                 data[i] = dt;
    1104                 order(dt, &cycles, &suffix);
    1105                 printf("OK (%" PRIu64 "%c cycles)\n", cycles, suffix);
     1152                data[i] = ucycles1 - ucycles0 + kcycles1 - kcycles0;
     1153                order_suffix(ucycles1 - ucycles0, &ucycles, &usuffix);
     1154                order_suffix(kcycles1 - kcycles0, &kcycles, &ksuffix);
     1155                printf("OK (%" PRIu64 "%c user cycles, %" PRIu64 "%c kernel cycles)\n",
     1156                    ucycles, usuffix, kcycles, ksuffix);
    11061157        }
    11071158       
     
    11151166                }
    11161167               
    1117                 order(sum / (uint64_t) cnt, &cycles, &suffix);
    1118                 printf("Average\t\t%" PRIu64 "%c\n", cycles, suffix);
     1168                order_suffix(sum / (uint64_t) cnt, &ucycles, &usuffix);
     1169                printf("Average\t\t%" PRIu64 "%c\n", ucycles, usuffix);
    11191170        }
    11201171       
     
    11241175}
    11251176
    1126 /** Command for returning kernel tests
     1177static void list_tests(void)
     1178{
     1179        size_t len = 0;
     1180        test_t *test;
     1181       
     1182        for (test = tests; test->name != NULL; test++) {
     1183                if (str_length(test->name) > len)
     1184                        len = str_length(test->name);
     1185        }
     1186       
     1187        unsigned int _len = (unsigned int) len;
     1188        if ((_len != len) || (((int) _len) < 0)) {
     1189                printf("Command length overflow\n");
     1190                return;
     1191        }
     1192       
     1193        for (test = tests; test->name != NULL; test++)
     1194                printf("%-*s %s%s\n", _len, test->name, test->desc,
     1195                    (test->safe ? "" : " (unsafe)"));
     1196       
     1197        printf("%-*s Run all safe tests\n", _len, "*");
     1198}
     1199
     1200/** Command for listing and running kernel tests
    11271201 *
    11281202 * @param argv Argument vector.
    11291203 *
    11301204 * return Always 1.
     1205 *
    11311206 */
    11321207int cmd_test(cmd_arg_t *argv)
     
    11421217                        }
    11431218                }
    1144         } else {
     1219        } else if (str_cmp((char *) argv->buffer, "") != 0) {
    11451220                bool fnd = false;
    11461221               
     
    11551230                if (!fnd)
    11561231                        printf("Unknown test\n");
    1157         }
     1232        } else
     1233                list_tests();
    11581234       
    11591235        return 1;
  • kernel/generic/src/console/console.c

    rfb150d78 r46c20c8  
    3939#include <synch/waitq.h>
    4040#include <synch/spinlock.h>
    41 #include <arch/types.h>
     41#include <typedefs.h>
    4242#include <ddi/irq.h>
    4343#include <ddi/ddi.h>
     
    4545#include <ipc/irq.h>
    4646#include <arch.h>
     47#include <panic.h>
    4748#include <print.h>
    4849#include <putchar.h>
     
    5051#include <syscall/copy.h>
    5152#include <errno.h>
    52 #include <string.h>
     53#include <str.h>
    5354
    5455#define KLOG_PAGES    4
     
    6162/** Kernel log initialized */
    6263static bool klog_inited = false;
     64
    6365/** First kernel log characters */
    6466static size_t klog_start = 0;
     67
    6568/** Number of valid kernel log characters */
    6669static size_t klog_len = 0;
     70
    6771/** Number of stored (not printed) kernel log characters */
    6872static size_t klog_stored = 0;
     73
    6974/** Number of stored kernel log characters for uspace */
    7075static size_t klog_uspace = 0;
     
    8388};
    8489
    85 static void stdout_write(outdev_t *dev, wchar_t ch, bool silent);
    86 static void stdout_redraw(outdev_t *dev);
     90static void stdout_write(outdev_t *, wchar_t, bool);
     91static void stdout_redraw(outdev_t *);
    8792
    8893static outdev_operations_t stdout_ops = {
     
    173178                stdout->op->redraw(stdout);
    174179       
    175         /* Force the console to print the prompt */
    176         if ((stdin) && (prev))
     180        if ((stdin) && (prev)) {
     181                /*
     182                 * Force the console to print the prompt.
     183                 */
    177184                indev_push_character(stdin, '\n');
     185        }
    178186}
    179187
     
    286294                stdout->op->write(stdout, ch, silent);
    287295        else {
    288                 /* The character is just in the kernel log */
     296                /*
     297                 * No standard output routine defined yet.
     298                 * The character is still stored in the kernel log
     299                 * for possible future output.
     300                 *
     301                 * The early_putchar() function is used to output
     302                 * the character for low-level debugging purposes.
     303                 * Note that the early_putc() function might be
     304                 * a no-op on certain hardware configurations.
     305                 *
     306                 */
     307                early_putchar(ch);
     308               
    289309                if (klog_stored < klog_len)
    290310                        klog_stored++;
  • kernel/generic/src/console/kconsole.c

    rfb150d78 r46c20c8  
    4545#include <print.h>
    4646#include <panic.h>
    47 #include <arch/types.h>
     47#include <typedefs.h>
    4848#include <adt/list.h>
    4949#include <arch.h>
     
    5151#include <debug.h>
    5252#include <func.h>
    53 #include <string.h>
     53#include <str.h>
    5454#include <macros.h>
    5555#include <sysinfo/sysinfo.h>
     
    5858#include <errno.h>
    5959#include <putchar.h>
    60 #include <string.h>
     60#include <str.h>
    6161
    6262/** Simple kernel console.
     
    160160
    161161/** Print count times a character */
    162 static void print_cc(wchar_t ch, size_t count)
     162NO_TRACE static void print_cc(wchar_t ch, size_t count)
    163163{
    164164        size_t i;
     
    168168
    169169/** Try to find a command beginning with prefix */
    170 static const char *cmdtab_search_one(const char *name, link_t **startpos)
     170NO_TRACE static const char *cmdtab_search_one(const char *name,
     171    link_t **startpos)
    171172{
    172173        size_t namelen = str_length(name);
     
    202203 *
    203204 */
    204 static int cmdtab_compl(char *input, size_t size)
     205NO_TRACE static int cmdtab_compl(char *input, size_t size)
    205206{
    206207        const char *name = input;
     
    209210        link_t *pos = NULL;
    210211        const char *hint;
    211         char output[MAX_CMDLINE];
     212        char *output = malloc(MAX_CMDLINE, 0);
    212213       
    213214        output[0] = 0;
     
    224225                printf("\n");
    225226                pos = NULL;
    226                 while ((hint = cmdtab_search_one(name, &pos))) {
     227                while (cmdtab_search_one(name, &pos)) {
    227228                        cmd_info_t *hlp = list_get_instance(pos, cmd_info_t, link);
    228229                        printf("%s (%s)\n", hlp->name, hlp->description);
     
    234235                str_cpy(input, size, output);
    235236       
     237        free(output);
    236238        return found;
    237239}
    238240
    239 static wchar_t *clever_readline(const char *prompt, indev_t *indev)
     241NO_TRACE static wchar_t *clever_readline(const char *prompt, indev_t *indev)
    240242{
    241243        printf("%s> ", prompt);
     
    244246        wchar_t *current = history[history_pos];
    245247        current[0] = 0;
     248        char *tmp = malloc(STR_BOUNDS(MAX_CMDLINE), 0);
    246249       
    247250        while (true) {
     
    288291                                beg++;
    289292                       
    290                         char tmp[STR_BOUNDS(MAX_CMDLINE)];
    291293                        wstr_to_str(tmp, position - beg + 1, current + beg);
    292294                       
     
    414416        }
    415417       
     418        free(tmp);
    416419        return current;
    417420}
     
    422425}
    423426
    424 static bool parse_int_arg(const char *text, size_t len, unative_t *result)
     427NO_TRACE static bool parse_int_arg(const char *text, size_t len,
     428    unative_t *result)
    425429{
    426430        bool isaddr = false;
     
    455459                        printf("No symbol information available.\n");
    456460                        return false;
    457                 }
    458                
    459                 if (isaddr)
    460                         *result = (unative_t) symaddr;
    461                 else if (isptr)
    462                         *result = **((unative_t **) symaddr);
    463                 else
    464                         *result = *((unative_t *) symaddr);
     461                case EOK:
     462                        if (isaddr)
     463                                *result = (unative_t) symaddr;
     464                        else if (isptr)
     465                                *result = **((unative_t **) symaddr);
     466                        else
     467                                *result = *((unative_t *) symaddr);
     468                        break;
     469                default:
     470                        printf("Unknown error.\n");
     471                        return false;
     472                }
    465473        } else {
    466474                /* It's a number - convert it */
    467                 *result = atoi(text);
    468                 if (isptr)
    469                         *result = *((unative_t *) *result);
     475                uint64_t value;
     476                int rc = str_uint64(text, NULL, 0, true, &value);
     477                switch (rc) {
     478                case EINVAL:
     479                        printf("Invalid number.\n");
     480                        return false;
     481                case EOVERFLOW:
     482                        printf("Integer overflow.\n");
     483                        return false;
     484                case EOK:
     485                        *result = (unative_t) value;
     486                        if (isptr)
     487                                *result = *((unative_t *) *result);
     488                        break;
     489                default:
     490                        printf("Unknown error.\n");
     491                        return false;
     492                }
    470493        }
    471494       
     
    488511 *
    489512 */
    490 static bool parse_argument(const char *cmdline, size_t size, size_t *start, size_t *end)
     513NO_TRACE static bool parse_argument(const char *cmdline, size_t size,
     514    size_t *start, size_t *end)
    491515{
    492516        ASSERT(start != NULL);
     
    524548 *
    525549 */
    526 static cmd_info_t *parse_cmdline(const char *cmdline, size_t size)
     550NO_TRACE static cmd_info_t *parse_cmdline(const char *cmdline, size_t size)
    527551{
    528552        size_t start = 0;
     
    571595        size_t i;
    572596        for (i = 0; i < cmd->argc; i++) {
     597                char *buf;
     598               
    573599                start = end;
    574600                if (!parse_argument(cmdline, size, &start, &end)) {
     601                        if (cmd->argv[i].type == ARG_TYPE_STRING_OPTIONAL) {
     602                                buf = (char *) cmd->argv[i].buffer;
     603                                str_cpy(buf, cmd->argv[i].len, "");
     604                                continue;
     605                        }
     606                       
    575607                        printf("Too few arguments.\n");
    576608                        spinlock_unlock(&cmd->lock);
     
    578610                }
    579611               
    580                 char *buf;
    581612                switch (cmd->argv[i].type) {
    582613                case ARG_TYPE_STRING:
     614                case ARG_TYPE_STRING_OPTIONAL:
    583615                        buf = (char *) cmd->argv[i].buffer;
    584616                        str_ncpy(buf, cmd->argv[i].len, cmdline + start,
     
    600632                                        cmd->argv[i].vartype = ARG_TYPE_STRING;
    601633                                } else {
    602                                         printf("Wrong synxtax.\n");
     634                                        printf("Wrong syntax.\n");
    603635                                        error = true;
    604636                                }
     
    643675 *
    644676 */
    645 void kconsole(char *prompt, char *msg, bool kcon)
     677void kconsole(const char *prompt, const char *msg, bool kcon)
    646678{
    647679        if (!stdin) {
     
    658690                printf("Type \"exit\" to leave the console.\n");
    659691       
     692        char *cmdline = malloc(STR_BOUNDS(MAX_CMDLINE), 0);
    660693        while (true) {
    661694                wchar_t *tmp = clever_readline((char *) prompt, stdin);
     
    664697                        continue;
    665698               
    666                 char cmdline[STR_BOUNDS(MAX_CMDLINE)];
    667699                wstr_to_str(cmdline, STR_BOUNDS(MAX_CMDLINE), tmp);
    668700               
     
    676708                (void) cmd_info->func(cmd_info->argv);
    677709        }
     710        free(cmdline);
    678711}
    679712
Note: See TracChangeset for help on using the changeset viewer.