Commit 7feb5557 authored by Kai Germaschewski's avatar Kai Germaschewski

kbuild: asm offset generation for x86_64

Switch to a new way of generating a header file defining the offsets
into C structs for use in assembler code.

This method will hopefully be shared by all archs in the future.

The way to do handle things is taken from (or at least inspired by) 
Keith Owens' kbuild-2.5, so credit for this and the following patches
goes to him ;)
parent 4d0b85ea
...@@ -420,8 +420,8 @@ $(patsubst %, _modinst_%, $(SUBDIRS)) : ...@@ -420,8 +420,8 @@ $(patsubst %, _modinst_%, $(SUBDIRS)) :
else # CONFIG_MODULES else # CONFIG_MODULES
# ---------------------------------------------------------------------------
# Modules not configured # Modules not configured
# ---------------------------------------------------------------------------
modules modules_install: FORCE modules modules_install: FORCE
@echo @echo
...@@ -433,6 +433,25 @@ modules modules_install: FORCE ...@@ -433,6 +433,25 @@ modules modules_install: FORCE
endif # CONFIG_MODULES endif # CONFIG_MODULES
# Generate asm-offsets.h
# ---------------------------------------------------------------------------
define generate-asm-offsets.h
(set -e; \
echo "#ifndef __ASM_OFFSETS_H__"; \
echo "#define __ASM_OFFSETS_H__"; \
echo "/*"; \
echo " * DO NOT MODIFY."; \
echo " *"; \
echo " * This file was generated by arch/$(ARCH)/Makefile"; \
echo " *"; \
echo " */"; \
echo ""; \
sed -ne "/^->/{s:^->\([^ ]*\) [\$$#]\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; s:->::; p;}"; \
echo ""; \
echo "#endif" )
endef
# RPM target # RPM target
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
......
...@@ -54,7 +54,7 @@ CFLAGS += -finline-limit=2000 ...@@ -54,7 +54,7 @@ CFLAGS += -finline-limit=2000
HEAD := arch/x86_64/kernel/head.o arch/x86_64/kernel/head64.o arch/x86_64/kernel/init_task.o HEAD := arch/x86_64/kernel/head.o arch/x86_64/kernel/head64.o arch/x86_64/kernel/init_task.o
SUBDIRS := arch/x86_64/tools $(SUBDIRS) arch/x86_64/kernel arch/x86_64/mm arch/x86_64/lib SUBDIRS += arch/x86_64/kernel arch/x86_64/mm arch/x86_64/lib
CORE_FILES := arch/x86_64/kernel/kernel.o $(CORE_FILES) CORE_FILES := arch/x86_64/kernel/kernel.o $(CORE_FILES)
CORE_FILES += arch/x86_64/mm/mm.o CORE_FILES += arch/x86_64/mm/mm.o
LIBS := $(TOPDIR)/arch/x86_64/lib/lib.a $(LIBS) LIBS := $(TOPDIR)/arch/x86_64/lib/lib.a $(LIBS)
...@@ -78,36 +78,44 @@ vmlinux: arch/x86_64/vmlinux.lds ...@@ -78,36 +78,44 @@ vmlinux: arch/x86_64/vmlinux.lds
.PHONY: zImage bzImage compressed zlilo bzlilo zdisk bzdisk install \ .PHONY: zImage bzImage compressed zlilo bzlilo zdisk bzdisk install \
clean archclean archmrproper archdep checkoffset clean archclean archmrproper archdep checkoffset
checkoffset: FORCE include/asm bzImage: vmlinux
make -C arch/$(ARCH)/tools $(TOPDIR)/include/asm-x86_64/offset.h
bzImage: checkoffset vmlinux
@$(MAKEBOOT) bzImage @$(MAKEBOOT) bzImage
bzImage-padded: checkoffset vmlinux bzImage-padded: vmlinux
@$(MAKEBOOT) bzImage-padded @$(MAKEBOOT) bzImage-padded
tmp: tmp:
@$(MAKEBOOT) BOOTIMAGE=bzImage zlilo @$(MAKEBOOT) BOOTIMAGE=bzImage zlilo
bzlilo: checkoffset vmlinux bzlilo: vmlinux
@$(MAKEBOOT) BOOTIMAGE=bzImage zlilo @$(MAKEBOOT) BOOTIMAGE=bzImage zlilo
bzdisk: checkoffset vmlinux bzdisk: vmlinux
@$(MAKEBOOT) BOOTIMAGE=bzImage zdisk @$(MAKEBOOT) BOOTIMAGE=bzImage zdisk
install: checkoffset vmlinux install: vmlinux
@$(MAKEBOOT) BOOTIMAGE=bzImage install @$(MAKEBOOT) BOOTIMAGE=bzImage install
archclean: archclean:
@$(MAKEBOOT) clean @$(MAKEBOOT) clean
@$(MAKE) -C $(TOPDIR)/arch/x86_64/tools clean
archmrproper: archmrproper:
rm -f $(TOPDIR)/arch/x86_64/tools/offset.h
rm -f $(TOPDIR)/arch/x86_64/tools/offset.tmp
rm -f $(TOPDIR)/include/asm-x86_64/offset.h
archdep: archdep:
@$(MAKE) -C $(TOPDIR)/arch/x86_64/tools all
@$(MAKEBOOT) dep @$(MAKEBOOT) dep
prepare: include/asm-$(ARCH)/offset.h
arch/$(ARCH)/kernel/asm-offsets.s: include/asm include/linux/version.h \
include/config/MARKER
include/asm-$(ARCH)/offset.h.tmp: arch/$(ARCH)/kernel/asm-offsets.s
@$(generate-asm-offsets.h) < $< > $@
include/asm-$(ARCH)/offset.h: include/asm-$(ARCH)/offset.h.tmp
@echo -n ' Generating $@'
@$(update-if-changed)
CLEAN_FILES += include/asm-$(ARCH)/offset.h.tmp \
include/asm-$(ARCH)/offset.h
\ No newline at end of file
/* Written 2000 by Andi Kleen */ /*
/* This program is never executed, just its assembly is examined for offsets * Generate definitions needed by assembly language modules.
(this trick is needed to get cross compiling right) */ * This code generates raw asm output which is post-processed to extract
/* $Id: offset.c,v 1.13 2002/01/08 15:19:57 ak Exp $ */ * and format the required data.
#define ASM_OFFSET_H 1 */
#ifndef __KERNEL__
#define __KERNEL__
#endif
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/stddef.h> #include <linux/stddef.h>
#include <linux/errno.h> #include <linux/errno.h>
...@@ -15,26 +13,26 @@ ...@@ -15,26 +13,26 @@
#include <asm/segment.h> #include <asm/segment.h>
#include <asm/thread_info.h> #include <asm/thread_info.h>
#define output(x) asm volatile ("--- " x) #define DEFINE(sym, val) \
#define outconst(x,y) asm volatile ("--- " x : : "i" (y)) asm volatile("\n->" #sym " %0 " #val : : "i" (val))
int main(void) #define BLANK() asm volatile("\n->" : : )
{
output("/* Auto generated by arch/../tools/offset.c at " __DATE__ ". Do not edit. */\n");
output("#ifndef ASM_OFFSET_H\n");
output("#define ASM_OFFSET_H 1\n");
#define ENTRY(entry) outconst("#define tsk_" #entry " %0", offsetof(struct task_struct, entry)) int main(void)
{
#define ENTRY(entry) DEFINE(tsk_ ## entry, offsetof(struct task_struct, entry))
ENTRY(state); ENTRY(state);
ENTRY(flags); ENTRY(flags);
ENTRY(thread); ENTRY(thread);
BLANK();
#undef ENTRY #undef ENTRY
#define ENTRY(entry) outconst("#define threadinfo_" #entry " %0", offsetof(struct thread_info, entry)) #define ENTRY(entry) DEFINE(threadinfo__ ## entry, offsetof(struct thread_info, entry))
ENTRY(flags); ENTRY(flags);
ENTRY(addr_limit); ENTRY(addr_limit);
ENTRY(preempt_count); ENTRY(preempt_count);
BLANK();
#undef ENTRY #undef ENTRY
#define ENTRY(entry) outconst("#define pda_" #entry " %0", offsetof(struct x8664_pda, entry)) #define ENTRY(entry) DEFINE(pda__ ## entry, offsetof(struct x8664_pda, entry))
ENTRY(kernelstack); ENTRY(kernelstack);
ENTRY(oldrsp); ENTRY(oldrsp);
ENTRY(pcurrent); ENTRY(pcurrent);
...@@ -42,8 +40,7 @@ int main(void) ...@@ -42,8 +40,7 @@ int main(void)
ENTRY(irqcount); ENTRY(irqcount);
ENTRY(cpunumber); ENTRY(cpunumber);
ENTRY(irqstackptr); ENTRY(irqstackptr);
BLANK();
#undef ENTRY #undef ENTRY
output("#endif\n"); return 0;
}
return(0);
}
TARGET = $(TOPDIR)/include/asm-x86_64/offset.h
all:
mrproper:
fastdep: $(TARGET)
.PHONY: all
$(TARGET): offset.h
cmp -s $^ $@ || (cp $^ $(TARGET).new && mv $(TARGET).new $(TARGET))
.PHONY : offset.h all modules modules_install
offset.h: offset.sed offset.c FORCE
$(CC) $(CFLAGS) -S -o offset.tmp offset.c
sed -n -f offset.sed < offset.tmp > offset.h
clean:
rm -f offset.[hs] $(TARGET).new offset.tmp
mrproper:
rm -f offset.[hs] $(TARGET)
rm -f $(TARGET)
include $(TOPDIR)/Rules.make
/---/ {
s/---//
s/\$//
s/^ //
s/^ //
p
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment