Skip to content

Commit b3266bd

Browse files
Jarkko SakkinenH. Peter Anvin
authored andcommitted
x86, realmode: realmode.bin infrastructure
Create realmode.bin and realmode.relocs files. Piggy pack them into relocatable object that will be included into .init.data section of the main kernel image. The first file includes binary image of the real-mode code. The latter file includes all relocations. The layout of the binary image is specified in realmode.lds.S. The makefile generates pa_ prefixed symbols for each exported global. These are used in 32-bit code and in realmode header to define symbols that need to be relocated. Signed-off-by: Jarkko Sakkinen <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Originally-by: H. Peter Anvin <[email protected]> Signed-off-by: H. Peter Anvin <[email protected]>
1 parent 433de73 commit b3266bd

File tree

7 files changed

+189
-1
lines changed

7 files changed

+189
-1
lines changed

arch/x86/Kbuild

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
obj-$(CONFIG_KVM) += kvm/
32

43
# Xen paravirtualization support
@@ -7,6 +6,7 @@ obj-$(CONFIG_XEN) += xen/
76
# lguest paravirtualization support
87
obj-$(CONFIG_LGUEST_GUEST) += lguest/
98

9+
obj-y += realmode/
1010
obj-y += kernel/
1111
obj-y += mm/
1212

arch/x86/realmode/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# arch/x86/realmode/Makefile
3+
#
4+
# This file is subject to the terms and conditions of the GNU General Public
5+
# License. See the file "COPYING" in the main directory of this archive
6+
# for more details.
7+
#
8+
#
9+
10+
subdir- := rm
11+
12+
obj-y += rmpiggy.o
13+
14+
$(obj)/rmpiggy.o: $(obj)/rm/realmode.relocs $(obj)/rm/realmode.bin
15+
16+
$(obj)/rm/realmode.bin: FORCE
17+
$(Q)$(MAKE) $(build)=$(obj)/rm $@
18+
19+
$(obj)/rm/realmode.relocs: FORCE
20+
$(Q)$(MAKE) $(build)=$(obj)/rm $@

arch/x86/realmode/rm/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pasyms.h
2+
realmode.lds
3+
realmode.relocs

