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