]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - sys/boot/i386/common/drv.c
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.git] / sys / boot / i386 / common / drv.c
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$");
19
20 #include <sys/param.h>
21
22 #include <machine/psl.h>
23
24 #include <btxv86.h>
25
26 #include "rbx.h"
27 #include "util.h"
28 #include "drv.h"
29 #include "edd.h"
30 #ifdef USE_XREAD
31 #include "xreadorg.h"
32 #endif
33
34 #define V86_CY(x)       ((x) & PSL_C)
35 #define V86_ZR(x)       ((x) & PSL_Z)
36
37 #ifdef GPT
38 static struct edd_params params;
39
40 uint64_t
41 drvsize(struct dsk *dskp)
42 {
43
44         params.len = sizeof(struct edd_params);
45         v86.ctl = V86_FLAGS;
46         v86.addr = 0x13;
47         v86.eax = 0x4800;
48         v86.edx = dskp->drive;
49         v86.ds = VTOPSEG(&params);
50         v86.esi = VTOPOFF(&params);
51         v86int();
52         if (V86_CY(v86.efl)) {
53                 printf("error %u\n", v86.eax >> 8 & 0xff);
54                 return (0);
55         }
56         return (params.sectors);
57 }
58 #endif  /* GPT */
59
60 #ifndef USE_XREAD
61 static struct edd_packet packet;
62 #endif
63
64 int
65 drvread(struct dsk *dskp, void *buf, daddr_t lba, unsigned nblk)
66 {
67         static unsigned c = 0x2d5c7c2f;
68
69         if (!OPT_CHECK(RBX_QUIET))
70                 printf("%c\b", c = c << 8 | c >> 24);
71 #ifndef USE_XREAD
72         packet.len = sizeof(struct edd_packet);
73         packet.count = nblk;
74         packet.off = VTOPOFF(buf);
75         packet.seg = VTOPSEG(buf);
76         packet.lba = lba;
77         v86.ctl = V86_FLAGS;
78         v86.addr = 0x13;
79         v86.eax = 0x4200;
80         v86.edx = dskp->drive;
81         v86.ds = VTOPSEG(&packet);
82         v86.esi = VTOPOFF(&packet);
83 #else   /* USE_XREAD */
84         v86.ctl = V86_ADDR | V86_CALLF | V86_FLAGS;
85         v86.addr = XREADORG;            /* call to xread in boot1 */
86         v86.es = VTOPSEG(buf);
87         v86.eax = lba;
88         v86.ebx = VTOPOFF(buf);
89         v86.ecx = lba >> 32;
90         v86.edx = nblk << 8 | dskp->drive;
91 #endif  /* USE_XREAD */
92         v86int();
93         if (V86_CY(v86.efl)) {
94                 printf("%s: error %u lba %u\n",
95                     BOOTPROG, v86.eax >> 8 & 0xff, lba);
96                 return (-1);
97         }
98         return (0);
99 }
100
101 #ifdef GPT
102 int
103 drvwrite(struct dsk *dskp, void *buf, daddr_t lba, unsigned nblk)
104 {
105
106         packet.len = sizeof(struct edd_packet);
107         packet.count = nblk;
108         packet.off = VTOPOFF(buf);
109         packet.seg = VTOPSEG(buf);
110         packet.lba = lba;
111         v86.ctl = V86_FLAGS;
112         v86.addr = 0x13;
113         v86.eax = 0x4300;
114         v86.edx = dskp->drive;
115         v86.ds = VTOPSEG(&packet);
116         v86.esi = VTOPOFF(&packet);
117         v86int();
118         if (V86_CY(v86.efl)) {
119                 printf("error %u lba %u\n", v86.eax >> 8 & 0xff, lba);
120                 return (-1);
121         }
122         return (0);
123 }
124 #endif  /* GPT */