Aviation Week has some really interesting cockpit HUD footage from a F-16 training flight where the pilot loses consciousness and would have gone straight into the ground but for the F-16's Auto-GCAS (ground collision avoidance system). In the video, you'll see SULLY 2 roll wings level, then roll into a hard left bank. He starts to lose it around 7Gs, and the aircraft starts to overbank pulling to a maximum of 8.3G. The aircraft finds something like equilibrium at a 90 degree left bank, 50 degrees nose low, passing through mach 1, with the flight lead yelling "TWO, RECOVER!"
I'm a little surprised how alert and oriented our pilot sounds when he gets back on the radio ("Sully two, knock it off.") Flight lead sounds more freaked out than our pilot, perhaps because our pilot slept through a lot of the action.
I haven't seen a source for the exact math that Auto-GCAS does, but it sounds like it's constantly computing "starting now, if I roll wings upright and level, then pull into a climb, how many Gs do I have to pull to avoid hitting terrain?" When that number exceeds 4G, the computer rolls upright and enters a 5G pull. (I'm sure it's more nuanced than this. The design challenge is avoidance of nuisance fly-ups when navigating through canyons. There may be terrain close ahead that the pilot intends to avoid by turning rather than climbing.)