summaryrefslogtreecommitdiffhomepage
path: root/src/boot/BootKit/HW/SATA.h
blob: c6ad7cfd746d1d3b18da46f17c3fb671bc6cd8a0 (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
// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org)
// Licensed under the Apache License, Version 2.0 (see LICENSE file)
// Official repository: https://github.com/ne-foss-org/nekernel

#ifndef BOOTKIT_SATA_H
#define BOOTKIT_SATA_H

#include <BootKit/BootKit.h>
#include <CompilerKit/CompilerKit.h>
#include <modules/AHCI/AHCI.h>

#define kAHCISectorSz (512)

namespace Boot {
class BootDeviceSATA final {
 public:
  explicit BootDeviceSATA();
  ~BootDeviceSATA() = default;

  NE_COPY_DEFAULT(BootDeviceSATA)

  struct SATATrait final : public Device::Trait {
    Kernel::Boolean mErr{false};
    Kernel::Boolean mDetected{false};

    explicit operator bool() { return !this->mErr; }
  };

  operator bool() { return this->Leak().mDetected; }

  SizeT GetDiskSize() { return drv_std_get_size(); }

  constexpr static auto kSectorSize = kAHCISectorSize;

  BootDeviceSATA& Read(Boot::CharacterTypeASCII* Buf, const Kernel::SizeT SecCount);
  BootDeviceSATA& Write(Boot::CharacterTypeASCII* Buf, const Kernel::SizeT SecCount);

  SATATrait& Leak();

 private:
  SATATrait mTrait;
};
}  // namespace Boot

#endif