Skip to content

Commit f910d13

Browse files
author
H. Peter Anvin
committed
x86: unify and correct the GDT_ENTRY() macro
Impact: None (cleanup only) Merge the GDT_ENTRY() macro between arch/x86/boot/pm.c and arch/x86/kernel/acpi/sleep.c and put the new one in <asm-x86/segment.h>. While we're at it, correct the bitmasks for the limit and flags. The new version relies on using ULL constants in order to cause type promotion rather than explicit casts; this avoids having to include <linux/types.h> in <asm-x86/segments.h>. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
1 parent 5b664cb commit f910d13

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

arch/x86/boot/pm.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,6 @@ static void reset_coprocessor(void)
9898
/*
9999
* Set up the GDT
100100
*/
101-
#define GDT_ENTRY(flags, base, limit) \
102-
(((u64)(base & 0xff000000) << 32) | \
103-
((u64)flags << 40) | \
104-
((u64)(limit & 0x00ff0000) << 32) | \
105-
((u64)(base & 0x00ffffff) << 16) | \
106-
((u64)(limit & 0x0000ffff)))
107101

108102
struct gdt_ptr {
109103
u16 len;

arch/x86/kernel/acpi/sleep.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/bootmem.h>
1010
#include <linux/dmi.h>
1111
#include <linux/cpumask.h>
12+
#include <asm/segment.h>
1213

1314
#include "realmode/wakeup.h"
1415
#include "sleep.h"
@@ -23,15 +24,6 @@ static unsigned long acpi_realmode;
2324
static char temp_stack[10240];
2425
#endif
2526

26-
/* XXX: this macro should move to asm-x86/segment.h and be shared with the
27-
boot code... */
28-
#define GDT_ENTRY(flags, base, limit) \
29-
(((u64)(base & 0xff000000) << 32) | \
30-
((u64)flags << 40) | \
31-
((u64)(limit & 0x00ff0000) << 32) | \
32-
((u64)(base & 0x00ffffff) << 16) | \
33-
((u64)(limit & 0x0000ffff)))
34-
3527
/**
3628
* acpi_save_state_mem - save kernel state
3729
*

include/asm-x86/segment.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
#ifndef _ASM_X86_SEGMENT_H_
22
#define _ASM_X86_SEGMENT_H_
33

4+
/* Constructor for a conventional segment GDT (or LDT) entry */
5+
/* This is a macro so it can be used in initializers */
6+
#define GDT_ENTRY(flags, base, limit) \
7+
((((base) & 0xff000000ULL) << (56-24)) | \
8+
(((flags) & 0x0000f0ffULL) << 40) | \
9+
(((limit) & 0x000f0000ULL) << (48-16)) | \
10+
(((base) & 0x00ffffffULL) << 16) | \
11+
(((limit) & 0x0000ffffULL)))
12+
413
/* Simple and small GDT entries for booting only */
514

615
#define GDT_ENTRY_BOOT_CS 2

0 commit comments

Comments
 (0)