#include <sys/param.h>
#include <sys/reboot.h>
#include <machine/cpu.h>
#include <machine/pmon.h>
#include "libsa.h"
#include <lib/libsa/loadfile.h>
typedef void (*program)(int32_t, int32_t, int32_t *, int32_t, uint64_t *);
#define PTR_TO_CKSEG1(ptr) (int32_t)(CKSEG1_BASE | (uint64_t)(ptr))
void
run_loadfile(uint64_t *marks, int howto)
{
int32_t newargc;
int32_t *newargv;
char kernelflags[8];
char *c;
const char *arg;
newargc = howto == 0 ? 2 : 3;
newargv = alloc(newargc * sizeof(int32_t));
if (newargv == NULL)
panic("out of memory");
arg = "boot";
newargv[0] = PTR_TO_CKSEG1(arg);
newargv[1] = PTR_TO_CKSEG1(&pmon_bootdev);
if (howto != 0) {
c = kernelflags;
*c++ = '-';
if (howto & RB_ASKNAME)
*c++ = 'a';
if (howto & RB_CONFIG)
*c++ = 'c';
if (howto & RB_KDB)
*c++ = 'd';
if (howto & RB_GOODRANDOM)
*c++ = 'g';
if (howto & RB_SINGLE)
*c++ = 's';
*c = '\0';
newargv[2] = PTR_TO_CKSEG1(&kernelflags);
}
pmon_cacheflush();
(*(program)(marks[MARK_ENTRY]))(newargc, PTR_TO_CKSEG1(newargv),
pmon_envp, pmon_callvec,
(uint64_t *)PHYS_TO_CKSEG0(marks[MARK_END]));
rd_invalidate();
_rtt();
}