{% raw %}
Blaž Šnuderl

Hey. This post seems to break returning from interruptions.

Eg. int!(3) produces a double fault while it returned correctly in the previous post

Aside from that, thanks for this series. It is superbly written with lots of useful info :)

Philipp Oppermann

You're right, I don't know how I didn't notice this.

It seems like the problem is our new GDT, which doesn't have a data segment descriptor. This alone is fine, but the `ss` register still holds a value which is saved to the stack when an exception occurs and checked by `iretq` when we return. One possible solution is to load 0 into the `ss` register after entering long mode (null descriptors are explicitely allowed in `ss` in 64-bit mode). Another solution is to add a valid writable data segment to our new GDT.

This issue is tracked in #277 and I plan to fix it in the next few days. Thanks a lot for reporting!

Aside from that, thanks for this series. It is superbly written with lots of useful info :)

Thanks so much!

Philipp Oppermann

For all people that have the same problem:

The problem is that the ss segment register still contains a selector of the previous GDT that is no longer valid. The iretq instruction expects a valid data segment selector or a null selector. So the easiest way to fix this problem is to add the following to the long_mode_init.asm:

long_mode_start:
; load 0 into all data segment registers
mov ax, 0
mov ss, ax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax

(You only need to reload ss. However, the other registers also no longer point to valid data segments, so it's cleaner to invalidate them, too.)

boomshroom

I just asked on the irc because this seemed like it could be possible with lifetimes. They suggested using PhantomData to add a lifetime parameter to the index and the stack pointers could be replaced by Option<&_>, which is easily obtained by an as_ref() method on a raw pointer.

The biggest issue here is verifying that the Option is the correct size.

Philipp Oppermann

The biggest issue here is verifying that the Option is the correct size.

As far as I know, an Option<&X> has always the same size as a &X, since references implement the the NonZero trait. We could also use a struct StackPointer(usize) and implement NonZero for it. Then an Option<stackpointer> has the same size as an usize.

However, I don't think that it suffices to add a lifetime parameter to the index. For example, we could create two static TSSs A and B. Now we can load TSS A in the CPU but use an index from TSS B in our IDT.

Thank you for series. It is great

Rajivteja Nagipogu

Hi Phill sir. I implemented the OS following the blog till here. So, I was trying to implement system calls to the OS. I tried to use the "syscall" crate and implement a "write" syscall but it caused a Double fault. Is this due to the page fault? Here is the stack frame

IP : 0x110e43
code_segment : 8
cpu_flags : 0x200006
stack_pointer : 0x121dd0
stack_segment : 0

Guard page is at 0x11b000

Philipp Oppermann

The problem might be that you didn't define a handler function for the syscall interrupt or that the privilege level of the IDT entry doesn't allow invokations from userland. In that case, a general protection exception occurs. If you didn't define a handler for this exception, it causes a double fault.

boris

Very interesting series, thank you. Please feel free to add some sort of subscriber feed (RSS,Atom,..)! If there is one, Firefox didn't find it. Haven't tried inoreader yet.

Philipp Oppermann

There should be a feed at https://os.phil-opp.com/rss.xml

Nitin John

Hey! I've been going through your blog, and I think it's splendidly written. I was wondering when the next post would be out

Philipp Oppermann

Thanks a lot! I'm currently working on a second edition of this blog, which reorders the posts (exceptions before page tables) and uses an own bootloader. So the plan is to rewrite the earlier posts, reuse the posts about exceptions, and then write some new posts about hardware interrupts and keyboard input.

I created an issue to track this.

Anonym

Waiting next..... :)

Anonym

thanks

Are you running your own blog post ? i've reading it the first half and already want to point out, this is all i need from such a great programmer. Otherways i would have asked my boss for such a course, but i think this can bring me to the path i wanted, i am a webdeveloper and want to serve json files on the internet. But to be ISO 27001 compliant i needed this information...

Philipp Oppermann
Are you running your own blog post ?

Sorry, I don't understand what you mean.

Wanted to share a project I am working on, I started from this awesome blog! https://github.com/arbel03/os

Philipp Oppermann

Looks like you created your own bootloader and already have some kind of filesystem. Really cool!

We have just created the rust-osdev organization on Github, where we plan to host and maintain all kinds of libraries needed for OS development in Rust (e.g. the x86_64 crate, a bootloader, etc.). Let me know if you'd like to become a member, maybe we can join forces.

Dan Cross

Sadly, this appears to no longer compile, as some of the dependencies are now rather different and some language features have changed. I know you're busy with the second edition effort, but is there any chance there are updates waiting in the wings to the first edition parts?

Philipp Oppermann

Sorry, I don't have the time to keep the first version up to date. I try my best to incorporate the first edition posts into the second edition soon, but it will take some time.

Dan Cross

I understand. It's a great service to the community that this exists at all; would you accept pull requests to fix code while the second edition is still being prepared?

Philipp Oppermann

Sure!

{% endraw %}