iPXE
Data Structures | Macros | Functions | Variables
vesafb.c File Reference

VESA frame buffer console. More...

#include <stdlib.h>
#include <errno.h>
#include <limits.h>
#include <realmode.h>
#include <ipxe/console.h>
#include <ipxe/io.h>
#include <ipxe/ansicol.h>
#include <ipxe/fbcon.h>
#include <ipxe/vesafb.h>
#include <config/console.h>

Go to the source code of this file.

Data Structures

struct  vesafb
 A VESA frame buffer. More...
 
union  vbe_buffer
 Base memory buffer used for VBE calls. More...
 

Macros

#define EIO_FAILED   __einfo_error ( EINFO_EIO_FAILED )
 
#define EINFO_EIO_FAILED
 
#define EIO_HARDWARE   __einfo_error ( EINFO_EIO_HARDWARE )
 
#define EINFO_EIO_HARDWARE
 
#define EIO_MODE   __einfo_error ( EINFO_EIO_MODE )
 
#define EINFO_EIO_MODE
 
#define EIO_VBE(code)   EUNIQ ( EINFO_EIO, (code), EIO_FAILED, EIO_HARDWARE, EIO_MODE )
 
#define CONSOLE_VESAFB   ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_LOG )
 
#define VESAFB_CHAR_HEIGHT   16
 Character height. More...
 
#define VESAFB_FONT   VBE_FONT_8x16
 Font corresponding to selected character width and height. More...
 
#define VESAFB_ASCII   128
 Number of ASCII glyphs within the font. More...
 
#define VESAFB_UNKNOWN   0xfe
 Glyph to render for non-ASCII characters. More...
 
#define vbe_buf   __use_data16 ( vbe_buf )
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static union vbe_buffer __bss16 (vbe_buf)
 
static int vesafb_rc (unsigned int status)
 Convert VBE status code to iPXE status code. More...
 
static void vesafb_glyph (unsigned int character, uint8_t *glyph)
 Get character glyph. More...
 
static void vesafb_font (void)
 Get font definition. More...
 
static int vesafb_mode_list (uint16_t **mode_numbers)
 Get VBE mode list. More...
 
static int vesafb_mode_info (unsigned int mode_number)
 Get video mode information. More...
 
static int vesafb_set_mode (unsigned int mode_number)
 Set video mode. More...
 
static int vesafb_select_mode (const uint16_t *mode_numbers, unsigned int min_width, unsigned int min_height, unsigned int min_bpp)
 Select video mode. More...
 
static void vesafb_restore (void)
 Restore video mode. More...
 
static int vesafb_init (struct console_configuration *config)
 Initialise VESA frame buffer. More...
 
static void vesafb_fini (void)
 Finalise VESA frame buffer. More...
 
static void vesafb_putchar (int character)
 Print a character to current cursor position. More...
 
static int vesafb_configure (struct console_configuration *config)
 Configure console. More...
 

Variables

struct console_driver bios_console
 
struct console_driver vesafb_console __console_driver
 VESA frame buffer console driver. More...
 
struct vesafb __attribute__
 
static struct vesafb vesafb
 The VESA frame buffer. More...
 

Detailed Description

VESA frame buffer console.

Definition in file vesafb.c.

Macro Definition Documentation

◆ EIO_FAILED

#define EIO_FAILED   __einfo_error ( EINFO_EIO_FAILED )

Definition at line 48 of file vesafb.c.

◆ EINFO_EIO_FAILED

#define EINFO_EIO_FAILED
Value:
"Function call failed" )
#define EINFO_EIO
Definition: errno.h:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 49 of file vesafb.c.

◆ EIO_HARDWARE

#define EIO_HARDWARE   __einfo_error ( EINFO_EIO_HARDWARE )

Definition at line 52 of file vesafb.c.

◆ EINFO_EIO_HARDWARE

#define EINFO_EIO_HARDWARE
Value:
"Not supported in current configuration" )
#define EINFO_EIO
Definition: errno.h:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 53 of file vesafb.c.

◆ EIO_MODE

#define EIO_MODE   __einfo_error ( EINFO_EIO_MODE )

Definition at line 56 of file vesafb.c.

◆ EINFO_EIO_MODE

#define EINFO_EIO_MODE
Value:
"Invalid in current video mode" )
#define EINFO_EIO
Definition: errno.h:434
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 57 of file vesafb.c.

◆ EIO_VBE

#define EIO_VBE (   code)    EUNIQ ( EINFO_EIO, (code), EIO_FAILED, EIO_HARDWARE, EIO_MODE )

Definition at line 60 of file vesafb.c.

◆ CONSOLE_VESAFB

#define CONSOLE_VESAFB   ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_LOG )

Definition at line 72 of file vesafb.c.

◆ VESAFB_CHAR_HEIGHT

#define VESAFB_CHAR_HEIGHT   16

Character height.

Definition at line 76 of file vesafb.c.

◆ VESAFB_FONT

#define VESAFB_FONT   VBE_FONT_8x16

Font corresponding to selected character width and height.

Definition at line 79 of file vesafb.c.

◆ VESAFB_ASCII

#define VESAFB_ASCII   128

Number of ASCII glyphs within the font.

Definition at line 82 of file vesafb.c.

◆ VESAFB_UNKNOWN

#define VESAFB_UNKNOWN   0xfe

Glyph to render for non-ASCII characters.

We choose to use one of the box-drawing glyphs.

Definition at line 88 of file vesafb.c.

◆ vbe_buf

#define vbe_buf   __use_data16 ( vbe_buf )

Definition at line 122 of file vesafb.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ __bss16()

