summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkettenis <kettenis@openbsd.org>2016-12-19 20:03:15 +0000
committerkettenis <kettenis@openbsd.org>2016-12-19 20:03:15 +0000
commita175244698d03f60581128e7cdf980c34a41905a (patch)
tree6bcf0326feed1bd1de44459a6460a6e66ce6ae02
parentRevert r1.934 to unbreak autoinstall (diff)
downloadwireguard-openbsd-a175244698d03f60581128e7cdf980c34a41905a.tar.xz
wireguard-openbsd-a175244698d03f60581128e7cdf980c34a41905a.zip
Generating mixed 16-bit/32-bit/64-bit code with clang's integrated
assembler is a bit tricky. It supports the .code16, .code32 and .code64 directives. But it doesn't know about the data16/data32 and addr16/addr32 instruction prefixes. Instead it tries to determine those from the instruction opcode. It mostly succeeds, but there are a couple of corner cases where clang will generate the "addr32" form where gas generates the "addr16" form in .code16 segments. That should be no problem (and just waste a couple of bytes), but it makes comparing the generated code a bit difficult. Allow the trampoline code to be compiled with both. For clang #define away the addr32 prefix and avoid using the data32 prefix by using a mnemonic that explicitly encodes the size of the operand. Add a few addr32 prefixes in .code16 blocks to reduce the differences between code generated by clang and gas. ok patrick@, deraadt@, mlarkin@
-rw-r--r--sys/arch/amd64/amd64/acpi_wakecode.S14
-rw-r--r--sys/arch/amd64/amd64/mptramp.S8
2 files changed, 15 insertions, 7 deletions
diff --git a/sys/arch/amd64/amd64/acpi_wakecode.S b/sys/arch/amd64/amd64/acpi_wakecode.S
index 7823861205b..363b34dd7f4 100644
--- a/sys/arch/amd64/amd64/acpi_wakecode.S
+++ b/sys/arch/amd64/amd64/acpi_wakecode.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: acpi_wakecode.S,v 1.38 2016/05/16 01:19:27 mlarkin Exp $ */
+/* $OpenBSD: acpi_wakecode.S,v 1.39 2016/12/19 20:03:15 kettenis Exp $ */
/*
* Copyright (c) 2001 Takanori Watanabe <takawata@jp.freebsd.org>
* Copyright (c) 2001 Mitsuru IWASAKI <iwasaki@jp.freebsd.org>
@@ -54,6 +54,10 @@
#include <dev/acpi/acpivar.h>
#include "lapic.h"
+#ifdef __clang__
+#define addr32
+#endif
+
#define _ACPI_TRMP_LABEL(a) a = . - _C_LABEL(acpi_real_mode_resume) + \
ACPI_TRAMPOLINE
#define _ACPI_TRMP_OFFSET(a) a = . - _C_LABEL(acpi_real_mode_resume)
@@ -109,7 +113,7 @@ _ACPI_TRMP_OFFSET(acpi_s3_vector_real)
movw %ax, %ss
movw %cs, %ax
movw %ax, %es
- lidtl clean_idt
+ addr32 lidtl clean_idt
/*
* Set up stack to grow down from offset 0x0FFE.
@@ -140,7 +144,7 @@ _ACPI_TRMP_OFFSET(acpi_s3_vector_real)
* time, until we restore the saved GDT that we had when we went
* to sleep.
*/
- data32 addr32 lgdt tmp_gdt
+ addr32 lgdtl tmp_gdt
/*
* Enable protected mode by setting the PE bit in CR0
@@ -385,7 +389,7 @@ _ACPI_TRMP_OFFSET(hibernate_resume_vector_3)
movw %ax, %fs
movw %ax, %gs
movl $0x0FFE, %esp
- lidtl clean_idt
+ addr32 lidtl clean_idt
/* Jump to the S3 resume vector */
ljmp $(_ACPI_RM_CODE_SEG), $acpi_s3_vector_real
@@ -422,7 +426,7 @@ _ACPI_TRMP_OFFSET(hibernate_resume_vector_3b)
movw %ax, %gs
movw %ax, %ss
movl $0x0FFE, %esp
- lidtl clean_idt
+ addr32 lidtl clean_idt
_ACPI_TRMP_OFFSET(hib_hlt_real)
hlt
diff --git a/sys/arch/amd64/amd64/mptramp.S b/sys/arch/amd64/amd64/mptramp.S
index 0d545ddb3e6..e02eb8cb235 100644
--- a/sys/arch/amd64/amd64/mptramp.S
+++ b/sys/arch/amd64/amd64/mptramp.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: mptramp.S,v 1.13 2016/05/16 01:54:15 mlarkin Exp $ */
+/* $OpenBSD: mptramp.S,v 1.14 2016/12/19 20:03:15 kettenis Exp $ */
/* $NetBSD: mptramp.S,v 1.1 2003/04/26 18:39:30 fvdl Exp $ */
/*-
@@ -84,6 +84,10 @@
#include <machine/mpbiosvar.h>
#include <machine/i82489reg.h>
+#ifdef __clang__
+#define addr32
+#endif
+
#define _RELOC(x) ((x) - KERNBASE)
#define RELOC(x) _RELOC(_C_LABEL(x))
@@ -114,7 +118,7 @@ _C_LABEL(cpu_spinup_trampoline):
movw %cs, %ax
movw %ax, %es
movw %ax, %ss
- data32 addr32 lgdt (mptramp_gdt32_desc) # load flat descriptor table
+ addr32 lgdtl (mptramp_gdt32_desc) # load flat descriptor table
movl %cr0, %eax # get cr0
orl $0x1, %eax # enable protected mode
movl %eax, %cr0 # doit