osSetTLBASID osSetTLBASID (function)

osMapTLB, osUnmapTLB, osUnmapTLBAll, osSetTLBASID


#include <ultra64.h>     /* ultra64.h */
void osMapTLB(s32 index, OSPageMask pm, void *vaddr, u32 evenpaddr, 
                u32 oddpaddr, s32 asid);
void osUnmapTLB(s32 index);
void osUnmapTLBAll(void);
void osSetTLBASID(s32 asid);


These calls provide low-level access to the CPU Translation Lookaside Buffer (TLB). The remainder of the CPU virtual address space outside of the direct mapped address spaces KSEG0 and KSEG1 are mapped address spaces that use the TLB to specify the mapping to physical memory on a per-page basis. The CPU TLB consists of 32 entries, which provide mapping to 32 odd/even physical page pairs (64 total pages). Each TLB entry is associated with a particular page size that varies from 4096 bytes to as much as 16 megabytes.

The osMapTLB function sets the TLB entry index, where index ranges from 0 to 31. The pm argument specifies the page size; it can be one of the following defined constants:

OS_PM_4K : 4096 byte page size
OS_PM_16K : 16384 byte page size
OS_PM_64K : 65536 byte page size
OS_PM_256K : 262144 byte page size
OS_PM_1M : 1048576 byte page size
OS_PM_4M : 4194304 byte page size
OS_PM_16M : 16777216 byte page size

The vaddr argument specifies the beginning virtual address to map, and the evenpaddr and oddpaddr arguments specify the corresponding odd and even physical page addresses. A value of -1 for evenpaddr or oddpaddr indicates that no mapping is to be made for the even or odd page, respectively. The asid argument specifies an address space identifier that makes the mappings valid only when a specific address space identifier register is loaded. (See osSetTLBASID.) A value of -1 for asid specifies a global mapping that is always valid. For example, the following call specifies a global mapping of the virtual address range [0x2000, 0x3000] to the physical address range [0xab000, 0xac000] and the virtual address range [0x3000, 0x4000] to the physical address range [0xcd000, 0xce000]:

osMapTLB(0, (void *)0x2000, 0xab000, 0xcd000, -1);

The osUnmapTLB function removes any existing even or odd page mapping for the TLB entry index. The osUnmapTLBAll function removes all mappings at all indexes effectively invalidating the entire TLB. Call osUnmapTLBAll before using any other TLB calls to remove any stale mappings.

The osSetTLBASID function sets a system-wide address space identifier register that makes valid only mappings of the given address space identifier (as well as global mappings). This feature can be useful for detecting address errors that may lead to unpredictable results.

See Also
osMapTLB, osUnmapTLB, osUnmapTLBAll, and osVirtualToPhysical

Revision history

1999/04/30 Changed format