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/disklog.h>
#include <ipxe/init.h>
#include <realmode.h>
#include <int13.h>
#include <config/console.h>

Go to the source code of this file.

Macros

#define CONSOLE_INT13   ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_LOG )
#define INT13CON_DRIVE   0x80
 Disk drive number.
#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 int int13con_write (void)
 Write current logical block.
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.
 __asm__ (".globl ipxe_oem_info_disklog\n\t" ".equ ipxe_oem_info_disklog, 0x0001\n\t")

Variables

static struct disklog int13con_disklog
 Disk log.
struct console_driver int13con __console_driver
 INT13 console driver.
static struct disklog_operations int13con_op
 INT13 disk log operations.

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 51 of file int13con.c.

◆ INT13CON_DRIVE

#define INT13CON_DRIVE   0x80

Disk drive number.

Definition at line 55 of file int13con.c.

Referenced by int13con_init(), and int13con_rw().

◆ int13con_vector

#define int13con_vector   __use_data16 ( int13con_vector )

Definition at line 59 of file int13con.c.

Referenced by __bss16(), and int13con_init().

◆ int13con_buffer

#define int13con_buffer   __use_data16 ( int13con_buffer )

Definition at line 63 of file int13con.c.

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

◆ int13con_address

#define int13con_address   __use_data16 ( int13con_address )

Definition at line 67 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 81 of file int13con.c.

81 {
83
84 /* Construct disk address packet */
85 int13con_address.bufsize = sizeof ( int13con_address );
86 int13con_address.count = 1;
87 int13con_address.buffer.segment = rm_ds;
90
91 /* Emulate INT13 via original vector. We do this since iPXE
92 * (or another subsequent bootloader) may hook INT13 and remap
93 * drive numbers.
94 */
95 __asm__ ( REAL_CODE ( "pushfw\n\t"
96 "cli\n\t"
97 "lcall *int13con_vector\n\t" )
98 : "=a" ( error )
99 : "0" ( op << 8 ), "d" ( INT13CON_DRIVE ),
100 "S" ( __from_data16 ( &int13con_address ) ) );
101 if ( error ) {
102 DBG ( "INT13CON operation %04x failed: %02x\n",
103 op, error );
104 return -EIO;
105 }
106
107 return 0;
108}
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:523
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:55
__asm__(".globl ipxe_oem_info_disklog\n\t" ".equ ipxe_oem_info_disklog, 0x0001\n\t")
#define int13con_address
Definition int13con.c:67
#define int13con_buffer
Definition int13con.c:63
#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

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

◆ int13con_write()

int int13con_write ( void )
static

Write current logical block.

Return values
rcReturn status code

Definition at line 115 of file int13con.c.

115 {
116
117 /* Write block */
119}
#define INT13_EXTENDED_WRITE
Extended write.
Definition int13.h:39
static int int13con_rw(unsigned int op, uint64_t lba)
Read/write disk sector.
Definition int13con.c:81
static struct disklog int13con_disklog
Disk log.
Definition int13con.c:70

References INT13_EXTENDED_WRITE, int13con_disklog, and int13con_rw().

◆ int13con_putchar()

void int13con_putchar ( int character)
static

Write character to console.

Parameters
characterCharacter

Definition at line 131 of file int13con.c.

131 {
132
133 /* Write character */
134 disklog_putchar ( &int13con_disklog, character );
135}
void disklog_putchar(struct disklog *disklog, int character)
Write character to disk log console.
Definition disklog.c:85

References disklog_putchar(), and int13con_disklog.

◆ int13con_find()

int int13con_find ( void )
static

Find log partition.

Return values
rcReturn status code

Definition at line 142 of file int13con.c.

