From aa650fe614d0fc3fa8d69d0bd2c588f1bd1163e7 Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Sat, 24 Oct 2015 11:17:17 +0100 Subject: [PATCH] Introduce macros for basic number manipulation And sprinkle them through the existing code. Signed-off-by: Andrew Cooper --- arch/x86/link.lds.S | 4 +++- include/arch/x86/page.h | 8 +++----- include/xtf/asm_macros.h | 2 ++ include/xtf/lib.h | 1 + include/xtf/numbers.h | 35 +++++++++++++++++++++++++++++++++++ 5 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 include/xtf/numbers.h diff --git a/arch/x86/link.lds.S b/arch/x86/link.lds.S index 93e362a..031e2cd 100644 --- a/arch/x86/link.lds.S +++ b/arch/x86/link.lds.S @@ -2,6 +2,8 @@ * Common linker file for all x86 environments */ +#include + /* Don't clobber the ld directive */ #undef i386 @@ -36,7 +38,7 @@ ENTRY(_start) SECTIONS { - . = 0x10000; + . = MB(1); .text : { *(.text) diff --git a/include/arch/x86/page.h b/include/arch/x86/page.h index 5d9a5f1..adb8016 100644 --- a/include/arch/x86/page.h +++ b/include/arch/x86/page.h @@ -1,17 +1,15 @@ #ifndef XTF_X86_PAGE_H #define XTF_X86_PAGE_H +#include + /* * Nomenclature inherited from Xen. */ #define PAGE_SHIFT 12 -#ifdef __ASSEMBLY__ -#define PAGE_SIZE (1 << PAGE_SHIFT) -#else -#define PAGE_SIZE (1L << PAGE_SHIFT) -#endif +#define PAGE_SIZE (_AC(1, L) << PAGE_SHIFT) #define PAGE_MASK (~(PAGE_SIZE - 1)) diff --git a/include/xtf/asm_macros.h b/include/xtf/asm_macros.h index 4f356b2..4d0092c 100644 --- a/include/xtf/asm_macros.h +++ b/include/xtf/asm_macros.h @@ -6,6 +6,8 @@ #ifndef XTF_ASM_MACROS_H #define XTF_ASM_MACROS_H +#include + /* Declare data at the architectures width. */ #if defined(__x86_64__) # define _WORD .quad diff --git a/include/xtf/lib.h b/include/xtf/lib.h index fa7d684..86f9f0a 100644 --- a/include/xtf/lib.h +++ b/include/xtf/lib.h @@ -3,6 +3,7 @@ #include #include +#include #include diff --git a/include/xtf/numbers.h b/include/xtf/numbers.h new file mode 100644 index 0000000..aa36f40 --- /dev/null +++ b/include/xtf/numbers.h @@ -0,0 +1,35 @@ +/** + * @file include/xtf/numbers.h + * + * Primatives for number manipulation. + */ +#ifndef XTF_NUMBERS_H +#define XTF_NUMBERS_H + +/** + * Create an integer usable in both C and Assembly, even when @p suf is + * needed. + */ +#ifdef __ASSEMBLY__ +# define _AC(num, suf) num +#else +# define _AC(num, suf) __tok(num, suf) +# define __tok(a, b) (a ## b) +#endif + +#define KB(num) (_AC(num, ULL) << 10) +#define MB(num) (_AC(num, ULL) << 20) +#define GB(num) (_AC(num, ULL) << 30) +#define TB(num) (_AC(num, ULL) << 40) + +#endif /* XTF_NUMBERS_H */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ -- 2.39.5