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