lib copied from F1 code. Needs check the regs.