1c3e289e1SNathan Whitehorn 2c3e289e1SNathan Whitehorn/*- 3ca496abdSNathan Whitehorn * Copyright (C) 2010-2016 Nathan Whitehorn 4c3e289e1SNathan Whitehorn * All rights reserved. 5c3e289e1SNathan Whitehorn * 6c3e289e1SNathan Whitehorn * Redistribution and use in source and binary forms, with or without 7c3e289e1SNathan Whitehorn * modification, are permitted provided that the following conditions 8c3e289e1SNathan Whitehorn * are met: 9c3e289e1SNathan Whitehorn * 1. Redistributions of source code must retain the above copyright 10c3e289e1SNathan Whitehorn * notice, this list of conditions and the following disclaimer. 11c3e289e1SNathan Whitehorn * 2. Redistributions in binary form must reproduce the above copyright 12c3e289e1SNathan Whitehorn * notice, this list of conditions and the following disclaimer in the 13c3e289e1SNathan Whitehorn * documentation and/or other materials provided with the distribution. 14c3e289e1SNathan Whitehorn * 15ca496abdSNathan Whitehorn * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16c3e289e1SNathan Whitehorn * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17c3e289e1SNathan Whitehorn * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18c3e289e1SNathan Whitehorn * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19c3e289e1SNathan Whitehorn * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20c3e289e1SNathan Whitehorn * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 21c3e289e1SNathan Whitehorn * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22c3e289e1SNathan Whitehorn * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23c3e289e1SNathan Whitehorn * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24c3e289e1SNathan Whitehorn * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25c3e289e1SNathan Whitehorn */ 26c3e289e1SNathan Whitehorn 27fc2a8776SEd Maste#include "assym.inc" 28c3e289e1SNathan Whitehorn 29c3e289e1SNathan Whitehorn#include <sys/syscall.h> 30c3e289e1SNathan Whitehorn 31c3e289e1SNathan Whitehorn#include <machine/trap.h> 32c3e289e1SNathan Whitehorn#include <machine/param.h> 33c3e289e1SNathan Whitehorn#include <machine/spr.h> 34c3e289e1SNathan Whitehorn#include <machine/asm.h> 358f69e36dSJustin Hibbits#include <machine/vmparam.h> 36aef8ef51SAdrian Chadd#include "opt_platform.h" 37c3e289e1SNathan Whitehorn 38c3e289e1SNathan Whitehorn/* Locate the per-CPU data structure */ 39c3e289e1SNathan Whitehorn#define GET_CPUINFO(r) \ 40c3e289e1SNathan Whitehorn mfsprg0 r 41c3e289e1SNathan Whitehorn 42c3e289e1SNathan Whitehorn/* 43c3e289e1SNathan Whitehorn * Compiled KERNBASE location and the kernel load address 44c3e289e1SNathan Whitehorn */ 45c3e289e1SNathan Whitehorn .globl kernbase 46c3e289e1SNathan Whitehorn .set kernbase, KERNBASE 47c3e289e1SNathan Whitehorn 48c3e289e1SNathan Whitehorn/* 49c3e289e1SNathan Whitehorn * Globals 50c3e289e1SNathan Whitehorn */ 51c3e289e1SNathan Whitehorn .data 52bb808254SNathan Whitehorn .align 3 53bb808254SNathan WhitehornGLOBAL(__startkernel) 54bb808254SNathan Whitehorn .long begin 55bb808254SNathan WhitehornGLOBAL(__endkernel) 56bb808254SNathan Whitehorn .long end 57c3e289e1SNathan Whitehorn .align 4 58bb808254SNathan Whitehorn#define TMPSTKSZ 8192 /* 8K temporary stack */ 59c3e289e1SNathan WhitehornGLOBAL(tmpstk) 60c3e289e1SNathan Whitehorn .space TMPSTKSZ 61c3e289e1SNathan Whitehorn 62*61740482SLeandro Lupori#ifdef KDB 63*61740482SLeandro Lupori#define TRAPSTKSZ 4096 /* 4k trap stack */ 64*61740482SLeandro LuporiGLOBAL(trapstk) 65*61740482SLeandro Lupori .space TRAPSTKSZ 66*61740482SLeandro Lupori#endif 67*61740482SLeandro Lupori 68c3e289e1SNathan Whitehorn .text 69c3e289e1SNathan Whitehorn .globl btext 70c3e289e1SNathan Whitehornbtext: 71c3e289e1SNathan Whitehorn 72c3e289e1SNathan Whitehorn/* 73ca496abdSNathan Whitehorn * Main kernel entry point. 74c3e289e1SNathan Whitehorn */ 75c3e289e1SNathan Whitehorn .text 76c3e289e1SNathan Whitehorn .globl __start 77c3e289e1SNathan Whitehorn__start: 785c845fdeSNathan Whitehorn /* Figure out where we are */ 795c845fdeSNathan Whitehorn bl 1f 805c845fdeSNathan Whitehorn .long _DYNAMIC-. 815c845fdeSNathan Whitehorn .long _GLOBAL_OFFSET_TABLE_-. 825c845fdeSNathan Whitehorn .long tmpstk-. 835c845fdeSNathan Whitehorn1: mflr %r30 8429d0137aSRui Paulo 855c845fdeSNathan Whitehorn /* Set up temporary stack pointer */ 865c845fdeSNathan Whitehorn lwz %r1,8(%r30) 875c845fdeSNathan Whitehorn add %r1,%r1,%r30 8847f69f4fSNathan Whitehorn addi %r1,%r1,(8+TMPSTKSZ-40) 89b059c637SNathan Whitehorn 905c845fdeSNathan Whitehorn /* Relocate self */ 915c845fdeSNathan Whitehorn stw %r3,16(%r1) 925c845fdeSNathan Whitehorn stw %r4,20(%r1) 935c845fdeSNathan Whitehorn stw %r5,24(%r1) 945c845fdeSNathan Whitehorn stw %r6,28(%r1) 9547f69f4fSNathan Whitehorn stw %r7,32(%r1) 96c3e289e1SNathan Whitehorn 975c845fdeSNathan Whitehorn lwz %r3,0(%r30) /* _DYNAMIC in %r3 */ 985c845fdeSNathan Whitehorn add %r3,%r3,%r30 995c845fdeSNathan Whitehorn lwz %r4,4(%r30) /* GOT pointer */ 1005c845fdeSNathan Whitehorn add %r4,%r4,%r30 1015c845fdeSNathan Whitehorn lwz %r4,4(%r4) /* got[0] is _DYNAMIC link addr */ 1025c845fdeSNathan Whitehorn subf %r4,%r4,%r3 /* subtract to calculate relocbase */ 1035c845fdeSNathan Whitehorn bl elf_reloc_self 1045c845fdeSNathan Whitehorn 1055c845fdeSNathan Whitehorn lwz %r3,16(%r1) 1065c845fdeSNathan Whitehorn lwz %r4,20(%r1) 1075c845fdeSNathan Whitehorn lwz %r5,24(%r1) 1085c845fdeSNathan Whitehorn lwz %r6,28(%r1) 10947f69f4fSNathan Whitehorn lwz %r7,32(%r1) 1105c845fdeSNathan Whitehorn 1115c845fdeSNathan Whitehorn /* MD setup */ 112c3e289e1SNathan Whitehorn bl powerpc_init 1135c845fdeSNathan Whitehorn 1145c845fdeSNathan Whitehorn /* Set stack pointer to new value and branch to mi_startup */ 115c3e289e1SNathan Whitehorn mr %r1, %r3 116c3e289e1SNathan Whitehorn li %r3, 0 117c3e289e1SNathan Whitehorn stw %r3, 0(%r1) 118c3e289e1SNathan Whitehorn bl mi_startup 1195c845fdeSNathan Whitehorn 120ca496abdSNathan Whitehorn /* mi_startup() does not return */ 121ca496abdSNathan Whitehorn b . 122c3e289e1SNathan Whitehorn 123c3e289e1SNathan Whitehorn#include <powerpc/aim/trap_subr32.S> 124