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