First, remember that there are two possibilities for conveying past tense and modal verbs: Either one puts the modal verb into the past tense or one puts the main verb into the past tense. Compare the two English examples.
I have to work.
I had to work.
I have to have worked.
In English, the first option works with both past tense (simple past and present perfect) while the second option only works for present perfect — and of course, they differ in meaning.
Both options are also possible in German with the same general differences in meaning:
Ich muss arbeiten.
Ich musste arbeiten.
Ich muss gearbeitet haben.
And again, the first option allows the speaker to use perfect tense rather than preterite. At first glance, this works much the same way as all verb chains in German: Work yourself from the main verb outwards. So we could naively assume:
*Ich habe arbeiten gemusst.
(Note the star denoting a sentence typically considered wrong.)
The thing is that it sounds strange to have a past participle following an infinitive. I don’t know whether there is an actual etymologic explanation for the phenomenon but that sentence is what popular etymology would make of it. In any case, modal verbs usually form their perfect tense with the so-called Ersatzinfinitve (replacement infinitive) which just means that you have to use the verb’s infinitive rather than a past participle:
Ich habe arbeiten müssen.
In a nutshell:
- second sentence fragment must be the finite verb;
- in perfect tense, the finite verb is haben or sein (depending on the main verb);
- all other verbs wander to the end of the sentence;
- the order at the end is from the verb carrying the greatest meaning to that carrying least meaning;
- if you run into infinitive + past participle, consider an Ersatzinfinitiv.
With that you can build sentences as you wish:
Ich hab(e) gestern nicht den ganzen Tag von zuhause aus arbeiten sollen.