/// lcrash entry point
/// super awesome...

#include <lcrash/gdb/gdb.h>
#include <lcrash/pci/pci.h>
#include <lcrash/mm/phys.h>
#include <lcrash/mm/kmalloc.h>
#include <lcrash/cmdline.h>
#include <lcrash/debug/debug.h>
#include <lcrash/driver/sysbus.h>

#include "types.h"
#include "lnxboot.h"

#include "efi/efi.h"

[[noreturn]]
void entry64(struct boot_params* BootParams) {
	BootBootParams = BootParams;
	BootSetupInfo  = (void*)BootParams + 0x1f1;

	// Notify the debugger that we're ready
	struct GdbDataBlock* GdbDataBlock = (struct GdbDataBlock*)0x100000;
	GdbDataBlock->KernelLoaded = true;
	GdbDataBlock->KernelBase = (void*)BootSetupInfo->code32_start;
	GdbDataBlock->Update++;

	// Parse the kernel command line
	CmdlineParse((c8*)( ((uptr)BootSetupInfo->cmd_line_ptr)
		           |((uptr)BootBootParams->ext_cmd_line_ptr << 32)));

	// Initialize the physical memory manager
	if (PmemInitialize()) while (1) {}
	
	// Initialize the kernel heap
	if (KernelHeapInitialize()) while (1) {}

	// Initialize the extended debugging information block
	if (DebugInitialize()) while (1) {}

	// Initialize the system bus
	SysbusInitialize();

	// Initialize EFI code if we had EFI
	EfiInitialize();

	// Initialize ACPI code if we have ACPI
	AcpiInitialize();

	// Initialize PCI code..
	PciInitialize();

	// Hang :)	
	while (1) {}
}