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