Page 1 of 1
Reserving register for OS
Posted: Thu Oct 24, 2013 6:08 am
by depletionmode
Is there any way to reserve a register for use?
I.e. A way to get gcc to never generate code using a specific register so that I am in no danger of ever clobbering the 'reserved' register?
Speaking IA-32 here (not 64-bit with all the extra regs)
Re: Reserving register for OS
Posted: Thu Oct 24, 2013 6:53 am
by sortie
Yes. You'll have to modify GCC to teach it your custom ABI. The
OS Specific Toolchain article on the wiki teaches you how to add a custom new target to GCC based on a *-elf target. You can, of course, continue your modifications to add a custom ABI - naturally that tutorial doesn't teach you that. You should probably talk with GCC developers or find out how some registers are reserved for existing ABIs, such as x86_64-linux-gnu and shared libraries.
Re: Reserving register for OS
Posted: Thu Oct 24, 2013 7:13 am
by bluemoon
Just curious why you want to do that.
The number of general purpose registers in x86 is very limited. Saving such push/pop could result in big impact on code generation.
By the way, if you do that you need to ensure applications are compiled with your toolchain, and misbehave programs (intentional or buggy) may still trash the OS-dedicated registers, there is no hardware protection.
Re: Reserving register for OS
Posted: Thu Oct 24, 2013 7:33 am
by depletionmode
Well I'm not really building a general purpose OS - more of a real-time application and as part of that I have an emulation layer that I'd like to reserve a register for.
Re: Reserving register for OS
Posted: Thu Oct 24, 2013 9:21 am
by Jezze
Re: Reserving register for OS
Posted: Mon Nov 04, 2013 5:38 am
by depletionmode
Jezze wrote:You could use the debug registers perhaps?
I don't believe one can move literals to the debug register?
If I need to work through other registers anyway it'll slow me down...