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