🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.intel
Article #1285

Question about i386/i486 protected mode far jumps

#1285
From: Paul Scherf
Date: Wed, 18 Nov 1992 22:27
49 lines
3100 bytes
In an attempt to better understand protected mode, I'm trying to figure out far
CALL, far IRET and far JMP. Let me call them simply CALL, IRET and JMP.

When a CALL, IRET or JMP causes a task switch (e.g. by referencing a TSS or a
task gate), it appears that the important things to understand are what happens
to the busy bits, NT flags and link fields of the old and new tasks.

The busy bit seems straight forward. It keeps track of whether the TSS is in
the middle of execution. JMP and IRET clear the busy bit of the old TSS (the
old TSS is becoming inactive), while CALL leaves the busy bit of the old TSS
(it will be on) alone. JMP and CALL ensure the busy bit of the new TSS was off
and turn on the busy bit of the new TSS (the new TSS is becoming active), while
IRET leaves the busy bit of the new TSS (it better already be on) alone.

The link field of a TSS is used to keep a stack of TSS's (implemented as a
linked list). CALL pushes a TSS onto the stack. That is, CALL points the link
field of the new TSS at the old TSS, and sets the NT flag. IRET pops a TSS from
the stack. That is, IRET uses the link field of the old TSS to find the new
TSS, and clears the NT flag of the old TSS.

JMP, well, I'm a bit confused about JMP. The book (i486 Programmer's Reference
Manual) says that JMP clears the NT flag of the new TSS. If JMP left the NT
flag of the new TSS alone, it would make more sense to me.

I can think of several possible scenarios where a system might have several TSS
stacks. I can imagine the currently executing task (at the top of a TSS stack)
wanting to switch to a particular other task (e.g. at the top of one of the
other TSS stacks).

JMP seems to do the right thing with the busy bits. The new TSS becomes busy.
The old TSS becomes not busy. JMP seems to do the right thing with the link
fields of the old and new tasks, it leaves them alone. That seems reasonable,
they should return to whatever CALL'd them. JMP doesn't seem to do quite the
right thing with the NT flags. It does leave the NT flag alone on the old TSS,
but it clears the NT flag on the new TSS. This invalidates the return chain of
the new TSS.

I can see a work-around for this situation. CALL a "task switcher" TSS, that
IRET's to the desired new TSS. This still leaves me wondering what JMP is good
for.

Why does JMP clear the NT flag of the new TSS? JMP clearly doesn't do the right
thing for my example. What are some correct uses of JMP? Am I missing something
about CALL and IRET? Is there a good book that gets to at least this level of
detail about the i486?

Paul Scherf
pauls@truevision.com
Truevision Inc., Indianapolis, IN
Technical Details
Message-ID: <1992Nov18.222722.26786@truevision.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!epicb!pauls

Show Full Headers
Complete Article Headers
Newsgroups: comp.sys.intel
Path: arc1-ca.pugleaf.net!sparky!uunet!epicb!pauls
From: pauls@truevision.com (Paul Scherf)
Subject: Question about i386/i486 protected mode far jumps
Message-ID: <1992Nov18.222722.26786@truevision.com>
Summary: Why does it clear the NT flag of the destination
Keywords: protected mode, far jumps
Organization: Truevision Inc., Indianapolis, IN
Date: Wed, 18 Nov 1992 22:27:22 GMT
Lines: 49