1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright IBM Corp. 2005
4 *
5 * Author(s): Rolf Adelsberger
6 *
7 */
8
9#include <linux/linkage.h>
10#include <asm/page.h>
11#include <asm/sigp.h>
12
13/*
14 * moves the new kernel to its destination...
15 * %r2 = pointer to first kimage_entry_t
16 * %r3 = start address - where to jump to after the job is done...
17 *
18 * %r5 will be used as temp. storage
19 * %r6 holds the destination address
20 * %r7 = PAGE_SIZE
21 * %r8 holds the source address
22 * %r9 = PAGE_SIZE
23 *
24 * 0xf000 is a page_mask
25 */
26
27	.text
28ENTRY(relocate_kernel)
29		basr	%r13,0		# base address
30	.base:
31		lghi	%r7,PAGE_SIZE	# load PAGE_SIZE in r7
32		lghi	%r9,PAGE_SIZE	# load PAGE_SIZE in r9
33		lg	%r5,0(%r2)	# read another word for indirection page
34		aghi	%r2,8		# increment pointer
35		tml	%r5,0x1		# is it a destination page?
36		je	.indir_check	# NO, goto "indir_check"
37		lgr	%r6,%r5		# r6 = r5
38		nill	%r6,0xf000	# mask it out and...
39		j	.base		# ...next iteration
40	.indir_check:
41		tml	%r5,0x2		# is it a indirection page?
42		je	.done_test	# NO, goto "done_test"
43		nill	%r5,0xf000	# YES, mask out,
44		lgr	%r2,%r5		# move it into the right register,
45		j	.base		# and read next...
46	.done_test:
47		tml	%r5,0x4		# is it the done indicator?
48		je	.source_test	# NO! Well, then it should be the source indicator...
49		j	.done		# ok, lets finish it here...
50	.source_test:
51		tml	%r5,0x8		# it should be a source indicator...
52		je	.base		# NO, ignore it...
53		lgr	%r8,%r5		# r8 = r5
54		nill	%r8,0xf000	# masking
55	0:	mvcle	%r6,%r8,0x0	# copy PAGE_SIZE bytes from r8 to r6 - pad with 0
56		jo	0b
57		j	.base
58	.done:
59		sgr	%r0,%r0		# clear register r0
60		cghi	%r3,0
61		je	.diag
62		la	%r4,load_psw-.base(%r13)	# load psw-address into the register
63		o	%r3,4(%r4)	# or load address into psw
64		st	%r3,4(%r4)
65		mvc	0(8,%r0),0(%r4)	# copy psw to absolute address 0
66	.diag:
67		diag	%r0,%r0,0x308
68ENDPROC(relocate_kernel)
69
70		.align	8
71	load_psw:
72		.long	0x00080000,0x80000000
73	relocate_kernel_end:
74	.align 8
75	.globl	relocate_kernel_len
76	relocate_kernel_len:
77		.quad	relocate_kernel_end - relocate_kernel
78