diff mbox series

[kvm-unit-tests] s390x/snippets: Fix compilation with Clang 15

Message ID 20230404101434.172721-1-thuth@redhat.com (mailing list archive)
State New, archived
Headers show
Series [kvm-unit-tests] s390x/snippets: Fix compilation with Clang 15 | expand

Commit Message

Thomas Huth April 4, 2023, 10:14 a.m. UTC
Clang complains:

 s390x/snippets/c/cstart.S:22:13: error: invalid operand for instruction
  lghi %r15, stackptr
             ^
Let's load the address with "larl" instead, like we already do
it in s390x/cstart64.S. For this we should also switch to 64-bit
mode first, then we also don't have to clear r15 right in front
of this anymore.

Changing the code here triggered another problem: initial_cr0
must be aligned on a double-word boundary, otherwise the lctlg
instruction will fail with an specification exception. This was
just working by accident so far - add an ".align 8" now to avoid
the problem.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 s390x/snippets/c/cstart.S | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Claudio Imbrenda April 4, 2023, 10:31 a.m. UTC | #1
On Tue,  4 Apr 2023 12:14:34 +0200
Thomas Huth <thuth@redhat.com> wrote:

> Clang complains:
> 
>  s390x/snippets/c/cstart.S:22:13: error: invalid operand for instruction
>   lghi %r15, stackptr
>              ^
> Let's load the address with "larl" instead, like we already do
> it in s390x/cstart64.S. For this we should also switch to 64-bit
> mode first, then we also don't have to clear r15 right in front
> of this anymore.
> 
> Changing the code here triggered another problem: initial_cr0
> must be aligned on a double-word boundary, otherwise the lctlg
> instruction will fail with an specification exception. This was
> just working by accident so far - add an ".align 8" now to avoid
> the problem.
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>

Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>

> ---
>  s390x/snippets/c/cstart.S | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/s390x/snippets/c/cstart.S b/s390x/snippets/c/cstart.S
> index a7d4cd42..c80ccfed 100644
> --- a/s390x/snippets/c/cstart.S
> +++ b/s390x/snippets/c/cstart.S
> @@ -15,12 +15,12 @@ start:
>  	larl	%r1, initial_cr0
>  	lctlg	%c0, %c0, 0(%r1)
>  	/* XOR all registers with themselves to clear them fully. */
> -	.irp i, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
> +	.irp i, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14
>  	xgr \i,\i
>  	.endr
> -	/* 0x3000 is the stack page for now */
> -	lghi	%r15, stackptr
>  	sam64
> +	/* 0x3000 is the stack page for now */
> +	larl	%r15, stackptr
>  	brasl	%r14, main
>  	/*
>  	 * If main() returns, we stop the CPU with the code below. We also
> @@ -37,6 +37,7 @@ exit:
>  	xgr	%r0, %r0
>  	sigp    %r2, %r0, SIGP_STOP
>  
> +	.align 8
>  initial_cr0:
>  	/* enable AFP-register control, so FP regs (+BFP instr) can be used */
>  	.quad	0x0000000000040000
Janosch Frank April 4, 2023, 11:21 a.m. UTC | #2
On 4/4/23 12:14, Thomas Huth wrote:
> Clang complains:
> 
>   s390x/snippets/c/cstart.S:22:13: error: invalid operand for instruction
>    lghi %r15, stackptr
>               ^
> Let's load the address with "larl" instead, like we already do
> it in s390x/cstart64.S. For this we should also switch to 64-bit
> mode first, then we also don't have to clear r15 right in front
> of this anymore.
> 
> Changing the code here triggered another problem: initial_cr0
> must be aligned on a double-word boundary, otherwise the lctlg
> instruction will fail with an specification exception. This was
> just working by accident so far - add an ".align 8" now to avoid
> the problem.
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>   s390x/snippets/c/cstart.S | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/s390x/snippets/c/cstart.S b/s390x/snippets/c/cstart.S
> index a7d4cd42..c80ccfed 100644
> --- a/s390x/snippets/c/cstart.S
> +++ b/s390x/snippets/c/cstart.S
> @@ -15,12 +15,12 @@ start:
>   	larl	%r1, initial_cr0
>   	lctlg	%c0, %c0, 0(%r1)
>   	/* XOR all registers with themselves to clear them fully. */
> -	.irp i, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
> +	.irp i, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14

Eh, I would have left that in, it doesn't hurt us after all.

Reviewed-by: Janosch Frank <frankja@linux.ibm.com>

>   	xgr \i,\i
>   	.endr
> -	/* 0x3000 is the stack page for now */
> -	lghi	%r15, stackptr
>   	sam64
> +	/* 0x3000 is the stack page for now */
> +	larl	%r15, stackptr
>   	brasl	%r14, main
>   	/*
>   	 * If main() returns, we stop the CPU with the code below. We also
> @@ -37,6 +37,7 @@ exit:
>   	xgr	%r0, %r0
>   	sigp    %r2, %r0, SIGP_STOP
>   
> +	.align 8
>   initial_cr0:
>   	/* enable AFP-register control, so FP regs (+BFP instr) can be used */
>   	.quad	0x0000000000040000
Nico Boehr April 4, 2023, 11:40 a.m. UTC | #3
Quoting Thomas Huth (2023-04-04 12:14:34)
> Clang complains:
> 
>  s390x/snippets/c/cstart.S:22:13: error: invalid operand for instruction
>   lghi %r15, stackptr
>              ^
> Let's load the address with "larl" instead, like we already do
> it in s390x/cstart64.S. For this we should also switch to 64-bit
> mode first, then we also don't have to clear r15 right in front
> of this anymore.
> 
> Changing the code here triggered another problem: initial_cr0
> must be aligned on a double-word boundary, otherwise the lctlg
> instruction will fail with an specification exception. This was
> just working by accident so far - add an ".align 8" now to avoid
> the problem.
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>

Reviewed-by: Nico Boehr <nrb@linux.ibm.com>
diff mbox series

Patch

diff --git a/s390x/snippets/c/cstart.S b/s390x/snippets/c/cstart.S
index a7d4cd42..c80ccfed 100644
--- a/s390x/snippets/c/cstart.S
+++ b/s390x/snippets/c/cstart.S
@@ -15,12 +15,12 @@  start:
 	larl	%r1, initial_cr0
 	lctlg	%c0, %c0, 0(%r1)
 	/* XOR all registers with themselves to clear them fully. */
-	.irp i, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
+	.irp i, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14
 	xgr \i,\i
 	.endr
-	/* 0x3000 is the stack page for now */
-	lghi	%r15, stackptr
 	sam64
+	/* 0x3000 is the stack page for now */
+	larl	%r15, stackptr
 	brasl	%r14, main
 	/*
 	 * If main() returns, we stop the CPU with the code below. We also
@@ -37,6 +37,7 @@  exit:
 	xgr	%r0, %r0
 	sigp    %r2, %r0, SIGP_STOP
 
+	.align 8
 initial_cr0:
 	/* enable AFP-register control, so FP regs (+BFP instr) can be used */
 	.quad	0x0000000000040000