Timer Facilities 6-3
Table 6-1 summarizes the TBRs, instructions used to access the TBRs, and access restrictions.
6.1.1 Reading the Time Base
The following code provides an example of reading the time base. mftb moves the low-order 32 bits
of the time base to a GPR; mftbu moves the high-order 32 bits of the time base to a second GPR.
loop:
mftbu Rx # load from TBU
mftb Ry # load from TBL
mftbu Rz # load from TBU
cmpw Rz, Rx # see if old = new
bne loop # loop/reread if rollover occurred
The comparison and loop ensure that a consistent pair of values is obtained.
6.1.2 Writing the Time Base
The following code provides an example of writing the time base. Writing the time base is privileged.
mttbl moves the contents of a GPR to the low-order 32 bits of the time base; mttbu moves the
contents of a second GPR to the high-order 32 bits of the time base.
lwz Rx, upper # load 64-bit time base value into Rx and Ry
lwz Ry, lower
li Rz, 0
mttbl Rz # force TBL to 0 to avoid rollover while writing TBU
mttbu Rx # set TBU
mttbl Ry # set TBL
Table 6-1. Time Base Access
Instructions
Register
Number Access Restrictions
TBU
Upper
32 bits
mftbu RT
Extended mnemonic for
mftb RT,TBU
0x10D Read-only
mttbu RS
Extended mnemonic for
mtspr TBU,RS
0x11D Privileged; write-only
TBL
Lower
32 bits
mftb RT
Extended mnemonic for
mftb RT,TBL
0x10C Read-only
mttbl RS
Extended mnemonic for
mtspr TBL,RS
0x11C Privileged; write-only