Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Understanding "You are not expected to understand this."

In the early days of Unix V6 to Vax porting, the author often encountered the line "You are not expected to understand this." in the context switch code. This mysterious line puzzled the author, who didn't fully comprehend its purpose. However, after exploring the code through a different path, the author finally deciphered its meaning.

V6 Unix stored per-process state in two places: a small entry in the process table and the 'udot' structure, which was mapped by the MMU at a well-known kernel virtual address referenced as "u." This structure contained the kernel stack and was always mapped to the same address in all running processes. During a process switch, the state of a running process had to be saved and restored using the 'savu()' and 'retu()' functions, which were inspired by the 'setjmp()' and 'longjmp()' functions in V7 Unix.

The 'savu()' function saved critical state information, including the stack pointer (r6) and frame pointer (r5), but omitted the registers r2-r4. The 'retu()' function restored the current state, leaving any local variables stored on the stack in a fragile state. This fragility increased when interrupts were enabled, making the code surrounding the infamous line particularly tricky to understand.

The code responsible for handling context switches and swapping processes out of memory was complex, with many nuances that contributed to the enigmatic nature of the "You are not expected to understand this" line. The code included checks for available memory, swapping processes out if necessary, and marking processes with the SSWAP flag when they were swapped out.

When a swapped-in process encountered the SSWAP flag, it would clear the flag and execute an 'aretu()' function, which restored the saved state at the swap save address.

In summary, the "You are not expected to understand this" line referred to the intricate process of context switching, swapping processes out of memory, and returning control to the appropriate place after a context switch. This process was essential for managing system resources and enabling multiple processes to run concurrently, but it required careful handling to ensure the stability of the system.

Rewritten by urgent.news; may contain errors — check the original.

Source: taniwha.com

Read the original at taniwha.com →

Report a problem with this story

More in Tech

More from Thursday 26 November →