Assume that your loader is written by ASM, and your kernel is written by C. When your loader is to jump to kernel start addr, you have to set ds, es, ss to the same value. I think C language has promised that all its data after compiling will be put to the same segment, under protected mode. So, at runtime, you should promise it too. But you should know that C compiler will not set these three segment registers' values to the current segment because it won't figure out you are writing an OS (I think :)).
But there's another issue left, making ds, es, ss unique means that all your data should be put to the same segment where the kernel also exists. So it'll be too complex if you separate your kernel into an individual segment.
So, as the common solution, treat the whole 4G memory as one segment before entering kernel. Don't worry, you have chance to update GDT later:)
本文探讨了从由汇编语言编写的加载器跳转到由C语言编写的内核启动地址的方法。为了确保所有数据都放置在同一段中,需要设置ds、es和ss寄存器的值相同。此外,文章还讨论了将整个4GB内存视为单一内存段的原因,并提到了后续更新全局描述符表(GDT)的机会。

被折叠的 条评论
为什么被折叠?



