00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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
00050
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
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