[f761f1eb] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2001-2004 Jakub Jermar
|
---|
[f761f1eb] | 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
[9979acb] | 29 | /** @addtogroup genarch_drivers
|
---|
[b45c443] | 30 | * @{
|
---|
| 31 | */
|
---|
[3c5006a0] | 32 | /**
|
---|
| 33 | * @file
|
---|
| 34 | * @brief EGA driver.
|
---|
[b45c443] | 35 | */
|
---|
| 36 |
|
---|
[f245145] | 37 | #include <genarch/drivers/ega/ega.h>
|
---|
[f761f1eb] | 38 | #include <putchar.h>
|
---|
| 39 | #include <mm/page.h>
|
---|
[fc1e4f6] | 40 | #include <mm/as.h>
|
---|
[9a63657] | 41 | #include <mm/slab.h>
|
---|
[b07769b6] | 42 | #include <arch/mm/page.h>
|
---|
[d99c1d2] | 43 | #include <typedefs.h>
|
---|
[f761f1eb] | 44 | #include <arch/asm.h>
|
---|
[9c0a9b3] | 45 | #include <memstr.h>
|
---|
[19f857a] | 46 | #include <str.h>
|
---|
[973be64e] | 47 | #include <console/chardev.h>
|
---|
| 48 | #include <console/console.h>
|
---|
[018f95a] | 49 | #include <sysinfo/sysinfo.h>
|
---|
[f8ddd17] | 50 | #include <ddi/ddi.h>
|
---|
[f761f1eb] | 51 |
|
---|
| 52 | /*
|
---|
| 53 | * The EGA driver.
|
---|
| 54 | * Simple and short. Function for displaying characters and "scrolling".
|
---|
| 55 | */
|
---|
| 56 |
|
---|
[a0e1b48] | 57 | #define SPACE 0x20
|
---|
[accc088] | 58 | #define STYLE 0x1e
|
---|
| 59 | #define INVAL 0x17
|
---|
[5d9d9a9] | 60 |
|
---|
[accc088] | 61 | #define EMPTY_CHAR ((STYLE << 8) | SPACE)
|
---|
| 62 |
|
---|
[a71c158] | 63 | typedef struct {
|
---|
[c263c77] | 64 | IRQ_SPINLOCK_DECLARE(lock);
|
---|
[a71c158] | 65 |
|
---|
[b366a6f4] | 66 | parea_t parea;
|
---|
| 67 |
|
---|
[a71c158] | 68 | uint32_t cursor;
|
---|
| 69 | uint8_t *addr;
|
---|
| 70 | uint8_t *backbuf;
|
---|
| 71 | ioport8_t *base;
|
---|
| 72 | } ega_instance_t;
|
---|
| 73 |
|
---|
[b366a6f4] | 74 | static void ega_putchar(outdev_t *, wchar_t);
|
---|
[da1bafb] | 75 | static void ega_redraw(outdev_t *);
|
---|
[a71c158] | 76 |
|
---|
| 77 | static outdev_operations_t egadev_ops = {
|
---|
| 78 | .write = ega_putchar,
|
---|
| 79 | .redraw = ega_redraw
|
---|
| 80 | };
|
---|
| 81 |
|
---|
[accc088] | 82 | static uint16_t ega_oem_glyph(const wchar_t ch)
|
---|
| 83 | {
|
---|
| 84 | if ((ch >= 0x0000) && (ch <= 0x007f))
|
---|
| 85 | return ch;
|
---|
| 86 |
|
---|
| 87 | if (ch == 0x00a0)
|
---|
| 88 | return 255;
|
---|
| 89 |
|
---|
| 90 | if (ch == 0x00a1)
|
---|
| 91 | return 173;
|
---|
| 92 |
|
---|
| 93 | if ((ch >= 0x00a2) && (ch <= 0x00a3))
|
---|
| 94 | return (ch - 7);
|
---|
| 95 |
|
---|
| 96 | if (ch == 0x00a5)
|
---|
| 97 | return 157;
|
---|
| 98 |
|
---|
| 99 | if (ch == 0x00aa)
|
---|
| 100 | return 166;
|
---|
| 101 |
|
---|
| 102 | if (ch == 0x00ab)
|
---|
| 103 | return 174;
|
---|
| 104 |
|
---|
| 105 | if (ch == 0x00ac)
|
---|
| 106 | return 170;
|
---|
| 107 |
|
---|
| 108 | if (ch == 0x00b0)
|
---|
| 109 | return 248;
|
---|
| 110 |
|
---|
| 111 | if (ch == 0x00b1)
|
---|
| 112 | return 241;
|
---|
| 113 |
|
---|
| 114 | if (ch == 0x00b2)
|
---|
| 115 | return 253;
|
---|
| 116 |
|
---|
| 117 | if (ch == 0x00b5)
|
---|
| 118 | return 230;
|
---|
| 119 |
|
---|
| 120 | if (ch == 0x00b7)
|
---|
| 121 | return 250;
|
---|
| 122 |
|
---|
| 123 | if (ch == 0x00ba)
|
---|
| 124 | return 167;
|
---|
| 125 |
|
---|
| 126 | if (ch == 0x00bb)
|
---|
| 127 | return 175;
|
---|
| 128 |
|
---|
| 129 | if (ch == 0x00bc)
|
---|
| 130 | return 172;
|
---|
| 131 |
|
---|
| 132 | if (ch == 0x00bd)
|
---|
| 133 | return 171;
|
---|
| 134 |
|
---|
| 135 | if (ch == 0x00bf)
|
---|
| 136 | return 168;
|
---|
| 137 |
|
---|
| 138 | if ((ch >= 0x00c4) && (ch <= 0x00c5))
|
---|
| 139 | return (ch - 54);
|
---|
| 140 |
|
---|
| 141 | if (ch == 0x00c6)
|
---|
| 142 | return 146;
|
---|
| 143 |
|
---|
| 144 | if (ch == 0x00c7)
|
---|
| 145 | return 128;
|
---|
| 146 |
|
---|
| 147 | if (ch == 0x00c9)
|
---|
| 148 | return 144;
|
---|
| 149 |
|
---|
| 150 | if (ch == 0x00d1)
|
---|
| 151 | return 165;
|
---|
| 152 |
|
---|
| 153 | if (ch == 0x00d6)
|
---|
| 154 | return 153;
|
---|
| 155 |
|
---|
| 156 | if (ch == 0x00dc)
|
---|
| 157 | return 154;
|
---|
| 158 |
|
---|
| 159 | if (ch == 0x00df)
|
---|
| 160 | return 225;
|
---|
| 161 |
|
---|
| 162 | if (ch == 0x00e0)
|
---|
| 163 | return 133;
|
---|
| 164 |
|
---|
| 165 | if (ch == 0x00e1)
|
---|
| 166 | return 160;
|
---|
| 167 |
|
---|
| 168 | if (ch == 0x00e2)
|
---|
| 169 | return 131;
|
---|
| 170 |
|
---|
| 171 | if (ch == 0x00e4)
|
---|
| 172 | return 132;
|
---|
| 173 |
|
---|
| 174 | if (ch == 0x00e5)
|
---|
| 175 | return 134;
|
---|
| 176 |
|
---|
| 177 | if (ch == 0x00e6)
|
---|
| 178 | return 145;
|
---|
| 179 |
|
---|
| 180 | if (ch == 0x00e7)
|
---|
| 181 | return 135;
|
---|
| 182 |
|
---|
| 183 | if (ch == 0x00e8)
|
---|
| 184 | return 138;
|
---|
| 185 |
|
---|
| 186 | if (ch == 0x00e9)
|
---|
| 187 | return 130;
|
---|
| 188 |
|
---|
| 189 | if ((ch >= 0x00ea) && (ch <= 0x00eb))
|
---|
| 190 | return (ch - 98);
|
---|
| 191 |
|
---|
| 192 | if (ch == 0x00ec)
|
---|
| 193 | return 141;
|
---|
| 194 |
|
---|
| 195 | if (ch == 0x00ed)
|
---|
| 196 | return 161;
|
---|
| 197 |
|
---|
| 198 | if (ch == 0x00ee)
|
---|
| 199 | return 140;
|
---|
| 200 |
|
---|
| 201 | if (ch == 0x00ef)
|
---|
| 202 | return 139;
|
---|
| 203 |
|
---|
| 204 | if (ch == 0x00f1)
|
---|
| 205 | return 164;
|
---|
| 206 |
|
---|
| 207 | if (ch == 0x00f2)
|
---|
| 208 | return 149;
|
---|
| 209 |
|
---|
| 210 | if (ch == 0x00f3)
|
---|
| 211 | return 162;
|
---|
| 212 |
|
---|
| 213 | if (ch == 0x00f4)
|
---|
| 214 | return 147;
|
---|
| 215 |
|
---|
| 216 | if (ch == 0x00f6)
|
---|
| 217 | return 148;
|
---|
| 218 |
|
---|
| 219 | if (ch == 0x00f7)
|
---|
| 220 | return 246;
|
---|
| 221 |
|
---|
| 222 | if (ch == 0x00f9)
|
---|
| 223 | return 151;
|
---|
| 224 |
|
---|
| 225 | if (ch == 0x00fa)
|
---|
| 226 | return 163;
|
---|
| 227 |
|
---|
| 228 | if (ch == 0x00fb)
|
---|
| 229 | return 150;
|
---|
| 230 |
|
---|
| 231 | if (ch == 0x00fc)
|
---|
| 232 | return 129;
|
---|
| 233 |
|
---|
| 234 | if (ch == 0x00ff)
|
---|
| 235 | return 152;
|
---|
| 236 |
|
---|
| 237 | if (ch == 0x0192)
|
---|
| 238 | return 159;
|
---|
| 239 |
|
---|
| 240 | if (ch == 0x0393)
|
---|
| 241 | return 226;
|
---|
| 242 |
|
---|
| 243 | if (ch == 0x0398)
|
---|
| 244 | return 233;
|
---|
| 245 |
|
---|
| 246 | if (ch == 0x03a3)
|
---|
| 247 | return 228;
|
---|
| 248 |
|
---|
| 249 | if (ch == 0x03a6)
|
---|
| 250 | return 232;
|
---|
| 251 |
|
---|
| 252 | if (ch == 0x03a9)
|
---|
| 253 | return 234;
|
---|
| 254 |
|
---|
| 255 | if (ch == 0x03b1)
|
---|
| 256 | return 224;
|
---|
| 257 |
|
---|
| 258 | if (ch == 0x03b4)
|
---|
| 259 | return 235;
|
---|
| 260 |
|
---|
| 261 | if (ch == 0x03b5)
|
---|
| 262 | return 238;
|
---|
| 263 |
|
---|
| 264 | if (ch == 0x03c0)
|
---|
| 265 | return 227;
|
---|
| 266 |
|
---|
| 267 | if (ch == 0x03c3)
|
---|
| 268 | return 229;
|
---|
| 269 |
|
---|
| 270 | if (ch == 0x03c4)
|
---|
| 271 | return 231;
|
---|
| 272 |
|
---|
| 273 | if (ch == 0x03c6)
|
---|
| 274 | return 237;
|
---|
| 275 |
|
---|
| 276 | if (ch == 0x207f)
|
---|
| 277 | return 252;
|
---|
| 278 |
|
---|
| 279 | if (ch == 0x20a7)
|
---|
| 280 | return 158;
|
---|
| 281 |
|
---|
| 282 | if (ch == 0x2219)
|
---|
| 283 | return 249;
|
---|
| 284 |
|
---|
| 285 | if (ch == 0x221a)
|
---|
| 286 | return 251;
|
---|
| 287 |
|
---|
| 288 | if (ch == 0x221e)
|
---|
| 289 | return 236;
|
---|
| 290 |
|
---|
| 291 | if (ch == 0x2229)
|
---|
| 292 | return 239;
|
---|
| 293 |
|
---|
| 294 | if (ch == 0x2248)
|
---|
| 295 | return 247;
|
---|
| 296 |
|
---|
| 297 | if (ch == 0x2261)
|
---|
| 298 | return 240;
|
---|
| 299 |
|
---|
| 300 | if (ch == 0x2264)
|
---|
| 301 | return 243;
|
---|
| 302 |
|
---|
| 303 | if (ch == 0x2265)
|
---|
| 304 | return 242;
|
---|
| 305 |
|
---|
| 306 | if (ch == 0x2310)
|
---|
| 307 | return 169;
|
---|
| 308 |
|
---|
| 309 | if ((ch >= 0x2320) && (ch <= 0x2321))
|
---|
| 310 | return (ch - 8748);
|
---|
| 311 |
|
---|
| 312 | if (ch == 0x2500)
|
---|
| 313 | return 196;
|
---|
| 314 |
|
---|
| 315 | if (ch == 0x2502)
|
---|
| 316 | return 179;
|
---|
| 317 |
|
---|
| 318 | if (ch == 0x250c)
|
---|
| 319 | return 218;
|
---|
| 320 |
|
---|
| 321 | if (ch == 0x2510)
|
---|
| 322 | return 191;
|
---|
| 323 |
|
---|
| 324 | if (ch == 0x2514)
|
---|
| 325 | return 192;
|
---|
| 326 |
|
---|
| 327 | if (ch == 0x2518)
|
---|
| 328 | return 217;
|
---|
| 329 |
|
---|
| 330 | if (ch == 0x251c)
|
---|
| 331 | return 195;
|
---|
| 332 |
|
---|
| 333 | if (ch == 0x2524)
|
---|
| 334 | return 180;
|
---|
| 335 |
|
---|
| 336 | if (ch == 0x252c)
|
---|
| 337 | return 194;
|
---|
| 338 |
|
---|
| 339 | if (ch == 0x2534)
|
---|
| 340 | return 193;
|
---|
| 341 |
|
---|
| 342 | if (ch == 0x253c)
|
---|
| 343 | return 197;
|
---|
| 344 |
|
---|
| 345 | if (ch == 0x2550)
|
---|
| 346 | return 205;
|
---|
| 347 |
|
---|
| 348 | if (ch == 0x2551)
|
---|
| 349 | return 186;
|
---|
| 350 |
|
---|
| 351 | if ((ch >= 0x2552) && (ch <= 0x2553))
|
---|
| 352 | return (ch - 9341);
|
---|
| 353 |
|
---|
| 354 | if (ch == 0x2554)
|
---|
| 355 | return 201;
|
---|
| 356 |
|
---|
| 357 | if (ch == 0x2555)
|
---|
| 358 | return 184;
|
---|
| 359 |
|
---|
| 360 | if (ch == 0x2556)
|
---|
| 361 | return 183;
|
---|
| 362 |
|
---|
| 363 | if (ch == 0x2557)
|
---|
| 364 | return 187;
|
---|
| 365 |
|
---|
| 366 | if (ch == 0x2558)
|
---|
| 367 | return 212;
|
---|
| 368 |
|
---|
| 369 | if (ch == 0x2559)
|
---|
| 370 | return 211;
|
---|
| 371 |
|
---|
| 372 | if (ch == 0x255a)
|
---|
| 373 | return 200;
|
---|
| 374 |
|
---|
| 375 | if (ch == 0x255b)
|
---|
| 376 | return 190;
|
---|
| 377 |
|
---|
| 378 | if (ch == 0x255c)
|
---|
| 379 | return 189;
|
---|
| 380 |
|
---|
| 381 | if (ch == 0x255d)
|
---|
| 382 | return 188;
|
---|
| 383 |
|
---|
| 384 | if ((ch >= 0x255e) && (ch <= 0x255f))
|
---|
| 385 | return (ch - 9368);
|
---|
| 386 |
|
---|
| 387 | if (ch == 0x2560)
|
---|
| 388 | return 204;
|
---|
| 389 |
|
---|
| 390 | if ((ch >= 0x2561) && (ch <= 0x2562))
|
---|
| 391 | return (ch - 9388);
|
---|
| 392 |
|
---|
| 393 | if (ch == 0x2563)
|
---|
| 394 | return 185;
|
---|
| 395 |
|
---|
| 396 | if ((ch >= 0x2564) && (ch <= 0x2565))
|
---|
| 397 | return (ch - 9363);
|
---|
| 398 |
|
---|
| 399 | if (ch == 0x2566)
|
---|
| 400 | return 203;
|
---|
| 401 |
|
---|
| 402 | if ((ch >= 0x2567) && (ch <= 0x2568))
|
---|
| 403 | return (ch - 9368);
|
---|
| 404 |
|
---|
| 405 | if (ch == 0x2569)
|
---|
| 406 | return 202;
|
---|
| 407 |
|
---|
| 408 | if (ch == 0x256a)
|
---|
| 409 | return 216;
|
---|
| 410 |
|
---|
| 411 | if (ch == 0x256b)
|
---|
| 412 | return 215;
|
---|
| 413 |
|
---|
| 414 | if (ch == 0x256c)
|
---|
| 415 | return 206;
|
---|
| 416 |
|
---|
| 417 | if (ch == 0x2580)
|
---|
| 418 | return 223;
|
---|
| 419 |
|
---|
| 420 | if (ch == 0x2584)
|
---|
| 421 | return 220;
|
---|
| 422 |
|
---|
| 423 | if (ch == 0x2588)
|
---|
| 424 | return 219;
|
---|
| 425 |
|
---|
| 426 | if (ch == 0x258c)
|
---|
| 427 | return 221;
|
---|
| 428 |
|
---|
| 429 | if (ch == 0x2590)
|
---|
| 430 | return 222;
|
---|
| 431 |
|
---|
| 432 | if ((ch >= 0x2591) && (ch <= 0x2593))
|
---|
| 433 | return (ch - 9441);
|
---|
| 434 |
|
---|
| 435 | return 256;
|
---|
| 436 | }
|
---|
[f761f1eb] | 437 |
|
---|
| 438 | /*
|
---|
| 439 | * This function takes care of scrolling.
|
---|
| 440 | */
|
---|
[b366a6f4] | 441 | static void ega_check_cursor(ega_instance_t *instance)
|
---|
[f761f1eb] | 442 | {
|
---|
[a71c158] | 443 | if (instance->cursor < EGA_SCREEN)
|
---|
[76cec1e] | 444 | return;
|
---|
[5d9d9a9] | 445 |
|
---|
[a71c158] | 446 | memmove((void *) instance->backbuf,
|
---|
| 447 | (void *) (instance->backbuf + EGA_COLS * 2),
|
---|
[9979acb] | 448 | (EGA_SCREEN - EGA_COLS) * 2);
|
---|
[a71c158] | 449 | memsetw(instance->backbuf + (EGA_SCREEN - EGA_COLS) * 2,
|
---|
| 450 | EGA_COLS, EMPTY_CHAR);
|
---|
[d797054c] | 451 |
|
---|
[b366a6f4] | 452 | if ((!instance->parea.mapped) || (console_override)) {
|
---|
[a71c158] | 453 | memmove((void *) instance->addr,
|
---|
| 454 | (void *) (instance->addr + EGA_COLS * 2),
|
---|
[d797054c] | 455 | (EGA_SCREEN - EGA_COLS) * 2);
|
---|
[a71c158] | 456 | memsetw(instance->addr + (EGA_SCREEN - EGA_COLS) * 2,
|
---|
| 457 | EGA_COLS, EMPTY_CHAR);
|
---|
[d797054c] | 458 | }
|
---|
| 459 |
|
---|
[a71c158] | 460 | instance->cursor = instance->cursor - EGA_COLS;
|
---|
[f761f1eb] | 461 | }
|
---|
| 462 |
|
---|
[b366a6f4] | 463 | static void ega_show_cursor(ega_instance_t *instance)
|
---|
[c214a65] | 464 | {
|
---|
[b366a6f4] | 465 | if ((!instance->parea.mapped) || (console_override)) {
|
---|
[a71c158] | 466 | pio_write_8(instance->base + EGA_INDEX_REG, 0x0a);
|
---|
| 467 | uint8_t stat = pio_read_8(instance->base + EGA_DATA_REG);
|
---|
| 468 | pio_write_8(instance->base + EGA_INDEX_REG, 0x0a);
|
---|
| 469 | pio_write_8(instance->base + EGA_DATA_REG, stat & (~(1 << 5)));
|
---|
[d797054c] | 470 | }
|
---|
[c214a65] | 471 | }
|
---|
| 472 |
|
---|
[b366a6f4] | 473 | static void ega_move_cursor(ega_instance_t *instance)
|
---|
[f761f1eb] | 474 | {
|
---|
[b366a6f4] | 475 | if ((!instance->parea.mapped) || (console_override)) {
|
---|
[a71c158] | 476 | pio_write_8(instance->base + EGA_INDEX_REG, 0x0e);
|
---|
| 477 | pio_write_8(instance->base + EGA_DATA_REG,
|
---|
| 478 | (uint8_t) ((instance->cursor >> 8) & 0xff));
|
---|
| 479 | pio_write_8(instance->base + EGA_INDEX_REG, 0x0f);
|
---|
| 480 | pio_write_8(instance->base + EGA_DATA_REG,
|
---|
| 481 | (uint8_t) (instance->cursor & 0xff));
|
---|
[d797054c] | 482 | }
|
---|
[516ff92] | 483 | }
|
---|
| 484 |
|
---|
[b366a6f4] | 485 | static void ega_sync_cursor(ega_instance_t *instance)
|
---|
[c214a65] | 486 | {
|
---|
[b366a6f4] | 487 | if ((!instance->parea.mapped) || (console_override)) {
|
---|
[a71c158] | 488 | pio_write_8(instance->base + EGA_INDEX_REG, 0x0e);
|
---|
| 489 | uint8_t hi = pio_read_8(instance->base + EGA_DATA_REG);
|
---|
| 490 | pio_write_8(instance->base + EGA_INDEX_REG, 0x0f);
|
---|
| 491 | uint8_t lo = pio_read_8(instance->base + EGA_DATA_REG);
|
---|
[d797054c] | 492 |
|
---|
[a71c158] | 493 | instance->cursor = (hi << 8) | lo;
|
---|
[d797054c] | 494 | } else
|
---|
[a71c158] | 495 | instance->cursor = 0;
|
---|
[5d9d9a9] | 496 |
|
---|
[a71c158] | 497 | if (instance->cursor >= EGA_SCREEN)
|
---|
| 498 | instance->cursor = 0;
|
---|
[5d9d9a9] | 499 |
|
---|
[a71c158] | 500 | if ((instance->cursor % EGA_COLS) != 0)
|
---|
| 501 | instance->cursor =
|
---|
| 502 | (instance->cursor + EGA_COLS) - instance->cursor % EGA_COLS;
|
---|
[c214a65] | 503 |
|
---|
[a71c158] | 504 | memsetw(instance->backbuf + instance->cursor * 2,
|
---|
| 505 | EGA_SCREEN - instance->cursor, EMPTY_CHAR);
|
---|
[5d9d9a9] | 506 |
|
---|
[b366a6f4] | 507 | if ((!instance->parea.mapped) || (console_override))
|
---|
[a71c158] | 508 | memsetw(instance->addr + instance->cursor * 2,
|
---|
| 509 | EGA_SCREEN - instance->cursor, EMPTY_CHAR);
|
---|
[d797054c] | 510 |
|
---|
[b366a6f4] | 511 | ega_check_cursor(instance);
|
---|
| 512 | ega_move_cursor(instance);
|
---|
| 513 | ega_show_cursor(instance);
|
---|
[c214a65] | 514 | }
|
---|
| 515 |
|
---|
[b366a6f4] | 516 | static void ega_display_char(ega_instance_t *instance, wchar_t ch)
|
---|
[516ff92] | 517 | {
|
---|
[accc088] | 518 | uint16_t index = ega_oem_glyph(ch);
|
---|
| 519 | uint8_t glyph;
|
---|
| 520 | uint8_t style;
|
---|
| 521 |
|
---|
| 522 | if ((index >> 8)) {
|
---|
[c8bf88d] | 523 | glyph = U_SPECIAL;
|
---|
[accc088] | 524 | style = INVAL;
|
---|
| 525 | } else {
|
---|
| 526 | glyph = index & 0xff;
|
---|
| 527 | style = STYLE;
|
---|
| 528 | }
|
---|
| 529 |
|
---|
[a71c158] | 530 | instance->backbuf[instance->cursor * 2] = glyph;
|
---|
| 531 | instance->backbuf[instance->cursor * 2 + 1] = style;
|
---|
[516ff92] | 532 |
|
---|
[b366a6f4] | 533 | if ((!instance->parea.mapped) || (console_override)) {
|
---|
[a71c158] | 534 | instance->addr[instance->cursor * 2] = glyph;
|
---|
| 535 | instance->addr[instance->cursor * 2 + 1] = style;
|
---|
[a0e1b48] | 536 | }
|
---|
[516ff92] | 537 | }
|
---|
[f761f1eb] | 538 |
|
---|
[b366a6f4] | 539 | static void ega_putchar(outdev_t *dev, wchar_t ch)
|
---|
[516ff92] | 540 | {
|
---|
[a71c158] | 541 | ega_instance_t *instance = (ega_instance_t *) dev->data;
|
---|
[516ff92] | 542 |
|
---|
[c263c77] | 543 | irq_spinlock_lock(&instance->lock, true);
|
---|
[516ff92] | 544 |
|
---|
[f761f1eb] | 545 | switch (ch) {
|
---|
[6dbe6844] | 546 | case '\n':
|
---|
[a71c158] | 547 | instance->cursor = (instance->cursor + EGA_COLS)
|
---|
| 548 | - instance->cursor % EGA_COLS;
|
---|
[6dbe6844] | 549 | break;
|
---|
| 550 | case '\t':
|
---|
[a71c158] | 551 | instance->cursor = (instance->cursor + 8)
|
---|
| 552 | - instance->cursor % 8;
|
---|
[accc088] | 553 | break;
|
---|
[6dbe6844] | 554 | case '\b':
|
---|
[a71c158] | 555 | if (instance->cursor % EGA_COLS)
|
---|
| 556 | instance->cursor--;
|
---|
[6dbe6844] | 557 | break;
|
---|
| 558 | default:
|
---|
[b366a6f4] | 559 | ega_display_char(instance, ch);
|
---|
[a71c158] | 560 | instance->cursor++;
|
---|
[6dbe6844] | 561 | break;
|
---|
[018f95a] | 562 | }
|
---|
[b366a6f4] | 563 | ega_check_cursor(instance);
|
---|
| 564 | ega_move_cursor(instance);
|
---|
[516ff92] | 565 |
|
---|
[c263c77] | 566 | irq_spinlock_unlock(&instance->lock, true);
|
---|
[f761f1eb] | 567 | }
|
---|
| 568 |
|
---|
[a71c158] | 569 | static void ega_redraw(outdev_t *dev)
|
---|
[f761f1eb] | 570 | {
|
---|
[a71c158] | 571 | ega_instance_t *instance = (ega_instance_t *) dev->data;
|
---|
[516ff92] | 572 |
|
---|
[c263c77] | 573 | irq_spinlock_lock(&instance->lock, true);
|
---|
[516ff92] | 574 |
|
---|
[a71c158] | 575 | memcpy(instance->addr, instance->backbuf, EGA_VRAM_SIZE);
|
---|
[b366a6f4] | 576 | ega_move_cursor(instance);
|
---|
| 577 | ega_show_cursor(instance);
|
---|
[516ff92] | 578 |
|
---|
[c263c77] | 579 | irq_spinlock_unlock(&instance->lock, true);
|
---|
[f761f1eb] | 580 | }
|
---|
[b45c443] | 581 |
|
---|
[a71c158] | 582 | outdev_t *ega_init(ioport8_t *base, uintptr_t addr)
|
---|
[9a63657] | 583 | {
|
---|
[a71c158] | 584 | outdev_t *egadev = malloc(sizeof(outdev_t), FRAME_ATOMIC);
|
---|
| 585 | if (!egadev)
|
---|
| 586 | return NULL;
|
---|
| 587 |
|
---|
| 588 | ega_instance_t *instance = malloc(sizeof(ega_instance_t), FRAME_ATOMIC);
|
---|
| 589 | if (!instance) {
|
---|
| 590 | free(egadev);
|
---|
| 591 | return NULL;
|
---|
| 592 | }
|
---|
| 593 |
|
---|
| 594 | outdev_initialize("egadev", egadev, &egadev_ops);
|
---|
| 595 | egadev->data = instance;
|
---|
| 596 |
|
---|
[c263c77] | 597 | irq_spinlock_initialize(&instance->lock, "*ega.instance.lock");
|
---|
[a71c158] | 598 |
|
---|
| 599 | instance->base = base;
|
---|
| 600 | instance->addr = (uint8_t *) hw_map(addr, EGA_VRAM_SIZE);
|
---|
| 601 | if (!instance->addr) {
|
---|
| 602 | LOG("Unable to EGA video memory.");
|
---|
| 603 | free(instance);
|
---|
| 604 | free(egadev);
|
---|
| 605 | return NULL;
|
---|
| 606 | }
|
---|
| 607 |
|
---|
| 608 | instance->backbuf = (uint8_t *) malloc(EGA_VRAM_SIZE, 0);
|
---|
| 609 | if (!instance->backbuf) {
|
---|
| 610 | LOG("Unable to allocate backbuffer.");
|
---|
| 611 | free(instance);
|
---|
| 612 | free(egadev);
|
---|
| 613 | return NULL;
|
---|
| 614 | }
|
---|
| 615 |
|
---|
[b366a6f4] | 616 | link_initialize(&instance->parea.link);
|
---|
| 617 | instance->parea.pbase = addr;
|
---|
| 618 | instance->parea.frames = SIZE2FRAMES(EGA_VRAM_SIZE);
|
---|
| 619 | instance->parea.unpriv = false;
|
---|
| 620 | instance->parea.mapped = false;
|
---|
| 621 | ddi_parea_register(&instance->parea);
|
---|
| 622 |
|
---|
[a71c158] | 623 | /* Synchronize the back buffer and cursor position. */
|
---|
| 624 | memcpy(instance->backbuf, instance->addr, EGA_VRAM_SIZE);
|
---|
[b366a6f4] | 625 | ega_sync_cursor(instance);
|
---|
[a71c158] | 626 |
|
---|
| 627 | if (!fb_exported) {
|
---|
| 628 | /*
|
---|
[b366a6f4] | 629 | * We export the kernel framebuffer for uspace usage.
|
---|
| 630 | * This is used in the case the uspace framebuffer
|
---|
| 631 | * driver is not self-sufficient.
|
---|
[a71c158] | 632 | */
|
---|
| 633 | sysinfo_set_item_val("fb", NULL, true);
|
---|
| 634 | sysinfo_set_item_val("fb.kind", NULL, 2);
|
---|
| 635 | sysinfo_set_item_val("fb.width", NULL, EGA_COLS);
|
---|
| 636 | sysinfo_set_item_val("fb.height", NULL, EGA_ROWS);
|
---|
| 637 | sysinfo_set_item_val("fb.blinking", NULL, true);
|
---|
| 638 | sysinfo_set_item_val("fb.address.physical", NULL, addr);
|
---|
| 639 |
|
---|
| 640 | fb_exported = true;
|
---|
| 641 | }
|
---|
| 642 |
|
---|
| 643 | return egadev;
|
---|
[9a63657] | 644 | }
|
---|
| 645 |
|
---|
[3c5006a0] | 646 | /** @}
|
---|
[b45c443] | 647 | */
|
---|