James Molloy's Tutorial Known Bugs: Difference between revisions

Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Line 107:
It is strongly recommended that you write your own implementation of this and disregard the tutorial. The tutorial attempts to implement forking kernel threads by searching for magic values on the stack, which is insanity. If you wish to create a new kernel thread, simply decide which registers it should have and point its stack pointer at its freshly allocated stack. It will then start executing at your desired entry point. The part where it disables paging is bad and you should just map the source and destination physical frames at appropriate virtual addresses and memcpy with paging on at all times. Section 9.3 in particular is insanity and has blown up at least one well-established hobby operating system.
 
=== Inline assemblyAssembly optimiser problem with gccGCC 4.8 ===
As mentioned above, writing inlineInline assemblyAssembly can be tricky. The original inlineInline assemblyAssembly is this:
 
<nowiki>
Line 133:
10388c: ff e1 jmp *%ecx</nowiki>
 
Note how the eaxEAX register is assigned to the ecxECX register. However, later on the ecxECX register is assigned to ebpEBP register. The reason for this is that the optimizer was using the eaxEAX register to store the eipEIP variable and the ecxECX register to store the ebpEBP variable. This results in the eipEIP variable being assigned to the ecxECX register ''as well as'' the ebpEBP register. This leads to a subsequent '''ret''' statement sending the cpuCPU to some invalid memory location.
 
A way to fix this is to remove the inlineInline assemblyAssembly by, for example adding this to '''process.c''':
<nowiki>
; Here we:
Line 143:
; * Set the base and stack pointers
; * Set the page directory
; * Put a dummy value (0x12345) in EAX so that above we can recogniserecognize that we've just
; switched task.
; * Restart interrupts. The STI instruction has a delay - it doesn't take effect until after
Line 152:
perform_task_switch:
cli;
mov ecx, [esp+4] ; eipEIP
mov eax, [esp+8] ; physical address of current directory
mov ebp, [esp+12] ; ebpEBP
mov esp, [esp+16] ; espESP
mov cr3, eax ; set the page directory
mov eax, 0x12345 ; magic number to detect a task switch
Line 164:
<nowiki>
extern void perform_task_switch(u32int, u32int, u32int, u32int);</nowiki>
and replace the inlineInline assemblyAssembly with:
<nowiki>
perform_task_switch(eip, current_directory->physicalAddr, ebp, esp);</nowiki>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu