Skip to content
12 changes: 12 additions & 0 deletions head.asm
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,19 @@ load_gdt:
ret

keyboard_handler:
push ds
push es
push fs
push gs
pushad

call keyboard_handler_main

popad
pop ds
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be in reverse order?

Copy link
Copy Markdown
Author

@mkilgore mkilgore Dec 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say you would be right. I'm guessing I never noticed this bug because all of those segments probably contain the same value everywhere in the program. but obviously it's still a bug and it would easily blow things up if/when features are added that make use of the segment registers (Such as using them for CPU-local data).

On that note it also appears the segments are also never assigned, so it's quite likely this code got lucky in other areas. A while back I had an issue stemming from something similar in my kernel, it's fixed here. The code in this PR doesn't reload the segments after the lgdt, but that's necessary to ensure they actually contain the correct values and also to ensure they start utilizing the newly defined segments.

pop es
pop fs
pop gs
iretd

start:
Expand Down