我应该什么时候设置堆栈 [英] When should I set up the stack

查看:82
本文介绍了我应该什么时候设置堆栈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了新操作系统的主要部分.我想创建一个4 MiB堆栈,但我不知道这是否可以在16位实模式下完成,还是我是否必须先加载内核(将在32位保护模式下进行).

谢谢

I''ve written the main parts of my new operating system. I want to create a 4 MiB stack but I don''t know if that could be done in 16 bits real mode or whether I have to load the kernel first, which will be in 32 bits protected mode.

Thanks

推荐答案

请参阅我对问题的提问.即使答案取决于您的体系结构,但我的基本想法是:我建议您仅使用实模式进行引导.在操作系统开始运行保护模式之后,您应该立即摆脱所有实模式内容(所有代码段,数据段,堆栈段).加载内核时,您可以具有一个临时的16位实模式堆栈,仅用于引导.完成此操作后(或在引导结束时),您将需要调整内存并删除实模式使用的所有内存段,将所有内存释放为保护模式.在跳转到保护模式代码指令指针之前,立即创建保护模式堆栈.

还有一条建议:不要重复某些Microsoft内存模型的错误:将堆栈和静态内存段或页面分开.

—SA
Please see my questions to the question. Even though the answer depends on your architecture, my basic idea is the following: I would advise you to use the real mode only to bootstrap. Immediately after the time OS is started to run protected mode, you should get rid of all real-mode stuff (all code segments, data segments, stack segments). You can have a temporary 16-bit real-mode stack just for bootstrap purposes when you are loading your kernel. When this is done (or at the very end of bootstrap), you will need to adjust your memory and remove all the memory segments used by real mode, free all memory for protected mode. Create the protected-mode stack immediately before jumping to protected-mode code instruction pointer.

One more advice: don''t repeat a mistake of some Microsoft memory models: keep stack and static memory segments or pages separate.

—SA


这篇关于我应该什么时候设置堆栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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