~src/kernel/idt.cr
.cr
Crystal
(text/x-crystal)
require "./vga.cr"

 @[Packed]
struct Entry
  offset_low : UInt16
  selector : UInt16
  ist : UInt8
  type_attr : UInt8
  offset_mid : UInt16
  offset_high : UInt32
  zero : UInt32
end

@[Packed]
struct Ptr
  limit : UInt16
  base : UInt64
end

lib KernelShim
  # External functions from assembly
  # fun lidt(ptr : Ptr): Nil
  # fun isr_handler_common(): Nil
end

# IDT module
module IDT

  IDT_ENTRIES = 256

  # # Storage for the IDT entries
  # @@idt : StaticArray(Entry, IDT_ENTRIES) = StaticArray(Entry, IDT_ENTRIES).new()
  # property idt

  # # IRQ handlers storage
  # @@irq_handlers : StaticArray(Proc(Nil, Nil), IDT_ENTRIES) = StaticArray(Proc(Nil, Nil), IDT_ENTRIES).new()
  # property irq_handlers

  # def self.register_irq(irq : Int32, handler : Proc(Nil, Nil)) : Nil
  #   if irq >= 0 && irq < IDT_ENTRIES
  #     @irq_handlers[irq] = handler
  #   end
  # end

  def self.init : Nil
    #ptr = Ptr.new
    #ptr.limit = (IDT_ENTRIES * Entry.size) - 1
    #ptr.base = getaddr(&@idt).to_u64
    #lidt(&ptr)

    # VGA.puts("IDT initialized\n")
  end
end