I am looking at some old code from a school project, and in trying to compile it on my laptop I ran into some problems. It was originally written for an old 32 bit version of gcc. Anyway I was trying to convert some of the assembly over to 64 bit compatible code and hit a few snags.
Here is the original code:
pusha
pushl %ds
pushl %es
pushl %fs
pushl %gs
pushl %ss
pusha
is not valid in 64 bit mode. So what would be the proper way to do this in x86_64 assembly while in 64 bit mode?
There has got to be a reason why pusha
is not valid in 64 bit mode, so I have a feeling manually pushing all the registers may not be a good idea.
Learn from existing code that does this kind of thing. For example:
SAVE_ARGS_IRQ
): entry_64.SINTR_PUSH
): privregs.hIDT_VEC
): exception.S (similar is vector.S in NetBSD)In fact, "manually pushing" the regs is the only way on AMD64 since PUSHA
doesn't exist there. AMD64 isn't unique in this aspect - most non-x86 CPUs do require register-by-register saves/restores as well at some point.
But if you inspect the referenced sourcecode closely you'll find that not all interrupt handlers require to save/restore the entire register set, so there is room for optimizations.