Avoiding patching, how could I configure GCC to use a custom calling convention? Say I wanted to specify ints should be passed in registers a, c, b, d in that order, how could I do that?
Avoiding patching, how could I configure GCC to use a custom calling convention? Say I wanted to specify ints should be passed in registers a, c, b, d in that order, how could I do that?
I guess I should clarify, by a, c, b, d, I mean either the 32 bit or 64 bit (e/r)*x registers.
So how would you distinquish between calling your functions (with some params in regs) with other library functions (which expect everything on the stack)?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
You can use gcc's regparm(n) function attribute to specify arguments passed via registers. As far as I can tell, you can only use it for x86, which means no 64bit registers.
Stick close to your desks and never program a thing,
And you all may sit in the standards commitee!
> So how would you distinquish between calling your functions (with some params in regs) with other library functions (which expect everything on the stack)?
I wouldn't need to. Everything in my OS would use my calling convention. It will be as widely used as Windows' stdcall. I want to use a stack based calling convention in my 64bit OS, but for x86-64, GCC defaults to a really confusing register based convention. I want my OS to be easy to program for in both C and asm. Using a register based convention makes asm a real pain.
regparm is similar, but I actually want to avoid register based conventions. My example was just to show how specific I wanted to be, not what I really wanted to do.