Print this page
armv6: bcm2835 & qvpb have nearly identical locore _start
It makes sense to common-ize _start for all armv6 machines.  They will all
have to do the same basic setup.  If there is any machine specific setup
they need to do, they can do so in the new _mach_start function.


   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 2013 (c) Joyent, Inc. All rights reserved.
  14  * Copyright (c) 2015 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  15  */
  16 
  17 #include <sys/asm_linkage.h>
  18 #include <sys/machparam.h>
  19 #include <sys/cpu_asm.h>
  20 
  21 #include "assym.h"
  22 
  23 #if defined(__lint)
  24 
  25 #endif
  26 
  27 /*
  28  * Each of the different machines has its own locore.s to take care of getting
  29  * us into fakebop for the first time. After that, they all return here to a
  30  * generic locore to take us into mlsetup and then to main forever more.















  31  */
  32 
  33         /*
  34          * External globals
  35          */
  36         .globl  _locore_start
  37         .globl  mlsetup
  38         .globl  sysp
  39         .globl  bootops
  40         .globl  bootopsp
  41         .globl  t0
  42 
  43         .data
  44         .comm   t0stack, DEFAULTSTKSZ, 32
  45         .comm   t0, 4094, 32
  46 







































  47 #if defined(__lint)
  48 
  49 /* ARGSUSED */
  50 void
  51 _locore_start(struct boot_syscalls *sysp, struct bootops *bop)
  52 {}
  53 
  54 #else   /* __lint */
  55 
  56         /*
  57          * We got here from _kobj_init() via exitto().  We have a few different
  58          * tasks that we need to take care of before we hop into mlsetup and
  59          * then main. We're never going back so we shouldn't feel compelled to
  60          * preserve any registers.
  61          *
  62          *  o Enable our I/D-caches
  63          *  o Save the boot syscalls and bootops for later
  64          *  o Set up our stack to be the real stack of t0stack.
  65          *  o Save t0 as curthread
  66          *  o Set up a struct REGS for mlsetup


 125          * 4-byte aligned stack.  So, to keep things nice and correct, we
 126          * push a zero value twice - it's similar to a typical function
 127          * entry:
 128          *      push { r9, lr }
 129          */
 130         mov     r9,#0
 131         push    { r9 }          /* link register */
 132         push    { r9 }          /* frame pointer */
 133         mov     r0, sp
 134         bl      mlsetup
 135         bl      main
 136         /* NOTREACHED */
 137         ldr     r0,=__return_from_main
 138         ldr     r0,[r0]
 139         bl      panic
 140         SET_SIZE(_locore_start)
 141 
 142 __return_from_main:
 143         .string "main() returned"
 144 #endif  /* __lint */












   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 2013 (c) Joyent, Inc. All rights reserved.
  14  * Copyright (c) 2015 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  15  */
  16 
  17 #include <sys/asm_linkage.h>
  18 #include <sys/machparam.h>
  19 #include <sys/cpu_asm.h>
  20 
  21 #include "assym.h"
  22 
  23 /*
  24  * Every story needs a beginning. This is ours.
  25  */
  26 
  27 /*
  28  * Each of the different machines has its own locore.s to take care of getting
  29  * the machine specific setup done.  Just before jumping into fakebop the
  30  * first time, we call this machine specific code.
  31  */
  32 
  33 /*
  34  * We are in a primordial world here. The loader is going to come along and
  35  * boot us at _start. As we've started the world, we also need to set up a
  36  * few things about us, for example our stack pointer. To help us out, it's
  37  * useful to remember what the loader set up for us:
  38  *
  39  * - unaligned access are allowed (A = 0, U = 1)
  40  * - virtual memory is enabled
  41  *   - we (unix) are mapped right were we want to be
  42  *   - a UART has been enabled & any memory mapped registers have been 1:1
  43  *     mapped
  44  *   - ATAGs have been updated to tell us what the mappings are
  45  * - I/D L1 caches have been enabled
  46  */
  47 
  48         /*
  49          * External globals
  50          */
  51         .globl  _locore_start
  52         .globl  mlsetup
  53         .globl  sysp
  54         .globl  bootops
  55         .globl  bootopsp
  56         .globl  t0
  57 
  58         .data
  59         .comm   t0stack, DEFAULTSTKSZ, 32
  60         .comm   t0, 4094, 32
  61 
  62 
  63 /*
  64  * Recall that _start is the traditional entry point for an ELF binary.
  65  */
  66         ENTRY(_start)
  67         ldr     sp, =t0stack
  68         ldr     r4, =DEFAULTSTKSZ
  69         add     sp, r4
  70         bic     sp, sp, #0xff
  71 
  72         /*
  73          * establish bogus stacks for exceptional CPU states, our exception
  74          * code should never make use of these, and we want loud and violent
  75          * failure should we accidentally try.
  76          */
  77         cps     #(CPU_MODE_UND)
  78         mov     sp, #-1
  79         cps     #(CPU_MODE_ABT)
  80         mov     sp, #-1
  81         cps     #(CPU_MODE_FIQ)
  82         mov     sp, #-1
  83         cps     #(CPU_MODE_IRQ)
  84         mov     sp, #-1
  85         cps     #(CPU_MODE_SVC)
  86 
  87         /* Enable highvecs (moves the base of the exception vector) */
  88         mrc     p15, 0, r3, c1, c0, 0
  89         mov     r4, #1
  90         lsl     r4, r4, #13
  91         orr     r3, r3, r4
  92         mcr     p15, 0, r3, c1, c0, 0
  93 
  94         /* invoke machine specific setup */
  95         bl      _mach_start
  96 
  97         bl      _fakebop_start
  98         SET_SIZE(_start)
  99 
 100 
 101 #if defined(__lint)
 102 
 103 /* ARGSUSED */
 104 void
 105 _locore_start(struct boot_syscalls *sysp, struct bootops *bop)
 106 {}
 107 
 108 #else   /* __lint */
 109 
 110         /*
 111          * We got here from _kobj_init() via exitto().  We have a few different
 112          * tasks that we need to take care of before we hop into mlsetup and
 113          * then main. We're never going back so we shouldn't feel compelled to
 114          * preserve any registers.
 115          *
 116          *  o Enable our I/D-caches
 117          *  o Save the boot syscalls and bootops for later
 118          *  o Set up our stack to be the real stack of t0stack.
 119          *  o Save t0 as curthread
 120          *  o Set up a struct REGS for mlsetup


 179          * 4-byte aligned stack.  So, to keep things nice and correct, we
 180          * push a zero value twice - it's similar to a typical function
 181          * entry:
 182          *      push { r9, lr }
 183          */
 184         mov     r9,#0
 185         push    { r9 }          /* link register */
 186         push    { r9 }          /* frame pointer */
 187         mov     r0, sp
 188         bl      mlsetup
 189         bl      main
 190         /* NOTREACHED */
 191         ldr     r0,=__return_from_main
 192         ldr     r0,[r0]
 193         bl      panic
 194         SET_SIZE(_locore_start)
 195 
 196 __return_from_main:
 197         .string "main() returned"
 198 #endif  /* __lint */
 199 
 200         ENTRY(arm_reg_read)
 201         ldr r0, [r0]
 202         bx lr
 203         SET_SIZE(arm_reg_read)
 204 
 205         ENTRY(arm_reg_write)
 206         str r1, [r0]
 207         bx lr
 208         SET_SIZE(arm_reg_write)