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 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.

◆ vbe_buf

#define vbe_buf   __use_data16 ( vbe_buf )

Definition at line 113 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 121 of file vesafb.c.

121  {
122  unsigned int code;
123 
124  if ( ( status & 0xff ) != 0x4f )
125  return -ENOTSUP;
126  code = ( ( status >> 8 ) & 0xff );
127  return ( code ? -EIO_VBE ( code ) : 0 );
128 }
#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
characterCharacter
glyphCharacter glyph to fill in

Definition at line 136 of file vesafb.c.

136  {
137  size_t offset = ( character * VESAFB_CHAR_HEIGHT );
138 
141 }
uint16_t segment
Definition: registers.h:193
#define VESAFB_CHAR_HEIGHT
Character height.
Definition: vesafb.c:76
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:97
#define copy_from_real
Definition: libkir.h:79
A VESA frame buffer.
Definition: vesafb.c:85

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

Referenced by vesafb_font().

◆ vesafb_font()

static void vesafb_font ( void  )
static

Get font definition.

Definition at line 147 of file vesafb.c.

147  {
148 
149  /* Get font information
150  *
151  * Working around gcc bugs is icky here. The value we want is
152  * returned in %ebp, but there's no way to specify %ebp in an
153  * output constraint. We can't put %ebp in the clobber list,
154  * because this tends to cause random build failures on some
155  * gcc versions. We can't manually push/pop %ebp and return
156  * the value via a generic register output constraint, because
157  * gcc might choose to use %ebp to satisfy that constraint
158  * (and we have no way to prevent it from so doing).
159  *
160  * Work around this hideous mess by using %ecx and %edx as the
161  * output registers, since they get clobbered anyway.
162  */
163  __asm__ __volatile__ ( REAL_CODE ( "pushw %%bp\n\t" /* gcc bug */
164  "int $0x10\n\t"
165  "movw %%es, %%cx\n\t"
166  "movw %%bp, %%dx\n\t"
167  "popw %%bp\n\t" /* gcc bug */ )
168  : "=c" ( vesafb.glyphs.segment ),
169  "=d" ( vesafb.glyphs.offset )
170  : "a" ( VBE_GET_FONT ),
171  "b" ( VESAFB_FONT ) );
172  DBGC ( &vbe_buf, "VESAFB has font %04x at %04x:%04x\n",
176 }
uint16_t segment
Definition: registers.h:193
unsigned int height
Character height (in pixels)
Definition: fbcon.h:35
#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:42
uint16_t offset
Definition: registers.h:192
static void vesafb_glyph(unsigned int character, uint8_t *glyph)
Get character glyph.
Definition: vesafb.c:136
#define VBE_GET_FONT
INT 10,1130: get font information.
Definition: vesafb.h:186
struct fbcon_font font
Font definition.
Definition: vesafb.c:95
__asm__ __volatile__("\n1:\n\t" "movb -1(%2,%1), %%al\n\t" "stosb\n\t" "loop 1b\n\t" "xorl %%eax, %%eax\n\t" "mov %3, %1\n\t" "rep stosb\n\t" :"=&D"(discard_D), "=&c"(discard_c) :"r"(data), "g"(pad_len), "0"(value0), "1"(len) :"eax")
struct segoff glyphs
Character glyphs.
Definition: vesafb.c:97
__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:113
#define REAL_CODE(asm_code_str)
Definition: libkir.h:226
A VESA frame buffer.
Definition: vesafb.c:85

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

186  {
187  struct vbe_controller_info *controller = &vbe_buf.controller;
189  uint16_t mode_number;
191  size_t len;
192  int rc;
193 
194  /* Avoid returning uninitialised data on error */
195  *mode_numbers = NULL;
196 
197  /* Get controller information block */
198  controller->vbe_signature = 0;
199  __asm__ __volatile__ ( REAL_CODE ( "int $0x10" )
200  : "=a" ( status )
201  : "a" ( VBE_CONTROLLER_INFO ),
202  "D" ( __from_data16 ( controller ) )
203  : "memory", "ebx", "edx" );
204  if ( ( rc = vesafb_rc ( status ) ) != 0 ) {
205  DBGC ( &vbe_buf, "VESAFB could not get controller information: "
206  "[%04x] %s\n", status, strerror ( rc ) );
207  return rc;
208  }
209  if ( controller->vbe_signature != VBE_CONTROLLER_SIGNATURE ) {
210  DBGC ( &vbe_buf, "VESAFB invalid controller signature "
211  "\"%c%c%c%c\"\n", ( controller->vbe_signature >> 0 ),
212  ( controller->vbe_signature >> 8 ),
213  ( controller->vbe_signature >> 16 ),
214  ( controller->vbe_signature >> 24 ) );
215  DBGC_HDA ( &vbe_buf, 0, controller, sizeof ( *controller ) );
216  return -EINVAL;
217  }
218  DBGC ( &vbe_buf, "VESAFB found VBE version %d.%d with mode list at "
219  "%04x:%04x\n", controller->vbe_major_version,
220  controller->vbe_minor_version,
221  controller->video_mode_ptr.segment,
222  controller->video_mode_ptr.offset );
223 
224  /* Calculate length of mode list */
225  video_mode_ptr = real_to_user ( controller->video_mode_ptr.segment,
226  controller->video_mode_ptr.offset );
227  len = 0;
228  do {
229  copy_from_user ( &mode_number, video_mode_ptr, len,
230  sizeof ( mode_number ) );
231  len += sizeof ( mode_number );
232  } while ( mode_number != VBE_MODE_END );
233 
234  /* Allocate and fill mode list */
235  *mode_numbers = malloc ( len );
236  if ( ! *mode_numbers )
237  return -ENOMEM;
238  copy_from_user ( *mode_numbers, video_mode_ptr, 0, len );
239 
240  return 0;
241 }
#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
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:583
__asm__ __volatile__("\n1:\n\t" "movb -1(%2,%1), %%al\n\t" "stosb\n\t" "loop 1b\n\t" "xorl %%eax, %%eax\n\t" "mov %3, %1\n\t" "rep stosb\n\t" :"=&D"(discard_D), "=&c"(discard_c) :"r"(data), "g"(pad_len), "0"(value0), "1"(len) :"eax")
#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:113
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:121
#define REAL_CODE(asm_code_str)
Definition: libkir.h:226
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
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 249 of file vesafb.c.

249  {
250  struct vbe_mode_info *mode = &vbe_buf.mode;
252  int rc;
253 
254  /* Get mode information */
255  __asm__ __volatile__ ( REAL_CODE ( "int $0x10" )
256  : "=a" ( status )
257  : "a" ( VBE_MODE_INFO ),
258  "c" ( mode_number ),
259  "D" ( __from_data16 ( mode ) )
260  : "memory" );
261  if ( ( rc = vesafb_rc ( status ) ) != 0 ) {
262  DBGC ( &vbe_buf, "VESAFB could not get mode %04x information: "
263  "[%04x] %s\n", mode_number, status, strerror ( rc ) );
264  return rc;
265  }
266  DBGC ( &vbe_buf, "VESAFB mode %04x %dx%d %dbpp(%d:%d:%d:%d) model "
267  "%02x [x%d]%s%s%s%s%s\n", mode_number, mode->x_resolution,
268  mode->y_resolution, mode->bits_per_pixel, mode->rsvd_mask_size,
269  mode->red_mask_size, mode->green_mask_size, mode->blue_mask_size,
270  mode->memory_model, ( mode->number_of_image_pages + 1 ),
272  "" : " [unsupported]" ),
273  ( ( mode->mode_attributes & VBE_MODE_ATTR_TTY ) ?
274  " [tty]" : "" ),
276  "" : " [text]" ),
277  ( ( mode->mode_attributes & VBE_MODE_ATTR_LINEAR ) ?
278  "" : " [nonlinear]" ),
280  " [buf]" : "" ) );
281 
282  return 0;
283 }
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
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__ __volatile__("\n1:\n\t" "movb -1(%2,%1), %%al\n\t" "stosb\n\t" "loop 1b\n\t" "xorl %%eax, %%eax\n\t" "mov %3, %1\n\t" "rep stosb\n\t" :"=&D"(discard_D), "=&c"(discard_c) :"r"(data), "g"(pad_len), "0"(value0), "1"(len) :"eax")
__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:113
static int vesafb_rc(unsigned int status)
Convert VBE status code to iPXE status code.
Definition: vesafb.c:121
#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 291 of file vesafb.c.