arch/x86/realmode/rm/Makefile

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#
2+
# arch/x86/realmode/Makefile
3+
#
4+
# This file is subject to the terms and conditions of the GNU General Public
5+
# License. See the file "COPYING" in the main directory of this archive
6+
# for more details.
7+
#
8+
#
9+
10+
subdir- := wakeup
11+
12+
always := realmode.bin
13+
14+
realmode-y += header.o
15+
16+
targets += $(realmode-y)
17+
18+
REALMODE_OBJS = $(addprefix $(obj)/,$(realmode-y))
19+
20+
sed-pasyms := -n -r -e 's/^([0-9a-fA-F]+) [ABCDGRSTVW] (.+)$$/pa_\2 = \2;/p'
21+
22+
quiet_cmd_pasyms = PASYMS $@
23+
cmd_pasyms = $(NM) $(filter-out FORCE,$^) | \
24+
sed $(sed-pasyms) | sort | uniq > $@
25+
26+
$(obj)/pasyms.h: $(REALMODE_OBJS) FORCE
27+
$(call if_changed,pasyms)
28+
29+
$(obj)/realmode.lds: $(obj)/pasyms.h
30+
31+
LDFLAGS_realmode.elf := --emit-relocs -T
32+
CPPFLAGS_realmode.lds += -P -C -I$(obj)
33+
34+
$(obj)/realmode.elf: $(obj)/realmode.lds $(REALMODE_OBJS) FORCE
35+
$(call if_changed,ld)
36+
37+
OBJCOPYFLAGS_realmode.bin := -O binary
38+
39+
$(obj)/realmode.bin: $(obj)/realmode.elf
40+
$(call if_changed,objcopy)
41+
42+
quiet_cmd_relocs = RELOCS $@
43+
cmd_relocs = scripts/x86-relocs --realmode $< > $@
44+
$(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
45+
$(call if_changed,relocs)
46+
47+
# ---------------------------------------------------------------------------
48+
49+
# How to compile the 16-bit code. Note we always compile for -march=i386,
50+
# that way we can complain to the user if the CPU is insufficient.
51+
KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ \
52+
-DDISABLE_BRANCH_PROFILING \
53+
-Wall -Wstrict-prototypes \
54+
-march=i386 -mregparm=3 \
55+
-include $(srctree)/$(src)/../../boot/code16gcc.h \
56+
-fno-strict-aliasing -fomit-frame-pointer \
57+
$(call cc-option, -ffreestanding) \
58+
$(call cc-option, -fno-toplevel-reorder,\
59+
$(call cc-option, -fno-unit-at-a-time)) \
60+
$(call cc-option, -fno-stack-protector) \
61+
$(call cc-option, -mpreferred-stack-boundary=2)
62+
KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
63+
GCOV_PROFILE := n

arch/x86/realmode/rm/header.S

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Real-mode blob header; this should match realmode.h and be
3+
* readonly; for mutable data instead add pointers into the .data
4+
* or .bss sections as appropriate.
5+
*/
6+
7+
#include <linux/linkage.h>
8+
#include <asm/page_types.h>
9+
10+
.section ".header", "a"
11+
12+
ENTRY(real_mode_header)
13+
.long pa_text_start
14+
.long pa_ro_end
15+
.long pa_end
16+
END(real_mode_header)

arch/x86/realmode/rm/realmode.lds.S

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* realmode.lds.S
3+
*
4+
* Linker script for the real-mode code
5+
*/
6+
7+
#include <asm/page_types.h>
8+
9+
#undef i386
10+
11+
OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
12+
OUTPUT_ARCH(i386)
13+
14+
SECTIONS
15+
{
16+
real_mode_seg = 0;
17+
18+
. = 0;
19+
.header : {
20+
pa_real_mode_base = .;
21+
*(.header)
22+
}
23+
24+
. = ALIGN(4);
25+
.rodata : {
26+
*(.rodata)
27+
*(.rodata.*)
28+
}
29+
30+
. = ALIGN(PAGE_SIZE);
31+
.text : {
32+
pa_text_start = .;
33+
*(.text)
34+
*(.text.*)
35+
}
36+
37+
.text32 : {
38+
*(.text32)
39+
*(.text32.*)
40+
pa_ro_end = .;
41+
}
42+
43+
. = ALIGN(PAGE_SIZE);
44+
.data : {
45+
*(.data)
46+
*(.data.*)
47+
}
48+
49+
. = ALIGN(128);
50+
.bss : {
51+
*(.bss*)
52+
}
53+
54+
/* End signature for integrity checking */
55+
. = ALIGN(4);
56+
.signature : {
57+
*(.signature)
58+
pa_end = .;
59+
}
60+
61+
/DISCARD/ : {
62+
*(.note*)
63+
*(.debug*)
64+
*(.eh_frame*)
65+
}
66+
67+
#include "pasyms.h"
68+
}

arch/x86/realmode/rmpiggy.S

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Wrapper script for the realmode binary as a transport object
3+
* before copying to low memory.
4+
*/
5+
#include <linux/linkage.h>
6+
#include <asm/page_types.h>
7+
8+
.section ".init.data","aw"
9+
10+
.balign PAGE_SIZE
11+
12+
ENTRY(real_mode_blob)
13+
.incbin "arch/x86/realmode/rm/realmode.bin"
14+
END(real_mode_blob)
15+
16+
ENTRY(real_mode_relocs)
17+
.incbin "arch/x86/realmode/rm/realmode.relocs"
18+
END(real_mode_relocs)

0 commit comments

Comments
 (0)