[BACK]Return to system.c CVS log [TXT][DIR] Up to [local] / prex-old / sys / kern

Annotation of prex-old/sys/kern/system.c, Revision 1.1.1.1.2.1

1.1       nbrk        1: /*-
                      2:  * Copyright (c) 2005-2007, Kohsuke Ohtani
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms, with or without
                      6:  * modification, are permitted provided that the following conditions
                      7:  * are met:
                      8:  * 1. Redistributions of source code must retain the above copyright
                      9:  *    notice, this list of conditions and the following disclaimer.
                     10:  * 2. Redistributions in binary form must reproduce the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer in the
                     12:  *    documentation and/or other materials provided with the distribution.
                     13:  * 3. Neither the name of the author nor the names of any co-contributors
                     14:  *    may be used to endorse or promote products derived from this software
                     15:  *    without specific prior written permission.
                     16:  *
                     17:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
                     18:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     19:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     20:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
                     21:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     22:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     23:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     24:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     25:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     26:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     27:  * SUCH DAMAGE.
                     28:  */
                     29:
                     30: /*
                     31:  * system.c - system services
                     32:  */
                     33:
                     34: #include <kernel.h>
                     35: #include <thread.h>
                     36: #include <sched.h>
                     37: #include <task.h>
                     38: #include <irq.h>
                     39: #include <page.h>
                     40: #include <device.h>
                     41: #include <system.h>
1.1.1.1.2.1! nbrk       42: #include <version.h>
1.1       nbrk       43:
                     44: /*
                     45:  * kernel information.
                     46:  */
1.1.1.1.2.1! nbrk       47: static const struct info_kernel kern_info = {
        !            48:        "Prex", VERSION, __DATE__, MACHINE, "preky"
        !            49: };
