Page 1 of 1

str ax; ltr ax == general protection fault

Posted: Sat Apr 30, 2016 12:09 pm
by rianquinn
If I run the following in the Linux kernel (just as a test), I get a general protection fault (nasm syntax):

Code: Select all

test_tr:
    str ax
    ltr ax
    ret
I get a general protection fault. Looking at the manual, the only things that cause a GPF are:
- Setting a NULL selector (cannot be true since I am using the existing TSS)
- Index out of bounds (also cannot be true since I am using the existing TSS)
- TSS is not available (no idea what this means)

I suspect the "not available" must be the issue, but I'm not sure what this means. Any ideas why the above code would fail? My only guess is that you cannot change to the same TSS and must always change to a different TSS.

Thanks
- Rian

Re: str ax; ltr ax == general protection fault

Posted: Sat Apr 30, 2016 12:27 pm
by MDenham
When you store the current task register, it's marked as busy.

You get a GPF trying to switch to a busy task.

Re: str ax; ltr ax == general protection fault

Posted: Sat Apr 30, 2016 1:15 pm
by rianquinn
The str operation says nothing about setting the busy bit, but ltr does say that:

"if the source selector points to a segment that is not a TSS or to one for a task that is already busy". My interpretation here is that you cannot load an already loaded TSS.

Thoughts?
- Rian

Re: str ax; ltr ax == general protection fault

Posted: Sat Apr 30, 2016 1:19 pm
by Octocontrabass
MDenham wrote:When you store the current task register, it's marked as busy.
When you load the task register, it's marked as busy.

Trying to load it a second time causes a fault because it's already marked as busy.

Re: str ax; ltr ax == general protection fault

Posted: Sat Apr 30, 2016 1:37 pm
by MDenham
Octocontrabass wrote:
MDenham wrote:When you store the current task register, it's marked as busy.
When you load the task register, it's marked as busy.
Whoops. Bad wording on my part; I wasn't intending to imply that storing the current task register was what marked it as busy, just that you're storing one that is marked as busy.