From 7f5499972e115cafc861ec438cd7237422cd9b7c Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Mon, 16 Dec 2019 21:52:12 +0000 Subject: [PATCH] Use symbolic names for int13 calls For all the INT13 calls, use symbolic names instead of magic numbers. This makes it easier to understand what the code is doing w/o a trip to google to find what these numbers mean. --- stand/i386/common/edd.h | 3 ++ stand/i386/libi386/biosdisk.c | 65 +++++++++++++++++++++-------------- 2 files changed, 43 insertions(+), 25 deletions(-) diff --git a/stand/i386/common/edd.h b/stand/i386/common/edd.h index 7d1f45020f9d..9739c45b0f38 100644 --- a/stand/i386/common/edd.h +++ b/stand/i386/common/edd.h @@ -107,4 +107,7 @@ struct edd_params_v4 { #define EDD_DEVICE_PATH_KEY 0xbedd +#define EDD_QUERY_MAGIC 0x55aa +#define EDD_INSTALLED 0xaa55 + #endif /* !_EDD_H_ */ diff --git a/stand/i386/libi386/biosdisk.c b/stand/i386/libi386/biosdisk.c index 3a7266acbdcf..2cbc5f63027a 100644 --- a/stand/i386/libi386/biosdisk.c +++ b/stand/i386/libi386/biosdisk.c @@ -64,6 +64,22 @@ __FBSDID("$FreeBSD$"); #define ACDMAJOR 117 #define CDMAJOR 15 +/* + * INT13 commands + */ +#define CMD_RESET 0x0000 +#define CMD_READ_CHS 0x0200 +#define CMD_WRITE_CHS 0x0300 +#define CMD_READ_PARAM 0x0800 +#define CMD_DRIVE_TYPE 0x1500 +#define CMD_CHECK_EDD 0x4100 +#define CMD_READ_LBA 0x4200 +#define CMD_WRITE_LBA 0x4300 +#define CMD_EXT_PARAM 0x4800 +#define CMD_CD_GET_STATUS 0x4b01 + +#define DISK_BIOS 0x13 + #ifdef DISK_DEBUG #define DPRINTF(fmt, args...) printf("%s: " fmt "\n", __func__, ## args) #else @@ -265,8 +281,8 @@ fd_count(void) bd_reset_disk(drive); v86.ctl = V86_FLAGS; - v86.addr = 0x13; - v86.eax = 0x1500; + v86.addr = DISK_BIOS; + v86.eax = CMD_DRIVE_TYPE; v86.edx = drive; v86int(); @@ -367,8 +383,8 @@ bc_add(int biosdev) return (-1); v86.ctl = V86_FLAGS; - v86.addr = 0x13; - v86.eax = 0x4b01; + v86.addr = DISK_BIOS; + v86.eax = CMD_CD_GET_STATUS; v86.edx = biosdev; v86.ds = VTOPSEG(&bc_sp); v86.esi = VTOPOFF(&bc_sp); @@ -422,14 +438,14 @@ bd_check_extensions(int unit) /* Determine if we can use EDD with this device. */ v86.ctl = V86_FLAGS; - v86.addr = 0x13; - v86.eax = 0x4100; + v86.addr = DISK_BIOS; + v86.eax = CMD_CHECK_EDD; v86.edx = unit; - v86.ebx = 0x55aa; + v86.ebx = EDD_QUERY_MAGIC; v86int(); if (V86_CY(v86.efl) || /* carry set */ - (v86.ebx & 0xffff) != 0xaa55) /* signature */ + (v86.ebx & 0xffff) != EDD_INSTALLED) /* signature */ return (0); /* extended disk access functions (AH=42h-44h,47h,48h) supported */ @@ -444,8 +460,8 @@ bd_reset_disk(int unit) { /* reset disk */ v86.ctl = V86_FLAGS; - v86.addr = 0x13; - v86.eax = 0; + v86.addr = DISK_BIOS; + v86.eax = CMD_RESET; v86.edx = unit; v86int(); } @@ -458,8 +474,8 @@ bd_get_diskinfo_std(struct bdinfo *bd) { bzero(&v86, sizeof(v86)); v86.ctl = V86_FLAGS; - v86.addr = 0x13; - v86.eax = 0x800; + v86.addr = DISK_BIOS; + v86.eax = CMD_READ_PARAM; v86.edx = bd->bd_unit; v86int(); @@ -493,8 +509,8 @@ bd_get_diskinfo_ext(struct bdinfo *bd) bzero(¶ms, sizeof(params)); params.len = sizeof(params); v86.ctl = V86_FLAGS; - v86.addr = 0x13; - v86.eax = 0x4800; + v86.addr = DISK_BIOS; + v86.eax = CMD_EXT_PARAM; v86.edx = bd->bd_unit; v86.ds = VTOPSEG(¶ms); v86.esi = VTOPOFF(¶ms); @@ -560,8 +576,8 @@ bd_int13probe(bdinfo_t *bd) /* Get disk type */ v86.ctl = V86_FLAGS; - v86.addr = 0x13; - v86.eax = 0x1500; + v86.addr = DISK_BIOS; + v86.eax = CMD_DRIVE_TYPE; v86.edx = bd->bd_unit; v86int(); if (V86_CY(v86.efl) || (v86.eax & 0x300) == 0) @@ -1076,12 +1092,11 @@ bd_edd_io(bdinfo_t *bd, daddr_t dblk, int blks, caddr_t dest, packet.seg = VTOPSEG(dest); packet.lba = dblk; v86.ctl = V86_FLAGS; - v86.addr = 0x13; - /* Should we Write with verify ?? 0x4302 ? */ + v86.addr = DISK_BIOS; if (dowrite == BD_WR) - v86.eax = 0x4300; + v86.eax = CMD_WRITE_LBA; /* maybe Write with verify 0x4302? */ else - v86.eax = 0x4200; + v86.eax = CMD_READ_LBA; v86.edx = bd->bd_unit; v86.ds = VTOPSEG(&packet); v86.esi = VTOPOFF(&packet); @@ -1113,11 +1128,11 @@ bd_chs_io(bdinfo_t *bd, daddr_t dblk, int blks, caddr_t dest, } v86.ctl = V86_FLAGS; - v86.addr = 0x13; + v86.addr = DISK_BIOS; if (dowrite == BD_WR) - v86.eax = 0x300 | blks; + v86.eax = CMD_WRITE_CHS | blks; else - v86.eax = 0x200 | blks; + v86.eax = CMD_READ_CHS | blks; v86.ecx = ((cyl & 0xff) << 8) | ((cyl & 0x300) >> 2) | sec; v86.edx = (hd << 8) | bd->bd_unit; v86.es = VTOPSEG(dest); @@ -1222,8 +1237,8 @@ bd_getbigeom(int bunit) { v86.ctl = V86_FLAGS; - v86.addr = 0x13; - v86.eax = 0x800; + v86.addr = DISK_BIOS; + v86.eax = CMD_READ_PARAM; v86.edx = 0x80 + bunit; v86int(); if (V86_CY(v86.efl))