iPXE
fbcon.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2013 Michael Brown <mbrown@fensystems.co.uk>.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 *
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
22 */
23
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25FILE_SECBOOT ( PERMITTED );
26
27/** @file
28 *
29 * Frame buffer console
30 *
31 */
32
33#include <string.h>
34#include <errno.h>
35#include <assert.h>
36#include <byteswap.h>
37#include <ipxe/ansiesc.h>
38#include <ipxe/image.h>
39#include <ipxe/pixbuf.h>
40#include <ipxe/uaccess.h>
41#include <ipxe/umalloc.h>
42#include <ipxe/console.h>
43#include <ipxe/fbcon.h>
44
45/**
46 * Calculate raw colour value
47 *
48 * @v fbcon Frame buffer console
49 * @v rgb 24-bit RGB value
50 * @ret raw Raw colour
51 */
52static uint32_t fbcon_colour ( struct fbcon *fbcon, uint32_t rgb ) {
53 struct fbcon_colour_map *map = fbcon->map;
54 uint8_t red = ( rgb >> 16 );
55 uint8_t green = ( rgb >> 8 );
56 uint8_t blue = ( rgb >> 0 );
57 uint32_t mapped;
58
59 mapped = ( ( ( red >> map->red_scale ) << map->red_lsb ) |
60 ( ( green >> map->green_scale ) << map->green_lsb ) |
61 ( ( blue >> map->blue_scale ) << map->blue_lsb ) );
62 return cpu_to_le32 ( mapped );
63}
64
65/**
66 * Calculate ANSI font colour
67 *
68 * @v fbcon Frame buffer console
69 * @v ansicol ANSI colour value (0-based)
70 * @ret colour Raw colour
71 */
73 unsigned int ansicol ) {
74 uint32_t rgb;
75
76 /* Treat ansicol as 3-bit BGR with intensity 0xaa */
77 rgb = ( ( ( ansicol & ( 1 << 0 ) ) ? 0xaa0000 : 0 ) |
78 ( ( ansicol & ( 1 << 1 ) ) ? 0x00aa00 : 0 ) |
79 ( ( ansicol & ( 1 << 2 ) ) ? 0x0000aa : 0 ) );
80
81 return fbcon_colour ( fbcon, rgb );
82}
83
84/**
85 * Set default foreground colour
86 *
87 * @v fbcon Frame buffer console
88 */
89static void fbcon_set_default_foreground ( struct fbcon *fbcon ) {
90
91 /* Default to non-bold white foreground */
93 fbcon->bold = 0;
94}
95
96/**
97 * Set default background colour
98 *
99 * @v fbcon Frame buffer console
100 */
101static void fbcon_set_default_background ( struct fbcon *fbcon ) {
102
103 /* Default to transparent background */
105}
106
107/**
108 * Get character cell
109 *
110 * @v fbcon Frame buffer console
111 * @v xpos X position
112 * @v ypos Y position
113 * @ret cell Text cell
114 */
115static inline struct fbcon_text_cell * fbcon_cell ( struct fbcon *fbcon,
116 unsigned int xpos,
117 unsigned int ypos ) {
118 unsigned int index;
119
120 index = ( ( ypos * fbcon->character.width ) + xpos );
121 return &fbcon->text.cells[index];
122}
123
124/**
125 * Clear rows of characters
126 *
127 * @v fbcon Frame buffer console
128 * @v ypos Starting Y position
129 */
130static void fbcon_clear ( struct fbcon *fbcon, unsigned int ypos ) {
131 struct fbcon_text_cell *cell;
132 unsigned int xpos;
133
134 /* Clear stored character array */
135 cell = fbcon_cell ( fbcon, 0, ypos );
136 for ( ; ypos < fbcon->character.height ; ypos++ ) {
137 for ( xpos = 0 ; xpos < fbcon->character.width ; xpos++ ) {
138 cell->foreground = fbcon->foreground;
139 cell->background = fbcon->background;
140 cell->character = ' ';
141 cell++;
142 }
143 }
144}
145
146/**
147 * Draw character at specified position
148 *
149 * @v fbcon Frame buffer console
150 * @v cell Text cell
151 * @v xpos X position
152 * @v ypos Y position
153 */
154static void fbcon_draw ( struct fbcon *fbcon, struct fbcon_text_cell *cell,
155 unsigned int xpos, unsigned int ypos ) {
156 const uint8_t *glyph;
157 size_t offset;
158 size_t pixel_len;
159 size_t skip_len;
160 unsigned int row;
161 unsigned int column;
162 uint8_t bitmask;
163 int transparent;
164 const void *src;
165
166 /* Get font character */
167 glyph = fbcon->font->glyph ( cell->character );
168
169 /* Calculate pixel geometry */
170 offset = ( fbcon->indent +
171 ( ypos * fbcon->character.stride ) +
172 ( xpos * fbcon->character.len ) );
173 pixel_len = fbcon->pixel->len;
174 skip_len = ( fbcon->pixel->stride - fbcon->character.len );
175
176 /* Check for transparent background colour */
177 transparent = ( cell->background == FBCON_TRANSPARENT );
178
179 /* Draw character rows */
180 for ( row = 0 ; row < fbcon->font->height ; row++ ) {
181
182 /* Draw background picture, if applicable */
183 if ( transparent ) {
184 if ( fbcon->picture.start ) {
185 memcpy ( ( fbcon->start + offset ),
186 ( fbcon->picture.start + offset ),
188 } else {
189 memset ( ( fbcon->start + offset ), 0,
191 }
192 }
193
194 /* Draw character row */
195 for ( column = FBCON_CHAR_WIDTH, bitmask = glyph[row] ;
196 column ; column--, bitmask <<= 1, offset += pixel_len ) {
197 if ( bitmask & 0x80 ) {
198 src = &cell->foreground;
199 } else if ( ! transparent ) {
200 src = &cell->background;
201 } else {
202 continue;
203 }
204 memcpy ( ( fbcon->start + offset ), src, pixel_len );
205 }
206
207 /* Move to next row */
208 offset += skip_len;
209 }
210}
211
212/**
213 * Redraw all characters
214 *
215 * @v fbcon Frame buffer console
216 */
217static void fbcon_redraw ( struct fbcon *fbcon ) {
218 struct fbcon_text_cell *cell;
219 unsigned int xpos;
220 unsigned int ypos;
221
222 /* Redraw characters */
223 cell = fbcon_cell ( fbcon, 0, 0 );
224 for ( ypos = 0 ; ypos < fbcon->character.height ; ypos++ ) {
225 for ( xpos = 0 ; xpos < fbcon->character.width ; xpos++ ) {
226 fbcon_draw ( fbcon, cell, xpos, ypos );
227 cell++;
228 }
229 }
230}
231
232/**
233 * Scroll screen
234 *
235 * @v fbcon Frame buffer console
236 */
237static void fbcon_scroll ( struct fbcon *fbcon ) {
238 const struct fbcon_text_cell *old;
239 struct fbcon_text_cell *new;
240 unsigned int xpos;
241 unsigned int ypos;
242 unsigned int character;
245
246 /* Sanity check */
248
249 /* Scroll up character array */
250 new = fbcon_cell ( fbcon, 0, 0 );
251 old = fbcon_cell ( fbcon, 0, 1 );
252 for ( ypos = 0 ; ypos < ( fbcon->character.height - 1 ) ; ypos++ ) {
253 for ( xpos = 0 ; xpos < fbcon->character.width ; xpos++ ) {
254 /* Redraw character (if changed) */
255 character = old->character;
256 foreground = old->foreground;
257 background = old->background;
258 if ( ( new->character != character ) ||
259 ( new->foreground != foreground ) ||
260 ( new->background != background ) ) {
261 new->character = character;
262 new->foreground = foreground;
263 new->background = background;
264 fbcon_draw ( fbcon, new, xpos, ypos );
265 }
266 new++;
267 old++;
268 }
269 }
270
271 /* Clear bottom row */
272 fbcon_clear ( fbcon, ypos );
273 for ( xpos = 0 ; xpos < fbcon->character.width ; xpos++ )
274 fbcon_draw ( fbcon, new++, xpos, ypos );
275
276 /* Update cursor position */
277 fbcon->ypos--;
278}
279
280/**
281 * Draw character at cursor position
282 *
283 * @v fbcon Frame buffer console
284 * @v show_cursor Show cursor
285 */
286static void fbcon_draw_cursor ( struct fbcon *fbcon, int show_cursor ) {
287 struct fbcon_text_cell *cell;
288 struct fbcon_text_cell cursor;
289
290 cell = fbcon_cell ( fbcon, fbcon->xpos, fbcon->ypos );
291 if ( show_cursor ) {
292 cursor.background = fbcon->foreground;
293 cursor.foreground =
295 0 : fbcon->background );
296 cursor.character = cell->character;
297 cell = &cursor;
298 }
299 fbcon_draw ( fbcon, cell, fbcon->xpos, fbcon->ypos );
300}
301
302/**
303 * Handle ANSI CUP (cursor position)
304 *
305 * @v ctx ANSI escape sequence context
306 * @v count Parameter count
307 * @v params[0] Row (1 is top)
308 * @v params[1] Column (1 is left)
309 */
311 unsigned int count __unused, int params[] ) {
312 struct fbcon *fbcon = container_of ( ctx, struct fbcon, ctx );
313 int cx = ( params[1] - 1 );
314 int cy = ( params[0] - 1 );
315
317 fbcon->xpos = cx;
318 if ( fbcon->xpos >= fbcon->character.width )
319 fbcon->xpos = 0;
320 fbcon->ypos = cy;
321 if ( fbcon->ypos >= fbcon->character.height )
322 fbcon->ypos = 0;
324}
325
326/**
327 * Handle ANSI ED (erase in page)
328 *
329 * @v ctx ANSI escape sequence context
330 * @v count Parameter count
331 * @v params[0] Region to erase
332 */
333static void fbcon_handle_ed ( struct ansiesc_context *ctx,
334 unsigned int count __unused,
335 int params[] __unused ) {
336 struct fbcon *fbcon = container_of ( ctx, struct fbcon, ctx );
337
338 /* We assume that we always clear the whole screen */
339 assert ( params[0] == ANSIESC_ED_ALL );
340
341 /* Clear character array */
342 fbcon_clear ( fbcon, 0 );
343
344 /* Redraw all characters */
346
347 /* Reset cursor position */
348 fbcon->xpos = 0;
349 fbcon->ypos = 0;
351}
352
353/**
354 * Handle ANSI SGR (set graphics rendition)
355 *
356 * @v ctx ANSI escape sequence context
357 * @v count Parameter count
358 * @v params List of graphic rendition aspects
359 */
360static void fbcon_handle_sgr ( struct ansiesc_context *ctx, unsigned int count,
361 int params[] ) {
362 struct fbcon *fbcon = container_of ( ctx, struct fbcon, ctx );
363 uint32_t *custom = NULL;
364 uint32_t rgb;
365 unsigned int end;
366 unsigned int i;
367 int aspect;
368
369 for ( i = 0 ; i < count ; i++ ) {
370
371 /* Process aspect */
372 aspect = params[i];
373 if ( aspect == 0 ) {
376 } else if ( aspect == 1 ) {
378 } else if ( aspect == 22 ) {
379 fbcon->bold = 0;
380 } else if ( ( aspect >= 30 ) && ( aspect <= 37 ) ) {
382 fbcon_ansi_colour ( fbcon, aspect - 30 );
383 } else if ( aspect == 38 ) {
384 custom = &fbcon->foreground;
385 } else if ( aspect == 39 ) {
387 } else if ( ( aspect >= 40 ) && ( aspect <= 47 ) ) {
389 fbcon_ansi_colour ( fbcon, aspect - 40 );
390 } else if ( aspect == 48 ) {
391 custom = &fbcon->background;
392 } else if ( aspect == 49 ) {
394 }
395
396 /* Process custom RGB colour, if applicable
397 *
398 * We support the xterm-compatible
399 * "<ESC>[38;2;<red>;<green>;<blue>m" and
400 * "<ESC>[48;2;<red>;<green>;<blue>m" sequences.
401 */
402 if ( custom ) {
403 rgb = 0;
404 end = ( i + 5 );
405 for ( ; ( i < count ) && ( i < end ) ; i++ )
406 rgb = ( ( rgb << 8 ) | params[i] );
407 *custom = fbcon_colour ( fbcon, rgb );
408 custom = NULL;
409 }
410 }
411}
412
413/**
414 * Handle ANSI DECTCEM set (show cursor)
415 *
416 * @v ctx ANSI escape sequence context
417 * @v count Parameter count
418 * @v params List of graphic rendition aspects
419 */
421 unsigned int count __unused,
422 int params[] __unused ) {
423 struct fbcon *fbcon = container_of ( ctx, struct fbcon, ctx );
424
425 fbcon->show_cursor = 1;
427}
428
429/**
430 * Handle ANSI DECTCEM reset (hide cursor)
431 *
432 * @v ctx ANSI escape sequence context
433 * @v count Parameter count
434 * @v params List of graphic rendition aspects
435 */
437 unsigned int count __unused,
438 int params[] __unused ) {
439 struct fbcon *fbcon = container_of ( ctx, struct fbcon, ctx );
440
441 fbcon->show_cursor = 0;
443}
444
445/** ANSI escape sequence handlers */
454
455/**
456 * Print a character to current cursor position
457 *
458 * @v fbcon Frame buffer console
459 * @v character Character
460 */
461void fbcon_putchar ( struct fbcon *fbcon, int character ) {
462 struct fbcon_text_cell *cell;
463
464 /* Intercept ANSI escape sequences */
466 if ( character < 0 )
467 return;
468
469 /* Accumulate Unicode characters */
471 if ( character == 0 )
472 return;
473
474 /* Handle control characters */
475 switch ( character ) {
476 case '\r':
478 fbcon->xpos = 0;
479 break;
480 case '\n':
482 fbcon->xpos = 0;
483 fbcon->ypos++;
484 break;
485 case '\b':
487 if ( fbcon->xpos ) {
488 fbcon->xpos--;
489 } else if ( fbcon->ypos ) {
490 fbcon->xpos = ( fbcon->character.width - 1 );
491 fbcon->ypos--;
492 }
493 break;
494 default:
495 /* Print character at current cursor position */
496 cell = fbcon_cell ( fbcon, fbcon->xpos, fbcon->ypos );
497 cell->foreground = ( fbcon->foreground | fbcon->bold );
498 cell->background = fbcon->background;
499 cell->character = character;
500 fbcon_draw ( fbcon, cell, fbcon->xpos, fbcon->ypos );
501
502 /* Advance cursor */
503 fbcon->xpos++;
504 if ( fbcon->xpos >= fbcon->character.width ) {
505 fbcon->xpos = 0;
506 fbcon->ypos++;
507 }
508 break;
509 }
510
511 /* Scroll screen if necessary */
512 if ( fbcon->ypos >= fbcon->character.height )
514
515 /* Show cursor */
517}
518
519/**
520 * Initialise background picture
521 *
522 * @v fbcon Frame buffer console
523 * @v pixbuf Background picture
524 * @ret rc Return status code
525 */
526static int fbcon_picture_init ( struct fbcon *fbcon,
527 struct pixel_buffer *pixbuf ) {
528 struct fbcon_geometry *pixel = fbcon->pixel;
529 struct fbcon_picture *picture = &fbcon->picture;
530 size_t len;
531 size_t indent;
532 size_t offset;
533 const uint32_t *rgb;
535 unsigned int x;
536 unsigned int y;
537 unsigned int width;
538 unsigned int height;
539 int xgap;
540 int ygap;
541 int rc;
542
543 /* Allocate buffer */
544 len = ( pixel->height * pixel->stride );
545 picture->start = umalloc ( len );
546 if ( ! picture->start ) {
547 DBGC ( fbcon, "FBCON %p could not allocate %zd bytes for "
548 "picture\n", fbcon, len );
549 rc = -ENOMEM;
550 goto err_umalloc;
551 }
552
553 /* Centre picture on console */
554 xgap = ( ( ( int ) ( pixel->width - pixbuf->width ) ) / 2 );
555 ygap = ( ( ( int ) ( pixel->height - pixbuf->height ) ) / 2 );
556 indent = ( ( ( ( ygap >= 0 ) ? ygap : 0 ) * pixel->stride ) +
557 ( ( ( xgap >= 0 ) ? xgap : 0 ) * pixel->len ) );
558 width = pixbuf->width;
559 if ( width > pixel->width )
560 width = pixel->width;
561 height = pixbuf->height;
562 if ( height > pixel->height )
563 height = pixel->height;
564 DBGC ( fbcon, "FBCON %p picture is pixel %dx%d at [%d,%d),[%d,%d)\n",
565 fbcon, width, height, xgap, ( xgap + pixbuf->width ), ygap,
566 ( ygap + pixbuf->height ) );
567
568 /* Convert to frame buffer raw format */
569 memset ( picture->start, 0, len );
570 for ( y = 0 ; y < height ; y++ ) {
571 offset = ( indent + ( y * pixel->stride ) );
572 rgb = pixbuf_pixel ( pixbuf, ( ( xgap < 0 ) ? -xgap : 0 ),
573 ( ( ( ygap < 0 ) ? -ygap : 0 ) + y ) );
574 for ( x = 0 ; x < width ; x++ ) {
575 raw = fbcon_colour ( fbcon, *rgb );
576 memcpy ( ( picture->start + offset ), &raw,
577 pixel->len );
578 offset += pixel->len;
579 rgb++;
580 }
581 }
582
583 return 0;
584
585 ufree ( picture->start );
586 err_umalloc:
587 return rc;
588}
589
590/**
591 * Initialise frame buffer console
592 *
593 * @v fbcon Frame buffer console
594 * @v start Start address
595 * @v pixel Pixel geometry
596 * @v map Colour mapping
597 * @v font Font definition
598 * @v config Console configuration
599 * @ret rc Return status code
600 */
601int fbcon_init ( struct fbcon *fbcon, void *start,
602 struct fbcon_geometry *pixel,
603 struct fbcon_colour_map *map,
604 struct fbcon_font *font,
605 struct console_configuration *config ) {
606 int width;
607 int height;
608 unsigned int xgap;
609 unsigned int ygap;
610 unsigned int left;
611 unsigned int right;
612 unsigned int top;
613 unsigned int bottom;
614 int rc;
615
616 /* Initialise data structure */
617 memset ( fbcon, 0, sizeof ( *fbcon ) );
618 fbcon->start = start;
619 fbcon->pixel = pixel;
620 assert ( pixel->len <= sizeof ( uint32_t ) );
621 fbcon->map = map;
622 fbcon->font = font;
624 fbcon->show_cursor = 1;
625
626 /* Derive overall length */
627 fbcon->len = ( pixel->height * pixel->stride );
628 DBGC ( fbcon, "FBCON %p at [%08lx,%08lx)\n", fbcon,
629 virt_to_phys ( fbcon->start ),
630 ( virt_to_phys ( fbcon->start ) + fbcon->len ) );
631
632 /* Calculate margin. If the actual screen size is larger than
633 * the requested screen size, then update the margins so that
634 * the margin remains relative to the requested screen size.
635 * (As an exception, if a zero margin was specified then treat
636 * this as meaning "expand to edge of actual screen".)
637 */
638 xgap = ( pixel->width - config->width );
639 ygap = ( pixel->height - config->height );
640 left = ( xgap / 2 );
641 right = ( xgap - left );
642 top = ( ygap / 2 );
643 bottom = ( ygap - top );
644 fbcon->margin.left = ( config->left + ( config->left ? left : 0 ) );
645 fbcon->margin.right = ( config->right + ( config->right ? right : 0 ) );
646 fbcon->margin.top = ( config->top + ( config->top ? top : 0 ) );
648 ( config->bottom + ( config->bottom ? bottom : 0 ) );
649
650 /* Expand margin to accommodate whole characters */
651 width = ( pixel->width - fbcon->margin.left - fbcon->margin.right );
652 height = ( pixel->height - fbcon->margin.top - fbcon->margin.bottom );
653 if ( ( width < FBCON_CHAR_WIDTH ) ||
654 ( height < ( ( int ) font->height ) ) ) {
655 DBGC ( fbcon, "FBCON %p has unusable character area "
656 "[%d-%d),[%d-%d)\n", fbcon, fbcon->margin.left,
657 ( pixel->width - fbcon->margin.right ),
659 ( pixel->height - fbcon->margin.bottom ) );
660 rc = -EINVAL;
661 goto err_margin;
662 }
663 xgap = ( width % FBCON_CHAR_WIDTH );
664 ygap = ( height % font->height );
665 fbcon->margin.left += ( xgap / 2 );
666 fbcon->margin.top += ( ygap / 2 );
667 fbcon->margin.right += ( xgap - ( xgap / 2 ) );
668 fbcon->margin.bottom += ( ygap - ( ygap / 2 ) );
669 fbcon->indent = ( ( fbcon->margin.top * pixel->stride ) +
670 ( fbcon->margin.left * pixel->len ) );
671
672 /* Derive character geometry from pixel geometry */
673 fbcon->character.width = ( width / FBCON_CHAR_WIDTH );
674 fbcon->character.height = ( height / font->height );
675 fbcon->character.len = ( pixel->len * FBCON_CHAR_WIDTH );
676 fbcon->character.stride = ( pixel->stride * font->height );
677 DBGC ( fbcon, "FBCON %p is pixel %dx%d, char %dx%d at "
678 "[%d-%d),[%d-%d)\n", fbcon, fbcon->pixel->width,
683 ( fbcon->pixel->height - fbcon->margin.bottom ) );
684
685 /* Set default colours */
688
689 /* Allocate and initialise stored character array */
692 sizeof ( fbcon->text.cells[0] ) );
693 if ( ! fbcon->text.cells ) {
694 rc = -ENOMEM;
695 goto err_text;
696 }
697 fbcon_clear ( fbcon, 0 );
698
699 /* Set framebuffer to all black (including margins) */
700 memset ( fbcon->start, 0, fbcon->len );
701
702 /* Generate pixel buffer from background image, if applicable */
703 if ( config->pixbuf &&
704 ( ( rc = fbcon_picture_init ( fbcon, config->pixbuf ) ) != 0 ) )
705 goto err_picture;
706
707 /* Draw background picture (including margins), if applicable */
708 if ( fbcon->picture.start )
710
711 /* Update console width and height */
713
714 return 0;
715
717 err_picture:
718 ufree ( fbcon->text.cells );
719 err_text:
720 err_margin:
721 return rc;
722}
723
724/**
725 * Finalise frame buffer console
726 *
727 * @v fbcon Frame buffer console
728 */
729void fbcon_fini ( struct fbcon *fbcon ) {
730
731 ufree ( fbcon->text.cells );
733}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
struct golan_eq_context ctx
Definition CIB_PRM.h:0
__be32 raw[7]
Definition CIB_PRM.h:0
int ansiesc_process(struct ansiesc_context *ctx, int c)
Process character that may be part of ANSI escape sequence.
Definition ansiesc.c:75
ANSI escape sequences.
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
unsigned int uint32_t
Definition stdint.h:12
unsigned char uint8_t
Definition stdint.h:10
long index
Definition bigint.h:65
int old
Definition bitops.h:65
static const void * src
Definition string.h:48
Assertions.
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
uint16_t offset
Offset to command line.
Definition bzimage.h:3
ring len
Length.
Definition dwmac.h:226
Error codes.
static void fbcon_set_default_foreground(struct fbcon *fbcon)
Set default foreground colour.
Definition fbcon.c:89
int fbcon_init(struct fbcon *fbcon, void *start, struct fbcon_geometry *pixel, struct fbcon_colour_map *map, struct fbcon_font *font, struct console_configuration *config)
Initialise frame buffer console.
Definition fbcon.c:601
static void fbcon_set_default_background(struct fbcon *fbcon)
Set default background colour.
Definition fbcon.c:101
static void fbcon_handle_ed(struct ansiesc_context *ctx, unsigned int count __unused, int params[] __unused)
Handle ANSI ED (erase in page)
Definition fbcon.c:333
static void fbcon_handle_cup(struct ansiesc_context *ctx, unsigned int count __unused, int params[])
Handle ANSI CUP (cursor position)
Definition fbcon.c:310
static void fbcon_draw(struct fbcon *fbcon, struct fbcon_text_cell *cell, unsigned int xpos, unsigned int ypos)
Draw character at specified position.
Definition fbcon.c:154
static void fbcon_handle_sgr(struct ansiesc_context *ctx, unsigned int count, int params[])
Handle ANSI SGR (set graphics rendition)
Definition fbcon.c:360
static void fbcon_scroll(struct fbcon *fbcon)
Scroll screen.
Definition fbcon.c:237
static struct ansiesc_handler fbcon_ansiesc_handlers[]
ANSI escape sequence handlers.
Definition fbcon.c:446
void fbcon_fini(struct fbcon *fbcon)
Finalise frame buffer console.
Definition fbcon.c:729
static void fbcon_clear(struct fbcon *fbcon, unsigned int ypos)
Clear rows of characters.
Definition fbcon.c:130
static void fbcon_handle_dectcem_reset(struct ansiesc_context *ctx, unsigned int count __unused, int params[] __unused)
Handle ANSI DECTCEM reset (hide cursor)
Definition fbcon.c:436
static uint32_t fbcon_ansi_colour(struct fbcon *fbcon, unsigned int ansicol)
Calculate ANSI font colour.
Definition fbcon.c:72
static int fbcon_picture_init(struct fbcon *fbcon, struct pixel_buffer *pixbuf)
Initialise background picture.
Definition fbcon.c:526
static struct fbcon_text_cell * fbcon_cell(struct fbcon *fbcon, unsigned int xpos, unsigned int ypos)
Get character cell.
Definition fbcon.c:115
static uint32_t fbcon_colour(struct fbcon *fbcon, uint32_t rgb)
Calculate raw colour value.
Definition fbcon.c:52
void fbcon_putchar(struct fbcon *fbcon, int character)
Print a character to current cursor position.
Definition fbcon.c:461
static void fbcon_redraw(struct fbcon *fbcon)
Redraw all characters.
Definition fbcon.c:217
static void fbcon_draw_cursor(struct fbcon *fbcon, int show_cursor)
Draw character at cursor position.
Definition fbcon.c:286
static void fbcon_handle_dectcem_set(struct ansiesc_context *ctx, unsigned int count __unused, int params[] __unused)
Handle ANSI DECTCEM set (show cursor)
Definition fbcon.c:420
Frame buffer console.
#define FBCON_TRANSPARENT
Transparent background magic colour (raw colour value)
Definition fbcon.h:25
#define FBCON_BOLD
Bold colour modifier (RGB value)
Definition fbcon.h:22
#define FBCON_CHAR_WIDTH
Character width, in pixels.
Definition fbcon.h:19
#define ANSIESC_DECTCEM_SET
Show cursor.
Definition ansiesc.h:129
#define ANSIESC_ED
Erase in page.
Definition ansiesc.h:107
#define ANSIESC_DECTCEM_RESET
Hide cursor.
Definition ansiesc.h:132
#define ANSIESC_SGR
Select graphic rendition.
Definition ansiesc.h:119
#define ANSIESC_CUP
Cursor position.
Definition ansiesc.h:104
#define ANSIESC_ED_ALL
Erase whole page.
Definition ansiesc.h:116
#define __unused
Declare a variable or data structure as unused.
Definition compiler.h:573
#define DBGC(...)
Definition compiler.h:505
uint32_t start
Starting offset.
Definition netvsc.h:1
static unsigned int count
Number of entries.
Definition dwmac.h:220
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define EINVAL
Invalid argument.
Definition errno.h:429
#define ENOMEM
Not enough space.
Definition errno.h:535
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
Executable images.
#define cpu_to_le32(value)
Definition byteswap.h:108
User interaction.
static void console_set_size(unsigned int width, unsigned int height)
Set console size.
Definition console.h:202
User memory allocation.
static __always_inline void * umalloc(size_t size)
Allocate external memory.
Definition umalloc.h:57
static __always_inline void ufree(void *ptr)
Free external memory.
Definition umalloc.h:68
String functions.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * memset(void *dest, int character, size_t len) __nonnull
static __always_inline int struct dma_mapping * map
Definition dma.h:184
Access to external ("user") memory.
uint32_t end
Ending offset.
Definition netvsc.h:7
Pixel buffer.
static unsigned int unsigned int y
Definition pixbuf.h:63
static unsigned int x
Definition pixbuf.h:63
uint16_t cx
Definition registers.h:37
#define container_of(ptr, type, field)
Get containing structure.
Definition stddef.h:36
ANSI escape sequence context.
Definition ansiesc.h:74
struct ansiesc_handler * handlers
Array of handlers.
Definition ansiesc.h:80
A handler for an escape sequence.
Definition ansiesc.h:35
A console configuration.
Definition console.h:25
unsigned int right
Right margin.
Definition console.h:35
unsigned int left
Left margin.
Definition console.h:33
unsigned int top
Top margin.
Definition console.h:37
struct pixel_buffer * pixbuf
Background picture, if any.
Definition console.h:41
unsigned int height
Height.
Definition console.h:29
unsigned int bottom
Bottom margin.
Definition console.h:39
unsigned int width
Width.
Definition console.h:27
A frame buffer colour mapping.
Definition fbcon.h:75
A font definition.
Definition fbcon.h:34
unsigned int height
Character height (in pixels)
Definition fbcon.h:36
const uint8_t *(* glyph)(unsigned int character)
Get character glyph.
Definition fbcon.h:43
A frame buffer geometry.
Definition fbcon.h:51
unsigned int height
Height (number of entities per displayed column)
Definition fbcon.h:55
size_t len
Length of a single entity.
Definition fbcon.h:57
unsigned int width
Width (number of entities per displayed row)
Definition fbcon.h:53
size_t stride
Stride (offset between vertically adjacent entities)
Definition fbcon.h:59
unsigned int top
Top margin.
Definition fbcon.h:69
unsigned int left
Left margin.
Definition fbcon.h:65
unsigned int right
Right margin.
Definition fbcon.h:67
unsigned int bottom
Bottom margin.
Definition fbcon.h:71
A frame buffer background picture.
Definition fbcon.h:107
void * start
Start address.
Definition fbcon.h:109
A frame buffer text cell.
Definition fbcon.h:91
uint32_t background
Background colour.
Definition fbcon.h:95
unsigned int character
Unicode character.
Definition fbcon.h:97
uint32_t foreground
Foreground colour.
Definition fbcon.h:93
struct fbcon_text_cell * cells
Stored text cells.
Definition fbcon.h:103
A frame buffer console.
Definition fbcon.h:113
void * start
Start address.
Definition fbcon.h:115
unsigned int xpos
Text cursor X position.
Definition fbcon.h:137
struct fbcon_font * font
Font definition.
Definition fbcon.h:129
struct fbcon_geometry * pixel
Pixel geometry.
Definition fbcon.h:119
struct fbcon_colour_map * map
Colour mapping.
Definition fbcon.h:127
struct utf8_accumulator utf8
UTF-8 accumulator.
Definition fbcon.h:143
struct fbcon_picture picture
Background picture.
Definition fbcon.h:147
unsigned int ypos
Text cursor Y position.
Definition fbcon.h:139
int show_cursor
Display cursor.
Definition fbcon.h:149
size_t len
Length of one complete displayed screen.
Definition fbcon.h:117
uint32_t bold
Bold colour modifier raw colour.
Definition fbcon.h:135
struct fbcon_geometry character
Character geometry.
Definition fbcon.h:121
uint32_t foreground
Text foreground raw colour.
Definition fbcon.h:131
size_t indent
Indent to first character (in bytes)
Definition fbcon.h:125
struct fbcon_margin margin
Margin.
Definition fbcon.h:123
uint32_t background
Text background raw colour.
Definition fbcon.h:133
struct ansiesc_context ctx
ANSI escape sequence context.
Definition fbcon.h:141
struct fbcon_text text
Text array.
Definition fbcon.h:145
A pixel buffer.
Definition pixbuf.h:17
unsigned int height
Height.
Definition pixbuf.h:23
unsigned int width
Width.
Definition pixbuf.h:21
unsigned int utf8_accumulate(struct utf8_accumulator *utf8, uint8_t byte)
Accumulate Unicode character from UTF-8 byte sequence.
Definition utf8.c:44