Annotation of qemu/roms/openbios/arch/ppc/pearpc/pearpc.c, revision 1.1

1.1     ! root        1: /*
        !             2:  *   Creation Date: <2004/08/28 18:38:22 greg>
        !             3:  *   Time-stamp: <2004/08/28 18:38:22 greg>
        !             4:  *
        !             5:  *     <pearpc.c>
        !             6:  *
        !             7:  *   Copyright (C) 2004, Greg Watson
        !             8:  *
        !             9:  *   derived from mol.c
        !            10:  *
        !            11:  *   Copyright (C) 2003, 2004 Samuel Rydh ([email protected])
        !            12:  *
        !            13:  *   This program is free software; you can redistribute it and/or
        !            14:  *   modify it under the terms of the GNU General Public License
        !            15:  *   version 2
        !            16:  *
        !            17:  */
        !            18: 
        !            19: #include "config.h"
        !            20: #include "kernel/kernel.h"
        !            21: #include "arch/common/nvram.h"
        !            22: #include "libc/vsprintf.h"
        !            23: #include "libc/string.h"
        !            24: #include "pearpc/pearpc.h"
        !            25: #include <stdarg.h>
        !            26: 
        !            27: #define UART_BASE 0x3f8
        !            28: 
        !            29: // FIXME
        !            30: unsigned long virt_offset = 0;
        !            31: 
        !            32: 
        !            33: void
        !            34: exit( int status )
        !            35: {
        !            36:        for (;;);
        !            37: }
        !            38: 
        !            39: void
        !            40: fatal_error( const char *err )
        !            41: {
        !            42:        printk("Fatal error: %s\n", err );
        !            43:        exit(0);
        !            44: }
        !            45: 
        !            46: void
        !            47: panic( const char *err )
        !            48: {
        !            49:        printk("Panic: %s\n", err );
        !            50:        exit(0);
        !            51: 
        !            52:        /* won't come here... this keeps the gcc happy */
        !            53:        for( ;; )
        !            54:                ;
        !            55: }
        !            56: 
        !            57: 
        !            58: /************************************************************************/
        !            59: /*     print using OSI interface                                       */
        !            60: /************************************************************************/
        !            61: 
        !            62: static int do_indent;
        !            63: 
        !            64: int
        !            65: printk( const char *fmt, ... )
        !            66: {
        !            67:         char *p, buf[1024];
        !            68:        va_list args;
        !            69:        int i;
        !            70: 
        !            71:        va_start(args, fmt);
        !            72:         i = vsnprintf(buf, sizeof(buf), fmt, args);
        !            73:        va_end(args);
        !            74: 
        !            75:        for( p=buf; *p; p++ ) {
        !            76:                if( *p == '\n' )
        !            77:                        do_indent = 0;
        !            78:                if( do_indent++ == 1 ) {
        !            79:                        putchar( '>' );
        !            80:                        putchar( '>' );
        !            81:                        putchar( ' ' );
        !            82:                }
        !            83:                putchar( *p );
        !            84:        }
        !            85:        return i;
        !            86: }
        !            87: 
        !            88: 
        !            89: /************************************************************************/
        !            90: /*     TTY iface                                                       */
        !            91: /************************************************************************/
        !            92: 
        !            93: static int ttychar = -1;
        !            94: 
        !            95: static int
        !            96: tty_avail( void )
        !            97: {
        !            98:        return 1;
        !            99: }
        !           100: 
        !           101: static int
        !           102: tty_putchar( int c )
        !           103: {
        !           104:        if( tty_avail() ) {
        !           105:                while (!(inb(UART_BASE + 0x05) & 0x20))
        !           106:                        ;
        !           107:                outb(c, UART_BASE);
        !           108:                while (!(inb(UART_BASE + 0x05) & 0x40))
        !           109:                        ;
        !           110:        }
        !           111:        return c;
        !           112: }
        !           113: 
        !           114: int
        !           115: availchar( void )
        !           116: {
        !           117:        if( !tty_avail() )
        !           118:                return 0;
        !           119: 
        !           120:        if( ttychar < 0 )
        !           121:                ttychar = inb(UART_BASE);
        !           122:        return (ttychar >= 0);
        !           123: }
        !           124: 
        !           125: int
        !           126: getchar( void )
        !           127: {
        !           128:        int ch;
        !           129: 
        !           130:        if( !tty_avail() )
        !           131:                return 0;
        !           132: 
        !           133:        if( ttychar < 0 )
        !           134:                return inb(UART_BASE);
        !           135:        ch = ttychar;
        !           136:        ttychar = -1;
        !           137:        return ch;
        !           138: }
        !           139: 
        !           140: int
        !           141: putchar( int c )
        !           142: {
        !           143:        if (c == '\n')
        !           144:                tty_putchar('\r');
        !           145:        return tty_putchar(c);
        !           146: }
        !           147: 
        !           148: 
        !           149: /************************************************************************/
        !           150: /*     briQ specific stuff                                             */
        !           151: /************************************************************************/
        !           152: 
        !           153: #define IO_NVRAM_PA_START 0x80860000
        !           154: #define IO_NVRAM_PA_END 0x80880000
        !           155: 
        !           156: static char *nvram=(char *)IO_NVRAM_PA_START;
        !           157: 
        !           158: void
        !           159: dump_nvram(void)
        !           160: {
        !           161:   static char hexdigit[] = "0123456789abcdef";
        !           162:   int i;
        !           163:   for (i = 0; i < 16*4; i++)
        !           164:     {
        !           165:       printk ("%c", hexdigit[nvram[i<<4] >> 4]);
        !           166:       printk ("%c", hexdigit[nvram[i<<4] % 16]);
        !           167:       if (!((i + 1) % 16))
        !           168:         {
        !           169:           printk ("\n");
        !           170:         }
        !           171:       else
        !           172:         {
        !           173:           printk (" ");
        !           174:         }
        !           175:     }
        !           176: }
        !           177: 
        !           178: 
        !           179: int
        !           180: arch_nvram_size( void )
        !           181: {
        !           182:        return (IO_NVRAM_PA_END-IO_NVRAM_PA_START)>>4;
        !           183: }
        !           184: 
        !           185: void
        !           186: arch_nvram_put( char *buf )
        !           187: {
        !           188:        int i;
        !           189:        for (i=0; i<(IO_NVRAM_PA_END-IO_NVRAM_PA_START)>>4; i++)
        !           190:                nvram[i<<4]=buf[i];
        !           191:        // memcpy(nvram, buf, IO_NVRAM_PA_END-IO_NVRAM_PA_START);
        !           192:        printk("new nvram:\n");
        !           193:        dump_nvram();
        !           194: }
        !           195: 
        !           196: void
        !           197: arch_nvram_get( char *buf )
        !           198: {
        !           199:        int i;
        !           200:        for (i=0; i<(IO_NVRAM_PA_END-IO_NVRAM_PA_START)>>4; i++)
        !           201:                buf[i]=nvram[i<<4];
        !           202: 
        !           203:        //memcpy(buf, nvram, IO_NVRAM_PA_END-IO_NVRAM_PA_START);
        !           204:        printk("current nvram:\n");
        !           205:        dump_nvram();
        !           206: }

unix.superglobalmegacorp.com

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