Genes which produced traits which fostered proliferation of themselves tended to spread through the population. This is basic Darwin. This tendency is true not only of physical and mental traits, but also psychological ones--in my invented example, generosity. Once a psychological trait has become established and widely shared in a population, that trait will seem "normal," and so become a basis for shared values, which, when further institutionalized, become a system of morality.

I think you do have the idea, Drangontongue. One caveat: I have simplified greatly. In actual practice, things are far more complicated than in my example. Nevertheless, my example does explain, as you asked, how morality could have arisen via evolution.