aboutsummaryrefslogtreecommitdiff
path: root/test/sreset_world/sreset_kernel/sreset_kernel.S
blob: aae5fb73828c6f9c93830e65d04d0dfc1a850c0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* Copyright 2013-2017 IBM Corp.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 	http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
	Test the SRESET OPAL call in Mambo by
	having a bit of fun printing 'Hello World' from the SRESET vector.
*/

	. = 0x0
	.globl _start
_start:
/*
 * Save some values passed in from skiboot into registers that are
 * non-volatile over OPAL calls.
 *   r8 is the OPAL base
 *   r9 is the OPAL entry point point
 */
	mr	%r13, %r8
	mr	%r14, %r9

	bl	here
here:	mflr	%r8 /* work out where we are running */
	subi	%r8, %r8, here - _start
	/* Stash OPAL base and entry point somewhere SRESET can find it */
	li	%r6, 0xe0
	std	%r13, 0(%r6)
	std	%r14, 8(%r6)
	std	%r8, 16(%r6)
	addi	%r6, %r8, sreset_code_end - _start
	addi	%r7, %r8, sreset_code - _start
	li	%r10, 0x100
c:
	lwa	%r9, 0(%r7)
	stw	%r9, 0(%r10)
	addi	%r7,%r7,4
	addi	%r10,%r10,4
	cmpd	%r7,%r6
	bne	c
	sync
	icbi	0,%r0
	sync
	isync
	
	li	%r0, 1 /* OPAL_CONSOLE_WRITE */
	li	%r3, 0 /* terminal 0 */
	addi	%r4, %r8, len - _start /* ptr to length of string */
	addi	%r5, %r8, str - _start /* ptr to string start */
	mr	%r2, %r13
	mtctr	%r14
	bctrl

	li	%r0, 145 /* OPAL_SIGNAL_SYSTEM_RESET */
	li	%r3, -2 /* All *OTHER* CPUs */
	mr	%r2, %r13
	mtctr	%r14
	bctrl

	/* We shouldn't get here but if we do, just wait here */
	b	.

sreset_code:
	li	%r6, 0xe0
	ld	%r13, 0(%r6)
	ld	%r14, 8(%r6)
	ld	%r8, 16(%r6) /* "here" */
        li      %r0, 1 /* OPAL_CONSOLE_WRITE */
        li      %r3, 0 /* terminal 0 */
	li	%r4, len2 - _start
	li	%r5, str2 - _start
        add     %r4, %r8, %r4
        add     %r5, %r8, %r5
        mr      %r2, %r13
        mtctr   %r14
        bctrl
	li	%r0, 5 /* OPAL_CEC_POWER_DOWN */
	li	%r3, 0 /* normal shutdown */
	mr	%r2, %r13
	mtctr	%r14
	bctrl

	/* We shouldn't get here but if we do, just wait here */
	b	.

sreset_code_end:

len:
	.long 0x00
	.long (strend - str)
str:
	.string "Hello World!\n"
strend:

len2:
	.long 0x00
	.long (str2end - str2)
str2:
	.string "Hello SRESET!\n"
str2end: