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

INT13 disk log console. More...

#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <ipxe/console.h>
#include <ipxe/init.h>
#include <realmode.h>
#include <int13.h>
#include <config/console.h>

Go to the source code of this file.

Data Structures

struct  int13con_header
 Log partition header. More...
 

Macros

#define CONSOLE_INT13   ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_LOG )
 
#define INT13CON_DRIVE   0x80
 Disk drive number. More...
 
#define INT13CON_PARTITION_TYPE   0xe0
 Log partition type. More...
 
#define INT13CON_MAX_UNWRITTEN   64
 Maximum number of outstanding unwritten characters. More...
 
#define INT13CON_MAGIC   "iPXE LOG\n\n"
 Log partition magic signature. More...
 
#define int13con_vector   __use_data16 ( int13con_vector )
 
#define int13con_buffer   __use_data16 ( int13con_buffer )
 
#define int13con_address   __use_data16 ( int13con_address )
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static struct segoff __bss16 (int13con_vector)
 Original INT13 vector. More...
 
static uint8_t __bss16_array (int13con_buffer, [INT13_BLKSIZE])
 Sector buffer. More...
 
static struct int13_disk_address __bss16 (int13con_address)
 Disk address packet. More...
 
static int int13con_rw (unsigned int op, uint64_t lba)
 Read/write disk sector. More...
 
static void int13con_putchar (int character)
 Write character to console. More...
 
static int int13con_find (void)
 Find log partition. More...
 
static void int13con_init (void)
 Initialise INT13 console. More...
 
struct init_fn int13con_init_fn __init_fn (INIT_CONSOLE)
 INT13 console initialisation function. More...
 

Variables

static uint64_t int13con_lba
 Current LBA. More...
 
static uint64_t int13con_max_lba
 Maximum LBA. More...
 
static size_t int13con_offset
 Current offset within sector. More...
 
static size_t int13con_unwritten
 Number of unwritten characters. More...
 
struct console_driver int13con __console_driver
 INT13 console driver. More...
 

Detailed Description

INT13 disk log console.

Definition in file int13con.c.

Macro Definition Documentation

◆ CONSOLE_INT13

#define CONSOLE_INT13   ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_LOG )

Definition at line 44 of file int13con.c.

◆ INT13CON_DRIVE

#define INT13CON_DRIVE   0x80

Disk drive number.

Definition at line 48 of file int13con.c.

◆ INT13CON_PARTITION_TYPE

#define INT13CON_PARTITION_TYPE   0xe0

Log partition type.

Definition at line 51 of file int13con.c.

◆ INT13CON_MAX_UNWRITTEN

#define INT13CON_MAX_UNWRITTEN   64

Maximum number of outstanding unwritten characters.

Definition at line 54 of file int13con.c.

◆ INT13CON_MAGIC

#define INT13CON_MAGIC   "iPXE LOG\n\n"

Log partition magic signature.

Definition at line 63 of file int13con.c.

◆ int13con_vector

#define int13con_vector   __use_data16 ( int13con_vector )

Definition at line 67 of file int13con.c.

◆ int13con_buffer

#define int13con_buffer   __use_data16 ( int13con_buffer )

Definition at line 71 of file int13con.c.

◆ int13con_address

#define int13con_address   __use_data16 ( int13con_address )

Definition at line 75 of file int13con.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ __bss16() [1/2]

static struct segoff __bss16 ( int13con_vector  )
static

Original INT13 vector.

◆ __bss16_array()

static uint8_t __bss16_array ( int13con_buffer  )
static

Sector buffer.

◆ __bss16() [2/2]

static struct int13_disk_address __bss16 ( int13con_address  )
static

Disk address packet.

◆ int13con_rw()

static int int13con_rw ( unsigned int  op,
uint64_t  lba 
)
static

Read/write disk sector.

Parameters
opOperation
lbaLogical block address
Return values
rcReturn status code

Definition at line 98 of file int13con.c.

