Implementing GDT with basic kernel

时光怂恿深爱的人放手 提交于 2019-12-03 21:43:24

There seem to be several problems. I didn't check specific bits of your GDT entries (that's the work one must do on his own with Intel manuals in hands).

First thing (that doesn't cause problems now, but may do it in future) is that you specify and work with 4-byte wide limits, although GDT works only with 20 bits. You should change your gdt_install function to pass only 20-bit limit and document it in comments for future use. Another solution is of course to shift parameter twelve bits right, but it will make less sense and may be explained differently next time you get back to GDT management.

Second thing that doesn't seem to be correct is the way you get parameter for gdt_flush. Stack grows downwards, so the last pushed item is located on (%esp) (that's return address pushed by call instruction) and the parameter you want is located on 4(%esp).

I assume you already are in protected mode and actual GDT is already set up by boot loader, so I can't see any obvious reason for another far jump (that consumes at least three clocks), although it isn't always true that code segment is placed directly after null segment. What I don't like on that jump is the label used as jump destination. I would recommend checking it, as it is a far jump that needs absolute value.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!