A tonarius was a kind of index that grouped antiphons according to their psalm tones. They were created to assist finding applicable pieces for various church services, but also led to early theorists and analysts identifying the various ways the finalis (final note) and reciting tone (usually a fifth above) could be "filled-in" using step-wise motion. This led to four "species," each with it's own combination of semitones and tones to create a pentachord. The ending notes of these four species were dubbed the "four finals": D, E, F and G. The pentachord A-E was considered a doulbing of the first (D-A), while the one begining of B was deemed unusable due to it's including two semitones.
Chants ending on the four finals were then also categorised into two families. One where the final was at the bottom of the range of the melody, and one where it was in the middle. Analysts then categorised the different way the four species extended up (to the octave) and down (to the fifth) in the antiphons. The former were named "authentic" and the latter "plagal."
Thus the modes as we now know them (and named after tribes in Greece as well as Asia-minor) were first used as a method of categorising Gregorian chants, and only later became used as a basis for composition; chants composed after tonaries had been assembled demonstrate more clearly, in their melodic turns as well as their structure, the relationship between the final and reciting tone.