98  {
99  uint8_t error;
100 
101  /* Construct disk address packet */
102  int13con_address.bufsize = sizeof ( int13con_address );
103  int13con_address.count = 1;
104  int13con_address.buffer.segment = rm_ds;
105  int13con_address.buffer.offset = __from_data16 ( int13con_buffer );
106  int13con_address.lba = lba;
107 
108  /* Emulate INT13 via original vector. We do this since iPXE
109  * (or another subsequent bootloader) may hook INT13 and remap
110  * drive numbers.
111  */
112  __asm__ ( REAL_CODE ( "pushfw\n\t"
113  "cli\n\t"
114  "lcall *int13con_vector\n\t" )
115  : "=a" ( error )
116  : "0" ( op << 8 ), "d" ( INT13CON_DRIVE ),
117  "S" ( __from_data16 ( &int13con_address ) ) );
118  if ( error ) {
119  DBG ( "INT13CON operation %04x failed: %02x\n",
120  op, error );
121  return -EIO;
122  }
123 
124  return 0;
125 }
uint32_t lba
Start address.
Definition: scsi.h:23
#define INT13CON_DRIVE
Disk drive number.
Definition: int13con.c:48
struct arbelprm_completion_with_error error
Definition: arbel.h:12
#define rm_ds
Definition: libkir.h:39
#define int13con_address
Definition: int13con.c:75
unsigned char uint8_t
Definition: stdint.h:10
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
__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
#define EIO
Input/output error.
Definition: errno.h:433
#define int13con_buffer
Definition: int13con.c:71
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define REAL_CODE(asm_code_str)
Definition: libkir.h:226

References __asm__(), __from_data16, DBG, EIO, error, int13con_address, int13con_buffer, INT13CON_DRIVE, lba, op, REAL_CODE, and rm_ds.

Referenced by int13con_find(), and int13con_putchar().

◆ int13con_putchar()

static void int13con_putchar ( int  character)
static

Write character to console.

Parameters
characterCharacter

Definition at line 132 of file int13con.c.

132  {
133  static int busy;
134  int rc;
135 
136  /* Ignore if we are already mid-logging */
137  if ( busy )
138  return;
139  busy = 1;
140 
141  /* Write character to buffer */
142  int13con_buffer[int13con_offset++] = character;
144 
145  /* Write sector to disk, if applicable */
146  if ( ( int13con_offset == INT13_BLKSIZE ) ||
148  ( character == '\n' ) ) {
149 
150  /* Write sector to disk */
152  int13con_lba ) ) != 0 ) {
153  DBG ( "INT13CON could not write log\n" );
154  /* Ignore and continue; there's nothing we can do */
155  }
156 
157  /* Reset count of unwritten characters */
158  int13con_unwritten = 0;
159  }
160 
161  /* Move to next sector, if applicable */
162  if ( int13con_offset == INT13_BLKSIZE ) {
163 
164  /* Disable console if we have run out of space */
166  int13con.disabled = 1;
167 
168  /* Clear log buffer */
169  memset ( int13con_buffer, 0, sizeof ( int13con_buffer ) );
170  int13con_offset = 0;
171 
172  /* Move to next sector */
173  int13con_lba++;
174  }
175 
176  /* Clear busy flag */
177  busy = 0;
178 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static uint64_t int13con_max_lba
Maximum LBA.
Definition: int13con.c:81
#define INT13CON_MAX_UNWRITTEN
Maximum number of outstanding unwritten characters.
Definition: int13con.c:54
#define INT13_EXTENDED_WRITE
Extended write.
Definition: int13.h:39
static uint64_t int13con_lba
Current LBA.
Definition: int13con.c:78
static size_t int13con_unwritten
Number of unwritten characters.
Definition: int13con.c:87
#define INT13_BLKSIZE
Block size for non-extended INT 13 calls.
Definition: int13.h:72
static size_t int13con_offset
Current offset within sector.
Definition: int13con.c:84
static int int13con_rw(unsigned int op, uint64_t lba)
Read/write disk sector.
Definition: int13con.c:98
#define int13con_buffer
Definition: int13con.c:71
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
void * memset(void *dest, int character, size_t len) __nonnull

References DBG, INT13_BLKSIZE, INT13_EXTENDED_WRITE, int13con_buffer, int13con_lba, int13con_max_lba, INT13CON_MAX_UNWRITTEN, int13con_offset, int13con_rw(), int13con_unwritten, memset(), and rc.

◆ int13con_find()

static int int13con_find ( void  )
static

Find log partition.

