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 const uint8_tvesafb_glyph (unsigned int character)
 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 }
static unsigned int code
Response code.
Definition: hyperv.h:26
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
uint8_t status
Status.
Definition: ena.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 const uint8_t* vesafb_glyph ( unsigned int  character)
static

Get character glyph.

Parameters
characterUnicode character
Return values
glyphCharacter glyph

Definition at line 145 of file vesafb.c.

145  {
146  unsigned int index;
147 
148  /* Identify glyph */
149  if ( character < VESAFB_ASCII ) {
150  /* ASCII character: use corresponding glyph */
151  index = character;
152  } else {
153  /* Non-ASCII character: use "unknown" glyph */
155  }
156 
157  /* Return glyph in BIOS font table */
158  return &vesafb.glyphs[ index * VESAFB_CHAR_HEIGHT ];
159 }
#define VESAFB_CHAR_HEIGHT
Character height.
Definition: vesafb.c:76
long index
Definition: bigint.h:62
#define VESAFB_UNKNOWN
Glyph to render for non-ASCII characters.
Definition: vesafb.c:88
#define VESAFB_ASCII
Number of ASCII glyphs within the font.
Definition: vesafb.c:82
const uint8_t * glyphs
Character glyphs.
Definition: vesafb.c:106
A VESA frame buffer.
Definition: vesafb.c:94

References vesafb::glyphs, index, 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 165 of file vesafb.c.

165  {
166  struct segoff glyphs;
167 
168  /* Get font information
169  *
170  * Working around gcc bugs is icky here. The value we want is
171  * returned in %ebp, but there's no way to specify %ebp in an
172  * output constraint. We can't put %ebp in the clobber list,
173  * because this tends to cause random build failures on some
174  * gcc versions. We can't manually push/pop %ebp and return
175  * the value via a generic register output constraint, because
176  * gcc might choose to use %ebp to satisfy that constraint
177  * (and we have no way to prevent it from so doing).
178  *
179  * Work around this hideous mess by using %ecx and %edx as the
180  * output registers, since they get clobbered anyway.
181  */
182  __asm__ __volatile__ ( REAL_CODE ( "pushw %%bp\n\t" /* gcc bug */
183  "int $0x10\n\t"
184  "movw %%es, %%cx\n\t"
185  "movw %%bp, %%dx\n\t"
186  "popw %%bp\n\t" /* gcc bug */ )
187  : "=c" ( glyphs.segment ),
188  "=d" ( glyphs.offset )
189  : "a" ( VBE_GET_FONT ),
190  "b" ( VESAFB_FONT ) );
191  DBGC ( &vbe_buf, "VESAFB has font %04x at %04x:%04x\n",
192  VESAFB_FONT, glyphs.segment, glyphs.offset );
193  vesafb.glyphs = real_to_virt ( glyphs.segment, glyphs.offset );
196 }
unsigned int height
Character height (in pixels)
Definition: fbcon.h:35
static const uint8_t * vesafb_glyph(unsigned int character)
Get character glyph.
Definition: vesafb.c:145
#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
static __always_inline void * real_to_virt(unsigned int segment, unsigned int offset)
Convert segment:offset address to virtual address.
Definition: realmode.h:77
#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__("call *%9" :"=a"(result), "=c"(discard_ecx), "=d"(discard_edx) :"d"(0), "a"(code), "b"(0), "c"(in_phys), "D"(0), "S"(out_phys), "m"(hypercall))
__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")
const uint8_t *(* glyph)(unsigned int character)
Get character glyph.
Definition: fbcon.h:42
#define vbe_buf
Definition: vesafb.c:122
const uint8_t * glyphs
Character glyphs.
Definition: vesafb.c:106
#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, real_to_virt(), 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 206 of file vesafb.c.

