Discussion:
csSelector and dsSelector
(too old to reply)
J. Basir van de Fliert
2005-11-04 21:43:16 UTC
Permalink
I'm getting an
Exception 12 and I
think it is because
I am setting the
csSelector and
dsSelector
incorrectly for the
user processes in
kthread.c. I was
wondering what
values these
selectors are
supposed to be since
they are the same
for all user
processes because
each user process
does not have its
own LDT and all user
processes use the
same GDT entries.
Thanks.
Basir
Iulian Neamtiu
2005-11-04 22:14:38 UTC
Permalink
Exception 12 is stack exception. Most probably, your
stackPointerAddr or segment limit (Init_[Code/Data]_Segment Descriptor)
are incorrect.
There should be some extra info about the
error (Exception 12 by itself is not telling much), and you can check the
Intel docs (page 5-38) to find out what that specific error code means.

The selectors shouldn't be a problem, they're fixed as you say.

Iulian
Post by J. Basir van de Fliert
I'm getting an
Exception 12 and I
think it is because
I am setting the
csSelector and
dsSelector
incorrectly for the
user processes in
kthread.c. I was
wondering what
values these
selectors are
supposed to be since
they are the same
for all user
processes because
each user process
does not have its
own LDT and all user
processes use the
same GDT entries.
Thanks.
Basir
J. Basir van de Fliert
2005-11-05 21:53:55 UTC
Permalink
This is the exception I get.

Exception 12 received, killing thread 0x00036000
eax=00000000 ebx=00000000 ecx=00000000 edx=00000000
esi=fffff000 edi=00000000 ebp=00000000
eip=00001000 cs=0000001b eflags=00010202
Interrupt number=12, error code=0
index=0, TI=0, IDT=0, EXT=0
user esp=fffff000, user ss=00000023
cs: index=3, ti=0, rpl=3
ds: index=4, ti=0, rpl=3
es: index=4, ti=0, rpl=3
fs: index=4, ti=0, rpl=3
gs: index=4, ti=0, rpl=3
Init process exited with code -1

I am pretty sure that I am setting the stackPointerAddr correctly. I have tried
changing it, but I get the same exception. I am also pretty sure that I am
setting the Init_Code_Segment_Descriptor and Init_Data_Segment_Descriptor
correctly. All of the registers above including the esi and user esp registers
seem to be correct. The only thing I am not sure about is the user ss register,
but I tried to change it and my program completely crashed. I looked at the Intel
docs about exception 12, but it gave a description about the exception and it did
not help much.
J. Basir van de Fliert
2005-11-05 23:19:59 UTC
Permalink
I got help from Iulian and found out that I was making cs and ds selectors with
index 3 and 4 respectivily, which is incorrect because it points to bogus selector
indexes. I have copied all of the LDT, segment descriptor, and selector code back
from userseg.c to uservm.c and made the cs and ds selectors with index 0 and 1
respectivily and I don't get the exception 12 anymore. I know get an exception
13. From the interrupt state registers listed below it looks like the program is
faulting when it is running a kernel process. I looked at the Intel docs again
and as it is a "general protection fault" it has several pages worth of reasons of
why it could fault, and I am not sure which one it could be. The error code is 12
so looking at the errno.h file I think it might be an "invalid argument" error.

Exception 13 received, killing thread 0x00036000
eax=00030018 ebx=00100000 ecx=00036000 edx=00022ff8
esi=00036028 edi=00000200 ebp=00101f7c
eip=0001a76c cs=00000008 eflags=00010006
Interrupt number=13, error code=12
index=1, TI=1, IDT=0, EXT=0
cs: index=1, ti=0, rpl=0
ds: index=2, ti=0, rpl=0
es: index=2, ti=0, rpl=0
fs: index=2, ti=0, rpl=0
gs: index=2, ti=0, rpl=0
Init process exited with code -1
Iulian Neamtiu
2005-11-06 00:04:22 UTC
Permalink
Post by J. Basir van de Fliert
respectivily and I don't get the exception 12 anymore. I know get an exception
13. From the interrupt state registers listed below it looks like the program is
faulting when it is running a kernel process. I looked at the Intel docs again
and as it is a "general protection fault" it has several pages worth of reasons of
why it could fault, and I am not sure which one it could be. The error code is 12
so looking at the errno.h file I think it might be an "invalid argument" error.
Exception 13 received, killing thread 0x00036000
eax=00030018 ebx=00100000 ecx=00036000 edx=00022ff8
esi=00036028 edi=00000200 ebp=00101f7c
eip=0001a76c cs=00000008 eflags=00010006
Interrupt number=13, error code=12
index=1, TI=1, IDT=0, EXT=0
cs: index=1, ti=0, rpl=0
ds: index=2, ti=0, rpl=0
es: index=2, ti=0, rpl=0
fs: index=2, ti=0, rpl=0
gs: index=2, ti=0, rpl=0
Init process exited with code -1
Intel book 5-42 says the error stems from loading an illegal segment
descriptor, so the error code (12) is a segment descriptor...so check the
code in Switch_To_Address_Space(), make sure the LDT descriptor you're
trying to load is the one you created in Create_User_Context().
Also see my previous post onhow to use eipToFunction and see the function
it's crashing in.

Iulian
J. Basir van de Fliert
2005-11-07 20:06:41 UTC
Permalink
I forgot to copy back the code for switching to the LDT of the new user context in
Switch_To_Address_Space from userseg.c to uservm.c and once I did that I don't get
the exception 13 anymore. Know I am back to an exception 12 shown below. I used
print statements to see where it faults and I think it faults when I call
Switch_To_Thread, which is located in lowlevel.asm. I printed out the ldtSelector
right after I create it in Create_User_Context and again right before I call
Switch_To_Thread in Schedule in kthread.c. I get the same value of 32 in decimal
or 0x20 in hexadecimal so the ldtSelector isn't corrupted.

Exception 12 received, killing thread 0x00036000
eax=00000000 ebx=00000000 ecx=00000000 edx=00000000
esi=fffff000 edi=00000000 ebp=00000000
eip=00001000 cs=00000007 eflags=00010202
Interrupt number=12, error code=0
index=0, TI=0, IDT=0, EXT=0
user esp=fffff000, user ss=0000000f
cs: index=0, ti=1, rpl=3
ds: index=1, ti=1, rpl=3
es: index=1, ti=1, rpl=3
fs: index=1, ti=1, rpl=3
gs: index=1, ti=1, rpl=3
Init process exited with code -1
J. Basir van de Fliert
2005-11-08 18:41:43 UTC
Permalink
Nevermind. I figured out what the problem was. I was using linear addresses for
the third parameter of Format_Argument_Block and for argBlockAddr and
stackPointerAddr instead of logical addresses. Changing that gave me the shell
prompt and user programs work now. You have to remember that user processes use
logical address. You just have to be carefully about whether to use logical
addresses, linear addresses, or physical addresses.
Basir

Loading...