异或的精彩应用 FIX_BTMAP_END

本文深入探讨了源代码中的固定地址枚举和页映射机制,包括临时启动时间映射、永久固定地址边界计算以及页对齐检测等关键概念,详细解析了固定地址的使用场景及实现细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

源文件是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(0xFFFFFC00)对齐的检测

另一个异或的精彩应用是Buddy算法

http://blog.linuxeden.com/index.php/196616/viewspace-8149.html

转载于:https://www.cnblogs.com/mull/p/4477803.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值