Annotation of kernel/bsd/dev/i386/BasicConsole.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
        !             7:  * Reserved.  This file contains Original Code and/or Modifications of
        !             8:  * Original Code as defined in and that are subject to the Apple Public
        !             9:  * Source License Version 1.1 (the "License").  You may not use this file
        !            10:  * except in compliance with the License.  Please obtain a copy of the
        !            11:  * License at http://www.apple.com/publicsource and read it before using
        !            12:  * this file.
        !            13:  * 
        !            14:  * The Original Code and all software distributed under the License are
        !            15:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
        !            19:  * License for the specific language governing rights and limitations
        !            20:  * under the License.
        !            21:  * 
        !            22:  * @APPLE_LICENSE_HEADER_END@
        !            23:  */
        !            24: 
        !            25: /*
        !            26:  * Initialize the VGA console.
        !            27:  */
        !            28:  
        !            29: #import <bsd/i386/param.h>
        !            30: #import <bsd/dev/i386/BasicConsole.h>
        !            31: #import <bsd/dev/i386/VGAConsole.h>
        !            32: #import <driverkit/displayDefs.h>
        !            33: #import <machdep/i386/kernBootStruct.h>
        !            34: #import <machdep/i386/io_inline.h>
        !            35: 
        !            36: 
        !            37: #define VGA_MODE_S12           0       // 640x480x4 VGA mode
        !            38: #define        N_SMODES                1       // Total number of modes
        !            39: 
        !            40: 
        !            41: #define VGA_SEQ_ADDR           0x3c4
        !            42: #define VGA_SEQ_DATA           0x3c5
        !            43: 
        !            44: #define VGA_CLK_MODE_INDEX     0x01
        !            45: #define VGA_SCRN_OFF           0x20
        !            46: 
        !            47: 
        !            48: #define VGA_CRTC_ADDR                  0x3d4
        !            49: #define VGA_CRTC_DATA                  0x3d5
        !            50: 
        !            51: #define        VGA_ADDR                ((char *)0xA0000)
        !            52: #define        VGA_LENGTH              0x10000
        !            53: 
        !            54: // Generic VGA Stuff
        !            55: #define        INPUT_STATUS_1  0x3da
        !            56: 
        !            57: // Misc Output Register values
        !            58: #define        MISC_OUTPUT_PORT        0x3C2
        !            59: #define        FEAT_CNTRL_PORT         0x3da
        !            60: #define VGA_MISC_CNT           2
        !            61: static const unsigned char miscOutData[VGA_MISC_CNT] = {
        !            62:        0xe3,0, /* VGA_MODE_S12 */
        !            63: };
        !            64: 
        !            65: // Sequencer Data
        !            66: #define        VGA_SEQ_CNT     5
        !            67: 
        !            68: static const unsigned char sequencerData[VGA_SEQ_CNT] = {
        !            69:      0x03, 0x21, 0x0f, 0x00, 0x06      // VGA_MODE_S12
        !            70: };
        !            71: 
        !            72: #define        VGA_CRT_CNT     25
        !            73: 
        !            74: static const unsigned char crtData[VGA_CRT_CNT] = {
        !            75:         0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0x0b, 0x3e, 0x00, 0x40,
        !            76:         0x00, 0x00, 0x00, 0x00, 0x00, 0x59, 0xea, 0x8c, 0xdf, 0x28,
        !            77:         0x00, 0xe7, 0x04, 0xe3, 0xff   // VGA_MODE_S12
        !            78: };
        !            79: 
        !            80: #define        VGA_ATR_CNT     21
        !            81: #define ATTR_INDEX     0x3C0
        !            82: #define ATTR_DATA      0x3C0
        !            83: static const unsigned char attrData[VGA_ATR_CNT] = {
        !            84:         0x00, 0x01, 0x02, 0x03,
        !            85:         0x00, 0x01, 0x02, 0x03,
        !            86:         0x00, 0x01, 0x02, 0x03,
        !            87:         0x00, 0x01, 0x02, 0x03,
        !            88:         0x01, 0x00,
        !            89:         0x03, 0x00, 0
        !            90:         //VGA_MODE_S12
        !            91: };
        !            92: 
        !            93: #define        VGA_GFX_CNT     9
        !            94: #define GC_INDEX       0x3CE
        !            95: #define GC_DATA                0x3CF
        !            96: static const unsigned char gfxData[VGA_GFX_CNT] = {
        !            97:     0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0f, 0xff,      // VGA_MODE_S12
        !            98: };
        !            99: 
        !           100: #define VGA_PALETTE_REG                0x3C8
        !           101: #define VGA_PALETTE_DATA       0x3C9
        !           102: #define VGA_NUM_COLORS         16
        !           103: static const unsigned char paletteVals[VGA_NUM_COLORS][3] = {
        !           104:        {0,0,0},        // 0 black
        !           105:        {21, 21, 21},   // 1 dark gray
        !           106:        {42, 42, 42},   // 2 light gray
        !           107:        {63, 63, 63},   // 3 white
        !           108:        {0,0,0},        // 0 black
        !           109:        {21, 21, 21},   // 1 dark gray
        !           110:        {42, 42, 42},   // 2 light gray
        !           111:        {63, 63, 63},   // 3 white
        !           112:        {0,0,0},        // 0 black
        !           113:        {21, 21, 21},   // 1 dark gray
        !           114:        {42, 42, 42},   // 2 light gray
        !           115:        {63, 63, 63},   // 3 white
        !           116:        {0,0,0},        // 0 black
        !           117:        {21, 21, 21},   // 1 dark gray
        !           118:        {42, 42, 42},   // 2 light gray
        !           119:        {63, 63, 63},   // 3 white
        !           120: };
        !           121: 
        !           122: static inline void setColorReg(int reg, int red, int green, int blue)
        !           123: {
        !           124:        outb(VGA_PALETTE_REG, reg);     // VGA select color palette reg
        !           125:        DELAY(10);
        !           126:        outb(VGA_PALETTE_DATA, red);    // VGA now prepared to accept each color
        !           127:        DELAY(10);
        !           128:        outb(VGA_PALETTE_DATA, green);
        !           129:        DELAY(10);
        !           130:        outb(VGA_PALETTE_DATA, blue);
        !           131:        DELAY(10);
        !           132: }
        !           133: 
        !           134: static void setVGAcolors()
        !           135: {
        !           136:        int i, index;
        !           137:        // set the palette registers to something nice
        !           138:        for (i = 0; i < VGA_NUM_COLORS; i++)
        !           139:        {
        !           140:            index = i % 4;
        !           141:            setColorReg(i, paletteVals[index][0],
        !           142:                           paletteVals[index][1],
        !           143:                           paletteVals[index][2]);
        !           144:        }
        !           145: }
        !           146: 
        !           147: extern void bzero(void *, int);
        !           148: extern void memset(void *, unsigned char, int);
        !           149: 
        !           150: int VGASetGraphicsMode(void)
        !           151: // Description:        Sets the standard VGA registers based on the supplied mode.
        !           152: //             This code is pretty generic, maybe we should break it out
        !           153: //             as a standard utility routine.
        !           154: {
        !           155:     unsigned int i;
        !           156:     
        !           157:     // NOTE: The attribute registers are a little wierd. Normally there is a
        !           158:     // separate index and data port. The attribute register set has just
        !           159:     // one port that gets used for both. You write an index to the port then
        !           160:     // use the same port for data. The VGA automatically toggles the sense
        !           161:     // of the port (between index and data) with an internal flip-flop.
        !           162:     // You set the state of the flip-flop by doing an in() on the input
        !           163:     // status 1 port - I know its hokey, but thats the way it works...
        !           164:     // MORE: The other weird thing is that the attribute index register also
        !           165:     // contains a palette access bit. This bit determines whether the CPU or
        !           166:     // the VGA has control of the palette. While the CPU owns the palette, the
        !           167:     // display is effectively off.
        !           168: 
        !           169:     // Turn the video off while we are doing this...
        !           170:     outb(VGA_SEQ_ADDR, 1);
        !           171:     outb(VGA_SEQ_DATA, sequencerData[1]);
        !           172:     
        !           173:     inb(INPUT_STATUS_1);       // Set the attribute flip-flop to "index"
        !           174:     outb(ATTR_INDEX, 0x00);    // Gives palette to CPU, turning off video
        !           175: //    outb(ATTR_DATA, attrData[0]);
        !           176: 
        !           177:     // Set the misc. output register
        !           178:     outb(MISC_OUTPUT_PORT, miscOutData[0]);
        !           179:     
        !           180:     // Set the feature control register
        !           181:     outb(FEAT_CNTRL_PORT, miscOutData[1]);
        !           182: 
        !           183:     // Load the sequencer registers
        !           184:     for (i = 0; i < VGA_SEQ_CNT; i++)
        !           185:     {
        !           186:        outb(VGA_SEQ_ADDR, i);
        !           187:        outb(VGA_SEQ_DATA, sequencerData[i]);
        !           188:     }
        !           189: 
        !           190:     outb(VGA_SEQ_ADDR, 0x00);
        !           191:     outb(VGA_SEQ_DATA, 0x03);  // Low order two bits are reset bits
        !           192: 
        !           193:     // Load the CRTC registers
        !           194:     // CRTC registers 0-7 are locked by a bit in register 0x11. We need
        !           195:     // to unlock these registers before we can start setting them.
        !           196:     outb(VGA_CRTC_ADDR, 0x11);
        !           197:     outb(VGA_CRTC_DATA, 0x00); // Unlocks registers 0-7
        !           198:     for (i = 0; i < VGA_CRT_CNT; i++)
        !           199:     {
        !           200:        outb(VGA_CRTC_ADDR, i);
        !           201:        outb(VGA_CRTC_DATA, crtData[i]);
        !           202:     }
        !           203: 
        !           204: 
        !           205:     inb(INPUT_STATUS_1);       // Set the attribute flip-flop to "index"
        !           206:     // Load the attribute registers
        !           207:     for (i = 0; i < VGA_ATR_CNT; i++)
        !           208:     {
        !           209:        outb(ATTR_INDEX, i);
        !           210:        outb(ATTR_DATA, attrData[i]);
        !           211:     }
        !           212: 
        !           213: 
        !           214:     // Load graphics registers
        !           215:     for (i = 0; i < VGA_GFX_CNT; i++)
        !           216:     {
        !           217:        outb(GC_INDEX, i);
        !           218:        outb(GC_DATA, gfxData[i]);
        !           219:     }    
        !           220: 
        !           221:     setVGAcolors();
        !           222: 
        !           223:     // Clear display memory
        !           224:     // FIXME -- should ensure memory mapping here
        !           225:     // (this is relying on a straight physical-to-virtual mapping)
        !           226:     memset(VGA_ADDR, 0x01, VGA_LENGTH);
        !           227:     
        !           228:     // Re-enable video
        !           229:     inb(INPUT_STATUS_1);       // Set the attribute flip-flop to "index"
        !           230:     outb(ATTR_INDEX, 0x20);    // Give the palette back to the VGA
        !           231: //    outb(ATTR_DATA, attrData[0]);
        !           232: 
        !           233:     // Really re-enable video.
        !           234:     outb(VGA_SEQ_ADDR, 1);
        !           235:     outb(VGA_SEQ_DATA, ((sequencerData[1]) & (~0x20)));
        !           236: 
        !           237:     return 0;
        !           238: }
        !           239: 
        !           240: 
        !           241: IOConsoleInfo *BasicAllocateConsole()
        !           242: {
        !           243:     IODisplayInfo di;
        !           244:     KERNBOOTSTRUCT *kernbootstruct = KERNSTRUCT_ADDR;
        !           245:     
        !           246:     bzero(&di, sizeof(di));
        !           247:     di.width = 640;
        !           248:     di.height = 480;
        !           249:     return( VGAAllocateConsole(&di) );
        !           250: }
        !           251: 

unix.superglobalmegacorp.com

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