drv.c (226746) | drv.c (226748) |
---|---|
1/*- 2 * Copyright (c) 1998 Robert Nordier 3 * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms are freely 7 * permitted provided that the above copyright notice and this 8 * paragraph and the following disclaimer are duplicated in all 9 * such forms. 10 * 11 * This software is provided "AS IS" and without any express or 12 * implied warranties, including, without limitation, the implied 13 * warranties of merchantability and fitness for a particular 14 * purpose. 15 */ 16 17#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1998 Robert Nordier 3 * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms are freely 7 * permitted provided that the above copyright notice and this 8 * paragraph and the following disclaimer are duplicated in all 9 * such forms. 10 * 11 * This software is provided "AS IS" and without any express or 12 * implied warranties, including, without limitation, the implied 13 * warranties of merchantability and fitness for a particular 14 * purpose. 15 */ 16 17#include <sys/cdefs.h> |
18__FBSDID("$FreeBSD: head/sys/boot/i386/common/drv.c 226746 2011-10-25 19:45:12Z jhb $"); | 18__FBSDID("$FreeBSD: head/sys/boot/i386/common/drv.c 226748 2011-10-25 19:54:06Z jhb $"); |
19 20#include <sys/param.h> 21 22#include <btxv86.h> 23 24#include "rbx.h" 25#include "util.h" 26#include "drv.h" | 19 20#include <sys/param.h> 21 22#include <btxv86.h> 23 24#include "rbx.h" 25#include "util.h" 26#include "drv.h" |
27#include "edd.h" |
|
27#ifdef USE_XREAD 28#include "xreadorg.h" 29#endif 30 31#ifdef GPT | 28#ifdef USE_XREAD 29#include "xreadorg.h" 30#endif 31 32#ifdef GPT |
33static struct edd_params params; 34 |
|
32uint64_t 33drvsize(struct dsk *dskp) 34{ | 35uint64_t 36drvsize(struct dsk *dskp) 37{ |
35 unsigned char params[0x42]; 36 uint64_t sectors; | |
37 | 38 |
38 *(uint32_t *)params = sizeof(params); 39 | 39 params.len = sizeof(struct edd_params); |
40 v86.ctl = V86_FLAGS; 41 v86.addr = 0x13; 42 v86.eax = 0x4800; 43 v86.edx = dskp->drive; | 40 v86.ctl = V86_FLAGS; 41 v86.addr = 0x13; 42 v86.eax = 0x4800; 43 v86.edx = dskp->drive; |
44 v86.ds = VTOPSEG(params); 45 v86.esi = VTOPOFF(params); | 44 v86.ds = VTOPSEG(¶ms); 45 v86.esi = VTOPOFF(¶ms); |
46 v86int(); 47 if (V86_CY(v86.efl)) { 48 printf("error %u\n", v86.eax >> 8 & 0xff); 49 return (0); 50 } | 46 v86int(); 47 if (V86_CY(v86.efl)) { 48 printf("error %u\n", v86.eax >> 8 & 0xff); 49 return (0); 50 } |
51 memcpy(§ors, params + 0x10, sizeof(sectors)); 52 return (sectors); | 51 return (params.sectors); |
53} 54#endif /* GPT */ 55 56#ifndef USE_XREAD | 52} 53#endif /* GPT */ 54 55#ifndef USE_XREAD |
57static struct { 58 uint16_t len; 59 uint16_t count; 60 uint16_t off; 61 uint16_t seg; 62 uint64_t lba; 63} packet; | 56static struct edd_packet packet; |
64#endif 65 66int 67drvread(struct dsk *dskp, void *buf, daddr_t lba, unsigned nblk) 68{ 69 static unsigned c = 0x2d5c7c2f; 70 71 if (!OPT_CHECK(RBX_QUIET)) 72 printf("%c\b", c = c << 8 | c >> 24); 73#ifndef USE_XREAD | 57#endif 58 59int 60drvread(struct dsk *dskp, void *buf, daddr_t lba, unsigned nblk) 61{ 62 static unsigned c = 0x2d5c7c2f; 63 64 if (!OPT_CHECK(RBX_QUIET)) 65 printf("%c\b", c = c << 8 | c >> 24); 66#ifndef USE_XREAD |
74 packet.len = 0x10; | 67 packet.len = sizeof(struct edd_packet); |
75 packet.count = nblk; 76 packet.off = VTOPOFF(buf); 77 packet.seg = VTOPSEG(buf); 78 packet.lba = lba; 79 v86.ctl = V86_FLAGS; 80 v86.addr = 0x13; 81 v86.eax = 0x4200; 82 v86.edx = dskp->drive; --- 17 unchanged lines hidden (view full) --- 100 return (0); 101} 102 103#ifdef GPT 104int 105drvwrite(struct dsk *dskp, void *buf, daddr_t lba, unsigned nblk) 106{ 107 | 68 packet.count = nblk; 69 packet.off = VTOPOFF(buf); 70 packet.seg = VTOPSEG(buf); 71 packet.lba = lba; 72 v86.ctl = V86_FLAGS; 73 v86.addr = 0x13; 74 v86.eax = 0x4200; 75 v86.edx = dskp->drive; --- 17 unchanged lines hidden (view full) --- 93 return (0); 94} 95 96#ifdef GPT 97int 98drvwrite(struct dsk *dskp, void *buf, daddr_t lba, unsigned nblk) 99{ 100 |
108 packet.len = 0x10; | 101 packet.len = sizeof(struct edd_packet); |
109 packet.count = nblk; 110 packet.off = VTOPOFF(buf); 111 packet.seg = VTOPSEG(buf); 112 packet.lba = lba; 113 v86.ctl = V86_FLAGS; 114 v86.addr = 0x13; 115 v86.eax = 0x4300; 116 v86.edx = dskp->drive; 117 v86.ds = VTOPSEG(&packet); 118 v86.esi = VTOPOFF(&packet); 119 v86int(); 120 if (V86_CY(v86.efl)) { 121 printf("error %u lba %u\n", v86.eax >> 8 & 0xff, lba); 122 return (-1); 123 } 124 return (0); 125} 126#endif /* GPT */ | 102 packet.count = nblk; 103 packet.off = VTOPOFF(buf); 104 packet.seg = VTOPSEG(buf); 105 packet.lba = lba; 106 v86.ctl = V86_FLAGS; 107 v86.addr = 0x13; 108 v86.eax = 0x4300; 109 v86.edx = dskp->drive; 110 v86.ds = VTOPSEG(&packet); 111 v86.esi = VTOPOFF(&packet); 112 v86int(); 113 if (V86_CY(v86.efl)) { 114 printf("error %u lba %u\n", v86.eax >> 8 & 0xff, lba); 115 return (-1); 116 } 117 return (0); 118} 119#endif /* GPT */ |