Shengyu Zhang
Shengyu Zhang
> @SilverRainZ why did you create a fork? Because I don't own this repository and the maintainer hasn't replied to me for a year, see https://github.com/clayrisser/sphinx-markdown-builder/issues/59
@clayrisser Kindly ping :)
> Thanks. I don't have time to work on this right now, but pull requests are welcome. @clayrisser Fixed in #57.
This panic is thrown by bochs rather than this kernel. You may not get bochs installed correctly.
@enty8080 Sorry, I haven't touched the kernel for a long time. It panic in somewhere of [cinit.c](https://github.com/SilverRainZ/OS67/blob/master/usr/cinit.c) and here may a instruction divides by zero. Use bochs may prevent this...
Hello,我已经好几年没有继续研究 kernel 了,而且现在也没有从事相关的工作, 有些问题凭印象作答,难免有纰漏,太过细节的地方可能也无法深入研究, 因此这些回答仅供参考。
> 我现在理解的内核加载是:bootloader把软盘里的内容加载到内存,然后跳转到ELF文件找到入口执行内核程序,但是不太清楚这里elf是自行进入脚本ld文件设置的入口还是需要我们给定入口位置 你的理解大致没错,在 OS67 里,[boot/bootsect.asm](https://github.com/SilverRainZ/OS67/blob/master/boot/bootsect.asm) 会在实模式下把内核加载到 0x8000,开启保护模式并进入 32 位模式后之后跳转到 `Selec_Code32_R0:0x8000` 时,其控制流实际上是到了 [kern/loader.asm](https://github.com/SilverRainZ/OS67/blob/master/kern/loader.asm) 中,(loader.asm 会将内核整体从 0x8000 移到 0x100000,之所以这么做应该是由于 MBR 的历史原因)。 loader.asm 在这里是内核的一部分,和内核本体的 c 代码被编译成一个 binary,因此符号也是共享的,入口位置通过 [`[extern osmain]` ](https://github.com/SilverRainZ/OS67/blob/cdd1ed80edf2d1ff30b0742c345e77d0a408ed54/kern/loader.asm#L18) 伪指令即可获取。
Orz 好吧,看来我的理解有偏差,你要 ELF 入口点难道不是想找到内核代码开始的地方么?在没有 [crt0](https://en.wikipedia.org/wiki/Crt0) 的情况下(其实我不知道有没有……),入口点不就是 main 函数么地址么? 对 OS67 来说并不存在什么 ELF 入口点,[script/link.ld#L8](https://github.com/SilverRainZ/OS67/blob/master/script/link.ld#L8) 把内核的 .text 段安排在文件的最开始,生成一个 elf 格式的 kernel,然后 [Makefile#L54](https://github.com/SilverRainZ/OS67/blob/cdd1ed80edf2d1ff30b0742c345e77d0a408ed54/Makefile#L54) 会把 elf 给 strip 成 binary,所以其实加载到内核的只是一个普通的 binary,它的 0x0 处就是 kernstart。
> 然后我现在lgdt [gdtLimit] 后打算跳到内核执行 > jmp dword selgdt_code:0x10000 > 但是貌似bochs又跳回了boot未启动的部分,也就是说重新加载了一遍程序,我想问一下大佬这里跳转部分我应该怎么做。bochs的GDT表好像和设置的不太一样 你用 bochs 看过 GDT 表了么?建议用 bochsdbg 在 JMP 前加个 INT 3 断下来单步跟跟看。 :joy: 你贴的代码感觉我现在已经看不懂了,你列举的四个可能的问题,都可以通过 bochsdbg 来解决,当然由于 GDT 设置错误的问题可能调起来不是很直观。
> 还有大佬,代码段中限长为0xfffff-1好像不够管理4G空间吧。。。 记得 DA_LIMIT_4K 也就是 Gr 位被置位的段的粒度是 4K 吧。