1.1       nbrk       50:
                     51: /*
                     52:  * Logging system call.
                     53:  *
1.1.1.1.2.1! nbrk       54:  * Write a message to the logging device.  The log function is
        !            55:  * available only when kernel is built with debug option.
1.1       nbrk       56:  */
                     57: int
                     58: sys_log(const char *str)
                     59: {
                     60: #ifdef DEBUG
1.1.1.1.2.1! nbrk       61:        char buf[DBGMSG_SIZE];
1.1       nbrk       62:        size_t len;
                     63:
1.1.1.1.2.1! nbrk       64:        if (umem_strnlen(str, DBGMSG_SIZE, &len))
1.1       nbrk       65:                return EFAULT;
1.1.1.1.2.1! nbrk       66:        if (len >= DBGMSG_SIZE)
1.1       nbrk       67:                return EINVAL;
1.1.1.1.2.1! nbrk       68:        if (umem_copyin(str, buf, len + 1))
1.1       nbrk       69:                return EFAULT;
1.1.1.1.2.1! nbrk       70:        printf(buf);
1.1       nbrk       71:        return 0;
                     72: #else
                     73:        return ENOSYS;
                     74: #endif
                     75: }
                     76:
                     77: /*
                     78:  * Panic system call.
                     79:  *
1.1.1.1.2.1! nbrk       80:  * If kernel is built with debug option, sys_panic() displays
        !            81:  * a panic message and stops the enture system. Otherwise, it
        !            82:  * terminates the task which called sys_panic().
1.1       nbrk       83:  */
                     84: int
                     85: sys_panic(const char *str)
                     86: {
                     87: #ifdef DEBUG
1.1.1.1.2.1! nbrk       88:        task_t self = cur_task();
        !            89:
1.1       nbrk       90:        irq_lock();
1.1.1.1.2.1! nbrk       91:        printf("\nUser mode panic: task:%s thread:%x\n",
        !            92:               self->name != NULL ? self->name : "no name", cur_thread);
1.1       nbrk       93:
                     94:        sys_log(str);
1.1.1.1.2.1! nbrk       95:        printf("\n");
1.1       nbrk       96:
                     97:        sched_lock();
                     98:        irq_unlock();
                     99:        BREAKPOINT();
                    100:
                    101:        for (;;);
                    102: #else
                    103:        task_terminate(cur_task());
                    104: #endif
                    105:        /* NOTREACHED */
                    106:        return 0;
                    107: }
                    108:
                    109: /*
                    110:  * Get system information
                    111:  */
                    112: int
                    113: sys_info(int type, void *buf)
                    114: {
                    115:        int err = 0;
                    116:        struct info_memory imem;
                    117:        struct info_timer itmr;
                    118:        struct info_thread ithr;
                    119:        struct info_device idev;
                    120:
                    121:        if (buf == NULL || !user_area(buf))
                    122:                return EFAULT;
                    123:
                    124:        switch (type) {
                    125:        case INFO_KERNEL:
1.1.1.1.2.1! nbrk      126:                err = umem_copyout(&kern_info, buf, sizeof(kern_info));
1.1       nbrk      127:                break;
                    128:
                    129:        case INFO_MEMORY:
                    130:                page_info(&imem.total, &imem.free);
                    131:                err = umem_copyout(&imem, buf, sizeof(imem));
                    132:                break;
                    133:
                    134:        case INFO_THREAD:
                    135:                if (umem_copyin(buf, &ithr, sizeof(ithr)))
                    136:                        return EFAULT;
                    137:                if ((err = thread_info(&ithr)))
                    138:                        return err;
                    139:                ithr.cookie++;
                    140:                err = umem_copyout(&ithr, buf, sizeof(ithr));
                    141:                break;
                    142:
                    143:        case INFO_DEVICE:
                    144:                if (umem_copyin(buf, &idev, sizeof(idev)))
                    145:                        return EFAULT;
                    146:                if ((err = device_info(&idev)))
                    147:                        return err;
                    148:                idev.cookie++;
                    149:                err = umem_copyout(&idev, buf, sizeof(idev));
                    150:                break;
                    151:
                    152:        case INFO_TIMER:
                    153:                timer_info(&itmr);
                    154:                err = umem_copyout(&itmr, buf, sizeof(itmr));
                    155:                break;
                    156:
                    157:        default:
                    158:                err = EINVAL;
1.1.1.1.2.1! nbrk      159:                break;
1.1       nbrk      160:        }
                    161:        return err;
                    162: }
                    163:
                    164: /*
1.1.1.1.2.1! nbrk      165:  * Get system time - return ticks since OS boot.
1.1       nbrk      166:  */
                    167: int
                    168: sys_time(u_long *ticks)
                    169: {
                    170:        u_long t;
                    171:
                    172:        t = timer_count();
1.1.1.1.2.1! nbrk      173:        return umem_copyout(&t, ticks, sizeof(t));
1.1       nbrk      174: }
                    175:
                    176: /*
                    177:  * Kernel debug service.
                    178:  */
                    179: int
1.1.1.1.2.1! nbrk      180: sys_debug(int cmd, void *data)
1.1       nbrk      181: {
                    182: #ifdef DEBUG
                    183:        int err = EINVAL;
                    184:        size_t size;
1.1.1.1.2.1! nbrk      185:        int item;
1.1       nbrk      186:
                    187:        switch (cmd) {
                    188:        case DCMD_DUMP:
1.1.1.1.2.1! nbrk      189:                if (umem_copyin(data, &item, sizeof(item)))
        !           190:                        err = EFAULT;
        !           191:                else
        !           192:                        err = debug_dump(item);
1.1       nbrk      193:                break;
                    194:        case DCMD_LOGSIZE:
1.1.1.1.2.1! nbrk      195:                size = LOGBUF_SIZE;
        !           196:                err = umem_copyout(&size, data, sizeof(size));
1.1       nbrk      197:                break;
                    198:        case DCMD_GETLOG:
1.1.1.1.2.1! nbrk      199:                err = debug_getlog(data);
1.1       nbrk      200:                break;
                    201:        default:
1.1.1.1.2.1! nbrk      202:                /* DO NOTHING */
1.1       nbrk      203:                break;
                    204:        }
                    205:        return err;
                    206: #else
                    207:        return ENOSYS;
                    208: #endif
                    209: }

CVSweb