blob: 73d553bcb530b171399defca1e4840f674bdec5d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/*
RCC-Project
Copyright (C) 2026 Richard Qin
This file is part of RCC-Project.
RCC-Project is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your option) any
later version.
RCC-Project is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
RCC-Project; see the file COPYING. If not see
<http://www.gnu.org/licenses/>.
*/
#include "bios.h"
#include "regs.h"
#define BIOS_CF 0x0001u
struct edd_packet
{
u8 size;
u8 reserved;
u16 count;
u16 buffer_offset;
u16 buffer_segment;
u32 lba_low;
u32 lba_high;
} __attribute__ ((packed));
struct edd_parameters
{
u16 size;
u16 flags;
u32 cylinders_low;
u32 cylinders_high;
u32 heads;
u32 sectors_per_track;
u32 total_sectors_low;
u32 total_sectors_high;
u16 bytes_per_sector;
} __attribute__ ((packed));
static void
int13_fail (struct bios_regs *regs)
{
regs->eax = 0x0100u;
regs->flags |= BIOS_CF;
}
static struct edd_packet *
get_edd_packet (struct bios_regs *regs)
{
u32 address;
address = ((u32)regs->ds << 4) + (u16)regs->esi;
return (struct edd_packet *)address;
}
static struct edd_parameters *
get_edd_parameters (struct bios_regs *regs)
{
u32 address;
address = ((u32)regs->ds << 4) + (u16)regs->esi;
return (struct edd_parameters *)address;
}
void
int13_service (struct bios_regs *regs)
{
u8 function;
struct edd_packet *packet;
u32 buffer_address;
function = (u8)(regs->eax >> 8);
if (function == 0x41u)
{
if (regs->ebx != 0x55AAu)
{
int13_fail (regs);
return;
}
regs->eax = 0x3000u;
regs->ebx = 0xAA55u;
regs->ecx |= 0x0001u;
regs->flags &= (u16)~BIOS_CF;
return;
}
if (function == 0x42u)
{
packet = get_edd_packet (regs);
if (packet->size != 0x10u || packet->count == 0u || packet->count > 127u
|| packet->lba_high != 0u
|| packet->lba_low > 0x10000000u - (u32)packet->count)
{
int13_fail (regs);
return;
}
buffer_address
= ((u32)packet->buffer_segment << 4) + packet->buffer_offset;
if (ata_read_sectors28 (packet->lba_low, (u16 *)buffer_address,
packet->count)
!= 0)
{
int13_fail (regs);
return;
}
regs->eax = 0;
regs->flags &= (u16)~BIOS_CF;
return;
}
if (function == 0x48u)
{
struct edd_parameters *parameters;
u16 cylinders;
u16 heads;
u16 sectors_per_track;
u32 total_sectors_low;
u32 total_sectors_high;
parameters = get_edd_parameters (regs);
if (parameters->size < 0x001Eu
|| ata_identify (&cylinders, &heads, §ors_per_track,
&total_sectors_low, &total_sectors_high)
!= 0)
{
int13_fail (regs);
return;
}
parameters->size = 0x001Eu;
parameters->flags = 0;
parameters->cylinders_low = cylinders;
parameters->cylinders_high = 0;
parameters->heads = heads;
parameters->sectors_per_track = sectors_per_track;
parameters->total_sectors_low = total_sectors_low;
parameters->total_sectors_high = total_sectors_high;
parameters->bytes_per_sector = 512;
regs->eax = 0;
regs->flags &= (u16)~BIOS_CF;
return;
}
int13_fail (regs);
}
|