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
|
/* -------------------------------------------
Copyright ZKA Technologies.
------------------------------------------- */
#include <KernelKit/DebugOutput.hxx>
#include <KernelKit/DriveManager.hxx>
#include <Modules/ATA/ATA.hxx>
#include <Modules/AHCI/AHCI.hxx>
#include <NewKit/Utils.hxx>
/// @file DriveManager.cxx
/// @brief Kernel drive manager.
namespace Kernel
{
static UInt16 kATAIO = 0U;
static UInt8 kATAMaster = 0U;
/// @brief reads from an ATA drive.
/// @param pckt
/// @return
Void ke_drv_input(DriveTrait::DrivePacket* pckt)
{
if (!pckt)
{
return;
}
#ifdef __AHCI__
drv_std_read(pckt->fLba, (Char*)pckt->fPacketContent, kAHCISectorSize, pckt->fPacketSize);
#elif defined(__ATA_PIO__) || defined(__ATA_DMA__)
drv_std_read(pckt->fLba, kATAIO, kATAMaster, (Char*)pckt->fPacketContent, kATASectorSize, pckt->fPacketSize);
#endif
}
/// @brief Writes to an ATA drive.
/// @param pckt
/// @return
Void ke_drv_output(DriveTrait::DrivePacket* pckt)
{
if (!pckt)
{
return;
}
#ifdef __AHCI__
drv_std_write(pckt->fLba, (Char*)pckt->fPacketContent, kAHCISectorSize, pckt->fPacketSize);
#elif defined(__ATA_PIO__) || defined(__ATA_DMA__)
drv_std_write(pckt->fLba, kATAIO, kATAMaster, (Char*)pckt->fPacketContent, kATASectorSize, pckt->fPacketSize);
#endif
}
/// @brief Executes a disk check on the ATA drive.
/// @param pckt
/// @return
Void ke_drv_check_disk(DriveTrait::DrivePacket* pckt)
{
if (!pckt)
{
return;
}
pckt->fPacketGood = false;
#if defined(__ATA_PIO__) || defined(__ATA_DMA__)
kATAMaster = true;
kATAIO = ATA_PRIMARY_IO;
MUST_PASS(drv_std_init(kATAIO, kATAMaster, kATAIO, kATAMaster));
#elif defined(__AHCI__)
UInt16 pi = 0;
MUST_PASS(drv_std_init(pi));
#endif // if defined(__ATA_PIO__) || defined (__ATA_DMA__)
pckt->fPacketGood = true;
}
/// @brief Gets the drive kind (ATA, SCSI, AHCI...)
/// @param
/// @return
#ifdef __ATA_PIO__
const Char* io_drive_kind(Void)
{
return "ATA-PIO";
}
#endif
#ifdef __ATA_DMA__
const Char* io_drive_kind(Void)
{
return "ATA-DMA";
}
#endif
#ifdef __AHCI__
const Char* io_drive_kind(Void)
{
return "AHCI";
}
#endif
/// @brief Unimplemented drive.
/// @param pckt
/// @return
Void io_drv_unimplemented(DriveTrait::DrivePacket* pckt)
{
}
/// @brief Makes a new drive.
/// @return the new drive.
DriveTrait io_construct_drive() noexcept
{
DriveTrait trait;
rt_copy_memory((VoidPtr) "\\NUL", trait.fName, rt_string_len("\\NUL"));
trait.fKind = kInvalidDrive;
trait.fInput = io_drv_unimplemented;
trait.fOutput = io_drv_unimplemented;
trait.fVerify = io_drv_unimplemented;
trait.fDriveKind = io_drive_kind;
return trait;
}
/// @brief Fetches the main drive.
/// @return the new drive.
DriveTrait io_construct_main_drive() noexcept
{
DriveTrait trait;
rt_copy_memory((VoidPtr) "\\Mount\\NUL:", trait.fName, rt_string_len("\\Mount\\NUL:"));
trait.fKind = kMassStorage;
trait.fInput = ke_drv_input;
trait.fOutput = ke_drv_output;
trait.fVerify = ke_drv_check_disk;
trait.fDriveKind = io_drive_kind;
kcout << "newoskrnl: Construct drive with success.\r";
return trait;
}
} // namespace Kernel
|