I think, in the end, morality is born out of altruism. (Behavioural biology; not the kind of pink hippy altruism.)
Basically: Anything that effects the chances of the species as a whole in a negative way is bad. Strong competition within the same pack is a bad thing, for example, while strong competition with members of another pack is a good thing.
Taking care of old members of a pack is a good thing; that way, you can make sure that old people are respected, which means a lot of good for the old people of all times, and everyone who survives for a long time will be an old person, right? Besides; it's very rewarding after a long life of hard toil to be respected and taken care of. This is a very common structure in social predatory mammals.
But it's a bit vague.. So people tend to make 'morals,' which are basically concessions of allowing other people to do what you don't want them to do, and vice versa. They're unwritten rules, and as such, are much clearer than the vague thing called altruism. At least with morals, you can pin them down. But morals are little more than altruism given a spin of personal preference and favour, so it's still a good thing to question them. While morally right for a certain society, it may not always be 'good,' even for that society's standards.
the moral code itself may have been born out of immoral behaviour. A very good example of this is monotheistic morals. Read Leviticus, if you don't believe me. It's so full of hell, hatred and spite that all you can see is 'fear' written in stone-age Neon letters. Countless of people have tried to change it, but so far, the closed-minded hate-mongering has survived. These codes are, however, beneficial to the group. Either you join them, or you're condemned to hell. Either you repent, or you're doomed. It also keeps all the scary people out.