the castle was originally founded by king david the first of scotland