194b212c2SPaul Mackerras/* 294b212c2SPaul Mackerras * Copyright (C) Paul Mackerras 1997. 394b212c2SPaul Mackerras * 494b212c2SPaul Mackerras * This program is free software; you can redistribute it and/or 594b212c2SPaul Mackerras * modify it under the terms of the GNU General Public License 694b212c2SPaul Mackerras * as published by the Free Software Foundation; either version 794b212c2SPaul Mackerras * 2 of the License, or (at your option) any later version. 894b212c2SPaul Mackerras * 994b212c2SPaul Mackerras * NOTE: this code runs in 32 bit mode and is packaged as ELF32. 1094b212c2SPaul Mackerras */ 1194b212c2SPaul Mackerras 1294b212c2SPaul Mackerras#include "ppc_asm.h" 1394b212c2SPaul Mackerras 1494b212c2SPaul Mackerras .text 1566a45dd3SPaul Mackerras /* a procedure descriptor used when booting this as a COFF file */ 1666a45dd3SPaul Mackerras_zimage_start_opd: 1766a45dd3SPaul Mackerras .long _zimage_start, 0, 0, 0 1866a45dd3SPaul Mackerras 19cd197ffcSDavid Gibson .weak _zimage_start 2094b212c2SPaul Mackerras .globl _zimage_start 2194b212c2SPaul Mackerras_zimage_start: 2266a45dd3SPaul Mackerras /* Work out the offset between the address we were linked at 2366a45dd3SPaul Mackerras and the address where we're running. */ 2468643cfbSOlaf Hering bl 1f 2566a45dd3SPaul Mackerras1: mflr r0 2668643cfbSOlaf Hering lis r9,1b@ha 2768643cfbSOlaf Hering addi r9,r9,1b@l 2894b212c2SPaul Mackerras subf. r0,r9,r0 2966a45dd3SPaul Mackerras beq 3f /* if running at same address as linked */ 3094b212c2SPaul Mackerras 3166a45dd3SPaul Mackerras /* The .got2 section contains a list of addresses, so add 3266a45dd3SPaul Mackerras the address offset onto each entry. */ 3394b212c2SPaul Mackerras lis r9,__got2_start@ha 3494b212c2SPaul Mackerras addi r9,r9,__got2_start@l 3594b212c2SPaul Mackerras lis r8,__got2_end@ha 3694b212c2SPaul Mackerras addi r8,r8,__got2_end@l 3794b212c2SPaul Mackerras subf. r8,r9,r8 3868643cfbSOlaf Hering beq 3f 3994b212c2SPaul Mackerras srwi. r8,r8,2 4094b212c2SPaul Mackerras mtctr r8 4194b212c2SPaul Mackerras add r9,r0,r9 4266a45dd3SPaul Mackerras2: lwz r8,0(r9) 4394b212c2SPaul Mackerras add r8,r8,r0 4494b212c2SPaul Mackerras stw r8,0(r9) 4594b212c2SPaul Mackerras addi r9,r9,4 4668643cfbSOlaf Hering bdnz 2b 4794b212c2SPaul Mackerras 48cd197ffcSDavid Gibson /* Do a cache flush for our text, in case the loader didn't */ 49eacb1962SOlaf Hering3: lis r9,_start@ha 50eacb1962SOlaf Hering addi r9,r9,_start@l 5194b212c2SPaul Mackerras add r9,r0,r9 5294b212c2SPaul Mackerras lis r8,_etext@ha 5394b212c2SPaul Mackerras addi r8,r8,_etext@l 5494b212c2SPaul Mackerras add r8,r0,r8 5568643cfbSOlaf Hering4: dcbf r0,r9 5694b212c2SPaul Mackerras icbi r0,r9 5794b212c2SPaul Mackerras addi r9,r9,0x20 58eacb1962SOlaf Hering cmplw cr0,r9,r8 5968643cfbSOlaf Hering blt 4b 6094b212c2SPaul Mackerras sync 6194b212c2SPaul Mackerras isync 6294b212c2SPaul Mackerras 63cd197ffcSDavid Gibson /* Clear the BSS */ 64cd197ffcSDavid Gibson lis r9,__bss_start@ha 65cd197ffcSDavid Gibson addi r9,r9,__bss_start@l 66cd197ffcSDavid Gibson lis r8,_end@ha 67cd197ffcSDavid Gibson addi r8,r8,_end@l 68cd197ffcSDavid Gibson li r0,0 69cd197ffcSDavid Gibson5: stw r0,0(r9) 70cd197ffcSDavid Gibson addi r9,r9,4 71cd197ffcSDavid Gibson cmplw cr0,r9,r8 72cd197ffcSDavid Gibson blt 5b 7394b212c2SPaul Mackerras 74cd197ffcSDavid Gibson /* Possibly set up a custom stack */ 75cd197ffcSDavid Gibson.weak _platform_stack_top 76cd197ffcSDavid Gibson lis r8,_platform_stack_top@ha 77cd197ffcSDavid Gibson addi r8,r8,_platform_stack_top@l 78cd197ffcSDavid Gibson cmpwi r8,0 79cd197ffcSDavid Gibson beq 6f 80cd197ffcSDavid Gibson lwz r1,0(r8) 81cd197ffcSDavid Gibson li r0,0 82cd197ffcSDavid Gibson stwu r0,-16(r1) /* establish a stack frame */ 83cd197ffcSDavid Gibson6: 84cd197ffcSDavid Gibson 85cd197ffcSDavid Gibson /* Call platform_init() */ 86cd197ffcSDavid Gibson bl platform_init 87cd197ffcSDavid Gibson 88cd197ffcSDavid Gibson /* Call start */ 89cd197ffcSDavid Gibson mr r3,r1 90cd197ffcSDavid Gibson b start 91