static union vbe_buffer __bss16 ( vbe_buf  )
static

◆ vesafb_rc()

static int vesafb_rc ( unsigned int  status)
static

Convert VBE status code to iPXE status code.

Parameters
statusVBE status code
Return values
rcReturn status code

Definition at line 130 of file vesafb.c.

130  {
131  unsigned int code;
132 
133  if ( ( status & 0xff ) != 0x4f )
134  return -ENOTSUP;
135  code = ( ( status >> 8 ) & 0xff );
136  return ( code ? -EIO_VBE ( code ) : 0 );
137 }
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
uint8_t status
Status.
Definition: ena.h:16
uint8_t code
Response code.
Definition: scsi.h:16
#define EIO_VBE(code)
Definition: vesafb.c:60

References code, EIO_VBE, ENOTSUP, and status.

Referenced by vesafb_mode_info(), vesafb_mode_list(), and vesafb_set_mode().

◆ vesafb_glyph()

static void vesafb_glyph ( unsigned int  character,
uint8_t glyph 
)
static

Get character glyph.

Parameters
characterUnicode character
glyphCharacter glyph to fill in

Definition at line 145 of file vesafb.c.

145  {
146  unsigned int index;
147  size_t offset;
148 
149  /* Identify glyph */
150  if ( character < VESAFB_ASCII ) {
151  /* ASCII character: use corresponding glyph */
152  index = character;
153  } else {
154  /* Non-ASCII character: use "unknown" glyph */
156  }
157 
158  /* Copy glyph from BIOS font table */
162 }
uint16_t segment
Definition: registers.h:193
#define VESAFB_CHAR_HEIGHT
Character height.
Definition: vesafb.c:76
#define VESAFB_UNKNOWN
Glyph to render for non-ASCII characters.
Definition: vesafb.c:88
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
uint16_t offset
Definition: registers.h:192
struct segoff glyphs
Character glyphs.
Definition: vesafb.c:106
#define copy_from_real
Definition: libkir.h:79
#define VESAFB_ASCII
Number of ASCII glyphs within the font.
Definition: vesafb.c:82
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
A VESA frame buffer.
Definition: vesafb.c:94

References copy_from_real, vesafb::glyphs, index, segoff::offset, offset, segoff::segment, VESAFB_ASCII, VESAFB_CHAR_HEIGHT, and VESAFB_UNKNOWN.

Referenced by vesafb_font().

◆ vesafb_font()

static void vesafb_font ( void  )
static

Get font definition.

Definition at line 168 of file vesafb.c.

