GCC and memory segments

Etienne Lorrain etienne_lorrain@yahoo.fr
Fri Sep 26 11:32:00 GMT 2003


> Can anybody tell me how to make GCC to use memory segments?
> I mean memory segments like x86 in real mode. 

  With some restrictions, like having an i386 or better CPU in
 real mode, you can use:
------------------
typedef unsigned farptr; /* 16 bit MSB: segment, 16 bit LSB: offset */

extern inline unsigned peekb (farptr adr)
  {
  unsigned returned;
  unsigned short scratch;

  asm (
"	pushl	%2		\n"
"	popw	%w0		\n"
"	popw	%%fs		\n"
"	movzbl	%%fs:(%w0),%1	\n"
	: "=bSDB" (scratch), "=r" (returned)
	: "g" (adr), "m" (*memory)
	);
  return returned;
  }

extern inline unsigned peekw (farptr adr)
  {
  unsigned returned;
  unsigned short scratch;

  asm (
"	pushl	%2		\n"
"	popw	%w0		\n"
"	popw	%%fs		\n"
"	movzwl	%%fs:(%w0),%1	\n"
	: "=bSDB" (scratch), "=r" (returned)
	: "g" (adr), "m" (*memory)
	);
  return returned;
  }

extern inline unsigned peekl (farptr adr)
  {
  unsigned returned;
  unsigned short scratch;

  asm (
"	pushl	%2		\n"
"	popw	%w0		\n"
"	popw	%%fs		\n"
"	movl	%%fs:(%w0),%1	\n"
	: "=bSDB" (scratch), "=r" (returned)
	: "g" (adr), "m" (*memory)
	);
  return returned;
  }

extern inline void pokeb (farptr adr, unsigned char value)
  {
  unsigned short scratch;
  asm (
"	pushl	%3		\n"
"	popw	%w0		\n"
"	popw	%%fs		\n"
"	movb	%2,%%fs:(%w0)	\n"
	: "=&bSDB" (scratch), "=m" (*memory)
	: "qi" (value), "g" (adr)
	);
  }

extern inline void pokew (farptr adr, unsigned short value)
  {
  unsigned short scratch;
  asm (
"	pushl	%3		\n"
"	popw	%w0		\n"
"	popw	%%fs		\n"
"	movw	%2,%%fs:(%w0)	\n"
	: "=&bSDB" (scratch), "=m" (*memory)
	: "qi" (value), "g" (adr)
	);
  }

extern inline void pokel (farptr adr, unsigned value)
  {
  unsigned short scratch;
  asm (
"	pushl	%3		\n"
"	popw	%w0		\n"
"	popw	%%fs		\n"
"	movl	%2,%%fs:(%w0)	\n"
	: "=&bSDB" (scratch), "=m" (*memory)
	: "ri" (value), "g" (adr)
	);
  }

----------------------------

  More on how to use, memset(), memcopy(), linker files...
 on the newly released Gujin v0.8, at:

http://gujin.sourceforge.net/
 Source file (G.P.L. only) also on sourceforge, look for "library.h",
 and there is a lot of comment in this file...

  Etienne.

___________________________________________________________
Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
Yahoo! Mail : http://fr.mail.yahoo.com



More information about the Gcc mailing list