#include <amd64/apic.h>
#include <amd64/debug.h>
#include <amd64/hpet.h>
#include <amd64/init.h>
#include <amd64/intr_defs.h>
#include <amd64/msr-index.h>
#include <amd64/msr.h>
#include <aux/compiler.h>
#include <irq/irq.h>
#include <libk/std.h>
#include <limine/limine.h>
#include <mm/liballoc.h>
#include <mm/pmm.h>
#include <proc/proc.h>
#include <rd/rd.h>
#include <sys/debug.h>
#include <sys/mm.h>
#include <sys/smp.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <uacpi/uacpi.h>

#define UACPI_MEMORY_BUFFER_MAX 4096

ALIGNED (16) static uint8_t uacpi_memory_buffer[UACPI_MEMORY_BUFFER_MAX];

/*
 * The kernel starts booting here. This is the entry point after Limine hands control. We set up all
 * the necessary platform-dependent subsystems/drivers and jump into the init app.
 */
void bootmain (void) {
  struct cpu* bsp_cpu = cpu_make ();

  amd64_init (bsp_cpu, false);
  syscall_init ();
  amd64_debug_init ();
  pmm_init ();
  mm_init ();

  rd_init ();

  uacpi_setup_early_table_access ((void*)uacpi_memory_buffer, sizeof (uacpi_memory_buffer));

  amd64_ioapic_init ();
  amd64_hpet_init ();

  smp_init ();

  mm_init2 ();

  proc_init ();

  for (;;)
    ;
}
