Changeset 76fca31 in mainline for kernel/generic/src


Ignore:
Timestamp:
2008-12-16T19:02:07Z (17 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5ae4443
Parents:
8fe5980
Message:

kconsole is optional
kernel & uspace framebuffer rewrite with speedups (some things are slightly broken yet)

Location:
kernel/generic/src
Files:
10 edited

Legend:

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

    r8fe5980 r76fca31  
    502502                cmd_initialize(basic_commands[i]);
    503503                if (!cmd_register(basic_commands[i]))
    504                         panic("could not register command %s\n", basic_commands[i]->name);
     504                        printf("Cannot register command %s\n", basic_commands[i]->name);
    505505        }
    506506}
  • kernel/generic/src/console/console.c

    r8fe5980 r76fca31  
    168168                else
    169169                        printf("cpu: ");
    170                 printf("halted - no kconsole\n");
     170                printf("halted (no kconsole)\n");
    171171                cpu_halt();
    172172        }
  • kernel/generic/src/console/kconsole.c

    r8fe5980 r76fca31  
    402402}
    403403
    404 /** Kernel console managing thread.
     404/** Kernel console prompt.
    405405 *
    406406 * @param prompt Kernel console prompt (e.g kconsole/panic).
    407  */
    408 void kconsole(void *prompt)
     407 * @param msg    Message to display in the beginning.
     408 * @param kcon   Wait for keypress to show the prompt
     409 *               and never exit.
     410 *
     411 */
     412void kconsole(char *prompt, char *msg, bool kcon)
    409413{
    410414        cmd_info_t *cmd_info;
     
    413417
    414418        if (!stdin) {
    415                 printf("%s: no stdin\n", __func__);
     419                LOG("No stdin for kernel console");
    416420                return;
    417421        }
     422       
     423        if (msg)
     424                printf("%s", msg);
     425       
     426        if (kcon)
     427                _getc(stdin);
    418428       
    419429        while (true) {
     
    422432                if (!len)
    423433                        continue;
     434               
    424435                cmd_info = parse_cmdline(cmdline, len);
    425436                if (!cmd_info)
    426437                        continue;
    427                 if (strncmp(cmd_info->name, "exit",
    428                     min(strlen(cmd_info->name), 5)) == 0)
     438               
     439                if ((!kcon)
     440                    && (strncmp(cmd_info->name, "exit", min(strlen(cmd_info->name), 5)) == 0))
    429441                        break;
     442               
    430443                (void) cmd_info->func(cmd_info->argv);
    431444        }
     445}
     446
     447/** Kernel console managing thread.
     448 *
     449 */
     450void kconsole_thread(void *data)
     451{
     452        kconsole("kconsole", "Kernel console ready (press any key to activate)\n", true);
    432453}
    433454
  • kernel/generic/src/cpu/cpu.c

    r8fe5980 r76fca31  
    8787#endif /* CONFIG_SMP */
    8888
    89         CPU = &cpus[config.cpu_active-1];
     89        CPU = &cpus[config.cpu_active - 1];
    9090       
    9191        CPU->active = 1;
  • kernel/generic/src/interrupt/interrupt.c

    r8fe5980 r76fca31  
    110110}
    111111
     112#ifdef CONFIG_KCONSOLE
     113
    112114/** kconsole cmd - print all exceptions */
    113 static int exc_print_cmd(cmd_arg_t *argv)
     115static int cmd_exc_print(cmd_arg_t *argv)
    114116{
    115117#if (IVT_ITEMS > 0)
     
    159161}
    160162
     163
    161164static cmd_info_t exc_info = {
    162165        .name = "exc",
    163166        .description = "Print exception table.",
    164         .func = exc_print_cmd,
     167        .func = cmd_exc_print,
    165168        .help = NULL,
    166169        .argc = 0,
    167170        .argv = NULL
    168171};
     172
     173#endif
    169174
    170175/** Initialize generic exception handling support */
     
    176181                exc_register(i, "undef", (iroutine) exc_undef);
    177182
     183#ifdef CONFIG_KCONSOLE
    178184        cmd_initialize(&exc_info);
    179185        if (!cmd_register(&exc_info))
    180                 panic("could not register command %s\n", exc_info.name);
     186                printf("Cannot register command %s\n", exc_info.name);
     187#endif
    181188}
    182189
  • kernel/generic/src/lib/func.c

    r8fe5980 r76fca31  
    5656        bool rundebugger = false;
    5757
    58 //      TODO test_and_set not defined on all arches
    59 //      if (!test_and_set(&haltstate))
    6058        if (!atomic_get(&haltstate)) {
    6159                atomic_set(&haltstate, 1);
     
    6765
    6866        interrupts_disable();
    69 #ifdef CONFIG_DEBUG
    70         if (rundebugger) {
    71                 printf("\n");
    72                 kconsole("panic"); /* Run kconsole as a last resort to user */
    73         }
    74 #endif     
     67       
     68#if (defined(CONFIG_DEBUG)) && (defined(CONFIG_KCONSOLE))
     69        if (rundebugger)
     70                kconsole("panic", "\nLast resort kernel console ready\n", false);
     71#endif
     72       
    7573        if (CPU)
    7674                printf("cpu%u: halted\n", CPU->id);
  • kernel/generic/src/main/kinit.c

    r8fe5980 r76fca31  
    8383void kinit(void *arg)
    8484{
    85         thread_t *t;
     85
     86#if defined(CONFIG_SMP) || defined(CONFIG_KCONSOLE)
     87        thread_t *thread;
     88#endif
    8689
    8790        /*
     
    101104                 * Just a beautification.
    102105                 */
    103                 if ((t = thread_create(kmp, NULL, TASK, THREAD_FLAG_WIRED,
    104                     "kmp", true))) {
    105                         spinlock_lock(&t->lock);
    106                         t->cpu = &cpus[0];
    107                         spinlock_unlock(&t->lock);
    108                         thread_ready(t);
     106                thread = thread_create(kmp, NULL, TASK, THREAD_FLAG_WIRED, "kmp", true);
     107                if (thread != NULL) {
     108                        spinlock_lock(&thread->lock);
     109                        thread->cpu = &cpus[0];
     110                        spinlock_unlock(&thread->lock);
     111                        thread_ready(thread);
    109112                } else
    110                         panic("thread_create/kmp\n");
    111                 thread_join(t);
    112                 thread_detach(t);
     113                        panic("Unable to create kmp thread\n");
     114                thread_join(thread);
     115                thread_detach(thread);
    113116        }
    114117#endif /* CONFIG_SMP */
    115         /*
    116          * Now that all CPUs are up, we can report what we've found.
    117          */
    118         cpu_list();
    119 
     118       
    120119#ifdef CONFIG_SMP
    121120        if (config.cpu_count > 1) {
     
    126125                 */
    127126                for (i = 0; i < config.cpu_count; i++) {
    128 
    129                         if ((t = thread_create(kcpulb, NULL, TASK,
    130                             THREAD_FLAG_WIRED, "kcpulb", true))) {
    131                                 spinlock_lock(&t->lock);                       
    132                                 t->cpu = &cpus[i];
    133                                 spinlock_unlock(&t->lock);
    134                                 thread_ready(t);
     127                        thread = thread_create(kcpulb, NULL, TASK, THREAD_FLAG_WIRED, "kcpulb", true);
     128                        if (thread != NULL) {
     129                                spinlock_lock(&thread->lock);
     130                                thread->cpu = &cpus[i];
     131                                spinlock_unlock(&thread->lock);
     132                                thread_ready(thread);
    135133                        } else
    136                                 panic("thread_create/kcpulb\n");
     134                                printf("Unable to create kcpulb thread for cpu" PRIc "\n", i);
    137135
    138136                }
    139137        }
    140138#endif /* CONFIG_SMP */
    141 
     139       
    142140        /*
    143141         * At this point SMP, if present, is configured.
     
    145143        arch_post_smp_init();
    146144
    147         /*
    148          * Create kernel console.
    149          */
    150         t = thread_create(kconsole, (void *) "kconsole", TASK, 0, "kconsole",
    151             false);
    152         if (t)
    153                 thread_ready(t);
    154         else
    155                 panic("thread_create/kconsole\n");
    156 
     145#ifdef CONFIG_KCONSOLE
     146        if (stdin) {
     147                /*
     148                 * Create kernel console.
     149                 */
     150                thread = thread_create(kconsole_thread, NULL, TASK, 0, "kconsole", false);
     151                if (thread != NULL)
     152                        thread_ready(thread);
     153                else
     154                        printf("Unable to create kconsole thread\n");
     155        }
     156#endif /* CONFIG_KCONSOLE */
     157       
    157158        interrupts_enable();
    158159       
     
    165166        for (i = 0; i < init.cnt; i++) {
    166167                if (init.tasks[i].addr % FRAME_SIZE) {
    167                         printf("init[%" PRIc "].addr is not frame aligned", i);
     168                        printf("init[%" PRIc "].addr is not frame aligned\n", i);
    168169                        continue;
    169170                }
    170 
     171               
    171172                int rc = program_create_from_image((void *) init.tasks[i].addr,
    172173                    "init-bin", &programs[i]);
    173 
    174                 if (rc == 0 && programs[i].task != NULL) {
     174               
     175                if ((rc == 0) && (programs[i].task != NULL)) {
    175176                        /*
    176177                         * Set capabilities to init userspace tasks.
     
    185186                } else {
    186187                        /* RAM disk image */
    187                         int rd = init_rd((rd_header_t *) init.tasks[i].addr,
    188                             init.tasks[i].size);
     188                        int rd = init_rd((rd_header_t *) init.tasks[i].addr, init.tasks[i].size);
    189189                       
    190190                        if (rd != RE_OK)
    191                                 printf("Init binary %" PRIc " not used, error "
    192                                     "code %d.\n", i, rd);
     191                                printf("Init binary %" PRIc " not used (error %d)\n", i, rd);
    193192                }
    194193        }
     
    204203        }
    205204
     205#ifdef CONFIG_KCONSOLE
    206206        if (!stdin) {
     207                printf("kinit: No stdin\nKernel alive: ");
     208               
     209                uint64_t i = 0;
    207210                while (1) {
     211                        printf(PRIu64 " ", i);
    208212                        thread_sleep(1);
    209                         printf("kinit... ");
    210                 }
    211         }
     213                        i++;
     214                }
     215        }
     216#endif /* CONFIG_KCONSOLE */
    212217}
    213218
  • kernel/generic/src/main/main.c

    r8fe5980 r76fca31  
    192192        /* Keep this the first thing. */
    193193        the_initialize(THE);
    194 
    195         LOG();
    196194       
    197195        version_print();
     
    201199            config.base, config.kernel_size, config.stack_base,
    202200            config.stack_size);
    203        
    204 
     201
     202#ifdef CONFIG_KCONSOLE
    205203        /*
    206204         * kconsole data structures must be initialized very early
     
    209207         */
    210208        LOG_EXEC(kconsole_init());
     209#endif
    211210       
    212211        /*
     
    253252                count_t i;
    254253                for (i = 0; i < init.cnt; i++)
    255                         printf("init[%" PRIc "].addr=%#" PRIp ", init[%" PRIc
     254                        LOG("init[%" PRIc "].addr=%#" PRIp ", init[%" PRIc
    256255                            "].size=%#" PRIs "\n", i, init.tasks[i].addr, i,
    257256                            init.tasks[i].size);
     
    272271         * Create the first thread.
    273272         */
    274         thread_t *kinit_thread = thread_create(kinit, NULL, kernel, 0, "kinit",
    275             true);
     273        thread_t *kinit_thread
     274                = thread_create(kinit, NULL, kernel, 0, "kinit", true);
    276275        if (!kinit_thread)
    277276                panic("Can't create kinit thread\n");
  • kernel/generic/src/mm/as.c

    r8fe5980 r76fca31  
    147147        AS_KERNEL = as_create(FLAG_AS_KERNEL);
    148148        if (!AS_KERNEL)
    149                 panic("can't create kernel address space\n");
    150        
     149                panic("Cannot create kernel address space\n");
     150       
     151        /* Make sure the kernel address space
     152         * reference count never drops to zero.
     153         */
     154        atomic_set(&AS_KERNEL->refcount, 1);
    151155}
    152156
     
    177181        page_table_create(flags);
    178182#endif
    179 
     183       
    180184        return as;
    181185}
     
    770774 * into private anonymous memory (unless it's already there).
    771775 *
    772  * @param as            Address space.
    773  * @param flags         Flags of the area memory.
    774  * @param address       Address withing the area to be changed.
    775  *
    776  * @return              Zero on success or a value from @ref errno.h on failure.
     776 * @param as      Address space.
     777 * @param flags   Flags of the area memory.
     778 * @param address Address within the area to be changed.
     779 *
     780 * @return Zero on success or a value from @ref errno.h on failure.
     781 *
    777782 */
    778783int as_area_change_flags(as_t *as, int flags, uintptr_t address)
     
    786791        index_t frame_idx;
    787792        count_t used_pages;
    788 
     793       
    789794        /* Flags for the new memory mapping */
    790795        page_flags = area_flags_to_page_flags(flags);
     
    800805        }
    801806
    802         if (area->sh_info || area->backend != &anon_backend) {
     807        if ((area->sh_info) || (area->backend != &anon_backend)) {
    803808                /* Copying shared areas not supported yet */
    804809                /* Copying non-anonymous memory not supported yet */
     
    871876
    872877        tlb_invalidate_pages(as->asid, area->base, area->pages);
     878       
    873879        /*
    874880         * Invalidate potential software translation caches (e.g. TSB on
  • kernel/generic/src/syscall/syscall.c

    r8fe5980 r76fca31  
    9393static unative_t sys_debug_enable_console(void)
    9494{
     95#ifdef CONFIG_KCONSOLE
    9596        arch_grab_console();
    96         return 0;
     97        return true;
     98#else
     99        return false;
     100#endif
    97101}
    98102
Note: See TracChangeset for help on using the changeset viewer.