Reserving register for OS

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
depletionmode
Posts: 16
Joined: Sun Oct 20, 2013 1:28 pm

Reserving register for OS

Post 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)
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: Reserving register for OS

Post 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.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Reserving register for OS

Post 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.
depletionmode
Posts: 16
Joined: Sun Oct 20, 2013 1:28 pm

Re: Reserving register for OS

Post 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.
User avatar
Jezze
Member
Member
Posts: 395
Joined: Thu Jul 26, 2007 1:53 am
Libera.chat IRC: jfu
Contact:

Re: Reserving register for OS

Post by Jezze »

You could use the debug registers perhaps?

http://en.wikipedia.org/wiki/X86_debug_register
Fudge - Simplicity, clarity and speed.
http://github.com/Jezze/fudge/
depletionmode
Posts: 16
Joined: Sun Oct 20, 2013 1:28 pm

Re: Reserving register for OS

Post 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...
Post Reply