Glacial advance and stagnation caused by rock avalanches