xref: /linux/arch/powerpc/platforms/cell/spufs/spu_save_crt0.S (revision e58e871becec2d3b04ed91c0c16fe8deac9c9dfa)
1/*
2 * crt0_s.S: Entry function for SPU-side context save.
3 *
4 * Copyright (C) 2005 IBM
5 *
6 * Entry function for SPU-side of the context save sequence.
7 * Saves all 128 GPRs, sets up an initial stack frame, then
8 * branches to 'main'.
9 *
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
14 * any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26#include <asm/spu_csa.h>
27
28.data
29.align 7
30.globl regs_spill
31regs_spill:
32.space SIZEOF_SPU_SPILL_REGS, 0x0
33
34.text
35.global _start
36_start:
37	/* SPU Context Save Step 1: Save the first 16 GPRs. */
38	stqa $0, regs_spill + 0
39	stqa $1, regs_spill + 16
40	stqa $2, regs_spill + 32
41	stqa $3, regs_spill + 48
42	stqa $4, regs_spill + 64
43	stqa $5, regs_spill + 80
44	stqa $6, regs_spill + 96
45	stqa $7, regs_spill + 112
46	stqa $8, regs_spill + 128
47	stqa $9, regs_spill + 144
48	stqa $10, regs_spill + 160
49	stqa $11, regs_spill + 176
50	stqa $12, regs_spill + 192
51	stqa $13, regs_spill + 208
52	stqa $14, regs_spill + 224
53	stqa $15, regs_spill + 240
54
55	/* SPU Context Save, Step 8: Save the remaining 112 GPRs. */
56	ila     $3, regs_spill + 256
57save_regs:
58	lqr     $4, save_reg_insts
59save_reg_loop:
60	ai      $4, $4, 4
61	.balignl 16, 0x40200000
62save_reg_insts:       /* must be quad-word aligned. */
63	stqd    $16, 0($3)
64	stqd    $17, 16($3)
65	stqd    $18, 32($3)
66	stqd    $19, 48($3)
67	andi    $5, $4, 0x7F
68	stqr    $4, save_reg_insts
69	ai      $3, $3, 64
70	brnz    $5, save_reg_loop
71
72	/* Initialize the stack pointer to point to 16368
73	 * (16kb-16). The back chain pointer is initialized
74	 * to NULL.
75	 */
76	il	$0, 0
77	il	$SP, 16368
78	stqd	$0, 0($SP)
79
80	/* Allocate a minimum stack frame for the called main.
81	 * This is needed so that main has a place to save the
82	 * link register when it calls another function.
83	 */
84	stqd	$SP, -160($SP)
85	ai	$SP, $SP, -160
86
87	/* Call the program's main function. */
88	brsl	$0, main
89
90	/* In this case main should not return; if it does
91	 * there has been an error in the sequence.  Execute
92	 * stop-and-signal with code=0.
93	 */
94.global exit
95.global	_exit
96exit:
97_exit:
98	stop	0x0
99
100	/* Pad the size of this crt0.o to be multiple of 16 bytes. */
101.balignl 16, 0x0
102
103