168  {
169 
170  /* Get font information
171  *
172  * Working around gcc bugs is icky here. The value we want is
173  * returned in %ebp, but there's no way to specify %ebp in an
174  * output constraint. We can't put %ebp in the clobber list,
175  * because this tends to cause random build failures on some
176  * gcc versions. We can't manually push/pop %ebp and return
177  * the value via a generic register output constraint, because
178  * gcc might choose to use %ebp to satisfy that constraint
179  * (and we have no way to prevent it from so doing).
180  *
181  * Work around this hideous mess by using %ecx and %edx as the
182  * output registers, since they get clobbered anyway.
183  */
184  __asm__ __volatile__ ( REAL_CODE ( "pushw %%bp\n\t" /* gcc bug */
185  "int $0x10\n\t"
186  "movw %%es, %%cx\n\t"
187  "movw %%bp, %%dx\n\t"
188  "popw %%bp\n\t" /* gcc bug */ )
189  : "=c" ( vesafb.glyphs.segment ),
190  "=d" ( vesafb.glyphs.offset )
191  : "a" ( VBE_GET_FONT ),
192  "b" ( VESAFB_FONT ) );
193  DBGC ( &vbe_buf, "VESAFB has font %04x at %04x:%04x\n",
197 }
uint16_t segment
Definition: registers.h:193
unsigned int height
Character height (in pixels)
Definition: fbcon.h:36
#define VESAFB_FONT
Font corresponding to selected character width and height.
Definition: vesafb.c:79
#define DBGC(...)
Definition: compiler.h:505
#define VESAFB_CHAR_HEIGHT
Character height.
Definition: vesafb.c:76
void(* glyph)(unsigned int character, uint8_t *glyph)
Get character glyph.
Definition: fbcon.h:43
uint16_t offset
Definition: registers.h:192
static void vesafb_glyph(unsigned int character, uint8_t *glyph)
Get character glyph.
Definition: vesafb.c:145
#define VBE_GET_FONT
INT 10,1130: get font information.
Definition: vesafb.h:186
struct fbcon_font font
Font definition.
Definition: vesafb.c:104
__asm__ __volatile__("\n1:\n\t" "movb -1(%3,%1), %%al\n\t" "stosb\n\t" "loop 1b\n\t" "xorl %%eax, %%eax\n\t" "mov %4, %1\n\t" "rep stosb\n\t" :"=&D"(discard_D), "=&c"(discard_c), "+m"(*value) :"r"(data), "g"(pad_len), "0"(value0), "1"(len) :"eax")
struct segoff glyphs
Character glyphs.
Definition: vesafb.c:106
__asm__(".section \".rodata\", \"a\", " PROGBITS "\n\t" "\nprivate_key_data:\n\t" ".size private_key_data, ( . - private_key_data )\n\t" ".equ private_key_len, ( . - private_key_data )\n\t" ".previous\n\t")
#define vbe_buf
Definition: vesafb.c:122
#define REAL_CODE(asm_code_str)
Definition: libkir.h:226
A VESA frame buffer.
Definition: vesafb.c:94

References __asm__(), __volatile__(), DBGC, vesafb::font, fbcon_font::glyph, vesafb::glyphs, fbcon_font::height, segoff::offset, REAL_CODE, segoff::segment, vbe_buf, VBE_GET_FONT, VESAFB_CHAR_HEIGHT, VESAFB_FONT, and vesafb_glyph().

Referenced by vesafb_init().

◆ vesafb_mode_list()

static int vesafb_mode_list ( uint16_t **  mode_numbers)
static

Get VBE mode list.

Return values
mode_numbersMode number list (terminated with VBE_MODE_END)
rcReturn status code

The caller is responsible for eventually freeing the mode list.

Definition at line 207 of file vesafb.c.

207  {
208  struct vbe_controller_info *controller = &vbe_buf.controller;
210  uint16_t mode_number;
212  size_t len;
213  int rc;
214 
215  /* Avoid returning uninitialised data on error */
216  *mode_numbers = NULL;
217 
218  /* Get controller information block */
219  controller->vbe_signature = 0;
220  __asm__ __volatile__ ( REAL_CODE ( "int $0x10" )
221  : "=a" ( status )
222  : "a" ( VBE_CONTROLLER_INFO ),
223  "D" ( __from_data16 ( controller ) )
224  : "memory", "ebx", "edx" );
225  if ( ( rc = vesafb_rc ( status ) ) != 0 ) {
226  DBGC ( &vbe_buf, "VESAFB could not get controller information: "
227  "[%04x] %s\n", status, strerror ( rc ) );
228  return rc;
229  }
230  if ( controller->vbe_signature != VBE_CONTROLLER_SIGNATURE ) {
231  DBGC ( &vbe_buf, "VESAFB invalid controller signature "
232  "\"%c%c%c%c\"\n", ( controller->vbe_signature >> 0 ),
233  ( controller->vbe_signature >> 8 ),
234  ( controller->vbe_signature >> 16 ),
235  ( controller->vbe_signature >> 24 ) );
236  DBGC_HDA ( &vbe_buf, 0, controller, sizeof ( *controller ) );
237  return -EINVAL;
238  }
239  DBGC ( &vbe_buf, "VESAFB found VBE version %d.%d with mode list at "
240  "%04x:%04x\n", controller->vbe_major_version,
241  controller->vbe_minor_version,
242  controller->video_mode_ptr.segment,
243  controller->video_mode_ptr.offset );
244 
245  /* Calculate length of mode list */
246  video_mode_ptr = real_to_user ( controller->video_mode_ptr.segment,
247  controller->video_mode_ptr.offset );
248  len = 0;
249  do {
250  copy_from_user ( &mode_number, video_mode_ptr, len,
251  sizeof ( mode_number ) );
252  len += sizeof ( mode_number );
253  } while ( mode_number != VBE_MODE_END );
254 
255  /* Allocate and fill mode list */
256  *mode_numbers = malloc ( len );
257  if ( ! *mode_numbers )
258  return -ENOMEM;
259  copy_from_user ( *mode_numbers, video_mode_ptr, 0, len );
260 
261  return 0;
262 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned short uint16_t
Definition: stdint.h:11
VBE controller information.
Definition: vesafb.h:19
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
#define DBGC(...)
Definition: compiler.h:505
struct segoff video_mode_ptr
Pointer to video mode list.
Definition: vesafb.h:22
#define VBE_MODE_END
VBE mode list end marker.
Definition: vesafb.h:56
uint8_t status
Status.
Definition: ena.h:16
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define DBGC_HDA(...)
Definition: compiler.h:506
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
__asm__ __volatile__("\n1:\n\t" "movb -1(%3,%1), %%al\n\t" "stosb\n\t" "loop 1b\n\t" "xorl %%eax, %%eax\n\t" "mov %4, %1\n\t" "rep stosb\n\t" :"=&D"(discard_D), "=&c"(discard_c), "+m"(*value) :"r"(data), "g"(pad_len), "0"(value0), "1"(len) :"eax")
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:583
#define VBE_CONTROLLER_INFO
INT 10,4f00: return controller information.
Definition: vesafb.h:16
#define VBE_CONTROLLER_SIGNATURE
VBE controller information signature.
Definition: vesafb.h:52
__asm__(".section \".rodata\", \"a\", " PROGBITS "\n\t" "\nprivate_key_data:\n\t" ".size private_key_data, ( . - private_key_data )\n\t" ".equ private_key_len, ( . - private_key_data )\n\t" ".previous\n\t")
uint8_t controller
CD-ROM controller number.
Definition: int13.h:18
uint32_t len
Length.
Definition: ena.h:14
#define __from_data16(pointer)
Definition: libkir.h:22
#define vbe_buf
Definition: vesafb.c:122
static __always_inline userptr_t real_to_user(unsigned int segment, unsigned int offset)
Convert segment:offset address to user buffer.
Definition: realmode.h:75
static int vesafb_rc(unsigned int status)
Convert VBE status code to iPXE status code.
Definition: vesafb.c:130
#define REAL_CODE(asm_code_str)
Definition: libkir.h:226
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
unsigned long userptr_t
A pointer to a user buffer.
Definition: uaccess.h:33

References __asm__(), __from_data16, __volatile__(), controller, copy_from_user(), DBGC, DBGC_HDA, EINVAL, ENOMEM, len, malloc(), NULL, rc, REAL_CODE, real_to_user(), status, strerror(), vbe_buf, VBE_CONTROLLER_INFO, VBE_CONTROLLER_SIGNATURE, VBE_MODE_END, vesafb_rc(), and video_mode_ptr.

Referenced by vesafb_init().

◆ vesafb_mode_info()

static int vesafb_mode_info ( unsigned int  mode_number)
static

Get video mode information.

Parameters
mode_numberMode number
Return values
rcReturn status code

Definition at line 270 of file vesafb.c.

270  {
271  struct vbe_mode_info *mode = &vbe_buf.mode;
273  int rc;
274 
275  /* Get mode information */
276  __asm__ __volatile__ ( REAL_CODE ( "int $0x10" )
277  : "=a" ( status )
278  : "a" ( VBE_MODE_INFO ),
279  "c" ( mode_number ),
280  "D" ( __from_data16 ( mode ) )
281  : "memory" );
282  if ( ( rc = vesafb_rc ( status ) ) != 0 ) {
283  DBGC ( &vbe_buf, "VESAFB could not get mode %04x information: "
284  "[%04x] %s\n", mode_number, status, strerror ( rc ) );
285  return rc;
286  }
287  DBGC ( &vbe_buf, "VESAFB mode %04x %dx%d %dbpp(%d:%d:%d:%d) model "
288  "%02x [x%d]%s%s%s%s%s\n", mode_number, mode->x_resolution,
289  mode->y_resolution, mode->bits_per_pixel, mode->rsvd_mask_size,
290  mode->red_mask_size, mode->green_mask_size, mode->blue_mask_size,
291  mode->memory_model, ( mode->number_of_image_pages + 1 ),
293  "" : " [unsupported]" ),
294  ( ( mode->mode_attributes & VBE_MODE_ATTR_TTY ) ?
295  " [tty]" : "" ),
297  "" : " [text]" ),
298  ( ( mode->mode_attributes & VBE_MODE_ATTR_LINEAR ) ?
299  "" : " [nonlinear]" ),
301  " [buf]" : "" ) );
302 
303  return 0;
304 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned short uint16_t
Definition: stdint.h:11
uint8_t red_mask_size
Size of direct colour red mask in bits.
Definition: vesafb.h:104
uint8_t bits_per_pixel
Bits per pixel.
Definition: vesafb.h:92
uint8_t memory_model
Memory model type.
Definition: vesafb.h:96
#define VBE_MODE_INFO
INT 10,4f01: return VBE mode information.
Definition: vesafb.h:59
uint16_t y_resolution
Vertical resolution in pixels or characters.
Definition: vesafb.h:84
#define DBGC(...)
Definition: compiler.h:505
uint8_t status
Status.
Definition: ena.h:16
Linear frame buffer mode is available.
Definition: vesafb.h:146
uint8_t number_of_image_pages
Number of images.
Definition: vesafb.h:100
uint8_t rsvd_mask_size
Size of direct colour reserved mask in bits.
Definition: vesafb.h:116
uint8_t green_mask_size
Size of direct colour green mask in bits.
Definition: vesafb.h:108
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
TTY output functions supported by BIOS.
Definition: vesafb.h:136
__asm__ __volatile__("\n1:\n\t" "movb -1(%3,%1), %%al\n\t" "stosb\n\t" "loop 1b\n\t" "xorl %%eax, %%eax\n\t" "mov %4, %1\n\t" "rep stosb\n\t" :"=&D"(discard_D), "=&c"(discard_c), "+m"(*value) :"r"(data), "g"(pad_len), "0"(value0), "1"(len) :"eax")
uint16_t mode_attributes
Mode attributes.
Definition: vesafb.h:64
uint8_t blue_mask_size
Size of direct colour blue mask in bits.
Definition: vesafb.h:112
__asm__(".section \".rodata\", \"a\", " PROGBITS "\n\t" "\nprivate_key_data:\n\t" ".size private_key_data, ( . - private_key_data )\n\t" ".equ private_key_len, ( . - private_key_data )\n\t" ".previous\n\t")
uint16_t x_resolution
Horizontal resolution in pixels or characters.
Definition: vesafb.h:82
#define __from_data16(pointer)
Definition: libkir.h:22
Hardware triple buffering support.
Definition: vesafb.h:152
Mode supported in hardware.
Definition: vesafb.h:134
VBE mode information.
Definition: vesafb.h:62
#define vbe_buf
Definition: vesafb.c:122
static int vesafb_rc(unsigned int status)
Convert VBE status code to iPXE status code.
Definition: vesafb.c:130
#define REAL_CODE(asm_code_str)
Definition: libkir.h:226
Graphics mode.
Definition: vesafb.h:140

