1*a4f11372Smiod /* $OpenBSD: cdboot.c,v 1.16 2023/02/23 19:48:22 miod Exp $ */
2f6187715Smickey
3f6187715Smickey /*
4f6187715Smickey * Copyright (c) 2003 Michael Shalayeff
5f6187715Smickey * All rights reserved.
6f6187715Smickey *
7f6187715Smickey * Redistribution and use in source and binary forms, with or without
8f6187715Smickey * modification, are permitted provided that the following conditions
9f6187715Smickey * are met:
10f6187715Smickey * 1. Redistributions of source code must retain the above copyright
11f6187715Smickey * notice, this list of conditions and the following disclaimer.
12f6187715Smickey * 2. Redistributions in binary form must reproduce the above copyright
13f6187715Smickey * notice, this list of conditions and the following disclaimer in the
14f6187715Smickey * documentation and/or other materials provided with the distribution.
15f6187715Smickey *
16f6187715Smickey * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17fef2e65fSmickey * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18fef2e65fSmickey * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19fef2e65fSmickey * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
20fef2e65fSmickey * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21fef2e65fSmickey * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22fef2e65fSmickey * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23fef2e65fSmickey * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24fef2e65fSmickey * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25fef2e65fSmickey * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26fef2e65fSmickey * THE POSSIBILITY OF SUCH DAMAGE.
27f6187715Smickey */
28f6187715Smickey
29f6187715Smickey #include <sys/param.h>
30f6187715Smickey #include <sys/reboot.h>
31f6187715Smickey #include <sys/stat.h>
32f6187715Smickey #include <libsa.h>
334d145fc6Smickey #include <lib/libsa/cd9660.h>
34efd48a51Smickey #include <lib/libsa/loadfile.h>
35f65494e6Sderaadt #include <lib/libsa/arc4.h>
364d145fc6Smickey #include <dev/cons.h>
37efd48a51Smickey #include <machine/pdc.h>
385b194e1fSderaadt #include <machine/cpu.h>
39efd48a51Smickey #include <stand/boot/bootarg.h>
40efd48a51Smickey #include "dev_hppa.h"
41e74a1c36Smickey #include "cmd.h"
42f6187715Smickey
434d145fc6Smickey dev_t bootdev;
444d145fc6Smickey int debug = 1;
45c0f32d79Skettenis int boottimeout = 5;
46f6187715Smickey
474d145fc6Smickey struct fs_ops file_system[] = {
484d145fc6Smickey { cd9660_open, cd9660_close, cd9660_read, cd9660_write, cd9660_seek,
494d145fc6Smickey cd9660_stat, cd9660_readdir },
504d145fc6Smickey };
51cf92b8d0Sjasper int nfsys = nitems(file_system);
524d145fc6Smickey
534d145fc6Smickey struct devsw devsw[] = {
544d145fc6Smickey { "dk", iodcstrategy, dkopen, dkclose, noioctl },
554d145fc6Smickey };
56cf92b8d0Sjasper int ndevs = nitems(devsw);
574d145fc6Smickey
584d145fc6Smickey struct consdev constab[] = {
594d145fc6Smickey { ite_probe, ite_init, ite_getc, ite_putc },
604d145fc6Smickey { NULL }
614d145fc6Smickey };
624d145fc6Smickey struct consdev *cn_tab;
63f6187715Smickey
64e2b96ebfSderaadt typedef void (*startfuncp)(int, int, int, int, int, int, caddr_t)
65efd48a51Smickey __attribute__ ((noreturn));
66efd48a51Smickey
672afebeaeSderaadt char rnddata[BOOTRANDOM_MAX]; /* XXX dummy */
68f65494e6Sderaadt struct rc4_ctx randomctx;
692afebeaeSderaadt
70f6187715Smickey void
boot(dev_t dev)71e74a1c36Smickey boot(dev_t dev)
72f6187715Smickey {
732340cfa5Sderaadt uint64_t marks[MARK_MAX];
74efd48a51Smickey char path[128];
75efd48a51Smickey
764d145fc6Smickey pdc_init();
774d145fc6Smickey cninit();
784d145fc6Smickey devboot(dev, path);
794d145fc6Smickey strncpy(path + strlen(path), ":/bsd.rd", 9);
80c0f32d79Skettenis printf(">> OpenBSD/" MACHINE " CDBOOT 0.2\n"
814d145fc6Smickey "booting %s: ", path);
82f6187715Smickey
83f65494e6Sderaadt /* XXX note that rnddata is not initialized */
84f65494e6Sderaadt rc4_keysetup(&randomctx, rnddata, sizeof rnddata);
85f65494e6Sderaadt rc4_skip(&randomctx, 1536);
86f65494e6Sderaadt
87*a4f11372Smiod marks[MARK_START] = 0;
88efd48a51Smickey if (!loadfile(path, marks, LOAD_KERNEL)) {
89*a4f11372Smiod marks[MARK_END] = ALIGN(marks[MARK_END]);
90efd48a51Smickey fcacheall();
91efd48a51Smickey
92efd48a51Smickey __asm("mtctl %r0, %cr17");
93efd48a51Smickey __asm("mtctl %r0, %cr17");
942340cfa5Sderaadt (*(startfuncp)((u_long)marks[MARK_ENTRY]))((int)pdc, 0, bootdev,
952340cfa5Sderaadt (u_long)marks[MARK_END], BOOTARG_APIVER, BOOTARG_LEN,
96efd48a51Smickey (caddr_t)BOOTARG_OFF);
97efd48a51Smickey /* not reached */
98efd48a51Smickey }
99f6187715Smickey }
100