291  {
292  struct vbe_mode_info *mode = &vbe_buf.mode;
294  int rc;
295 
296  /* Get mode information */
297  if ( ( rc = vesafb_mode_info ( mode_number ) ) != 0 )
298  return rc;
299 
300  /* Record mode parameters */
301  vesafb.start = mode->phys_base_ptr;
302  vesafb.pixel.width = mode->x_resolution;
304  vesafb.pixel.len = ( ( mode->bits_per_pixel + 7 ) / 8 );
306  DBGC ( &vbe_buf, "VESAFB mode %04x has frame buffer at %08x\n",
307  mode_number, mode->phys_base_ptr );
308 
309  /* Initialise font colours */
310  vesafb.map.red_scale = ( 8 - mode->red_mask_size );
311  vesafb.map.green_scale = ( 8 - mode->green_mask_size );
312  vesafb.map.blue_scale = ( 8 - mode->blue_mask_size );
316 
317  /* Select this mode */
318  __asm__ __volatile__ ( REAL_CODE ( "int $0x10" )
319  : "=a" ( status )
320  : "a" ( VBE_SET_MODE ),
321  "b" ( mode_number ) );
322  if ( ( rc = vesafb_rc ( status ) ) != 0 ) {
323  DBGC ( &vbe_buf, "VESAFB could not set mode %04x: [%04x] %s\n",
324  mode_number, status, strerror ( rc ) );
325  return rc;
326  }
327 
328  return 0;
329 }
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:84
uint8_t red_lsb
Red LSB.
Definition: fbcon.h:82
unsigned int width
Width (number of entities per displayed row)
Definition: fbcon.h:52
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: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:249
physaddr_t start
Physical start address.
Definition: vesafb.c:89
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:78
struct fbcon_geometry pixel
Pixel geometry.
Definition: vesafb.c:91
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:80
__asm__ __volatile__("\n1:\n\t" "movb -1(%2,%1), %%al\n\t" "stosb\n\t" "loop 1b\n\t" "xorl %%eax, %%eax\n\t" "mov %3, %1\n\t" "rep stosb\n\t" :"=&D"(discard_D), "=&c"(discard_c) :"r"(data), "g"(pad_len), "0"(value0), "1"(len) :"eax")
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:54
VBE mode information.
Definition: vesafb.h:62
#define vbe_buf
Definition: vesafb.c:113
#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:121
struct fbcon_colour_map map
Colour mapping.
Definition: vesafb.c:93
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:85
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:58

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

