1/* $NetBSD: iris_boot.c,v 1.1 2019/01/12 16:44:47 tsutsui Exp $ */ 2 3/* 4 * Copyright (c) 2018 Naruaki Etomi 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28/* 29 * Silicon Graphics "IRIS" series MIPS processors machine bootloader. 30 * 31 * Notes: 32 * The amount of physical memory space available to 33 * the system is 3661820 (0x80002000 - 0x8037fffc) bytes. 34 * This space is too tight for kernel and bootloader. 35 * So we keep it simple. 36 */ 37 38#include <lib/libsa/stand.h> 39#include <lib/libsa/loadfile.h> 40#include <lib/libkern/libkern.h> 41 42#include <sys/param.h> 43#include <sys/exec.h> 44#include <sys/exec_elf.h> 45#include <sys/boot_flag.h> 46 47#ifndef INDIGO_R3K_MODE 48#include <dev/arcbios/arcbios.h> 49#endif 50 51#include "iris_machdep.h" 52 53#include "common.h" 54#include "bootinfo.h" 55 56int main(int, char **); 57 58/* Storage must be static. */ 59struct btinfo_symtab bi_syms; 60struct btinfo_bootpath bi_bpath; 61 62static uint8_t bootinfo[BOOTINFO_SIZE]; 63 64/* 65 * This gets arguments from the PROM monitor. 66 * argv[0] will be path to the bootloader (i.e., "dksc(X,Y,8)/bootiris"). 67 * 68 * argv[1] through argv[n] will contain arguments passed from the PROM, if any. 69 */ 70 71int 72main(int argc, char **argv) 73{ 74 char kernelname[1 + 32]; 75 void (*entry) (int, char *[], int, void *); 76 u_long marks[MARK_MAX]; 77 int win = 0; 78 int zs_addr, speed; 79 80 cninit(&zs_addr, &speed); 81 82 /* print a banner */ 83 printf("\n"); 84 printf("%s " NETBSD_VERS " Yet another Bootstrap, Revision %s\n", 85 bootprog_name, bootprog_rev); 86 printf("\n"); 87 88 memset(marks, 0, sizeof marks); 89 90 /* initialise bootinfo structure early */ 91 bi_init(bootinfo); 92 93 switch (argc) { 94#ifdef INDIGO_R3K_MODE 95 case 1: 96 again(); 97 break; 98#endif 99 case 2: 100 /* To specify HDD on Indigo R3K */ 101 if (strstr(argv[1], "dksc(")) { 102 parse(argv, kernelname); 103 } else { 104 again(); 105 } 106 break; 107 default: 108 /* To specify HDD on Indigo R4K and Indy */ 109 if (strstr(argv[1], "dksc(")) { 110 parse(argv, kernelname); 111 } else { 112 again(); 113 } 114 break; 115 } 116 117 find_devs(); 118 119 win = loadfile(kernelname, marks, LOAD_KERNEL); 120 121 if (win < 0) { 122 printf("Boot failed! Halting...\n"); 123 reboot(); 124 } 125 126 strlcpy(bi_bpath.bootpath, kernelname, BTINFO_BOOTPATH_LEN); 127 bi_add(&bi_bpath, BTINFO_BOOTPATH, sizeof(bi_bpath)); 128 129 bi_syms.nsym = marks[MARK_NSYM]; 130 bi_syms.ssym = marks[MARK_SYM]; 131 bi_syms.esym = marks[MARK_END]; 132 bi_add(&bi_syms, BTINFO_SYMTAB, sizeof(bi_syms)); 133 entry = (void *)marks[MARK_ENTRY]; 134 135 (*entry)(argc, argv, BOOTINFO_MAGIC, bootinfo); 136 137 printf("Kernel returned! Halting...\n"); 138 return 0; 139} 140 141void 142again(void) 143{ 144 printf("Invalid argument\n"); 145 printf("i.e., dksc(0,X,8)loader dksc(0,X,0)/kernel\n"); 146 reboot(); 147} 148 149void 150reboot(void) 151{ 152#ifdef INDIGO_R3K_MODE 153 romrestart(); 154#else 155 arcbios_Reboot(); 156#endif 157} 158