2 * Text console checksum and rendering functions
3 * NetWatch system management mode administration console
5 * Copyright (c) 2008 Jacob Potter and Joshua Wise. All rights reserved.
6 * This program is free software; you can redistribute and/or modify it under
7 * the terms found in the file LICENSE in the root of this source tree.
19 #include <video_defines.h>
21 static unsigned char _font[256 * 32];
23 /* XXX reunify this with vga-overlay? */
24 #define VRAM_BASE 0xA0000UL
25 #define TEXT_CONSOLE_OFFSET 0x18000UL
27 #define TEXT_CONSOLE_BASE (VRAM_BASE + TEXT_CONSOLE_OFFSET)
29 static unsigned char vga_read(unsigned char idx)
31 outb(CRTC_IDX_REG, idx);
32 return inb(CRTC_DATA_REG);
35 static char * vga_base()
39 + (((unsigned int) vga_read(CRTC_START_ADDR_MSB_IDX)) << 9)
40 + (((unsigned int) vga_read(CRTC_START_ADDR_LSB_IDX)) << 1)
44 /* Must be called from a firstrun context, where we don't care about saving
48 unsigned char oldread;
50 smram_state_t old_state = smram_save_state();
51 outb(0x3CE, 0x06 /* Miscellaneous */);
53 outb(0x3C4, 0x04 /* Seq memory mode */);
54 outb(0x3C5, inb(0x3C5) | 0x04);
55 outb(0x3CE, 0x05 /* Mode */);
56 outb(0x3CF, inb(0x3CF) & ~0x10);
57 outb(0x3CE, 0x04 /* Read register */);
59 outb(0x3CF, 0x02 /* Font plane */);
61 smram_aseg_set_state(SMRAM_ASEG_SMMCODE);
62 memcpy(_font, p2v(0xB8000), sizeof(_font));
63 smram_restore_state(old_state);
66 outb(0x3CE, 0x06 /* Miscellaneous */);
68 outb(0x3CE, 0x05 /* Mode */);
69 outb(0x3CF, inb(0x3CF) | 0x10);
70 outb(0x3C4, 0x04 /* Seq memory mode */);
71 outb(0x3C5, inb(0x3C5) & ~0x04);
74 void text_render(char *buf, int x, int y, int w, int h)
76 unsigned char *video = (unsigned char *)vga_base();
77 unsigned int textx = x / 9;
78 unsigned int texty = y / 16;
80 unsigned char ch, at, font;
81 smram_state_t old_state = smram_save_state();
83 outputf("text_render: (%d,%d),(%d,%d)", x, y, w, h);
85 smram_aseg_set_state(SMRAM_ASEG_SMMCODE);
86 for (cy = y; cy < (y + h); cy++)
91 ch = video[texty * 160 + textx * 2];
92 at = video[texty * 160 + textx * 2 + 1];
93 font = _font[ch * 32 + cy % 16];
94 for (cx = x; cx < (x + w); cx++)
96 unsigned int pos = cx % 8;
100 ch = video[texty * 160 + textx * 2];
101 at = video[texty * 160 + textx * 2 + 1];
102 font = _font[ch * 32 + cy % 16];
104 /* XXX always BGR888 */
105 if (pos == 8) /* 9th pixel is cloned */
107 if ((font >> (7 - pos)) & 1)
109 *(buf++) = (at & 0x01) ? 0xFF : 0x00;
110 *(buf++) = (at & 0x02) ? 0xFF : 0x00;
111 *(buf++) = (at & 0x04) ? 0xFF : 0x00;
113 *(buf++) = (at & 0x10) ? 0xFF : 0x00;
114 *(buf++) = (at & 0x20) ? 0xFF : 0x00;
115 *(buf++) = (at & 0x40) ? 0xFF : 0x00;
120 smram_restore_state(old_state);
123 uint32_t text_checksum(int x, int y, int w, int h)
125 unsigned char *video = (unsigned char *)vga_base();
126 unsigned int textx = x / 8;
127 unsigned int texty = y / 16;
130 smram_state_t old_state = smram_save_state();
132 smram_aseg_set_state(SMRAM_ASEG_SMMCODE);
134 for (cy = y; cy < (y + h); cy++)
139 cksm = crc32(video + texty * 160 + textx * 2, (w / 8) * 2 + 2, cksm); /* Err on the side of 'too many'. */
142 smram_restore_state(old_state);