1 /*
   2  * This file and its contents are supplied under the terms of the
   3  * Common Development and Distribution License ("CDDL"), version 1.0.
   4  * You may only use this file in accordance with the terms of version
   5  * 1.0 of the CDDL.
   6  *
   7  * A full copy of the text of the CDDL should have accompanied this
   8  * source.  A copy of the CDDL is also available via the Internet at
   9  * http://www.illumos.org/license/CDDL.
  10  */
  11 
  12 /*
  13  * Copyright (c) 2014 Joyent, Inc.  All rights reserved.
  14  */
  15 
  16 #include <sys/types.h>
  17 #include <sys/bootconf.h>
  18 #include <sys/obpdefs.h>
  19 #include <sys/promif.h>
  20 
  21 /*
  22  *      32-bit Kernel's Virtual memory layout.
  23  *              +-----------------------+
  24  *              |    exception table    |
  25  * 0xFFFF0000  -|-----------------------|- EXCEPTION_ADDRESS
  26  *              |                       |
  27  * 0xFFC00000  -|-----------------------|- ARGSBASE
  28  *              |   XXX  debugger?      |
  29  * 0xFF800000  -|-----------------------|- XXX SEGDEBUBBASE?+
  30  *              |      Kernel Data      |
  31  * 0xFEC00000  -|-----------------------|
  32  *              |      Kernel Text      |
  33  * 0xFE800000  -|-----------------------|- KERNEL_TEXT
  34  *              |                       |
  35  *              |    XXX No idea yet    |
  36  *              |                       |
  37  * 0xC8002000  -|-----------------------|- XXX segmap_start?
  38  *              |       Red Zone        |
  39  * 0xC8000000  -|-----------------------|- kernelbase / userlimit (floating)
  40  *              |      User Stack       |
  41  *              |                       |
  42  *              |                       |
  43  *
  44  *              :                       :
  45  *              |    shared objects     |
  46  *              :                       :
  47  *
  48  *              :                       :
  49  *              |       user data       |
  50  *             -|-----------------------|-
  51  *              |       user text       |
  52  * 0x00002000  -|-----------------------|-  XXX Not necessairily truetoday
  53  *              |       invalid         |
  54  * 0x00000000  -|-----------------------|-
  55  *
  56  * + Item does not exist at this time.
  57  */
  58 
  59 struct bootops          *bootops = 0;   /* passed in from boot */
  60 struct bootops          **bootopsp;
  61 struct boot_syscalls    *sysp;          /* passed in from boot */
  62 
  63 char kern_bootargs[OBP_MAXPATHLEN];
  64 char kern_bootfile[OBP_MAXPATHLEN];
  65 
  66 caddr_t s_text;         /* start of kernel text segment */
  67 caddr_t e_text;         /* end of kernel text segment */
  68 caddr_t s_data;         /* start of kernel data segment */
  69 caddr_t e_data;         /* end of kernel data segment */
  70 caddr_t modtext;        /* start of loadable module text reserved */
  71 caddr_t e_modtext;      /* end of loadable module text reserved */
  72 caddr_t moddata;        /* start of loadable module data reserved */
  73 caddr_t e_moddata;      /* end of loadable module data reserved */
  74 
  75 /*
  76  * Some CPUs have holes in the middle of the 64-bit virtual address range.
  77  */
  78 uintptr_t hole_start, hole_end;
  79 
  80 /*
  81  * PROM debugging facilities
  82  */
  83 int prom_debug = 1;
  84 
  85 /*
  86  * VM related data
  87  */
  88 long page_hashsz;               /* Size of page hash table (power of two) */
  89 unsigned int page_hashsz_shift; /* log2(page_hashsz) */
  90 struct page *pp_base;           /* Base of initial system page struct array */
  91 struct page **page_hash;        /* Page hash table */
  92 pad_mutex_t *pse_mutex;         /* Locks protecting pp->p_selock */
  93 size_t pse_table_size;          /* Number of mutexes in pse_mutex[] */
  94 int pse_shift;                  /* log2(pse_table_size) */
  95 
  96 /*
  97  * Cache size information filled in via cpuid and startup_cache()
  98  */
  99 int armv6_cachesz;              /* Total size of the l1 cache */
 100 int armv6_cache_assoc;          /* L1 cache associativity */
 101 int armv6_l2cache_linesz;       /* Size of a line in the l2 cache */
 102 int armv6_l2cache_size;         /* Total size of the l2 cache */
 103 
 104 /*
 105  * Do basic set up.
 106  */
 107 static void
 108 startup_init()
 109 {
 110         if (BOP_GETPROPLEN(bootops, "prom_debug") >= 0) {
 111                 ++prom_debug;
 112                 prom_printf("prom_debug found in boot enviroment");
 113         }
 114 }
 115 
 116 static void
 117 startup_memlist()
 118 {
 119         bop_panic("startup_memlist");
 120 }
 121 
 122 static void
 123 startup_kmem()
 124 {
 125         bop_panic("startup_kmem");
 126 }
 127 
 128 static void
 129 startup_vm()
 130 {
 131         bop_panic("startup_vm");
 132 }
 133 
 134 static void
 135 startup_modules()
 136 {
 137         bop_panic("startup_modules");
 138 }
 139 
 140 static void
 141 startup_end()
 142 {
 143         bop_panic("startup_end");
 144 }
 145 
 146 /*
 147  * Our kernel text is at 0xfe800000, data at 0xfec000000, and exception vector
 148  * at 0xffff0000. These addresses are all determined and set in stone at link
 149  * time.
 150  *
 151  * This is the ARM machine-dependent startup code. Let's startup the world!
 152  */
 153 void
 154 startup(void)
 155 {
 156         startup_init();
 157         /* TODO if we ever need a board specific startup, it goes here */
 158         startup_memlist();
 159         startup_kmem();
 160         startup_vm();
 161         startup_modules();
 162         startup_end();
 163 }