www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/06/18/09:10:17

Date: Tue, 18 Jun 1996 16:05:19 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Bob Platko <platko AT ix DOT netcom DOT com>
Cc: djgpp AT delorie DOT com
Subject: Re: __dmpi_regs bug?
In-Reply-To: <31C615A7.3FD4@ix.netcom.com>
Message-Id: <Pine.SUN.3.91.960618155227.16755A-100000@is>
Mime-Version: 1.0

On Mon, 17 Jun 1996, Bob Platko wrote:

>   __dpmi_int(0x10, &r);
> 	if(r.h.ah) return 0;
>   dosmemget(__tb, sizeof(mode_info_block), &info);
> 	return &info;

You assume that the struct fields are packed (i.e. that there are no holes
between them).  In DJGPP this is an incorrect assumption, because GCC
aligns struct fields on word and dword boundaries to avoid runtime penalty
of unaligned memory accesses.  Put the following pragmas around the struct
definitions to get the expected behavior: 

#pragma pack(1)

typedef struct { ...
...
} mode_info_block;

#pragma pack()

> With using the union REGS r & struct SREGS s, 
> how do I copy the contents of es thru di without
> using this:
> 
>   dosmemget(__tb, sizeof(mode_info_block), &info);

You can't.  ES:DI points to a buffer outside your program's address space,
and you can't access it without triggering a protection violation. 
(Actually, there is a way to accomplish this with `near pointers', but you
should only use that when you must have a very fast access to
memory-mapped devices, such as VGA, because this method effectively
disables memory-protection.  See section 18.6 in the DJGPP FAQ list for
details.)

> BTW, what is that __tb thing?  It's not in the C language index in info.exe.

`__tb' is #define'd to be the linear address of transfer buffer on 
<go32.h> header file.  The transfer buffer is a buffer in low (under 1MB 
mark) memory used by DJGPP and most other DOS-extended environments to 
move data between DOS and your application.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019