iPXE
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.
#define INT13CON_PARTITION_TYPE   0xe0
 Log partition type.
#define INT13CON_MAX_UNWRITTEN   64
 Maximum number of outstanding unwritten characters.
#define INT13CON_MAGIC   "iPXE LOG\n\n"
 Log partition magic signature.
#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.
static uint8_t __bss16_array (int13con_buffer, [INT13_BLKSIZE])
 Sector buffer.
static struct int13_disk_address __bss16 (int13con_address)
 Disk address packet.
static int int13con_rw (unsigned int op, uint64_t lba)
 Read/write disk sector.
static void int13con_putchar (int character)
 Write character to console.
static int int13con_find (void)
 Find log partition.
static void int13con_init (void)
 Initialise INT13 console.
struct init_fn int13con_init_fn __init_fn (INIT_CONSOLE)
 INT13 console initialisation function.

Variables

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

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.

Referenced by int13con_init(), and int13con_rw().

◆ INT13CON_PARTITION_TYPE

#define INT13CON_PARTITION_TYPE   0xe0

Log partition type.

Definition at line 51 of file int13con.c.

Referenced by int13con_find().

◆ INT13CON_MAX_UNWRITTEN

#define INT13CON_MAX_UNWRITTEN   64

Maximum number of outstanding unwritten characters.

Definition at line 54 of file int13con.c.

Referenced by int13con_putchar().

◆ INT13CON_MAGIC

#define INT13CON_MAGIC   "iPXE LOG\n\n"

Log partition magic signature.

Definition at line 63 of file int13con.c.

Referenced by int13con_find().

◆ int13con_vector

#define int13con_vector   __use_data16 ( int13con_vector )

Definition at line 67 of file int13con.c.

Referenced by __bss16(), and int13con_init().

◆ int13con_buffer

#define int13con_buffer   __use_data16 ( int13con_buffer )

Definition at line 71 of file int13con.c.

Referenced by __bss16_array(), int13con_find(), int13con_putchar(), and int13con_rw().

◆ int13con_address

#define int13con_address   __use_data16 ( int13con_address )

Definition at line 75 of file int13con.c.

Referenced by __bss16(), and int13con_rw().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ __bss16() [1/2]

struct segoff __bss16 ( int13con_vector )
static

Original INT13 vector.

References __bss16, and int13con_vector.

◆ __bss16_array()

uint8_t __bss16_array ( int13con_buffer )
static

Sector buffer.

References INT13_BLKSIZE, and int13con_buffer.

◆ __bss16() [2/2]

struct int13_disk_address __bss16 ( int13con_address )
static

Disk address packet.

References __bss16, and int13con_address.

◆ int13con_rw()

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 {
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;
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}
struct arbelprm_completion_with_error error
Definition arbel.h:1
unsigned char uint8_t
Definition stdint.h:10
#define DBG(...)
Print a debugging message.
Definition compiler.h:498
uint64_t lba
Starting block number.
Definition int13.h:11
#define EIO
Input/output error.
Definition errno.h:434
#define INT13CON_DRIVE
Disk drive number.
Definition int13con.c:48
#define int13con_address
Definition int13con.c:75
#define int13con_buffer
Definition int13con.c:71
#define rm_ds
Definition libkir.h:39
#define REAL_CODE(asm_code_str)
Definition libkir.h:226
#define __from_data16(pointer)
Definition libkir.h:22
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")

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()

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 */
159 }
160
161 /* Move to next sector, if applicable */
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:3
#define INT13_EXTENDED_WRITE
Extended write.
Definition int13.h:39
void * memset(void *dest, int character, size_t len) __nonnull
#define INT13_BLKSIZE
Block size for non-extended INT 13 calls.
Definition int13.h:72
static uint64_t int13con_max_lba
Maximum LBA.
Definition int13con.c:81
static size_t int13con_offset
Current offset within sector.
Definition int13con.c:84
#define INT13CON_MAX_UNWRITTEN
Maximum number of outstanding unwritten characters.
Definition int13con.c:54
static int int13con_rw(unsigned int op, uint64_t lba)
Read/write disk sector.
Definition int13con.c:98
static uint64_t int13con_lba
Current LBA.
Definition int13con.c:78
static size_t int13con_unwritten
Number of unwritten characters.
Definition int13con.c:87

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()

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}
struct golan_inbox_hdr hdr
Message header.
Definition CIB_PRM.h:0
uint32_t type
Operating system type.
Definition ena.h:1
#define DBG2_HDA(...)
Definition compiler.h:516
uint32_t start
Starting offset.
Definition netvsc.h:1
#define INT13_MBR_MAGIC
MBR magic signature.
Definition int13.h:292
uint16_t magic
0x55aa MBR signature
Definition int13.h:288
struct partition_table_entry partitions[4]
Partition table.
Definition int13.h:286
#define INT13_EXTENDED_READ
Extended read.
Definition int13.h:37
#define ENOENT
No such file or directory.
Definition errno.h:515
#define EINVAL
Invalid argument.
Definition errno.h:429
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define INT13CON_MAGIC
Log partition magic signature.
Definition int13con.c:63
#define INT13CON_PARTITION_TYPE
Log partition type.
Definition int13con.c:51
u16 length
Definition sky2.h:1
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition string.c:115
Log partition header.
Definition int13con.c:57
A Master Boot Record.
Definition int13.h:278
A partition table entry within the MBR.
Definition int13.h:262

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, partition_table_entry::start, start, strerror(), and type.

Referenced by int13con_init().

◆ int13con_init()

void int13con_init ( void )
static

Initialise INT13 console.

Definition at line 253 of file int13con.c.

253 {
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}
__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 short uint16_t
Definition stdint.h:11
long discard_c
Definition bigint.h:33
#define INT13_EXTENSION_CHECK
Extensions installation check.
Definition int13.h:35
static int int13con_find(void)
Find log partition.
Definition int13con.c:185
#define int13con_vector
Definition int13con.c:67
#define copy_from_real
Definition libkir.h:79

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

Referenced by __init_fn().

◆ __init_fn()

struct init_fn int13con_init_fn __init_fn ( INIT_CONSOLE )

INT13 console initialisation function.

References __init_fn, INIT_CONSOLE, and int13con_init().

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,
}
#define CONSOLE_INT13
Definition console.h:36
#define CONSOLE_DISABLED
Console is disabled for all uses.
Definition console.h:112
static void int13con_putchar(int character)
Write character to console.
Definition int13con.c:132

INT13 console driver.

Definition at line 89 of file int13con.c.