TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Beyond the 1 MB barrier in DOS

14 点作者 gone3510 天前

3 条评论

rep_lodsb10 天前
The absolutely minimal code to enter - and leave - protected mode is this:<p><pre><code> mov eax,cr0 inc ax ;sets bit 0, assuming it was clear mov cr0,eax dec ax ;clears bit 0 mov cr0,eax </code></pre> As the article correctly said, descriptor caches are what the CPU actually uses to access memory. Coming from real mode, the attributes are already set up the same as in privileged 16-bit protected mode (except that CS is writable), the limit is 64K, and the base is the segment number shifted left by 4, exactly what we require.<p>&quot;But that&#x27;s cheating!&quot;, some might say - not really, how else would it be possible to even execute one instruction in protected mode, if those registers weren&#x27;t already initialized to a sane state? CS at the very least has to be, so that you can execute a jump to the &quot;proper&quot; protected mode segment right after loading CR0.<p>I remember reading some documentation that even said you can load GDT either before or after the &quot;switch&quot; to protected mode, which would be even more impossible if that somehow required different segments already set up.<p>If you want to be pedantic, there also has to be a jump in there to clear the prefetch queue and make sure the CPU actually interprets code according to the new mode, instead of the one that was active when the instruction was fetched and decoded. But that first jump can - and according to some Intel manuals, <i>must!</i> - actually be a near jump, staying in the same code segment at least for the moment. Since a lot of protected mode init code gets this wrong however, they had to keep support for a far jump as the first instruction as well, probably making the microcode for that instruction slower than it could have otherwise been.<p>(To enter &quot;unreal mode&quot;, of course you do also need a GDT, but it doesn&#x27;t need to have any descriptors other than one for the flat 4G data segment)
jmmv10 天前
Happy to see this shared again!<p>The previous submission was ~1 year ago in <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=39292990">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=39292990</a>, although it did not spark significant discussion threads.<p>Also, here are the related articles from this series:<p>* <a href="https:&#x2F;&#x2F;blogsystem5.substack.com&#x2F;p&#x2F;from-0-to-1-mb-in-dos" rel="nofollow">https:&#x2F;&#x2F;blogsystem5.substack.com&#x2F;p&#x2F;from-0-to-1-mb-in-dos</a><p>* <a href="https:&#x2F;&#x2F;blogsystem5.substack.com&#x2F;p&#x2F;running-gnu-on-dos-with-djgpp" rel="nofollow">https:&#x2F;&#x2F;blogsystem5.substack.com&#x2F;p&#x2F;running-gnu-on-dos-with-d...</a><p>* <a href="https:&#x2F;&#x2F;blogsystem5.substack.com&#x2F;p&#x2F;dos-memory-models" rel="nofollow">https:&#x2F;&#x2F;blogsystem5.substack.com&#x2F;p&#x2F;dos-memory-models</a>
anthk10 天前
The books:<p>- Assembly language of the 80x86&#x27;es<p>- 8086, 80286 and 80386 microprocessors<p>- 386 and486 Advanced microprocessors &#x2F; Introduction to the Pentium and Pentium Pro<p>On DOS and DPMI, DOSEmu ran DOS (FreeDOS, DRDOS and MSDOS) and it was much faster than DOSBox as it was something closer to Wine than full emulation, and it had a setting for DPMI too. DN3D ran in real time on machines where DOSBox would halt to it knees.