Hi! Welcome to the forums.
I see a lot of these as my garden has both a preferred nectar source (H. patens) and the desired host for caterpillars (P. foetida), and I can tell you, sadly, if it is on its side, you are likely too late.
If you want to give a preferred last meal, offer a chunk of mushy banana. What a pretty little last respite you are providing.
I often run “day hospitals” for insects and my success rate is only about 50%, so please know there is likely nothing you could have done. Once a butterfly tips over, it’s usually done. :(