Return values
rcReturn status code

Definition at line 185 of file int13con.c.

185  {
186  struct master_boot_record *mbr =
187  ( ( struct master_boot_record * ) int13con_buffer );
188  struct int13con_header *hdr =
189  ( ( struct int13con_header * ) int13con_buffer );
190  struct partition_table_entry part[4];
191  unsigned int i;
192  int rc;
193 
194  /* Read MBR */
195  if ( ( rc = int13con_rw ( INT13_EXTENDED_READ, 0 ) ) != 0 ) {
196  DBG ( "INT13CON could not read MBR: %s\n", strerror ( rc ) );
197  return rc;
198  }
199 
200  /* Check MBR magic */
201  if ( mbr->magic != INT13_MBR_MAGIC ) {
202  DBG ( "INT13CON incorrect MBR magic\n" );
203  DBG2_HDA ( 0, mbr, sizeof ( *mbr ) );
204  return -EINVAL;
205  }
206 
207  /* Look for magic partition */
208  memcpy ( part, mbr->partitions, sizeof ( part ) );
209  for ( i = 0 ; i < ( sizeof ( part ) / sizeof ( part[0] ) ) ; i++ ) {
210 
211  /* Skip partitions of the wrong type */
212  if ( part[i].type != INT13CON_PARTITION_TYPE )
213  continue;
214 
215  /* Read partition header */
217  part[i].start ) ) != 0 ) {
218  DBG ( "INT13CON partition %d could not read header: "
219  "%s\n", ( i + 1 ), strerror ( rc ) );
220  continue;
221  }
222 
223  /* Check partition header */
224  if ( memcmp ( hdr->magic, INT13CON_MAGIC,
225  sizeof ( hdr->magic ) ) != 0 ) {
226  DBG ( "INT13CON partition %d bad magic\n", ( i + 1 ) );
227  DBG2_HDA ( 0, hdr, sizeof ( *hdr ) );
228  continue;
229  }
230 
231  /* Found log partition */
232  DBG ( "INT13CON partition %d at [%08x,%08x)\n", ( i + 1 ),
233  part[i].start, ( part[i].start + part[i].length ) );
234  int13con_lba = part[i].start;
235  int13con_max_lba = ( part[i].start + part[i].length - 1 );
236 
237  /* Initialise log buffer */
238  memset ( &int13con_buffer[ sizeof ( *hdr ) ], 0,
239  ( sizeof ( int13con_buffer ) - sizeof ( *hdr ) ) );
240  int13con_offset = sizeof ( hdr->magic );
241 
242  return 0;
243  }
244 
245  DBG ( "INT13CON found no log partition\n" );
246  return -ENOENT;
247 }
uint16_t length
Length.
Definition: intel.h:14
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define INT13_MBR_MAGIC
MBR magic signature.
Definition: int13.h:292
struct partition_table_entry partitions[4]
Partition table.
Definition: int13.h:286
static uint64_t int13con_max_lba
Maximum LBA.
Definition: int13con.c:81
static uint64_t int13con_lba
Current LBA.
Definition: int13con.c:78
uint8_t type
Type.
Definition: ena.h:16
#define ENOENT
No such file or directory.
Definition: errno.h:514
static size_t int13con_offset
Current offset within sector.
Definition: int13con.c:84
uint32_t start
Starting offset.
Definition: netvsc.h:12
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define INT13CON_MAGIC
Log partition magic signature.
Definition: int13con.c:63
A Master Boot Record.
Definition: int13.h:278
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define DBG2_HDA(...)
Definition: compiler.h:516
uint32_t hdr
Message header.
Definition: intelvf.h:12
static int int13con_rw(unsigned int op, uint64_t lba)
Read/write disk sector.
Definition: int13con.c:98
#define int13con_buffer
Definition: int13con.c:71
#define INT13CON_PARTITION_TYPE
Log partition type.
Definition: int13con.c:51
#define INT13_EXTENDED_READ
Extended read.
Definition: int13.h:37
Log partition header.
Definition: int13con.c:57
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
A partition table entry within the MBR.
Definition: int13.h:262
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:98
uint16_t magic
0x55aa MBR signature
Definition: int13.h:288
void * memset(void *dest, int character, size_t len) __nonnull

