在MikeOS引导程序堆栈段 [英] Stack segment in the MikeOS bootloader

查看:138
本文介绍了在MikeOS引导程序堆栈段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白,这片code的:

I don't understand this piece of code:

mov ax, 07C0h   ; Set up 4K of stack space above buffer
add ax, 544     ; 8k buffer = 512 paragraphs + 32 paragraphs (loader)
cli             ; Disable interrupts while changing stack
mov ss, ax
mov sp, 4096
sti             ; Restore interrupts


  • MOV AX,07C0h - 在这里BIOS加载我们
    code。但是,什么是4K?千字节?一世
    没有得到它:)

  • 添加斧,544 - 再次为什么8K?而为什么我们增加544?为什么不512?

  • MOV SP,4096 - 这里我们设置堆栈指针

  • 什么做我们做所有这些操作,在此之前我们设置堆栈指针?

    What for do we do all these manipulations, before we set stack pointer?

    推荐答案

    我想在最后一行的注释概括起来:

    I think the comment on the last line sums it up:

    buffer:             ; Disk buffer begins (8k after this, stack starts)
    

    内存布​​局是这样的:

    The memory layout looks like this:

    +-------------------+ <-- 07C0:0000, where the BIOS loads the boot sector
    | 512 bytes of code |
    +-------------------+
    | 8KB set aside for |
    |   a disk buffer   |
    +-------------------+ <-- SS:0000
    |   4KB of stack    |
    +-------------------+ <-- SS:1000 = SS:SP
    

    有关段落的评论是稍钝;我觉得它更容易在字节,其中16字节做一个段落的想法。

    The comment about paragraphs is slightly obtuse; I find it easier to think in bytes, where 16 bytes makes one paragraph.

    究其原因,这些神奇数字:

    The reason for these magic numbers:


    • 在开始细分07C0,其中BIOS加载code

    • 跳过512字节,要占code本身(512字节= 32段)

    • 跳过8KB,预留的磁盘缓存(8,192字节= 512段)空间

    • 把SS在4KB块的开始。 512 + 8192 = 8,704字节= 544段落

    • 把SP在该块的末端。把它放在最后因为栈需要在内存中。向上生长

    请注意,该数字4096 = 4KB显示为code正常的,因为SP寄存器需要以字节为单位的值。所有其它值段,因为它们涉及到的SS,这是一个段寄存器

    Note that the number 4096 = 4KB appears as normal in the code, because the SP register needs a value in bytes. All the other values are in paragraphs because they relate to SS, which is a segment register.

    这篇关于在MikeOS引导程序堆栈段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