Annotation of qemu/roms/SLOF/clients/net-snk/kernel/init.c, revision 1.1

1.1     ! root        1: /******************************************************************************
        !             2:  * Copyright (c) 2004, 2008 IBM Corporation
        !             3:  * All rights reserved.
        !             4:  * This program and the accompanying materials
        !             5:  * are made available under the terms of the BSD License
        !             6:  * which accompanies this distribution, and is available at
        !             7:  * http://www.opensource.org/licenses/bsd-license.php
        !             8:  *
        !             9:  * Contributors:
        !            10:  *     IBM Corporation - initial implementation
        !            11:  *****************************************************************************/
        !            12: 
        !            13: #include <of.h>
        !            14: #include <pci.h>
        !            15: #include <kernel.h>
        !            16: #include <stdint.h>
        !            17: #include <string.h>
        !            18: #include <cpu.h>
        !            19: #include <fileio.h>
        !            20: #include <stdlib.h> /* malloc */
        !            21: #include <ioctl.h> /* ioctl */
        !            22: 
        !            23: /* Application entry point .*/
        !            24: extern int _start(unsigned char *arg_string, long len);
        !            25: extern int main(int, char**);
        !            26: void * malloc_aligned(size_t size, int align);
        !            27: extern snk_module_t *insmod_by_type(int);
        !            28: extern void rmmod_by_type(int);
        !            29: 
        !            30: unsigned long exception_stack_frame;
        !            31: 
        !            32: snk_fileio_t fd_array[FILEIO_MAX];
        !            33: 
        !            34: extern uint64_t tb_freq;
        !            35: 
        !            36: void modules_init(void);
        !            37: void modules_term(void);
        !            38: int glue_init(snk_kernel_t *, unsigned int *, size_t, size_t);
        !            39: void glue_release(void);
        !            40: 
        !            41: static char save_vector[0x4000];
        !            42: extern char _lowmem_start;
        !            43: extern char _lowmem_end;
        !            44: extern char __client_start;
        !            45: extern char __client_end;
        !            46: 
        !            47: snk_kernel_t snk_kernel_interface = {
        !            48:        .version          = 1,
        !            49:        .print            = printk,
        !            50:        .us_delay         = udelay,
        !            51:        .ms_delay         = mdelay,
        !            52:        .k_malloc         = malloc,
        !            53:        .k_malloc_aligned = malloc_aligned,
        !            54:        .k_free           = free,
        !            55:        .strcmp           = strcmp,
        !            56:        .snk_call         = main,
        !            57:        .k_open           = open,
        !            58:        .k_close          = close,
        !            59:        .k_read           = read,
        !            60:        .k_write          = write,
        !            61:        .k_ioctl          = ioctl,
        !            62:        .modules_remove   = rmmod_by_type,
        !            63:        .modules_load     = insmod_by_type,
        !            64: };
        !            65: 
        !            66: void *
        !            67: malloc_aligned(size_t size, int align)
        !            68: {
        !            69:        unsigned long p = (unsigned long) malloc(size + align - 1);
        !            70:        p = p + align - 1;
        !            71:        p = p & ~(align - 1);
        !            72: 
        !            73:        return (void *) p;
        !            74: }
        !            75: 
        !            76: static void
        !            77: copy_exception_vectors()
        !            78: {
        !            79:        char *dest;
        !            80:        char *src;
        !            81:        int len;
        !            82: 
        !            83:        dest = save_vector;
        !            84:        src = (char *) 0x200;
        !            85:        len = &_lowmem_end - &_lowmem_start;
        !            86:        memcpy(dest, src, len);
        !            87: 
        !            88:        dest = (char *) 0x200;
        !            89:        src = &_lowmem_start;
        !            90:        memcpy(dest, src, len);
        !            91:        flush_cache(dest, len);
        !            92: }
        !            93: 
        !            94: static void
        !            95: restore_exception_vectors()
        !            96: {
        !            97:        char *dest;
        !            98:        char *src;
        !            99:        int len;
        !           100: 
        !           101:        dest = (char *) 0x200;
        !           102:        src = save_vector;
        !           103:        len = &_lowmem_end - &_lowmem_start;
        !           104:        memcpy(dest, src, len);
        !           105:        flush_cache(dest, len);
        !           106: }
        !           107: 
        !           108: int
        !           109: _start_kernel(unsigned long p0, unsigned long p1)
        !           110: {
        !           111:        int rc;
        !           112:        unsigned int timebase;
        !           113: 
        !           114:        /* initialize all file descriptor by marking them as empty */
        !           115:        for(rc=0; rc<FILEIO_MAX; ++rc) {
        !           116:                fd_array[rc].type = FILEIO_TYPE_EMPTY;
        !           117:                fd_array[rc].idx  = rc;
        !           118:        }
        !           119: 
        !           120:        /* this is step is e.g. resposible to initialize file descriptor 0 and 1 for STDIO */
        !           121:        rc = glue_init(&snk_kernel_interface, &timebase, (size_t)(unsigned long)&__client_start,
        !           122:                       (size_t)(unsigned long)&__client_end - (size_t)(unsigned long)&__client_start);
        !           123:        if(rc < 0)
        !           124:                return -1;
        !           125: 
        !           126:        tb_freq = (uint64_t) timebase;
        !           127:        copy_exception_vectors();
        !           128:        modules_init();
        !           129:        rc = _start((unsigned char *) p0, p1);
        !           130:        modules_term();
        !           131:        restore_exception_vectors();
        !           132: 
        !           133:        glue_release();
        !           134:        return rc;
        !           135: }
        !           136: 
        !           137: 
        !           138: void
        !           139: exception_forward(void)
        !           140: {
        !           141:        restore_exception_vectors();
        !           142:        undo_exception();
        !           143: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.