42 lines
1.1 KiB
C++
42 lines
1.1 KiB
C++
|
|
#pragma once
|
|
|
|
#if !defined(BAD_APPLE_OS_KERNEL_PIC_HPP_INCLUDED)
|
|
#define BAD_APPLE_OS_KERNEL_PIC_HPP_INCLUDED
|
|
|
|
#include <cstdint>
|
|
|
|
#include "os/port.hpp"
|
|
|
|
inline constexpr std::uint16_t PORT_PIC1 = 0x20;
|
|
inline constexpr std::uint16_t PORT_PIC2 = 0xA0;
|
|
inline constexpr std::uint8_t PIC_CMD_EOI = 0x20;
|
|
|
|
[[nodiscard]] bool initPICs(std::uint8_t masterOffset, std::uint8_t slaveOffset) noexcept;
|
|
__attribute__((no_caller_saved_registers))
|
|
void sendEndOfInterrupt(std::uint8_t irq) noexcept;
|
|
void maskIRQ(std::uint8_t irq) noexcept;
|
|
void unmaskIRQ(std::uint8_t irq) noexcept;
|
|
[[nodiscard]] std::uint16_t readPICIRR() noexcept;
|
|
[[nodiscard]] std::uint16_t readPICISR() noexcept;
|
|
|
|
[[nodiscard]] constexpr bool isValidPICOffset(std::uint8_t offset) noexcept
|
|
{
|
|
return (offset & 7) == 0;
|
|
}
|
|
|
|
#if defined(__x86_64__)
|
|
struct InterruptFrame
|
|
{
|
|
std::uint64_t ip;
|
|
std::uint64_t cs;
|
|
std::uint64_t flags;
|
|
std::uint64_t sp;
|
|
std::uint64_t ss;
|
|
};
|
|
#endif
|
|
|
|
using interrupt_handler_t = __attribute__((interrupt)) void(*)(InterruptFrame*);
|
|
|
|
#endif // !defined(BAD_APPLE_OS_KERNEL_PIC_HPP_INCLUDED)
|