VOGONS


First post, by superfury

User metadata
Rank l33t++
Rank
l33t++

I've been reading https://pdos.csail.mit.edu/6.828/2014/readings/i386/c07.htm , the 80386 chapter on task switching, but nothing is said about Page Fault exceptions(#PF)? At which point does it occur, before and after loading the new TSS? So what (and WHEN) happens when a Page Fault occurs during saving or loading states and/or segment descriptors? Say a page fault due to (partly) paged out or read-only(using Paging) TSS(es) or GDT?

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 1 of 4, by superfury

User metadata
Rank l33t++
Rank
l33t++

Just found this: https://news.ycombinator.com/item?id=5261598

Combining that info with the 80386 manual in interrupts(and task switching): a stack overflow pushing the error code after switching the task will result in a stack fault? Isn't the fault nesting 'level'(the CPU's idea of the previous fault for determining double faults) cleared/unset after loading state from the new task(thus allowing page faults)? Or is it only cleared after pushing the error code and starting the next instruction fetch(end of the task switch)?

Edit: Although cleared present bit on #SS&#NP in IDT on stack->#NP->double fault might trigger this?

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 2 of 4, by superfury

User metadata
Rank l33t++
Rank
l33t++

So, my current question is: is the fault status(keeping track of the previous fault to detect double fault) cleared when setting the TS flag in CR0(so immediately before starting to load the CS segment of the new task), or is it only cleared once the whole task swith completes(after the error code is pushed and the CPU is ready to start fetching/excuting the new instruction in the new task)?

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 3 of 4, by superfury

User metadata
Rank l33t++
Rank
l33t++

I've adjusted my code a bit according to the Bochs taslomg.cc ( http://bochs.sourceforge.net/cgi-bin/lxr/sour … /cpu/tasking.cc ). Now TR is properly reset when switching tasks. Also, the bug during JMP switching tasks(NT flag of incoming task unchanged instead of cleared) has been implemented.

The attachment debugger_landmarksupersoftBIOS_protectedmode_20180417_1807.7z is no longer available

It still somehow seems to try to execute an IRET loading 0x00000000 dwords from memory, causing an invalid #GP(it isn't supposed to happen)?

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 4 of 4, by superfury

User metadata
Rank l33t++
Rank
l33t++

Looking at the code, it's kind of acting odd: it goes from task 0068 to task 0048 using a CALL(allowing return by IRET because of the Nested flag), then proceeds to execute a JMP to transfer control to task 0058, which breaks the task linkage, continuing the delays(by loading 0 into CX and executing a LOOP instruction), eventually executing an IRET which crashes because NT isn't set anymore(due to the task switch from task 0048)? Or is task 0058 supposed to keep using the same TSS somehow?

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io