ega.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2001-2004 Jakub Jermar
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00035 #include <arch/drivers/ega.h>
00036 #include <putchar.h>
00037 #include <mm/page.h>
00038 #include <mm/as.h>
00039 #include <arch/mm/page.h>
00040 #include <synch/spinlock.h>
00041 #include <arch/types.h>
00042 #include <arch/asm.h>
00043 #include <memstr.h>
00044 #include <console/chardev.h>
00045 #include <console/console.h>
00046 #include <sysinfo/sysinfo.h>
00047 
00048 /*
00049  * The EGA driver.
00050  * Simple and short. Function for displaying characters and "scrolling".
00051  */
00052 
00053 SPINLOCK_INITIALIZE(egalock);
00054 static __u32 ega_cursor;
00055 static __u8 *videoram;
00056 
00057 static void ega_putchar(chardev_t *d, const char ch);
00058 
00059 chardev_t ega_console;
00060 static chardev_operations_t ega_ops = {
00061         .write = ega_putchar
00062 };
00063 
00064 void ega_move_cursor(void);
00065 
00066 void ega_init(void)
00067 {
00068         __u8 hi, lo;
00069         
00070         videoram = (__u8 *) hw_map(VIDEORAM, SCREEN * 2);
00071         outb(0x3d4, 0xe);
00072         hi = inb(0x3d5);
00073         outb(0x3d4, 0xf);
00074         lo = inb(0x3d5);
00075         ega_cursor = (hi << 8) | lo;
00076 
00077         chardev_initialize("ega_out", &ega_console, &ega_ops);
00078         stdout = &ega_console;
00079         
00080         sysinfo_set_item_val("fb", NULL, true);
00081         sysinfo_set_item_val("fb.kind", NULL, 2);
00082         sysinfo_set_item_val("fb.width", NULL, ROW);
00083         sysinfo_set_item_val("fb.height", NULL, ROWS);
00084         sysinfo_set_item_val("fb.address.physical", NULL, VIDEORAM);
00085         
00086 #ifndef CONFIG_FB
00087         putchar('\n');
00088 #endif  
00089 }
00090 
00091 static void ega_display_char(char ch)
00092 {
00093         videoram[ega_cursor * 2] = ch;
00094 }
00095 
00096 /*
00097  * This function takes care of scrolling.
00098  */
00099 static void ega_check_cursor(void)
00100 {
00101         if (ega_cursor < SCREEN)
00102                 return;
00103 
00104         memcpy((void *) videoram, (void *) (videoram + ROW * 2), (SCREEN - ROW) * 2);
00105         memsetw((__address) (videoram + (SCREEN - ROW) * 2), ROW, 0x0720);
00106         ega_cursor = ega_cursor - ROW;
00107 }
00108 
00109 void ega_putchar(chardev_t *d, const char ch)
00110 {
00111         ipl_t ipl;
00112 
00113         ipl = interrupts_disable();
00114         spinlock_lock(&egalock);
00115 
00116         switch (ch) {
00117                 case '\n':
00118                         ega_cursor = (ega_cursor + ROW) - ega_cursor % ROW;
00119                         break;
00120                 case '\t':
00121                         ega_cursor = (ega_cursor + 8) - ega_cursor % 8;
00122                         break; 
00123                 case '\b':
00124                         if (ega_cursor % ROW)
00125                                 ega_cursor--;
00126                         break;
00127                 default:
00128                         ega_display_char(ch);
00129                         ega_cursor++;
00130                         break;
00131         }
00132         ega_check_cursor();
00133         ega_move_cursor();
00134 
00135         spinlock_unlock(&egalock);
00136         interrupts_restore(ipl);
00137 }
00138 
00139 void ega_move_cursor(void)
00140 {
00141         outb(0x3d4, 0xe);
00142         outb(0x3d5, (ega_cursor >> 8) & 0xff);
00143         outb(0x3d4, 0xf);
00144         outb(0x3d5, ega_cursor & 0xff); 
00145 }
00146 

Generated on Sun Jun 18 16:38:50 2006 for HelenOS Kernel (ia32) by  doxygen 1.4.6