9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] gcc x86 assembly help
@ 2001-06-01 22:54 Russ Cox
  2001-06-02  2:53 ` Martin Harriss
  2001-06-04  8:48 ` Hermann Samso
  0 siblings, 2 replies; 4+ messages in thread
From: Russ Cox @ 2001-06-01 22:54 UTC (permalink / raw)
  To: 9fans

Ishwar has been trying to compile drawterm on a
Linux 2.4 kernel.  The drawterm code (like the Inferno
code before it) depends on the fact that there are
different TSS registers in each process in Linux,
but this changed in 2.4 so the Linux-specific code
broke.

He's now trying to use the pthread-specific code
(which works well under FreeBSD and Irix), but gets
a weird message from gcc about "impossible register
constraint in asm" on the x86 test-and-set code.

typedef struct Lock Lock;
struct Lock {
	int val;
};

int
canlock(Lock *l)
{
	int     v;

	__asm__(	"movl   $1, %%eax\n\t"
			"xchgl  %%eax,(%%ebx)"
			: "=a" (v)
			: "ebx" (&l->val)
	);
	switch(v) {
	case 0:	 return 1;
	case 1:	 return 0;
	default:	print("canlock: corrupted 0x%lux\n", v);
	}
	return 0;
}

Does anyone with more gcc inline assembly experience
know what's wrong with this (or what changed in gcc
in the latest Linux distributions to make it start
rejecting this)?

Thanks.
Russ


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] gcc x86 assembly help
  2001-06-01 22:54 [9fans] gcc x86 assembly help Russ Cox
@ 2001-06-02  2:53 ` Martin Harriss
  2001-06-04  8:48 ` Hermann Samso
  1 sibling, 0 replies; 4+ messages in thread
From: Martin Harriss @ 2001-06-02  2:53 UTC (permalink / raw)
  To: 9fans

Russ Cox wrote:
> 
> Ishwar has been trying to compile drawterm on a
> Linux 2.4 kernel.  The drawterm code (like the Inferno
> code before it) depends on the fact that there are
> different TSS registers in each process in Linux,
> but this changed in 2.4 so the Linux-specific code
> broke.
> 
> He's now trying to use the pthread-specific code
> (which works well under FreeBSD and Irix), but gets
> a weird message from gcc about "impossible register
> constraint in asm" on the x86 test-and-set code.
> 
> typedef struct Lock Lock;
> struct Lock {
>         int val;
> };
> 
> int
> canlock(Lock *l)
> {
>         int     v;
> 
>         __asm__(        "movl   $1, %%eax\n\t"
>                         "xchgl  %%eax,(%%ebx)"
>                         : "=a" (v)
>                         : "ebx" (&l->val)
>         );
>         switch(v) {
>         case 0:  return 1;
>         case 1:  return 0;
>         default:        print("canlock: corrupted 0x%lux\n", v);
>         }
>         return 0;
> }
> 
> Does anyone with more gcc inline assembly experience
> know what's wrong with this (or what changed in gcc
> in the latest Linux distributions to make it start
> rejecting this)?
> 
> Thanks.
> Russ

I think the problem may be the "ebx" constraint.  I've never seen it
written like that -- I thought that for the [e]bx register the
constraint was simply "b".  The current manual seems to confirm that.
Can you try "b" and see if you have any luck?

Martin

Reference: http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_16.html#SEC175


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] gcc x86 assembly help
  2001-06-01 22:54 [9fans] gcc x86 assembly help Russ Cox
  2001-06-02  2:53 ` Martin Harriss
@ 2001-06-04  8:48 ` Hermann Samso
  1 sibling, 0 replies; 4+ messages in thread
From: Hermann Samso @ 2001-06-04  8:48 UTC (permalink / raw)
  To: 9fans

Russ Cox <rsc@plan9.bell-labs.com> wrote:
> Ishwar has been trying to compile drawterm on a
> Linux 2.4 kernel.  The drawterm code (like the Inferno
> code before it) depends on the fact that there are
> different TSS registers in each process in Linux,
> but this changed in 2.4 so the Linux-specific code
> broke.

> He's now trying to use the pthread-specific code
> (which works well under FreeBSD and Irix), but gets
> a weird message from gcc about "impossible register
> constraint in asm" on the x86 test-and-set code.

	Seems to me, as if it where more a gcc specific
	problem. I am having the same difficulties to
	compile some Atari-ST emulator. Would also
	appreciate any help.

	hermann samso


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] gcc x86 assembly help
@ 2001-06-02  2:56 Russ Cox
  0 siblings, 0 replies; 4+ messages in thread
From: Russ Cox @ 2001-06-02  2:56 UTC (permalink / raw)
  To: 9fans

The problem is apparently that "ebx" should
just be "b" -- e and x mean other things.

Thanks to all who replied.  I've learned a lot
more about inline assembly than I had thought
was possible.

Russ


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-06-04  8:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-01 22:54 [9fans] gcc x86 assembly help Russ Cox
2001-06-02  2:53 ` Martin Harriss
2001-06-04  8:48 ` Hermann Samso
2001-06-02  2:56 Russ Cox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).