I just tried the patch, but it seems to produce some problems for me. The other patch which used a 64-bit specific register (r15) instead of rbx was easier to adapt to. The problem for me is that syscalls might clobber higher-half of all 32-bit registers, and that I cannot use the stack to preserve rbx in the call because of the red-zone.

Problem code:

#define RdosUserGateEdiEcxPar0RetEbx(nr, rdi, rcx, size, res) do { \
 register int _id asm("r14") = nr; \
 register typeof(rdi) _rdi asm("rdi") = (rdi); \
 register typeof(rcx) _rcx asm("r8") = (rcx); \
 register int _size asm("r12") = (size); \
 asm volatile ( \
   "syscall\n\t" \
   "jc 1f\n\t" \
   "movzx %%bx,%%rax\n\t" \
   "jmp 2f\n\t" \
   "1: \n\t" \
   "xorq %%rax,%%rax\n\t" \
   "2: \n\t" \
: "=a" (res) : "r" (_id), "r" (_rdi), "r" (_rcx), "r" (_size) : "rbx", "rdx", "rsi" \
 ); \
} while(0);

inline volatile int RdosCreateFile(const char *FileName, int Attrib)
{
   int res;
   int size = strlen(FileName) + 1;
RdosUserGateEdiEcxPar0RetEbx(usergate_create_file, FileName, Attrib, size, res);
   return res;
}

Error log:

$ rdos-gcc test.c -o test.exe
In file included from /usr/local/rdos/include/rdos.h:719:0,
from test.c:1:
/usr/local/rdos/include/rdosgcc.h: In function 'main':
/usr/local/rdos/include/rdosgcc.h:236:5: error: PIC register clobbered by 'rbx' in 'asm' RdosUserGateEdiEcxPar0RetEbx(usergate_open_file, FileName, Access, size, res);
^

I would prefer to change PIC register to r15 instead, or alternatively make this an target-option.

Regards,
Leif Ekblad


----- Original Message ----- From: "Uros Bizjak" <ubiz...@gmail.com>
To: "Richard Henderson" <r...@redhat.com>
Cc: "Andi Kleen" <a...@firstfloor.org>; "Mike Frysinger" <vap...@gentoo.org>; <gcc-patches@gcc.gnu.org>; "Leif Ekblad" <l...@rdos.net>; "Jakub Jelinek" <ja...@redhat.com>; <j...@suse.cz>; "H.J. Lu" <hjl.to...@gmail.com>
Sent: Sunday, December 30, 2012 8:08 PM
Subject: Re: [RFC PATCH, i386]: Use %r15 for REAL_PIC_OFFSET_TABLE_REGNUM on x86_64


On Fri, Dec 28, 2012 at 9:27 PM, Richard Henderson <r...@redhat.com> wrote:
On 12/27/2012 12:08 AM, Uros Bizjak wrote:
The alternative approach is changing cpuid definition in cpuid.h (as
in attached patch) to preserve %rbx, but we can't detect various code
model settings there. Since the change depends on the definition of
__PIC__, we unnecessary preserve %rbx also for -mcmodel=small.

Certainly we can.  We also control the preprocessor defines.
All that's needed is that we create one for the code model.

Something like attached?

I have also included all suggestions (earlyclobber and operand prefix
on temporary register).

2012-12-30  Uros Bizjak  <ubiz...@gmail.com>

PR target/55712
* config/i386/i386-c.c (ix86_target_macros_internal): Depending on
selected code model, define __code_mode_small__, __code_model_medium__,
__code_model_large__, __code_model_32__ or __code_model_kernel__.
* config/i386/cpuid.h (__cpuid, __cpuid_count) [__i386__]: Prefix
xchg temporary register with %k.  Declare temporary register as
early clobbered.
[__x86_64__]: For medium and large code models, preserve %rbx register.

Tested on x86_64-pc-linux-gnu {,-m32}.

Uros.


Reply via email to