Accessing the Code Segment

The processor accesses the code segment whenever it has to fetch an instruction from memory. Consider the following unconditional near jump instruction:

jmp 0009

The programmer has specified an offset, 0009h, within the current code segment as the target of this unconditional jump. In response, the processor compares the specified offset to the size, or limit, of the code segment currently in use to ensure that the programmer isn't attempting to jump outside the bounds of the current code segment. The code segment's start address, size and attributes are stored in the processor's internal CS cache register. If the target location is within the bounds of the segment, the processor adds the specified offset to the segment's base address to yield the memory address of the instruction to be jumped to. It then fetches the next instruction from that location.

In the following example, the programmer wishes the processor to perform an unconditional far jump instruction to fetch the next instruction from a location within a different code segment:

jmp 00d0:0003

Since this is an attempt to access a different code segment, the processor must first verify that the currently executing program is permitted to access the location in the new code segment. To do this, it must read the new code segment descriptor from memory and check its descriptor privilege level (DPL). The value 00d0h is placed into the CS register and is interpreted as indicated in Figure 8-4 on page 139 (the index field is binarily-weighted). The processor reads the 27th entry (d0h = 26d) from the GDT (TI = 0 selects the GDT). Figure 8-3 on page 138 illustrates the example code segment descriptor read from the GDT.

Figure 8-4. Example Value in CS Register


Figure 8-3. Sample Code Segment Descriptor


The processor verifies that the new segment is a code segment (System bit = 1, and C/D = 1) and is present in memory (P = 1). It must also determine if the currently executing program is sufficiently privileged to call or jump to the targeted code segment. This subject is covered in the next section (“Privilege Checking” on page 139). It checks the specified target offset, 0003h, to determine if it exceeds the limit (size) of the code segment (the segment size is 126525d bytes (the Granularity bit = 0, indicating that the size is specified in bytes, rather than in 4KB pages). If all tests are passed, it loads the new segment descriptor into its on-chip code segment cache register, adds the specified offset (0003h) to the code segment's base address (00131BCCh) and fetches the next instruction from the target address—00131BCFh.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.107.31