xref: /openbsd/sys/arch/i386/stand/libsa/exec_i386.c (revision 891d7ab6)
1 /*	$OpenBSD: exec_i386.c,v 1.34 2011/04/26 17:33:17 jsing Exp $	*/
2 
3 /*
4  * Copyright (c) 1997-1998 Michael Shalayeff
5  * Copyright (c) 1997 Tobias Weingartner
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  */
30 
31 #include <sys/param.h>
32 #include <dev/cons.h>
33 #include <stand/boot/bootarg.h>
34 #include <machine/biosvar.h>
35 #include <sys/disklabel.h>
36 #include "disk.h"
37 #include "libsa.h"
38 #include <lib/libsa/loadfile.h>
39 
40 typedef void (*startfuncp)(int, int, int, int, int, int, int, int)
41     __attribute__ ((noreturn));
42 
43 char *bootmac = NULL;
44 
45 void
46 run_loadfile(u_long *marks, int howto)
47 {
48 	u_long entry;
49 #ifndef _TEST
50 	dev_t bootdev = bootdev_dip->bootdev;
51 	size_t ac = BOOTARG_LEN;
52 	caddr_t av = (caddr_t)BOOTARG_OFF;
53 	bios_consdev_t cd;
54 	extern int com_speed; /* from bioscons.c */
55 	bios_ddb_t ddb;
56 	extern int db_console;
57 	bios_rootduid_t rootduid;
58 
59 	if (sa_cleanup != NULL)
60 		(*sa_cleanup)();
61 
62 	cd.consdev = cn_tab->cn_dev;
63 	cd.conspeed = com_speed;
64 	addbootarg(BOOTARG_CONSDEV, sizeof(cd), &cd);
65 
66 	if (bootmac != NULL)
67 		addbootarg(BOOTARG_BOOTMAC, sizeof(bios_bootmac_t), bootmac);
68 
69 	if (db_console != -1) {
70 		ddb.db_console = db_console;
71 		addbootarg(BOOTARG_DDB, sizeof(ddb), &ddb);
72 	}
73 
74 	bcopy(bootdev_dip->disklabel.d_uid, &rootduid.duid, sizeof(rootduid));
75 	addbootarg(BOOTARG_ROOTDUID, sizeof(rootduid), &rootduid);
76 
77 	/* Pass memory map to the kernel */
78 	mem_pass();
79 
80 	makebootargs(av, &ac);
81 
82 	entry = marks[MARK_ENTRY] & 0x0fffffff;
83 
84 	printf("entry point at 0x%x\n", (int) entry);
85 	/* stack and the gung is ok at this point, so, no need for asm setup */
86 	(*(startfuncp)entry)(howto, bootdev, BOOTARG_APIVER,
87 	    marks[MARK_END], extmem, cnvmem, ac, (int)av);
88 	/* not reached */
89 #endif
90 }
91