Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4bdf8bc4 authored by Jeff Dike's avatar Jeff Dike Committed by Linus Torvalds
Browse files

uml: borrow const.h techniques



Suggested by Geert Uytterhoeven - use const.h to get constants that are usable
in both C and assembly.  I can't include it directly since this code can't
include kernel headers.  const.h is also for numeric constants that can be
typed by tacking a "UL" or similar on the end.  The constants here have to be
typed by casting them.

So, the relevant parts of const.h are copied here and modified in order to
allow the constants to be uncasted in assembly and casted in C.

Signed-off-by: default avatarJeff Dike <jdike@linux.intel.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent ee56314b
Loading
Loading
Loading
Loading
+21 −13
Original line number Original line Diff line number Diff line
@@ -10,23 +10,31 @@
#include "kern_constants.h"
#include "kern_constants.h"


/*
/*
 * Assembly doesn't want any casting, but C does, so define these
 * Stolen from linux/const.h, which can't be directly included since
 * without casts here, and define new symbols with casts inside the C
 * this is used in userspace code, which has no access to the kernel
 * section.
 * headers.  Changed to be suitable for adding casts to the start,
 * rather than "UL" to the end.
 */
 */
#define ASM_STUB_CODE (UML_CONFIG_TOP_ADDR - 2 * UM_KERN_PAGE_SIZE)
#define ASM_STUB_DATA (UML_CONFIG_TOP_ADDR - UM_KERN_PAGE_SIZE)
#define ASM_STUB_START ASM_STUB_CODE


/*
/* Some constant macros are used in both assembler and
 * This file is included by the assembly stubs, which just want the
 * C code.  Therefore we cannot annotate them always with
 * definitions above.
 * 'UL' and other type specifiers unilaterally.  We
 * use the following macros to deal with this.
 */
 */
#ifndef __ASSEMBLY__


#define STUB_CODE ((unsigned long) ASM_STUB_CODE)
#ifdef __ASSEMBLY__
#define STUB_DATA ((unsigned long) ASM_STUB_DATA)
#define _AC(X, Y)	(Y)
#define STUB_START ((unsigned long) ASM_STUB_START)
#else
#define __AC(X, Y)	(X (Y))
#define _AC(X, Y)	__AC(X, Y)
#endif

#define STUB_CODE _AC((unsigned long), \
		      UML_CONFIG_TOP_ADDR - 2 * UM_KERN_PAGE_SIZE)
#define STUB_DATA _AC((unsigned long), UML_CONFIG_TOP_ADDR - UM_KERN_PAGE_SIZE)
#define STUB_START _AC(, STUB_CODE)

#ifndef __ASSEMBLY__


#include "sysdep/ptrace.h"
#include "sysdep/ptrace.h"


+4 −4
Original line number Original line Diff line number Diff line
@@ -7,7 +7,7 @@
	.globl batch_syscall_stub
	.globl batch_syscall_stub
batch_syscall_stub:
batch_syscall_stub:
	/* load pointer to first operation */
	/* load pointer to first operation */
	mov	$(ASM_STUB_DATA+8), %esp
	mov	$(STUB_DATA+8), %esp


again:
again:
	/* load length of additional data */
	/* load length of additional data */
@@ -15,12 +15,12 @@ again:


	/* if(length == 0) : end of list */
	/* if(length == 0) : end of list */
	/* write possible 0 to header */
	/* write possible 0 to header */
	mov	%eax, ASM_STUB_DATA+4
	mov	%eax, STUB_DATA+4
	cmpl	$0, %eax
	cmpl	$0, %eax
	jz	done
	jz	done


	/* save current pointer */
	/* save current pointer */
	mov	%esp, ASM_STUB_DATA+4
	mov	%esp, STUB_DATA+4


	/* skip additional data */
	/* skip additional data */
	add	%eax, %esp
	add	%eax, %esp
@@ -46,7 +46,7 @@ again:


done:
done:
	/* save return value */
	/* save return value */
	mov	%eax, ASM_STUB_DATA
	mov	%eax, STUB_DATA


	/* stop */
	/* stop */
	int3
	int3
+4 −4
Original line number Original line Diff line number Diff line
@@ -8,18 +8,18 @@ syscall_stub:
	/* We don't have 64-bit constants, so this constructs the address
	/* We don't have 64-bit constants, so this constructs the address
	 * we need.
	 * we need.
	 */
	 */
	movq	$(ASM_STUB_DATA >> 32), %rbx
	movq	$(STUB_DATA >> 32), %rbx
	salq	$32, %rbx
	salq	$32, %rbx
	movq	$(ASM_STUB_DATA & 0xffffffff), %rcx
	movq	$(STUB_DATA & 0xffffffff), %rcx
	or	%rcx, %rbx
	or	%rcx, %rbx
	movq	%rax, (%rbx)
	movq	%rax, (%rbx)
	int3
	int3


	.globl batch_syscall_stub
	.globl batch_syscall_stub
batch_syscall_stub:
batch_syscall_stub:
	mov	$(ASM_STUB_DATA >> 32), %rbx
	mov	$(STUB_DATA >> 32), %rbx
	sal	$32, %rbx
	sal	$32, %rbx
	mov	$(ASM_STUB_DATA & 0xffffffff), %rax
	mov	$(STUB_DATA & 0xffffffff), %rax
	or	%rax, %rbx
	or	%rax, %rbx
	/* load pointer to first operation */
	/* load pointer to first operation */
	mov	%rbx, %rsp
	mov	%rbx, %rsp