1 | /*
|
---|
2 | * Copyright (c) 2001-2004 Jakub Jermar
|
---|
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 |
|
---|
29 | /** @addtogroup genarch_drivers
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /**
|
---|
33 | * @file
|
---|
34 | * @brief EGA driver.
|
---|
35 | */
|
---|
36 |
|
---|
37 | #include <genarch/drivers/ega/ega.h>
|
---|
38 | #include <putchar.h>
|
---|
39 | #include <mm/page.h>
|
---|
40 | #include <mm/as.h>
|
---|
41 | #include <mm/slab.h>
|
---|
42 | #include <arch/mm/page.h>
|
---|
43 | #include <typedefs.h>
|
---|
44 | #include <arch/asm.h>
|
---|
45 | #include <memstr.h>
|
---|
46 | #include <str.h>
|
---|
47 | #include <console/chardev.h>
|
---|
48 | #include <console/console.h>
|
---|
49 | #include <sysinfo/sysinfo.h>
|
---|
50 | #include <ddi/ddi.h>
|
---|
51 |
|
---|
52 | /*
|
---|
53 | * The EGA driver.
|
---|
54 | * Simple and short. Function for displaying characters and "scrolling".
|
---|
55 | */
|
---|
56 |
|
---|
57 | #define SPACE 0x20
|
---|
58 | #define STYLE 0x1e
|
---|
59 | #define INVAL 0x17
|
---|
60 |
|
---|
61 | #define EMPTY_CHAR ((STYLE << 8) | SPACE)
|
---|
62 |
|
---|
63 | typedef struct {
|
---|
64 | IRQ_SPINLOCK_DECLARE(lock);
|
---|
65 |
|
---|
66 | parea_t parea;
|
---|
67 |
|
---|
68 | uint32_t cursor;
|
---|
69 | uint8_t *addr;
|
---|
70 | uint8_t *backbuf;
|
---|
71 | ioport8_t *base;
|
---|
72 | } ega_instance_t;
|
---|
73 |
|
---|
74 | static void ega_putchar(outdev_t *, wchar_t);
|
---|
75 | static void ega_redraw(outdev_t *);
|
---|
76 |
|
---|
77 | static outdev_operations_t egadev_ops = {
|
---|
78 | .write = ega_putchar,
|
---|
79 | .redraw = ega_redraw
|
---|
80 | };
|
---|
81 |
|
---|
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 | }
|
---|
437 |
|
---|
438 | /*
|
---|
439 | * This function takes care of scrolling.
|
---|
440 | */
|
---|
441 | static void ega_check_cursor(ega_instance_t *instance)
|
---|
442 | {
|
---|
443 | if (instance->cursor < EGA_SCREEN)
|
---|
444 | return;
|
---|
445 |
|
---|
446 | memmove((void *) instance->backbuf,
|
---|
447 | (void *) (instance->backbuf + EGA_COLS * 2),
|
---|
448 | (EGA_SCREEN - EGA_COLS) * 2);
|
---|
449 | memsetw(instance->backbuf + (EGA_SCREEN - EGA_COLS) * 2,
|
---|
450 | EGA_COLS, EMPTY_CHAR);
|
---|
451 |
|
---|
452 | if ((!instance->parea.mapped) || (console_override)) {
|
---|
453 | memmove((void *) instance->addr,
|
---|
454 | (void *) (instance->addr + EGA_COLS * 2),
|
---|
455 | (EGA_SCREEN - EGA_COLS) * 2);
|
---|
456 | memsetw(instance->addr + (EGA_SCREEN - EGA_COLS) * 2,
|
---|
457 | EGA_COLS, EMPTY_CHAR);
|
---|
458 | }
|
---|
459 |
|
---|
460 | instance->cursor = instance->cursor - EGA_COLS;
|
---|
461 | }
|
---|
462 |
|
---|
463 | static void ega_show_cursor(ega_instance_t *instance)
|
---|
464 | {
|
---|
465 | if ((!instance->parea.mapped) || (console_override)) {
|
---|
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)));
|
---|
470 | }
|
---|
471 | }
|
---|
472 |
|
---|
473 | static void ega_move_cursor(ega_instance_t *instance)
|
---|
474 | {
|
---|
475 | if ((!instance->parea.mapped) || (console_override)) {
|
---|
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));
|
---|
482 | }
|
---|
483 | }
|
---|
484 |
|
---|
485 | static void ega_sync_cursor(ega_instance_t *instance)
|
---|
486 | {
|
---|
487 | if ((!instance->parea.mapped) || (console_override)) {
|
---|
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);
|
---|
492 |
|
---|
493 | instance->cursor = (hi << 8) | lo;
|
---|
494 | } else
|
---|
495 | instance->cursor = 0;
|
---|
496 |
|
---|
497 | if (instance->cursor >= EGA_SCREEN)
|
---|
498 | instance->cursor = 0;
|
---|
499 |
|
---|
500 | if ((instance->cursor % EGA_COLS) != 0)
|
---|
501 | instance->cursor =
|
---|
502 | (instance->cursor + EGA_COLS) - instance->cursor % EGA_COLS;
|
---|
503 |
|
---|
504 | memsetw(instance->backbuf + instance->cursor * 2,
|
---|
505 | EGA_SCREEN - instance->cursor, EMPTY_CHAR);
|
---|
506 |
|
---|
507 | if ((!instance->parea.mapped) || (console_override))
|
---|
508 | memsetw(instance->addr + instance->cursor * 2,
|
---|
509 | EGA_SCREEN - instance->cursor, EMPTY_CHAR);
|
---|
510 |
|
---|
511 | ega_check_cursor(instance);
|
---|
512 | ega_move_cursor(instance);
|
---|
513 | ega_show_cursor(instance);
|
---|
514 | }
|
---|
515 |
|
---|
516 | static void ega_display_char(ega_instance_t *instance, wchar_t ch)
|
---|
517 | {
|
---|
518 | uint16_t index = ega_oem_glyph(ch);
|
---|
519 | uint8_t glyph;
|
---|
520 | uint8_t style;
|
---|
521 |
|
---|
522 | if ((index >> 8)) {
|
---|
523 | glyph = U_SPECIAL;
|
---|
524 | style = INVAL;
|
---|
525 | } else {
|
---|
526 | glyph = index & 0xff;
|
---|
527 | style = STYLE;
|
---|
528 | }
|
---|
529 |
|
---|
530 | instance->backbuf[instance->cursor * 2] = glyph;
|
---|
531 | instance->backbuf[instance->cursor * 2 + 1] = style;
|
---|
532 |
|
---|
533 | if ((!instance->parea.mapped) || (console_override)) {
|
---|
534 | instance->addr[instance->cursor * 2] = glyph;
|
---|
535 | instance->addr[instance->cursor * 2 + 1] = style;
|
---|
536 | }
|
---|
537 | }
|
---|
538 |
|
---|
539 | static void ega_putchar(outdev_t *dev, wchar_t ch)
|
---|
540 | {
|
---|
541 | ega_instance_t *instance = (ega_instance_t *) dev->data;
|
---|
542 |
|
---|
543 | irq_spinlock_lock(&instance->lock, true);
|
---|
544 |
|
---|
545 | switch (ch) {
|
---|
546 | case '\n':
|
---|
547 | instance->cursor = (instance->cursor + EGA_COLS)
|
---|
548 | - instance->cursor % EGA_COLS;
|
---|
549 | break;
|
---|
550 | case '\t':
|
---|
551 | instance->cursor = (instance->cursor + 8)
|
---|
552 | - instance->cursor % 8;
|
---|
553 | break;
|
---|
554 | case '\b':
|
---|
555 | if (instance->cursor % EGA_COLS)
|
---|
556 | instance->cursor--;
|
---|
557 | break;
|
---|
558 | default:
|
---|
559 | ega_display_char(instance, ch);
|
---|
560 | instance->cursor++;
|
---|
561 | break;
|
---|
562 | }
|
---|
563 | ega_check_cursor(instance);
|
---|
564 | ega_move_cursor(instance);
|
---|
565 |
|
---|
566 | irq_spinlock_unlock(&instance->lock, true);
|
---|
567 | }
|
---|
568 |
|
---|
569 | static void ega_redraw(outdev_t *dev)
|
---|
570 | {
|
---|
571 | ega_instance_t *instance = (ega_instance_t *) dev->data;
|
---|
572 |
|
---|
573 | irq_spinlock_lock(&instance->lock, true);
|
---|
574 |
|
---|
575 | memcpy(instance->addr, instance->backbuf, EGA_VRAM_SIZE);
|
---|
576 | ega_move_cursor(instance);
|
---|
577 | ega_show_cursor(instance);
|
---|
578 |
|
---|
579 | irq_spinlock_unlock(&instance->lock, true);
|
---|
580 | }
|
---|
581 |
|
---|
582 | outdev_t *ega_init(ioport8_t *base, uintptr_t addr)
|
---|
583 | {
|
---|
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 |
|
---|
597 | irq_spinlock_initialize(&instance->lock, "*ega.instance.lock");
|
---|
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 |
|
---|
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 |
|
---|
623 | /* Synchronize the back buffer and cursor position. */
|
---|
624 | memcpy(instance->backbuf, instance->addr, EGA_VRAM_SIZE);
|
---|
625 | ega_sync_cursor(instance);
|
---|
626 |
|
---|
627 | if (!fb_exported) {
|
---|
628 | /*
|
---|
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.
|
---|
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;
|
---|
644 | }
|
---|
645 |
|
---|
646 | /** @}
|
---|
647 | */
|
---|