142 {
143 struct master_boot_record *mbr =
144 ( ( struct master_boot_record * ) int13con_buffer );
145 struct partition_table_entry part[4];
146 unsigned int i;
147 int rc;
148
149 /* Read MBR */
150 if ( ( rc = int13con_rw ( INT13_EXTENDED_READ, 0 ) ) != 0 ) {
151 DBG ( "INT13CON could not read MBR: %s\n", strerror ( rc ) );
152 return rc;
153 }
154
155 /* Check MBR magic */
156 if ( mbr->magic != INT13_MBR_MAGIC ) {
157 DBG ( "INT13CON incorrect MBR magic\n" );
158 DBG2_HDA ( 0, mbr, sizeof ( *mbr ) );
159 return -EINVAL;
160 }
161
162 /* Look for magic partition */
163 memcpy ( part, mbr->partitions, sizeof ( part ) );
164 for ( i = 0 ; i < ( sizeof ( part ) / sizeof ( part[0] ) ) ; i++ ) {
165
166 /* Skip partitions of the wrong type */
167 if ( part[i].type != DISKLOG_PARTITION_TYPE )
168 continue;
169
170 /* Read partition header */
172 part[i].start ) ) != 0 ) {
173 DBG ( "INT13CON partition %d could not read header: "
174 "%s\n", ( i + 1 ), strerror ( rc ) );
175 continue;
176 }
177
178 /* Initialise disk log console */
181 ( part[i].start + part[i].length - 1 ) );
182
183 /* Open disk log console */
184 if ( ( rc = disklog_open ( &int13con_disklog ) ) != 0 ) {
185 DBG ( "INT13CON partition %d could not initialise: "
186 "%s\n", ( i + 1 ), strerror ( rc ) );
187 continue;
188 }
189
190 /* Found log partition */
191 DBG ( "INT13CON partition %d at [%08llx,%08llx)\n", ( i + 1 ),
192 ( ( unsigned long long ) int13con_disklog.lba ),
193 ( ( unsigned long long ) int13con_disklog.max_lba ) );
194
195 return 0;
196 }
197
198 DBG ( "INT13CON found no log partition\n" );
199 return -ENOENT;
200}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
int disklog_open(struct disklog *disklog)
Open disk log console.
Definition disklog.c:46
#define DISKLOG_PARTITION_TYPE
Disk log partition type.
Definition disklog.h:84
static void disklog_init(struct disklog *disklog, struct disklog_operations *op, struct console_driver *console, void *buffer, size_t blksize, uint64_t lba, uint64_t max_lba)
Initialise disk log console.
Definition disklog.h:66
uint32_t type
Operating system type.
Definition ena.h:1
#define DBG2_HDA(...)
Definition compiler.h:541
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 INT13_BLKSIZE
Block size for non-extended INT 13 calls.
Definition int13.h:72
static struct disklog_operations int13con_op
INT13 disk log operations.
Definition int13con.c:122
u16 length
Definition sky2.h:1
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
A Master Boot Record.
Definition int13.h:278
A partition table entry within the MBR.
Definition int13.h:262

References DBG, DBG2_HDA, disklog_init(), disklog_open(), DISKLOG_PARTITION_TYPE, EINVAL, ENOENT, INT13_BLKSIZE, INT13_EXTENDED_READ, INT13_MBR_MAGIC, int13con_buffer, int13con_disklog, int13con_op, int13con_rw(), length, master_boot_record::magic, memcpy(), master_boot_record::partitions, rc, start, strerror(), and type.

Referenced by int13con_init().

◆ int13con_init()

void int13con_init ( void )
static

Initialise INT13 console.

Definition at line 206 of file int13con.c.

206 {
208 uint16_t check;
209 unsigned int discard_c;
210 unsigned int discard_d;
211 int rc;
212
213 /* Check for INT13 extensions */
214 __asm__ __volatile__ ( REAL_CODE ( "int $0x13\n\t"
215 "setc %%al\n\t" )
216 : "=a" ( error ), "=b" ( check ),
217 "=c" ( discard_c ), "=d" ( discard_d )
218 : "0" ( INT13_EXTENSION_CHECK << 8 ),
219 "1" ( 0x55aa ), "3" ( INT13CON_DRIVE ) );
220 if ( error || ( check != 0xaa55 ) ) {
221 DBG ( "INT13CON missing extensions (%02x,%04x)\n",
222 error, check );
223 return;
224 }
225
226 /* Store original INT13 vector */
227 copy_from_real ( &int13con_vector, 0, ( 0x13 * 4 ),
228 sizeof ( int13con_vector ) );
229 DBG ( "INT13CON using original INT13 vector %04x:%04x\n",
230 int13con_vector.segment, int13con_vector.offset );
231
232 /* Locate log partition */
233 if ( ( rc = int13con_find() ) != 0)
234 return;
235
236 /* Enable console */
237 int13con.disabled = 0;
238}
__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:32
#define INT13_EXTENSION_CHECK
Extensions installation check.
Definition int13.h:35
static int int13con_find(void)
Find log partition.
Definition int13con.c:142
#define int13con_vector
Definition int13con.c:59
#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")

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

◆ __asm__()

__asm__ ( ".globl ipxe_oem_info_disklog\n\t" ".equ ipxe_oem_info_disklog,
0x0001\n\t"  )

Referenced by int13con_rw().

Variable Documentation

◆ int13con_disklog

struct disklog int13con_disklog
static

Disk log.

Definition at line 70 of file int13con.c.

Referenced by int13con_find(), int13con_putchar(), and int13con_write().

◆ __console_driver

struct console_driver int13con __console_driver
Initial value:
= {
.putchar = int13con_putchar,
.disabled = CONSOLE_DISABLED,
.usage = CONSOLE_INT13,
}
#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:131
#define CONSOLE_INT13
Definition int13con.c:51

INT13 console driver.

Definition at line 72 of file int13con.c.

◆ int13con_op

struct disklog_operations int13con_op
static
Initial value:
= {
.write = int13con_write,
}
static int int13con_write(void)
Write current logical block.
Definition int13con.c:115

INT13 disk log operations.

Definition at line 122 of file int13con.c.

122 {
123 .write = int13con_write,
124};

Referenced by int13con_find().