References __asm__(), __from_data16, __volatile__(), vbe_mode_info::bits_per_pixel, vbe_mode_info::blue_mask_size, DBGC, vbe_mode_info::green_mask_size, vbe_mode_info::memory_model, vbe_mode_info::mode_attributes, vbe_mode_info::number_of_image_pages, rc, REAL_CODE, vbe_mode_info::red_mask_size, vbe_mode_info::rsvd_mask_size, status, strerror(), vbe_buf, VBE_MODE_ATTR_GRAPHICS, VBE_MODE_ATTR_LINEAR, VBE_MODE_ATTR_SUPPORTED, VBE_MODE_ATTR_TRIPLE_BUF, VBE_MODE_ATTR_TTY, VBE_MODE_INFO, vesafb_rc(), vbe_mode_info::x_resolution, and vbe_mode_info::y_resolution.

Referenced by vesafb_select_mode(), and vesafb_set_mode().

◆ vesafb_set_mode()

static int vesafb_set_mode ( unsigned int  mode_number)
static

Set video mode.

Parameters
mode_numberMode number
Return values
rcReturn status code

Definition at line 312 of file vesafb.c.

312  {
313  struct vbe_mode_info *mode = &vbe_buf.mode;
315  int rc;
316 
317  /* Get mode information */
318  if ( ( rc = vesafb_mode_info ( mode_number ) ) != 0 )
319  return rc;
320 
321  /* Record mode parameters */
322  vesafb.start = mode->phys_base_ptr;
323  vesafb.pixel.width = mode->x_resolution;
325  vesafb.pixel.len = ( ( mode->bits_per_pixel + 7 ) / 8 );
327  DBGC ( &vbe_buf, "VESAFB mode %04x has frame buffer at %08x\n",
328  mode_number, mode->phys_base_ptr );
329 
330  /* Initialise font colours */
331  vesafb.map.red_scale = ( 8 - mode->red_mask_size );
332  vesafb.map.green_scale = ( 8 - mode->green_mask_size );
333  vesafb.map.blue_scale = ( 8 - mode->blue_mask_size );
337 
338  /* Select this mode */
339  __asm__ __volatile__ ( REAL_CODE ( "int $0x10" )
340  : "=a" ( status )
341  : "a" ( VBE_SET_MODE ),
342  "b" ( mode_number ) );
343  if ( ( rc = vesafb_rc ( status ) ) != 0 ) {
344  DBGC ( &vbe_buf, "VESAFB could not set mode %04x: [%04x] %s\n",
345  mode_number, status, strerror ( rc ) );
346  return rc;
347  }
348 
349  return 0;
350 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned short uint16_t
Definition: stdint.h:11
uint8_t blue_field_position
Bit position of LSB of blue mask.
Definition: vesafb.h:114
uint8_t red_mask_size
Size of direct colour red mask in bits.
Definition: vesafb.h:104
uint8_t bits_per_pixel
Bits per pixel.
Definition: vesafb.h:92
uint8_t green_lsb
Green LSB.
Definition: fbcon.h:85
uint8_t red_lsb
Red LSB.
Definition: fbcon.h:83
unsigned int width
Width (number of entities per displayed row)
Definition: fbcon.h:53
uint16_t y_resolution
Vertical resolution in pixels or characters.
Definition: vesafb.h:84
#define DBGC(...)
Definition: compiler.h:505
uint32_t phys_base_ptr
Physical address for flat memory frame buffer.
Definition: vesafb.h:122
uint8_t status
Status.
Definition: ena.h:16
uint8_t red_scale
Red scale (right shift amount from 24-bit RGB)
Definition: fbcon.h:77
size_t len
Length of a single entity.
Definition: fbcon.h:57
static int vesafb_mode_info(unsigned int mode_number)
Get video mode information.
Definition: vesafb.c:270
physaddr_t start
Physical start address.
Definition: vesafb.c:98
uint8_t green_mask_size
Size of direct colour green mask in bits.
Definition: vesafb.h:108
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
uint8_t green_scale
Green scale (right shift amount from 24-bit RGB)
Definition: fbcon.h:79
struct fbcon_geometry pixel
Pixel geometry.
Definition: vesafb.c:100
__asm__ __volatile__("\n1:\n\t" "movb -1(%3,%1), %%al\n\t" "stosb\n\t" "loop 1b\n\t" "xorl %%eax, %%eax\n\t" "mov %4, %1\n\t" "rep stosb\n\t" :"=&D"(discard_D), "=&c"(discard_c), "+m"(*value) :"r"(data), "g"(pad_len), "0"(value0), "1"(len) :"eax")
uint8_t blue_mask_size
Size of direct colour blue mask in bits.
Definition: vesafb.h:112
uint8_t blue_scale
Blue scale (right shift amount from 24-bit RGB)
Definition: fbcon.h:81
uint16_t bytes_per_scan_line
Bytes per scan line.
Definition: vesafb.h:80
__asm__(".section \".rodata\", \"a\", " PROGBITS "\n\t" "\nprivate_key_data:\n\t" ".size private_key_data, ( . - private_key_data )\n\t" ".equ private_key_len, ( . - private_key_data )\n\t" ".previous\n\t")
uint16_t x_resolution
Horizontal resolution in pixels or characters.
Definition: vesafb.h:82
unsigned int height
Height (number of entities per displayed column)
Definition: fbcon.h:55
VBE mode information.
Definition: vesafb.h:62
#define vbe_buf
Definition: vesafb.c:122
#define VBE_SET_MODE
INT 10,4f02: set VBE mode.
Definition: vesafb.h:180
uint8_t blue_lsb
Blue LSB.
Definition: fbcon.h:87
static int vesafb_rc(unsigned int status)
Convert VBE status code to iPXE status code.
Definition: vesafb.c:130
struct fbcon_colour_map map
Colour mapping.
Definition: vesafb.c:102
uint8_t red_field_position
Bit position of LSB of red mask.
Definition: vesafb.h:106
#define REAL_CODE(asm_code_str)
Definition: libkir.h:226
A VESA frame buffer.
Definition: vesafb.c:94
uint8_t green_field_position
Bit position of LSB of green mask.
Definition: vesafb.h:110
size_t stride
Stride (offset between vertically adjacent entities)
Definition: fbcon.h:59

References __asm__(), __volatile__(), vbe_mode_info::bits_per_pixel, vbe_mode_info::blue_field_position, fbcon_colour_map::blue_lsb, vbe_mode_info::blue_mask_size, fbcon_colour_map::blue_scale, vbe_mode_info::bytes_per_scan_line, DBGC, vbe_mode_info::green_field_position, fbcon_colour_map::green_lsb, vbe_mode_info::green_mask_size, fbcon_colour_map::green_scale, fbcon_geometry::height, fbcon_geometry::len, vesafb::map, vbe_mode_info::phys_base_ptr, vesafb::pixel, rc, REAL_CODE, vbe_mode_info::red_field_position, fbcon_colour_map::red_lsb, vbe_mode_info::red_mask_size, fbcon_colour_map::red_scale, vesafb::start, status, strerror(), fbcon_geometry::stride, vbe_buf, VBE_SET_MODE, vesafb_mode_info(), vesafb_rc(), fbcon_geometry::width, vbe_mode_info::x_resolution, and vbe_mode_info::y_resolution.

Referenced by vesafb_init().

◆ vesafb_select_mode()

static int vesafb_select_mode ( const uint16_t mode_numbers,
unsigned int  min_width,
unsigned int  min_height,
unsigned int  min_bpp 
)
static

Select video mode.

Parameters
mode_numbersMode number list (terminated with VBE_MODE_END)
min_widthMinimum required width (in pixels)
min_heightMinimum required height (in pixels)
min_bppMinimum required colour depth (in bits per pixel)
Return values
mode_numberMode number, or negative error

Definition at line 361 of file vesafb.c.

363  {
364  struct vbe_mode_info *mode = &vbe_buf.mode;
365  int best_mode_number = -ENOENT;
366  unsigned int best_score = INT_MAX;
367  unsigned int score;
368  uint16_t mode_number;
369  int rc;
370 
371  /* Find the first suitable mode */
372  while ( ( mode_number = *(mode_numbers++) ) != VBE_MODE_END ) {
373 
374  /* Force linear mode variant */
375  mode_number |= VBE_MODE_LINEAR;
376 
377  /* Get mode information */
378  if ( ( rc = vesafb_mode_info ( mode_number ) ) != 0 )
379  continue;
380 
381  /* Skip unusable modes */
382  if ( ( mode->mode_attributes & ( VBE_MODE_ATTR_SUPPORTED |
384  VBE_MODE_ATTR_LINEAR ) ) !=
387  continue;
388  }
390  continue;
391 
392  /* Skip modes not meeting the requirements */
393  if ( ( mode->x_resolution < min_width ) ||
394  ( mode->y_resolution < min_height ) ||
395  ( mode->bits_per_pixel < min_bpp ) ) {
396  continue;
397  }
398 
399  /* Select this mode if it has the best (i.e. lowest)
400  * score. We choose the scoring system to favour
401  * modes close to the specified width and height;
402  * within modes of the same width and height we prefer
403  * a higher colour depth.
404  */
405  score = ( ( mode->x_resolution * mode->y_resolution ) -
406  mode->bits_per_pixel );
407  if ( score < best_score ) {
408  best_mode_number = mode_number;
409  best_score = score;
410  }
411  }
412 
413  if ( best_mode_number >= 0 ) {
414  DBGC ( &vbe_buf, "VESAFB selected mode %04x\n",
415  best_mode_number );
416  } else {
417  DBGC ( &vbe_buf, "VESAFB found no suitable mode\n" );
418  }
419 
420  return best_mode_number;
421 }
Direct colour mode.
Definition: vesafb.h:174
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned short uint16_t
Definition: stdint.h:11
uint8_t bits_per_pixel
Bits per pixel.
Definition: vesafb.h:92
uint8_t memory_model
Memory model type.
Definition: vesafb.h:96
uint16_t y_resolution
Vertical resolution in pixels or characters.
Definition: vesafb.h:84
#define DBGC(...)
Definition: compiler.h:505
#define VBE_MODE_LINEAR
VBE linear frame buffer mode bit.
Definition: vesafb.h:183
#define ENOENT
No such file or directory.
Definition: errno.h:514
#define VBE_MODE_END
VBE mode list end marker.
Definition: vesafb.h:56
Linear frame buffer mode is available.
Definition: vesafb.h:146
static int vesafb_mode_info(unsigned int mode_number)
Get video mode information.
Definition: vesafb.c:270
uint16_t mode_attributes
Mode attributes.
Definition: vesafb.h:64
uint16_t x_resolution
Horizontal resolution in pixels or characters.
Definition: vesafb.h:82
Mode supported in hardware.
Definition: vesafb.h:134
VBE mode information.
Definition: vesafb.h:62
#define vbe_buf
Definition: vesafb.c:122
#define INT_MAX
Definition: limits.h:37
Graphics mode.
Definition: vesafb.h:140

References vbe_mode_info::bits_per_pixel, DBGC, ENOENT, INT_MAX, vbe_mode_info::memory_model, vbe_mode_info::mode_attributes, rc, vbe_buf, VBE_MODE_ATTR_GRAPHICS, VBE_MODE_ATTR_LINEAR, VBE_MODE_ATTR_SUPPORTED, VBE_MODE_END, VBE_MODE_LINEAR, VBE_MODE_MODEL_DIRECT_COLOUR, vesafb_mode_info(), vbe_mode_info::x_resolution, and vbe_mode_info::y_resolution.

Referenced by vesafb_init().

◆ vesafb_restore()

static void vesafb_restore ( void  )
static

Restore video mode.

Definition at line 427 of file vesafb.c.

427  {
428  uint32_t discard_a;
429 
430  /* Restore saved VGA mode */
431  __asm__ __volatile__ ( REAL_CODE ( "int $0x10" )
432  : "=a" ( discard_a )
433  : "a" ( VBE_SET_VGA_MODE | vesafb.saved_mode ) );
434  DBGC ( &vbe_buf, "VESAFB restored VGA mode %#02x\n",
435  vesafb.saved_mode );
436 }
#define DBGC(...)
Definition: compiler.h:505
#define VBE_SET_VGA_MODE
INT 10,00: set VGA mode.
Definition: vesafb.h:205
uint8_t saved_mode
Saved VGA mode.
Definition: vesafb.c:108
__asm__ __volatile__("\n1:\n\t" "movb -1(%3,%1), %%al\n\t" "stosb\n\t" "loop 1b\n\t" "xorl %%eax, %%eax\n\t" "mov %4, %1\n\t" "rep stosb\n\t" :"=&D"(discard_D), "=&c"(discard_c), "+m"(*value) :"r"(data), "g"(pad_len), "0"(value0), "1"(len) :"eax")
unsigned int uint32_t
Definition: stdint.h:12
__asm__(".section \".rodata\", \"a\", " PROGBITS "\n\t" "\nprivate_key_data:\n\t" ".size private_key_data, ( . - private_key_data )\n\t" ".equ private_key_len, ( . - private_key_data )\n\t" ".previous\n\t")
#define vbe_buf
Definition: vesafb.c:122
#define REAL_CODE(asm_code_str)
Definition: libkir.h:226
A VESA frame buffer.
Definition: vesafb.c:94

References __asm__(), __volatile__(), DBGC, REAL_CODE, vesafb::saved_mode, vbe_buf, and VBE_SET_VGA_MODE.

Referenced by vesafb_fini(), and vesafb_init().

◆ vesafb_init()

static int vesafb_init ( struct console_configuration config)
static

Initialise VESA frame buffer.

Parameters
configConsole configuration, or NULL to reset
Return values
rcReturn status code

Definition at line 444 of file vesafb.c.

444  {
445  uint32_t discard_b;
446  uint16_t *mode_numbers;
447  int mode_number;
448  int rc;
449 
450  /* Record current VGA mode */
451  __asm__ __volatile__ ( REAL_CODE ( "int $0x10" )
452  : "=a" ( vesafb.saved_mode ), "=b" ( discard_b )
453  : "a" ( VBE_GET_VGA_MODE ) );
454  DBGC ( &vbe_buf, "VESAFB saved VGA mode %#02x\n", vesafb.saved_mode );
455 
456  /* Get VESA mode list */
457  if ( ( rc = vesafb_mode_list ( &mode_numbers ) ) != 0 )
458  goto err_mode_list;
459 
460  /* Select mode */
461  if ( ( mode_number = vesafb_select_mode ( mode_numbers, config->width,
462  config->height,
463  config->depth ) ) < 0 ) {
464  rc = mode_number;
465  goto err_select_mode;
466  }
467 
468  /* Set mode */
469  if ( ( rc = vesafb_set_mode ( mode_number ) ) != 0 )
470  goto err_set_mode;
471 
472  /* Get font data */
473  vesafb_font();
474 
475  /* Initialise frame buffer console */
476  if ( ( rc = fbcon_init ( &vesafb.fbcon, phys_to_user ( vesafb.start ),
478  config ) ) != 0 )
479  goto err_fbcon_init;
480 
481  free ( mode_numbers );
482  return 0;
483 
484  fbcon_fini ( &vesafb.fbcon );
485  err_fbcon_init:
486  err_set_mode:
487  vesafb_restore();
488  err_select_mode:
489  free ( mode_numbers );
490  err_mode_list:
491  return rc;
492 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned short uint16_t
Definition: stdint.h:11
unsigned int height
Height.
Definition: console.h:28
#define DBGC(...)
Definition: compiler.h:505
userptr_t phys_to_user(unsigned long phys_addr)
Convert physical address to user pointer.
unsigned int width
Width.
Definition: console.h:26
struct fbcon fbcon
Frame buffer console.
Definition: vesafb.c:96
unsigned int depth
Colour depth.
Definition: console.h:30
uint8_t saved_mode
Saved VGA mode.
Definition: vesafb.c:108
static int vesafb_select_mode(const uint16_t *mode_numbers, unsigned int min_width, unsigned int min_height, unsigned int min_bpp)
Select video mode.
Definition: vesafb.c:361
#define VBE_GET_VGA_MODE
INT 10,0f: get VGA mode.
Definition: vesafb.h:208
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:588
void fbcon_fini(struct fbcon *fbcon)
Finalise frame buffer console.
Definition: fbcon.c:718
physaddr_t start
Physical start address.
Definition: vesafb.c:98
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
struct fbcon_font font
Font definition.
Definition: vesafb.c:104
struct fbcon_geometry pixel
Pixel geometry.
Definition: vesafb.c:100
static void vesafb_font(void)
Get font definition.
Definition: vesafb.c:168
__asm__ __volatile__("\n1:\n\t" "movb -1(%3,%1), %%al\n\t" "stosb\n\t" "loop 1b\n\t" "xorl %%eax, %%eax\n\t" "mov %4, %1\n\t" "rep stosb\n\t" :"=&D"(discard_D), "=&c"(discard_c), "+m"(*value) :"r"(data), "g"(pad_len), "0"(value0), "1"(len) :"eax")
unsigned int uint32_t
Definition: stdint.h:12
__asm__(".section \".rodata\", \"a\", " PROGBITS "\n\t" "\nprivate_key_data:\n\t" ".size private_key_data, ( . - private_key_data )\n\t" ".equ private_key_len, ( . - private_key_data )\n\t" ".previous\n\t")
static int vesafb_set_mode(unsigned int mode_number)
Set video mode.
Definition: vesafb.c:312
static void vesafb_restore(void)
Restore video mode.
Definition: vesafb.c:427
#define vbe_buf
Definition: vesafb.c:122
struct fbcon_colour_map map
Colour mapping.
Definition: vesafb.c:102
#define REAL_CODE(asm_code_str)
Definition: libkir.h:226
A VESA frame buffer.
Definition: vesafb.c:94
static int vesafb_mode_list(uint16_t **mode_numbers)
Get VBE mode list.
Definition: vesafb.c:207

References __asm__(), __volatile__(), DBGC, console_configuration::depth, vesafb::fbcon, fbcon_fini(), fbcon_init(), vesafb::font, free, console_configuration::height, vesafb::map, phys_to_user(), vesafb::pixel, rc, REAL_CODE, vesafb::saved_mode, vesafb::start, vbe_buf, VBE_GET_VGA_MODE, vesafb_font(), vesafb_mode_list(), vesafb_restore(), vesafb_select_mode(), vesafb_set_mode(), and console_configuration::width.

Referenced by vesafb_configure().

◆ vesafb_fini()

static void vesafb_fini ( void  )
static

Finalise VESA frame buffer.

Definition at line 498 of file vesafb.c.

498  {
499 
500  /* Finalise frame buffer console */
501  fbcon_fini ( &vesafb.fbcon );
502 
503  /* Restore saved VGA mode */
504  vesafb_restore();
505 }
struct fbcon fbcon
Frame buffer console.
Definition: vesafb.c:96
void fbcon_fini(struct fbcon *fbcon)
Finalise frame buffer console.
Definition: fbcon.c:718
static void vesafb_restore(void)
Restore video mode.
Definition: vesafb.c:427
A VESA frame buffer.
Definition: vesafb.c:94

References vesafb::fbcon, fbcon_fini(), and vesafb_restore().

Referenced by vesafb_configure().

◆ vesafb_putchar()

static void vesafb_putchar ( int  character)
static

Print a character to current cursor position.

Parameters
characterCharacter

Definition at line 512 of file vesafb.c.

512  {
513 
514  fbcon_putchar ( &vesafb.fbcon, character );
515 }
void fbcon_putchar(struct fbcon *fbcon, int character)
Print a character to current cursor position.
Definition: fbcon.c:441
struct fbcon fbcon
Frame buffer console.
Definition: vesafb.c:96
A VESA frame buffer.
Definition: vesafb.c:94

References vesafb::fbcon, and fbcon_putchar().

◆ vesafb_configure()

static int vesafb_configure ( struct console_configuration config)
static

Configure console.

Parameters
configConsole configuration, or NULL to reset
Return values
rcReturn status code

Definition at line 523 of file vesafb.c.

523  {
524  int rc;
525 
526  /* Reset console, if applicable */
527  if ( ! vesafb_console.disabled ) {
528  vesafb_fini();
531  }
532  vesafb_console.disabled = CONSOLE_DISABLED;
533 
534  /* Do nothing more unless we have a usable configuration */
535  if ( ( config == NULL ) ||
536  ( config->width == 0 ) || ( config->height == 0 ) ) {
537  return 0;
538  }
539 
540  /* Initialise VESA frame buffer */
541  if ( ( rc = vesafb_init ( config ) ) != 0 )
542  return rc;
543 
544  /* Mark console as enabled */
545  vesafb_console.disabled = 0;
547 
548  /* Set magic colour to transparent if we have a background picture */
549  if ( config->pixbuf )
551 
552  return 0;
553 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned int height
Height.
Definition: console.h:28
static int vesafb_init(struct console_configuration *config)
Initialise VESA frame buffer.
Definition: vesafb.c:444
#define CONSOLE_DISABLED
Console is disabled for all uses.
Definition: console.h:111
unsigned int width
Width.
Definition: console.h:26
#define CONSOLE_DISABLED_OUTPUT
Console is disabled for output.
Definition: console.h:108
struct console_driver bios_console
Definition: vesafb.c:45
void ansicol_set_magic_transparent(void)
Set magic colour to transparent.
Definition: ansicoldef.c:189
int disabled
Console disabled flags.
Definition: console.h:62
void ansicol_reset_magic(void)
Reset magic colour.
Definition: ansicoldef.c:179
struct pixel_buffer * pixbuf
Background picture, if any.
Definition: console.h:40
static void vesafb_fini(void)
Finalise VESA frame buffer.
Definition: vesafb.c:498
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References ansicol_reset_magic(), ansicol_set_magic_transparent(), bios_console, CONSOLE_DISABLED, CONSOLE_DISABLED_OUTPUT, console_driver::disabled, console_configuration::height, NULL, console_configuration::pixbuf, rc, vesafb_fini(), vesafb_init(), and console_configuration::width.

Variable Documentation

◆ bios_console

struct console_driver bios_console

Definition at line 45 of file vesafb.c.

Referenced by bios_inject(), and vesafb_configure().

◆ __console_driver

struct console_driver vesafb_console __console_driver
Initial value:
= {
.usage = CONSOLE_VESAFB,
.putchar = vesafb_putchar,
.configure = vesafb_configure,
.disabled = CONSOLE_DISABLED,
}
#define CONSOLE_VESAFB
Definition: vesafb.c:72
#define CONSOLE_DISABLED
Console is disabled for all uses.
Definition: console.h:111
static int vesafb_configure(struct console_configuration *config)
Configure console.
Definition: vesafb.c:523
static void vesafb_putchar(int character)
Print a character to current cursor position.
Definition: vesafb.c:512

VESA frame buffer console driver.

Definition at line 91 of file vesafb.c.

◆ __attribute__

◆ vesafb

struct vesafb vesafb
static

The VESA frame buffer.

Definition at line 112 of file vesafb.c.