[ros-dev] Kernel-mode stack layout (FPU save area, trap frames, etc.)

Anich Gregor blight at blight.eu.org
Thu Oct 21 17:47:51 CEST 2004


Hi!

I have changed all the places you mentioned (I hope) and even more - still the 
area gets written into... when I did a backtrace from the place where the 
memory was written it seemed to be in irq_handler_0. I did not see where the 
CPU was pointed to a TSS which it would take the stack pointer for the irq 
handler from, but I have changed all places where a stack pointer is setup in 
a TSS I think.
I have attached the changes which I have made so far, it's very unstable, some 
things are wrong and it does none of the important work (fsave on taskswitch 
is commented out because it crashed everytime, frstor with a corrupted FPU 
save area caused math-faults to raise after the not-present fault which also 
crashed somewhere in KiDispatchException - maybe because they were raised in 
KernelMode and not handled, so I replaced it by finit for now, ...)

In ke/i386/exp.c ExceptionToNtStatus and ExceptionTypeStrings are wrong I 
think, interrupt #15 is reserved by intel, #16 is math fault and #17 is 
alignment check. At the moment #15 is missing in the table, so #15 is math 
fault, #16 is alignment check and so on.
Maybe "if (ExceptionNr < 16)" (around line 170) should be changed to something 
like "if (ExceptionNr < ARRAY_SIZE(ExceptionToNtStatus)" (there are two other 
places where "ExceptionNr < 19" is hardcoded, and we could use "ExceptionNr < 
ARRAY_SIZE(ExceptionTypeStrings)".
Do we have any macro like ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) ?

I was also wondering about line 137 in tss.c (Tss->Esp0 = 
(ULONG)Ki386InitialStackArray[Id];) because it sets the stack pointer of the 
Tss to Ki386InitialStackArray[Id], which is set to &init stack on line 217 
(Ki386InitialStackArray[0] = (PVOID)&init_stack;) - shouldn't it be set to 
&init_stack_top?

- blight

On Saturday 16 October 2004 14:33, Hartmut Birr wrote:
> Hi,
>
> you must change all position where a kernel stack is initialized:
> - In multiboot.S is setup the initial stack
> - In tss.c is setup the tss with the initial stack
> - In w32call.c is setup a new kernel stack for the callback function.
> - In kthread.c are setup some values on the top of the stack
> - In bthread.S starts the execution of a new thread
>
> It seems that you have changed only the last two points. The size of the
> stack must not be changed.
>
> - Hartmut
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ntoskrnl.patch
Type: text/x-diff
Size: 29342 bytes
Desc: not available
Url : http://reactos.com:8080/pipermail/ros-dev/attachments/20041021/d03d71ec/ntoskrnl-0001.bin


More information about the Ros-dev mailing list