xref: /freebsd/sys/powerpc/ps3/ps3-hv-asm.awk (revision fe75646a0234a261c0013bf1840fdac4acaf0cec)
1# This script generates the PS3 hypervisor call stubs from an HV
2# interface definition file. The PS3 HV calling convention is very
3# similar to the PAPR one, except that the function token is passed in
4# r11 instead of r3.
5#
6# Invoke like so: awk -f ps3-hv-asm.awk < ps3-hvcall.master > ps3-hvcall.S
7#
8
9BEGIN {
10	printf("#include <machine/asm.h>\n\n");
11	printf("#define hc .long 0x44000022\n\n");
12}
13
14/HVCALL.*/ {
15	code = $2;
16	ins = split($4, a, ",")
17	outs = split($5, a, ",")
18
19	printf("ASENTRY(%s)\n",$3);
20	printf("\tmflr	%%r0\n");
21	printf("\tstd	%%r0,16(%%r1)\n");
22	printf("\tstdu	%%r1,-%d(%%r1)\n", 48+8*outs);
23
24	if ($4 == "UNUSED")
25		ins = 0
26
27	# Save output reg addresses to the stack
28	for (i = 0; i < outs; i++) {
29		if (ins+i >= 8) {
30		   printf("\tld	%%r11,%d(%%r1)\n", 48+8*outs + 48 + 8*(i+ins));
31		   printf("\tstd	%%r11,%d(%%r1)\n", 48+8*i);
32		} else {
33		   printf("\tstd	%%r%d,%d(%%r1)\n", 3+ins+i, 48+8*i);
34		}
35	}
36
37	printf("\tli	%%r11,%d\n", code);
38	printf("\thc\n");
39	printf("\textsw	%%r3,%%r3\n");
40
41	for (i = 0; i < outs; i++) {
42		printf("\tld	%%r11,%d(%%r1)\n", 48+8*i);
43		printf("\tstd	%%r%d,0(%%r11)\n", 4+i);
44	}
45
46	printf("\tld	%%r1,0(%%r1)\n");
47	printf("\tld	%%r0,16(%%r1)\n");
48	printf("\tmtlr	%%r0\n");
49	printf("\tblr\n\n");
50}
51