異或的用法

源文件是arch/x86/include/asm/fixmap.h

enum fixed_addresses {
#ifdef CONFIG_X86_32
        FIX_HOLE,
...
    __end_of_permanent_fixed_addresses,

    /*
     * 256 temporary boot-time mappings, used by early_ioremap(),
     * before ioremap() is functional.
     *
     * If necessary we round it up to the next 256 pages boundary so
     * that we can have a single pgd entry and a single pte table:
     */
#define NR_FIX_BTMAPS        64
#define FIX_BTMAPS_SLOTS    4
#define TOTAL_FIX_BTMAPS    (NR_FIX_BTMAPS * FIX_BTMAPS_SLOTS)
    FIX_BTMAP_END =
     (__end_of_permanent_fixed_addresses ^
      (__end_of_permanent_fixed_addresses + TOTAL_FIX_BTMAPS - 1)) &
     -PTRS_PER_PTE
     ? __end_of_permanent_fixed_addresses + TOTAL_FIX_BTMAPS -
       (__end_of_permanent_fixed_addresses & (TOTAL_FIX_BTMAPS - 1))
     : __end_of_permanent_fixed_addresses,
    FIX_BTMAP_BEGIN = FIX_BTMAP_END + TOTAL_FIX_BTMAPS - 1,

enum fixed_addresses 中每個項代表一個頁。通過__fix_to_virt獲得地址

#define __fix_to_virt(x)        (FIXADDR_TOP - ((x) << PAGE_SHIFT))

比如fix_to_virt(FIX_BTMAP_BEGIN),FIXADDR_TOP通常是0xFFFFF000 比如fix_to_virt(FIX_HOLE)是0xFFFFF000

FIX_BTMAP_END通過

(__end_of_permanent_fixed_addresses ^
  (__end_of_permanent_fixed_addresses + TOTAL_FIX_BTMAPS - 1))
    & -PTRS_PER_PTE

實現是否沿-PTRS_PER_PTE(0xFFFFC000)對齊的檢測

另一個異或的精彩應用是Buddy算法