【问题标题】:What's so special about 0x55AA?0x55AA有什么特别之处?
【发布时间】:2017-02-19 16:53:24
【问题描述】:

我在 2 个场景中遇到过 0x55AA:

  • 传统引导过程中引导扇区的最后 2 个字节包含 0x55AA
  • Option ROM 的前 2 个字节必须是 0x55AA

那么0x55AA 有什么特别之处呢?

0x55AA 的二进制版本是0101010110101010。是不是因为0和1是均匀交错的?但我不认为这是一个强有力的标准。

【问题讨论】:

标签: operating-system boot firmware


【解决方案1】:

0x55AA 是一个“签名字”。它用作 512 字节引导记录的最后 2 个字节中的“扇区结束”标记。这包括 MBR 和它的扩展引导记录以及在较新的 GPT 中的保护性 MBR。

参考资料:

图片来自Master Boot Record - microsoft.com

How Basic Disks and Volumes Work - microsoft.com.

【讨论】:

  • 应该指出作为 WORD 签名实际上是 0xAA55 或 2 字节 0x55 0xAA
【解决方案2】:

这种组合并没有什么神奇或神秘之处。实施者需要一种方法来确定设备的第一个扇区是否可引导(引导签名),并且在扇区的最后两个字节中出现的组合是如此不可能,这就是选择它的原因。

同样,SMBIOS 入口点可以在扫描 BIOS 中找到_SM_ 签名,该签名必须在这样的段边界上;

  Find_SMBIOS:
    push    ds
    push    bx                      ; Preserve essential
    push    si

; Establish DS:BX to point to base of BIOS code

    mov     ax, 0xf000
    mov     ds, ax                  ; Segment where table lives
    xor     bx, bx                  ; Initial pointer
    mov     eax, '_SM_'             ; Scan buffer for this signature

; Loop has maximum of 4096 interations. As table is probably at top of buffer, cycling
; though it backwards saves time. In my test bed, BOCH's 2.6.5 BIOS-bochs-latest it was
; 1,451 interations.

.L0: sub     bx, 16                  ; Bump pointer to previous segment
     jnz     .J0

; Return NULL in AX and set CF. Either AX or flag can be tested on return.

    mov     ax, bx
    stc
    jmp     .Done

; Did we find signature at this page

.J0: cmp     [bx], eax
    jnz     .L0                     ; NZ, keep looking

; Calculate checksum to verify position

    mov     cx, 15
    mov     ax, cx
    mov     si, bx                  ; DS:SI = Table entry point

; Compute checksum on next 15 bytes

.L1: lodsb
    add     ah, al
    loop    .L1

    or      ah, ah
    jnz     .L0                     ; Invalid, try to find another occurence

; As entry point is page aligned, we can do this to determine segment.

    shr     bx, 4
    mov     ax, ds
    add     ax, bx
    clc                             ; NC, found signature

.Done:
    pop     si
    pop     bx                      ; Restore essential
    pop     ds

    ret     

该签名在十六进制转储中很容易识别,并且适合 16 位寄存器。我不知道这两个标准的促成因素在哪里,但同样,0x5f4d535f 出现在偶数 16 字节边界上的可能性非常小。

【讨论】:

  • "该签名在十六进制转储中很容易识别,并且适合 16 位寄存器。" SM 签名适合 32 位,而不是 16 位。
猜你喜欢
  • 2011-04-18
  • 2016-09-30
  • 1970-01-01
  • 1970-01-01
  • 2011-07-13
  • 2013-05-11
  • 2016-08-20
  • 2011-05-19
相关资源
最近更新 更多