206  {
207  struct vbe_controller_info *controller = &vbe_buf.controller;
208  const uint16_t *video_mode_ptr;
209  const uint16_t *mode_number;
211  size_t len;
212  int rc;
213 
214  /* Avoid returning uninitialised data on error */
215  *mode_numbers = NULL;
216 
217  /* Get controller information block */
218  controller->vbe_signature = 0;
219  __asm__ __volatile__ ( REAL_CODE ( "int $0x10" )
220  : "=a" ( status )
221  : "a" ( VBE_CONTROLLER_INFO ),
222  "D" ( __from_data16 ( controller ) )
223  : "memory", "ebx", "edx" );
224  if ( ( rc = vesafb_rc ( status ) ) != 0 ) {
225  DBGC ( &vbe_buf, "VESAFB could not get controller information: "
226  "[%04x] %s\n", status, strerror ( rc ) );
227  return rc;
228  }
229  if ( controller->vbe_signature != VBE_CONTROLLER_SIGNATURE ) {
230  DBGC ( &vbe_buf, "VESAFB invalid controller signature "
231  "\"%c%c%c%c\"\n", ( controller->vbe_signature >> 0 ),
232  ( controller->vbe_signature >> 8 ),
233  ( controller->vbe_signature >> 16 ),
234  ( controller->vbe_signature >> 24 ) );
235  DBGC_HDA ( &vbe_buf, 0, controller, sizeof ( *controller ) );
236  return -EINVAL;
237  }
238  DBGC ( &vbe_buf, "VESAFB found VBE version %d.%d with mode list at "
239  "%04x:%04x\n", controller->vbe_major_version,
240  controller->vbe_minor_version,
241  controller->video_mode_ptr.segment,
242  controller->video_mode_ptr.offset );
243 
244  /* Calculate length of mode list */
245  video_mode_ptr = real_to_virt ( controller->video_mode_ptr.segment,
246  controller->video_mode_ptr.offset );
247  mode_number = video_mode_ptr;
248  while ( *(mode_number++) != VBE_MODE_END ) {}
249  len = ( ( ( const void * ) mode_number ) -
250  ( ( const void * ) video_mode_ptr ) );
251 
252  /* Allocate and fill mode list */
253  *mode_numbers = malloc ( len );
254  if ( ! *mode_numbers )
255  return -ENOMEM;
256  memcpy ( *mode_numbers, video_mode_ptr, len );
257 
258  return 0;
259 }
#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
#define DBGC(...)
Definition: compiler.h:505
struct segoff video_mode_ptr
Pointer to video mode list.
Definition: vesafb.h:22
static __always_inline void * real_to_virt(unsigned int segment, unsigned int offset)
Convert segment:offset address to virtual address.
Definition: realmode.h:77
#define VBE_MODE_END
VBE mode list end marker.
Definition: vesafb.h:56
#define ENOMEM
Not enough space.
Definition: errno.h:534
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define DBGC_HDA(...)
Definition: compiler.h:506
ring len
Length.
Definition: dwmac.h:231
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
__asm__ __volatile__("call *%9" :"=a"(result), "=c"(discard_ecx), "=d"(discard_edx) :"d"(0), "a"(code), "b"(0), "c"(in_phys), "D"(0), "S"(out_phys), "m"(hypercall))
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:620
uint8_t status
Status.
Definition: ena.h:16
#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
#define __from_data16(pointer)
Definition: libkir.h:22
#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
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References __asm__(), __from_data16, __volatile__(), controller, DBGC, DBGC_HDA, EINVAL, ENOMEM, len, malloc(), memcpy(), NULL, rc, REAL_CODE, real_to_virt(), 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 267 of file vesafb.c.

