xref: /kvm-unit-tests/powerpc/cstart64.S (revision 0c4e631ecaf30f8065dec5cc589d5894c961e6ee)
1/*
2 * Entry point and assembler functions for ppc64 tests.
3 *
4 * Copyright (C) 2016, Red Hat Inc, Andrew Jones <drjones@redhat.com>
5 *
6 * This work is licensed under the terms of the GNU LGPL, version 2.
7 */
8#define __ASSEMBLY__
9#include <asm/hcall.h>
10
11#define LOAD_REG_IMMEDIATE(reg,expr)		\
12	lis	reg,(expr)@highest;		\
13	ori	reg,reg,(expr)@higher;		\
14	rldicr	reg,reg,32,31;			\
15	oris	reg,reg,(expr)@h;		\
16	ori	reg,reg,(expr)@l;
17
18#define LOAD_REG_ADDR(reg,name)			\
19	ld	reg,name@got(r2)
20
21.section .init
22
23/*
24 * start is the entry point. r3 points to the DTB
25 */
26.globl start
27start:
28	/*
29	 * We were loaded at QEMU's kernel load address, but we're not
30	 * allowed to link there due to how QEMU deals with linker VMAs,
31	 * so we just linked at zero. This means the first thing to do is
32	 * to find our stack and toc, and then do a relocate.
33	 */
34	bl	0f
350:	mflr	r31
36	subi	r31, r31, 0b - start    /* QEMU's kernel load address */
37	ld	r1, (p_stack - start)(r31)
38	ld	r2, (p_toc - start)(r31)
39	add	r1, r1, r31
40	add	r2, r2, r31
41
42	/* save DTB pointer */
43	std	r3, 56(r1)
44
45	/*
46	 * Call relocate. relocate is C code, but careful to not use
47	 * any global references, as they may use absolute addresses,
48	 * which are, obviously, not yet relocated.
49	 */
50	mr	r3, r31
51	ld	r4, (p_dyn - start)(r31)
52	add	r4, r4, r31
53	bl	relocate
54
55	/* patch sc1 if needed */
56	bl	hcall_have_broken_sc1
57	cmpwi	r3, 0
58	beq	1f
59	LOAD_REG_ADDR(r3, hcall)
60	LOAD_REG_IMMEDIATE(r4, SC1_REPLACEMENT)
61	stw	r4, 0(r3)
62
63	/* complete setup */
641:	ld	r3, 56(r1)
65	bl	setup
66
67	/* run the test */
68	LOAD_REG_ADDR(r5, __argc)
69	LOAD_REG_ADDR(r4, __argv)
70	lwz	r3, 0(r5)
71	bl	main
72	bl	exit
73	b	halt
74
75.align 3
76p_stack:	.llong  stackptr
77p_toc:		.llong  tocptr
78p_dyn:		.llong  dynamic_start
79
80.text
81.align 3
82
83.globl hcall
84hcall:
85	sc	1
86	blr
87
88.globl halt
89halt:
901:	b	1b
91
92.globl enter_rtas
93enter_rtas:
94	mflr	r0
95	std	r0, 16(r1)
96	LOAD_REG_ADDR(r11, rtas_entry)
97	ld	r10, 0(r11)
98//FIXME: change this bctrl to an rtas-prep, rfid, rtas-return sequence
99	mtctr	r10
100	nop
101	bctrl
102	ld	r0, 16(r1)
103	mtlr	r0
104	blr
105