Previous Table of Contents Next


A couple of these special tag instructions can be used to set or test the tag bits. One of them, called Store Quadword (stq), stores 16 bytes of data from two 64-bit registers into memory and turns on the two tag bits. Another, called Load Quadword (lq), loads 16 bytes of data from memory into two 64-bit registers and sets a bit in a control register to 1 if both tag bits in the memory words fetched are 1; otherwise, the bit is set to 0. Still another instruction allows the tags to be fetched from memory and put into a special register in the processor. We describe the use of this last instruction in the next section.

The tag instructions are used only by SLIC; they are not generated by the translator for MI programs. This means that any store to memory that is generated for an MI program uses the standard instructions and always turns off the tag bits. When a pointer is created as part of a resolve operation, SLIC builds the pointer in two 64-bit registers and uses the stq instruction to turn the tag bits on in memory. Whenever an MI program attempts to use a pointer, SLIC uses the lq instruction to load the contents of the pointer into registers and then tests to see whether the tag bits are still on. If the tag bits are found to be off, someone modified the pointer and, therefore, it is invalid.

Tag bits in the AS/400 do not prevent the modification of pointers. Tag bits are used to detect the modification when the pointer is used. This approach is different from the one most memory-protection schemes use. Typically, memory protection prevents the modification. This is also important, and later we will see that the AS/400 has this type of protection on a page basis. For pointers, however, the modification is detected after the fact. This approach reduced the amount of hardware needed in the early implementations of the system and still provided the needed level of protection.

Pointers cannot be counterfeited. Tags ensure that a pointer was created by the operating system (SLIC) and that it has not been modified by anyone other than SLIC. Anyone else who creates a pointer, copies a pointer, or modifies a pointer has no way to turn the tag bits on and will end up with a useless 16-byte entity. An AS/400 always runs in the tags-active mode to provide this pointer protection, even though the PowerPC processors used in the AS/400s can also operate in the tags-inactive mode.

Pointers and Tags on Disk

When we wanted to move a page from memory to disk on a System/38, we had another problem. Memory has extra bits for ECC and tags; the disk does not. Disks use a different form of error-detection coding, called a cyclic redundancy check (CRC), which does not add extra bits to each memory word. We needed to find a way to keep the tag bits with the pointers when we moved the page containing the pointers to the disk. In short, we had to find some extra space on the disk.

A magnetic disk is a collection of platters, each of which has two recordable surfaces. Each disk surface is divided into concentric circles, called tracks. Each track in turn is divided into sectors that contain the information. The sector size for the System/38 and the AS/400 is 520 bytes. Each sector has an 8-byte sector header and a 512-byte data area. This sector size was selected to match the 512-byte page size of the System/38 — a page fits into a sector.

We defined some special IMPI instructions in the System/38 to manipulate tags. One of these instructions, called Extract Tags, was used to gather the tags from a page in memory. As part of the operation to write the page to disk, these tags were also written to disk. Another IMPI instruction, called Insert Tags, was used to put the tags back in memory when a page was read from disk.

Many ISVs and customers who knew about the tag bits in the System/38 assumed they were stored in the 8-byte sector headers on the disks. That was not the case. The information in the page itself was stored in the 512-byte data area of the sector. The sector header contained information about the page, but its most important function was to contain the virtual address of the page. This address was needed for recovery purposes. If we ever lost the table in memory that related the virtual addresses to the disk locations, we could re-create it by reading each sector header to see which virtual address was associated with each sector. With most of the space in the sector headers taken by the virtual address of the page, there was no room for the tags.

A quick calculation will show this. A single page can contain 32 pointers (16 bytes × 32 = 512 bytes), which means there are 32 tag bits per page. A virtual address for the System/38 was 48 bits, but we didn’t need all those bits to identify a page. The low-order 9 bits in the virtual address identify the byte in a 512-byte page (29 = 512). Therefore, we needed to store only the high-order 39 bits of the virtual address (48 bits - 9 bits = 39 bits) to uniquely identify the page. Even without any status bits, however, we would need a minimum of 71 bits to store both the virtual address of the page and all the tag bits (39 bits + 32 bits = 71 bits), and the sector headers each had only 64 bits. There was no way to store the tag bits in the sector headers.

We became very creative with the System/38 and found space inside the page for the tags. In the next section, we will see that a pointer contains some unused space. If a page contains at least one pointer, we have some unused space where we can store the tag bits. If there are no pointers on a page, all the tag bits for the page will be 0s, so there is no need to store any tags. The sector header in the System/38 contained information about whether there were tags on the page and, if so, where on the page they were located.

We continued to use the 512-byte page size in the AS/400 until the introduction of the RISC processors, and the method for storing tag bits was as we just described. But we had wanted to increase the page size for several years.


Previous Table of Contents Next

Copyright © NEWS/400 Books