267  {
268  struct vbe_mode_info *mode = &vbe_buf.mode;
270  int rc;
271 
272  /* Get mode information */
273  __asm__ __volatile__ ( REAL_CODE ( "int $0x10" )
274  : "=a" ( status )
275  : "a" ( VBE_MODE_INFO ),
276  "c" ( mode_number ),
277  "D" ( __from_data16 ( mode ) )
278  : "memory" );
279  if ( ( rc = vesafb_rc ( status ) ) != 0 ) {
280  DBGC ( &vbe_buf, "VESAFB could not get mode %04x information: "
281  "[%04x] %s\n", mode_number, status, strerror ( rc ) );
282  return rc;
283  }
284  DBGC ( &vbe_buf, "VESAFB mode %04x %dx%d %dbpp(%d:%d:%d:%d) model "
285  "%02x [x%d]%s%s%s%s%s\n", mode_number, mode->x_resolution,
286  mode->y_resolution, mode->bits_per_pixel, mode->rsvd_mask_size,
287  mode->red_mask_size, mode->green_mask_size, mode->blue_mask_size,
288  mode->memory_model, ( mode->number_of_image_pages + 1 ),
289  ( ( mode->mode_attributes & VBE_MODE_ATTR_SUPPORTED ) ?
290  "" : " [unsupported]" ),
291  ( ( mode->mode_attributes & VBE_MODE_ATTR_TTY ) ?
292  " [tty]" : "" ),
293  ( ( mode->mode_attributes & VBE_MODE_ATTR_GRAPHICS ) ?
294  "" : " [text]" ),
295  ( ( mode->mode_attributes & VBE_MODE_ATTR_LINEAR ) ?
296  "" : " [nonlinear]" ),
297  ( ( mode->mode_attributes & VBE_MODE_ATTR_TRIPLE_BUF ) ?
298  " [buf]" : "" ) );
299 
300  return 0;
301 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned short uint16_t
Definition: stdint.h:11
#define VBE_MODE_INFO
INT 10,4f01: return VBE mode information.
Definition: vesafb.h:59
uint16_t mode
Acceleration mode.
Definition: ena.h:26
#define DBGC(...)
Definition: compiler.h:505
Linear frame buffer mode is available.
Definition: vesafb.h:146
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
__asm__ __volatile__("call *%9" :"=a"(result), "=c"(discard_ecx), "=d"(discard_edx) :"d"(0), "a"(code), "b"(0), "c"(in_phys), "D"(0), "S"(out_phys), "m"(hypercall))
TTY output functions supported by BIOS.
Definition: vesafb.h:136
uint8_t status
Status.
Definition: ena.h:16
__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 __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__(), DBGC, mode, rc, REAL_CODE, 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, and vesafb_rc().

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 309 of file vesafb.c.

309  {
310  struct vbe_mode_info *mode = &vbe_buf.mode;
312  int rc;
313 
314  /* Get mode information */
315  if ( ( rc = vesafb_mode_info ( mode_number ) ) != 0 )
316  return rc;
317 
318  /* Record mode parameters */
319  vesafb.start = mode->phys_base_ptr;
320  vesafb.pixel.width = mode->x_resolution;
321  vesafb.pixel.height = mode->y_resolution;
322  vesafb.pixel.len = ( ( mode->bits_per_pixel + 7 ) / 8 );
323  vesafb.pixel.stride = mode->bytes_per_scan_line;
324  DBGC ( &vbe_buf, "VESAFB mode %04x has frame buffer at %08x\n",
325  mode_number, mode->phys_base_ptr );
326 
327  /* Initialise font colours */
328  vesafb.map.red_scale = ( 8 - mode->red_mask_size );
329  vesafb.map.green_scale = ( 8 - mode->green_mask_size );
330  vesafb.map.blue_scale = ( 8 - mode->blue_mask_size );
331  vesafb.map.red_lsb = mode->red_field_position;
332  vesafb.map.green_lsb = mode->green_field_position;
333  vesafb.map.blue_lsb = mode->blue_field_position;
334 
335  /* Select this mode */
336  __asm__ __volatile__ ( REAL_CODE ( "int $0x10" )
337  : "=a" ( status )
338  : "a" ( VBE_SET_MODE ),
339  "b" ( mode_number ) );
340  if ( ( rc = vesafb_rc ( status ) ) != 0 ) {
341  DBGC ( &vbe_buf, "VESAFB could not set mode %04x: [%04x] %s\n",
342  mode_number, status, strerror ( rc ) );
343  return rc;
344  }
345 
346  return 0;
347 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned short uint16_t
Definition: stdint.h:11
uint8_t green_lsb
Green LSB.
Definition: fbcon.h:84
uint8_t red_lsb
Red LSB.
Definition: fbcon.h:82
uint16_t mode
Acceleration mode.
Definition: ena.h:26
unsigned int width
Width (number of entities per displayed row)
Definition: fbcon.h:52
#define DBGC(...)
Definition: compiler.h:505
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
static int vesafb_mode_info(unsigned int mode_number)
Get video mode information.
Definition: vesafb.c:267
physaddr_t start
Physical start address.
Definition: vesafb.c:98
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:78
__asm__ __volatile__("call *%9" :"=a"(result), "=c"(discard_ecx), "=d"(discard_edx) :"d"(0), "a"(code), "b"(0), "c"(in_phys), "D"(0), "S"(out_phys), "m"(hypercall))
struct fbcon_geometry pixel
Pixel geometry.
Definition: vesafb.c:100
uint8_t blue_scale
Blue scale (right shift amount from 24-bit RGB)
Definition: fbcon.h:80
uint8_t status
Status.
Definition: ena.h:16
__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")
unsigned int height
Height (number of entities per displayed column)
Definition: fbcon.h:54
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:86
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
#define REAL_CODE(asm_code_str)
Definition: libkir.h:226
A VESA frame buffer.
Definition: vesafb.c:94
size_t stride
Stride (offset between vertically adjacent entities)
Definition: fbcon.h:58

References __asm__(), __volatile__(), fbcon_colour_map::blue_lsb, fbcon_colour_map::blue_scale, DBGC, fbcon_colour_map::green_lsb, fbcon_colour_map::green_scale, fbcon_geometry::height, fbcon_geometry::len, vesafb::map, mode, vesafb::pixel, rc, REAL_CODE, fbcon_colour_map::red_lsb, fbcon_colour_map::red_scale, vesafb::start, status, strerror(), fbcon_geometry::stride, vbe_buf, VBE_SET_MODE, vesafb_mode_info(), vesafb_rc(), and fbcon_geometry::width.

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 358 of file vesafb.c.

360  {
361  struct vbe_mode_info *mode = &vbe_buf.mode;
362  int best_mode_number = -ENOENT;
363  unsigned int best_score = INT_MAX;
364  unsigned int score;
365  uint16_t mode_number;
366  int rc;
367 
368  /* Find the first suitable mode */
369  while ( ( mode_number = *(mode_numbers++) ) != VBE_MODE_END ) {
370 
371  /* Force linear mode variant */
372  mode_number |= VBE_MODE_LINEAR;
373 
374  /* Get mode information */
375  if ( ( rc = vesafb_mode_info ( mode_number ) ) != 0 )
376  continue;
377 
378  /* Skip unusable modes */
379  if ( ( mode->mode_attributes & ( VBE_MODE_ATTR_SUPPORTED |
381  VBE_MODE_ATTR_LINEAR ) ) !=
384  continue;
385  }
386  if ( mode->memory_model != VBE_MODE_MODEL_DIRECT_COLOUR )
387  continue;
388 
389  /* Skip modes not meeting the requirements */
390  if ( ( mode->x_resolution < min_width ) ||
391  ( mode->y_resolution < min_height ) ||
392  ( mode->bits_per_pixel < min_bpp ) ) {
393  continue;
394  }
395 
396  /* Select this mode if it has the best (i.e. lowest)
397  * score. We choose the scoring system to favour
398  * modes close to the specified width and height;
399  * within modes of the same width and height we prefer
400  * a higher colour depth.
401  */
402  score = ( ( mode->x_resolution * mode->y_resolution ) -
403  mode->bits_per_pixel );
404  if ( score < best_score ) {
405  best_mode_number = mode_number;
406  best_score = score;
407  }
408  }
409 
410  if ( best_mode_number >= 0 ) {
411  DBGC ( &vbe_buf, "VESAFB selected mode %04x\n",
412  best_mode_number );
413  } else {
414  DBGC ( &vbe_buf, "VESAFB found no suitable mode\n" );
415  }
416 
417  return best_mode_number;
418 }
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
uint16_t mode
Acceleration mode.
Definition: ena.h:26
#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:267
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 DBGC, ENOENT, INT_MAX, mode, 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, and vesafb_mode_info().

Referenced by vesafb_init().

◆ vesafb_restore()

static void vesafb_restore ( void  )
static

Restore video mode.

Definition at line 424 of file vesafb.c.

424  {
425  uint32_t discard_a;
426 
427  /* Restore saved VGA mode */
428  __asm__ __volatile__ ( REAL_CODE ( "int $0x10" )
429  : "=a" ( discard_a )
430  : "a" ( VBE_SET_VGA_MODE | vesafb.saved_mode ) );
431  DBGC ( &vbe_buf, "VESAFB restored VGA mode %#02x\n",
432  vesafb.saved_mode );
433 }
#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__("call *%9" :"=a"(result), "=c"(discard_ecx), "=d"(discard_edx) :"d"(0), "a"(code), "b"(0), "c"(in_phys), "D"(0), "S"(out_phys), "m"(hypercall))
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 441 of file vesafb.c.

441  {
442  uint32_t discard_b;
443  uint16_t *mode_numbers;
444  int mode_number;
445  int rc;
446 
447  /* Record current VGA mode */
448  __asm__ __volatile__ ( REAL_CODE ( "int $0x10" )
449  : "=a" ( vesafb.saved_mode ), "=b" ( discard_b )
450  : "a" ( VBE_GET_VGA_MODE ) );
451  DBGC ( &vbe_buf, "VESAFB saved VGA mode %#02x\n", vesafb.saved_mode );
452 
453  /* Get VESA mode list */
454  if ( ( rc = vesafb_mode_list ( &mode_numbers ) ) != 0 )
455  goto err_mode_list;
456 
457  /* Select mode */
458  if ( ( mode_number = vesafb_select_mode ( mode_numbers, config->width,
459  config->height,
460  config->depth ) ) < 0 ) {
461  rc = mode_number;
462  goto err_select_mode;
463  }
464 
465  /* Set mode */
466  if ( ( rc = vesafb_set_mode ( mode_number ) ) != 0 )
467  goto err_set_mode;
468 
469  /* Get font data */
470  vesafb_font();
471 
472  /* Initialise frame buffer console */
473  if ( ( rc = fbcon_init ( &vesafb.fbcon, phys_to_virt ( vesafb.start ),
475  config ) ) != 0 )
476  goto err_fbcon_init;
477 
478  free ( mode_numbers );
479  return 0;
480 
481  fbcon_fini ( &vesafb.fbcon );
482  err_fbcon_init:
483  err_set_mode:
484  vesafb_restore();
485  err_select_mode:
486  free ( mode_numbers );
487  err_mode_list:
488  return rc;
489 }
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
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
#define DBGC(...)
Definition: compiler.h:505
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:358
#define VBE_GET_VGA_MODE
INT 10,0f: get VGA mode.
Definition: vesafb.h:208
void fbcon_fini(struct fbcon *fbcon)
Finalise frame buffer console.
Definition: fbcon.c:728
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
__asm__ __volatile__("call *%9" :"=a"(result), "=c"(discard_ecx), "=d"(discard_edx) :"d"(0), "a"(code), "b"(0), "c"(in_phys), "D"(0), "S"(out_phys), "m"(hypercall))
struct fbcon_geometry pixel
Pixel geometry.
Definition: vesafb.c:100
static void vesafb_font(void)
Get font definition.
Definition: vesafb.c:165
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:309
static void vesafb_restore(void)
Restore video mode.
Definition: vesafb.c:424
#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:206

References __asm__(), __volatile__(), DBGC, console_configuration::depth, vesafb::fbcon, fbcon_fini(), fbcon_init(), vesafb::font, free, console_configuration::height, vesafb::map, 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 495 of file vesafb.c.

495  {
496 
497  /* Finalise frame buffer console */
498  fbcon_fini ( &vesafb.fbcon );
499 
500  /* Restore saved VGA mode */
501  vesafb_restore();
502 }
struct fbcon fbcon
Frame buffer console.
Definition: vesafb.c:96
void fbcon_fini(struct fbcon *fbcon)
Finalise frame buffer console.
Definition: fbcon.c:728
static void vesafb_restore(void)
Restore video mode.
Definition: vesafb.c:424
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 509 of file vesafb.c.

509  {
510 
511  fbcon_putchar ( &vesafb.fbcon, character );
512 }
void fbcon_putchar(struct fbcon *fbcon, int character)
Print a character to current cursor position.
Definition: fbcon.c:460
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 520 of file vesafb.c.

520  {
521  int rc;
522 
523  /* Reset console, if applicable */
524  if ( ! vesafb_console.disabled ) {
525  vesafb_fini();
528  }
529  vesafb_console.disabled = CONSOLE_DISABLED;
530 
531  /* Do nothing more unless we have a usable configuration */
532  if ( ( config == NULL ) ||
533  ( config->width == 0 ) || ( config->height == 0 ) ) {
534  return 0;
535  }
536 
537  /* Initialise VESA frame buffer */
538  if ( ( rc = vesafb_init ( config ) ) != 0 )
539  return rc;
540 
541  /* Mark console as enabled */
542  vesafb_console.disabled = 0;
544 
545  /* Set magic colour to transparent if we have a background picture */
546  if ( config->pixbuf )
548 
549  return 0;
550 }
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:441
#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:495
#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:520
static void vesafb_putchar(int character)
Print a character to current cursor position.
Definition: vesafb.c:509

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.