summaryrefslogtreecommitdiff
path: root/sys/arch/loongson/stand/boot/exec.c
blob: c93a8e001534491ff90cd0358b051f4fdac740f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*	$OpenBSD: exec.c,v 1.4 2019/04/10 04:17:35 deraadt Exp $	*/

/*
 * Copyright (c) 2010 Miodrag Vallat.
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#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;

	/*
	 * Build a new commandline:
	 * boot <device kernel is loaded from> -<kernel options>
	 */

	newargc = howto == 0 ? 2 : 3;
	newargv = alloc(newargc * sizeof(int32_t));
	if (newargv == NULL)
		panic("out of memory");

	arg = "boot";	/* kernel needs this. */
	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_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();
}