342  {
343  struct vbe_mode_info *mode = &vbe_buf.mode;
344  int best_mode_number = -ENOENT;
345  unsigned int best_score = INT_MAX;
346  unsigned int score;
347  uint16_t mode_number;
348  int rc;
349 
350  /* Find the first suitable mode */
351  while ( ( mode_number = *(mode_numbers++) ) != VBE_MODE_END ) {
352 
353  /* Force linear mode variant */
354  mode_number |= VBE_MODE_LINEAR;
355 
356  /* Get mode information */
357  if ( ( rc = vesafb_mode_info ( mode_number ) ) != 0 )
358  continue;
359 
360  /* Skip unusable modes */
361  if ( ( mode->mode_attributes & ( VBE_MODE_ATTR_SUPPORTED |
363  VBE_MODE_ATTR_LINEAR ) ) !=
366  continue;
367  }
369  continue;
370 
371  /* Skip modes not meeting the requirements */
372  if ( ( mode->x_resolution < min_width ) ||
373  ( mode->y_resolution < min_height ) ||
374  ( mode->bits_per_pixel < min_bpp ) ) {
375  continue;
376  }
377 
378  /* Select this mode if it has the best (i.e. lowest)
379  * score. We choose the scoring system to favour
380  * modes close to the specified width and height;
381  * within modes of the same width and height we prefer
382  * a higher colour depth.
383  */
384  score = ( ( mode->x_resolution * mode->y_resolution ) -
385  mode->bits_per_pixel );
386  if ( score < best_score ) {
387  best_mode_number = mode_number;
388  best_score = score;
389  }
390  }
391 
392  if ( best_mode_number >= 0 ) {
393  DBGC ( &vbe_buf, "VESAFB selected mode %04x\n",
394  best_mode_number );
395  } else {
396  DBGC ( &vbe_buf, "VESAFB found no suitable mode\n" );
397  }
398 
399  return best_mode_number;
400 }
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:249
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:113
#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 406 of file vesafb.c.

406  {
407  uint32_t discard_a;
408 
409  /* Restore saved VGA mode */
410  __asm__ __volatile__ ( REAL_CODE ( "int $0x10" )
411  : "=a" ( discard_a )
412  : "a" ( VBE_SET_VGA_MODE | vesafb.saved_mode ) );
413  DBGC ( &vbe_buf, "VESAFB restored VGA mode %#02x\n",
414  vesafb.saved_mode );
415 }
#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:99
unsigned int uint32_t
Definition: stdint.h:12
__asm__ __volatile__("\n1:\n\t" "movb -1(%2,%1), %%al\n\t" "stosb\n\t" "loop 1b\n\t" "xorl %%eax, %%eax\n\t" "mov %3, %1\n\t" "rep stosb\n\t" :"=&D"(discard_D), "=&c"(discard_c) :"r"(data), "g"(pad_len), "0"(value0), "1"(len) :"eax")
__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:113
#define REAL_CODE(asm_code_str)
Definition: libkir.h:226
A VESA frame buffer.
Definition: vesafb.c:85

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