References DBG, DBG2_HDA, EINVAL, ENOENT, hdr, INT13_EXTENDED_READ, INT13_MBR_MAGIC, int13con_buffer, int13con_lba, INT13CON_MAGIC, int13con_max_lba, int13con_offset, INT13CON_PARTITION_TYPE, int13con_rw(), length, partition_table_entry::length, master_boot_record::magic, memcmp(), memcpy(), memset(), master_boot_record::partitions, rc, start, partition_table_entry::start, strerror(), and type.

Referenced by int13con_init().

◆ int13con_init()

static void int13con_init ( void  )
static

Initialise INT13 console.

Definition at line 253 of file int13con.c.

253  {
254  uint8_t error;
255  uint16_t check;
256  unsigned int discard_c;
257  unsigned int discard_d;
258  int rc;
259 
260  /* Check for INT13 extensions */
261  __asm__ __volatile__ ( REAL_CODE ( "int $0x13\n\t"
262  "setc %%al\n\t" )
263  : "=a" ( error ), "=b" ( check ),
264  "=c" ( discard_c ), "=d" ( discard_d )
265  : "0" ( INT13_EXTENSION_CHECK << 8 ),
266  "1" ( 0x55aa ), "3" ( INT13CON_DRIVE ) );
267  if ( error || ( check != 0xaa55 ) ) {
268  DBG ( "INT13CON missing extensions (%02x,%04x)\n",
269  error, check );
270  return;
271  }
272 
273  /* Store original INT13 vector */
274  copy_from_real ( &int13con_vector, 0, ( 0x13 * 4 ),
275  sizeof ( int13con_vector ) );
276  DBG ( "INT13CON using original INT13 vector %04x:%04x\n",
277  int13con_vector.segment, int13con_vector.offset );
278 
279  /* Locate log partition */
280  if ( ( rc = int13con_find() ) != 0)
281  return;
282 
283  /* Enable console */
284  int13con.disabled = 0;
285 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned short uint16_t
Definition: stdint.h:11
#define INT13_EXTENSION_CHECK
Extensions installation check.
Definition: int13.h:35
#define INT13CON_DRIVE
Disk drive number.
Definition: int13con.c:48
struct arbelprm_completion_with_error error
Definition: arbel.h:12
#define int13con_vector
Definition: int13con.c:67
unsigned char uint8_t
Definition: stdint.h:10
__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 copy_from_real
Definition: libkir.h:79
__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")
long discard_c
Definition: bigint.h:30
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define REAL_CODE(asm_code_str)
Definition: libkir.h:226
static int int13con_find(void)
Find log partition.
Definition: int13con.c:185

References __asm__(), __volatile__(), copy_from_real, DBG, discard_c, error, INT13_EXTENSION_CHECK, INT13CON_DRIVE, int13con_find(), int13con_vector, rc, and REAL_CODE.

◆ __init_fn()

struct init_fn int13con_init_fn __init_fn ( INIT_CONSOLE  )

INT13 console initialisation function.

Variable Documentation

◆ int13con_lba

uint64_t int13con_lba
static

Current LBA.

Definition at line 78 of file int13con.c.

Referenced by int13con_find(), and int13con_putchar().

◆ int13con_max_lba

uint64_t int13con_max_lba
static

Maximum LBA.

Definition at line 81 of file int13con.c.

Referenced by int13con_find(), and int13con_putchar().

◆ int13con_offset

size_t int13con_offset
static

Current offset within sector.

Definition at line 84 of file int13con.c.

Referenced by int13con_find(), and int13con_putchar().

◆ int13con_unwritten

size_t int13con_unwritten
static

Number of unwritten characters.

Definition at line 87 of file int13con.c.

Referenced by int13con_putchar().

◆ __console_driver

struct console_driver int13con __console_driver
Initial value:
= {
.putchar = int13con_putchar,
.disabled = CONSOLE_DISABLED,
.usage = CONSOLE_INT13,
}
static void int13con_putchar(int character)
Write character to console.
Definition: int13con.c:132
#define CONSOLE_DISABLED
Console is disabled for all uses.
Definition: console.h:111
#define CONSOLE_INT13
Definition: int13con.c:44

INT13 console driver.

Definition at line 89 of file int13con.c.