Today, when reviewing the knowledge about the Linux system architecture, I found that I was a little confused about the overflow and underflow code of the register window. I would like to record it, for more information about the structure of the system, see http://www.sics.se /~ In the text of PSM/sparcstack.html, only the overflow and overflow processing functions are analyzed here. 1. Overflow trap processing function
- /* A save instruction caused a trap */
- Window_overflow:
- /* Rotate Wim on bit right, We have 8 windows */
- MoV % Wim, % L3
- Sll % L3, 7, % L4
- SRL % L3, 1, % L3
- Or % L3, % L4, % L3
- And % L3, 0xff, % L3
- /* Disable Wim traps */
- MoV % G0, % WIM
- NOP; NOP
- /* Point to correct window */
- Save
- /* Dump registers to stack */
- STD % l0, [% sp + 0]
- STD % L2, [% sp + 8]
- STD % L4, [% sp + 16]
- STD % L6, [% sp + 24]
- STD % I0, [% sp + 32]
- STD % I2, [% sp + 40]
- STD % I4, [% sp + 48]
- STD % I6, [% sp + 56]
- /* Back to where we shoshould be */
- Restore
- /* Set new value of window */
- MoV % L3, % WIM
- NOP; NOP
- /* Go home */
- JMP % L1
- RET % L2
Use the code above to analyze a specific instance. Example: CWP = 3, Wim = 2. At this time, execute the save operation. When the save operation is executed, the first thing to do is to judge (CWP-1) = Wim? If they are equal, the overflow trap will be triggered. The specific code is as follows: (1) first, calculate the correct Wim value, that is, the 4th-8th line of code (at this time, because of the overflow trap, CMP = 2) (2) execute the save operation (save causes CWP --, so CWP = 1) (3) a series of STD, the purpose is to write the content in the CWP = 1 window to the memory (4) perform the restore operation (the restore operation causes CWP ++. At this time, CWP = 2) (5) execute the RET operation (JTs causes CWP ++, at this time, CWP = 3) after the above 5 steps, CWP = 3, Wim = 1, so when you execute the save operation again, CWP-1 = 2, not equal to Wim. The save operation is successful.
2. underflow trap processing function
- /* A restore instruction caused a trap */
- Window_underflow:
- /* Rotate Wim on bit left, we have 8 windows */
- MoV % Wim, % L3
- SRL % L3, 7, % L4
- Sll % L3, 1, % L3
- Or % L3, % L4, % L3
- And % L3, 0xff, % L3
- /* Disable Wim traps */
- MoV % G0, % WIM
- NOP; NOP
- /* Point to correct window */
- Restore
- Restore
- /* Dump registers to stack */
- LDD [% sp + 0], % l0
- LDD [% sp + 8], % L2
- LDD [% sp + 16], % L4
- LDD [% sp + 24], % L6
- LDD [% sp + 32], % I0
- LDD [% sp + 40], % I2
- LDD [% sp + 48], % I4
- LDD [% sp + 56], % I6
- /* Back to where we shoshould be */
- Save
- Save
- /* Set new value of window */
- MoV % L3, % WIM
- NOP; NOP
- /* Go home */
- JMP % L1
- RET % L2
Example: CWP = 3, Wim = 4. In this case, perform the restore operation. Similar to the Save operation, the first thing the restore operation will do is check (CWP + 1) = Wim? If yes, the underflow trap is triggered and the underflow trap handler function is entered. The specific code is as follows:
(1) Enter window_underflow (at this time, because it comes in through underflow trap, so CWP = 2)(2) Similarly, calculate the correct Wim value (3) Two restore operations (at this time, CWP = 4 because two restore operations are added) (4) restore the stored value in the memory to the CWP = 4 window (5) Two Save operations (at this time, CWP = 2) (6) the operation (at this time, CWP = 3) after the preceding six steps are completed, CWP = 3, Wim = 5. When the restore operation is executed again, CWP + 1 = 4. 3. to sum up, the most important thing to note here is that both overflow and underflow are traps, which will first enable CWP --. It is very difficult to understand the two restores of underflow, that is, when I forget to overflow, CWP must be reduced by one first.