423  {
424  uint32_t discard_b;
425  uint16_t *mode_numbers;
426  int mode_number;
427  int rc;
428 
429  /* Record current VGA mode */
430  __asm__ __volatile__ ( REAL_CODE ( "int $0x10" )
431  : "=a" ( vesafb.saved_mode ), "=b" ( discard_b )
432  : "a" ( VBE_GET_VGA_MODE ) );
433  DBGC ( &vbe_buf, "VESAFB saved VGA mode %#02x\n", vesafb.saved_mode );
434 
435  /* Get VESA mode list */
436  if ( ( rc = vesafb_mode_list ( &mode_numbers ) ) != 0 )
437  goto err_mode_list;
438 
439  /* Select mode */
440  if ( ( mode_number = vesafb_select_mode ( mode_numbers, config->width,
441  config->height,
442  config->depth ) ) < 0 ) {
443  rc = mode_number;
444  goto err_select_mode;
445  }
446 
447  /* Set mode */
448  if ( ( rc = vesafb_set_mode ( mode_number ) ) != 0 )
449  goto err_set_mode;
450 
451  /* Get font data */
452  vesafb_font();
453 
454  /* Initialise frame buffer console */
455  if ( ( rc = fbcon_init ( &vesafb.fbcon, phys_to_user ( vesafb.start ),
457  config ) ) != 0 )
458  goto err_fbcon_init;
459 
460  free ( mode_numbers );
461  return 0;
462 
463  fbcon_fini ( &vesafb.fbcon );
464  err_fbcon_init:
465  err_set_mode:
466  vesafb_restore();
467  err_select_mode:
468  free ( mode_numbers );
469  err_mode_list:
470  return rc;
471 }
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:87
unsigned int depth
Colour depth.
Definition: console.h:30
uint8_t saved_mode
Saved VGA mode.
Definition: vesafb.c:99
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:340
#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:583
void fbcon_fini(struct fbcon *fbcon)
Finalise frame buffer console.
Definition: fbcon.c:713
physaddr_t start
Physical start address.
Definition: vesafb.c:89
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
struct fbcon_font font
Font definition.
Definition: vesafb.c:95
struct fbcon_geometry pixel
Pixel geometry.
Definition: vesafb.c:91
static void vesafb_font(void)
Get font definition.
Definition: vesafb.c:147
unsigned int uint32_t
Definition: stdint.h:12
__asm__ __volatile__("\n1:\n\t" "movb -1(%2,%1), %%al\n\t" "stosb\n\t" "loop 1b\n\t" "xorl %%eax, %%eax\n\t" "mov %3, %1\n\t" "rep stosb\n\t" :"=&D"(discard_D), "=&c"(discard_c) :"r"(data), "g"(pad_len), "0"(value0), "1"(len) :"eax")
__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:291
static void vesafb_restore(void)
Restore video mode.
Definition: vesafb.c:406
#define vbe_buf
Definition: vesafb.c:113
struct fbcon_colour_map map
Colour mapping.
Definition: vesafb.c:93
#define REAL_CODE(asm_code_str)
Definition: libkir.h:226
A VESA frame buffer.
Definition: vesafb.c:85
static int vesafb_mode_list(uint16_t **mode_numbers)
Get VBE mode list.
Definition: vesafb.c:186

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

477  {
478 
479  /* Finalise frame buffer console */
480  fbcon_fini ( &vesafb.fbcon );
481 
482  /* Restore saved VGA mode */
483  vesafb_restore();
484 }
struct fbcon fbcon
Frame buffer console.
Definition: vesafb.c:87
void fbcon_fini(struct fbcon *fbcon)
Finalise frame buffer console.
Definition: fbcon.c:713
static void vesafb_restore(void)
Restore video mode.
Definition: vesafb.c:406
A VESA frame buffer.
Definition: vesafb.c:85

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

491  {
492 
493  fbcon_putchar ( &vesafb.fbcon, character );
494 }
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:87
A VESA frame buffer.
Definition: vesafb.c:85

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

502  {
503  int rc;
504 
505  /* Reset console, if applicable */
506  if ( ! vesafb_console.disabled ) {
507  vesafb_fini();
510  }
511  vesafb_console.disabled = CONSOLE_DISABLED;
512 
513  /* Do nothing more unless we have a usable configuration */
514  if ( ( config == NULL ) ||
515  ( config->width == 0 ) || ( config->height == 0 ) ) {
516  return 0;
517  }
518 
519  /* Initialise VESA frame buffer */
520  if ( ( rc = vesafb_init ( config ) ) != 0 )
521  return rc;
522 
523  /* Mark console as enabled */
524  vesafb_console.disabled = 0;
526 
527  /* Set magic colour to transparent if we have a background picture */
528  if ( config->pixbuf )
530 
531  return 0;
532 }
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:423
#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:477
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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:502
static void vesafb_putchar(int character)
Print a character to current cursor position.
Definition: vesafb.c:491

VESA frame buffer console driver.

Definition at line 82 of file vesafb.c.

◆ __attribute__

◆ vesafb

struct vesafb vesafb
static

The VESA frame buffer.

Definition at line 103 of file vesafb.c.