public inbox for linux-8086@vger.kernel.org
 help / color / mirror / Atom feed
* bcc question
@ 2002-05-26  1:25 Ken Martwick
  2002-05-26 12:03 ` Harry Kalogirou
  2002-05-28 19:14 ` Robert de Bath
  0 siblings, 2 replies; 3+ messages in thread
From: Ken Martwick @ 2002-05-26  1:25 UTC (permalink / raw)
  To: Linux 8086

How does one write inline assembly code in "bcc" to move
a register value to a "C" variable?  The following code
is acceptable to "bcc", but "ld86" fails with something
about undefined variables.  I couldn't find any examples.
 
--------------------------------------------------------
 
int main()
	{
	int codeseg, datseg;
 
	#asm
	push	cs
	pop	ax
	mov	codeseg,ax
	push	ds
	pop	ax
	mov	datseg,ax
	#endasm
     
--------------------------------------------------------
 
Ken Martwick
     



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

* Re: bcc question
  2002-05-26  1:25 bcc question Ken Martwick
@ 2002-05-26 12:03 ` Harry Kalogirou
  2002-05-28 19:14 ` Robert de Bath
  1 sibling, 0 replies; 3+ messages in thread
From: Harry Kalogirou @ 2002-05-26 12:03 UTC (permalink / raw)
  To: Ken Martwick; +Cc: Linux 8086

Την Κυρ, 26-05-2002 στις 04:25, ο/η Ken Martwick έγραψε:
> How does one write inline assembly code in "bcc" to move
> a register value to a "C" variable?  The following code
> is acceptable to "bcc", but "ld86" fails with something
> about undefined variables.  I couldn't find any examples.
>  
> --------------------------------------------------------
>  
> int main()
> 	{
> 	int codeseg, datseg;
>  
> 	#asm
> 	push	cs
> 	pop	ax
> 	mov	codeseg,ax
> 	push	ds
> 	pop	ax
> 	mov	datseg,ax
> 	#endasm
>      
> --------------------------------------------------------
>  
> Ken Martwick
>      

Replace "mov codeseg,ax" with "mov _codeseg,ax" and
"mov datseg,ax" with "mov _datseg,ax" and it should be fine...

Harry



-
To unsubscribe from this list: send the line "unsubscribe linux-8086" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: bcc question
  2002-05-26  1:25 bcc question Ken Martwick
  2002-05-26 12:03 ` Harry Kalogirou
@ 2002-05-28 19:14 ` Robert de Bath
  1 sibling, 0 replies; 3+ messages in thread
From: Robert de Bath @ 2002-05-28 19:14 UTC (permalink / raw)
  To: Ken Martwick; +Cc: Linux 8086

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1211 bytes --]

On Sat, 25 May 2002, Ken Martwick wrote:

> How does one write inline assembly code in "bcc" to move
> a register value to a "C" variable?  The following code
> is acceptable to "bcc", but "ld86" fails with something
> about undefined variables.  I couldn't find any examples.

Because until recently it didn't work with local variables.

For the most recent version I've found a way of fixing the old bug where
mixed C & assembler may get out of sequence and added some more 'magic'
symbols for frame pointer offsets to the local variables (as opposed to
the existing stack pointer relative offsets).

The general method is something like this:

void mem_check()
{
   /* Try int $15 EAX=$E801 */
   {
      unsigned int mem_64, mem_16;      /* For int $15,AX=$E801 */
#asm
      mov ax,#$E801
      int $15
      jc  no_e801
      mov .mem_check.mem_16[bp],ax
      mov .mem_check.mem_64[bp],bx
#endasm
      main_mem_top = ((unsigned long)mem_64<<6) + mem_16;
#asm
no_e801:
#endasm
   }
}

I've attached the whole function which has a couple of other bits too.

-- 
Rob.                          (Robert de Bath <robert$ @ debath.co.uk>)
                                       <http://www.cix.co.uk/~mayday>


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: TEXT/X-C-SOURCE; NAME="mem_check.c", Size: 1777 bytes --]

void mem_check()
{
#ifndef __STANDALONE__
   main_mem_top = 16384;
   return;	/* If not standalone don't try */
#else
#asm
  int	0x12		! Amount of boot memory
  mov	cl,#6
  sal	ax,cl		! In segments
  mov	[_boot_mem_top],ax

			! Next check for extended 
  mov	al,[_x86] 	! If we ain't got a 286+ we can't access it anyway
  cmp	al,#2
  jl  	is_xt

  mov	ah,#0x88	!
  int	0x15
  jnc	got_ext		! Error!? This should _not_ happen ... but ...
is_xt:
  xor	ax,ax
got_ext:
  mov	word ptr [_main_mem_top+2],#0
  mov	[_main_mem_top],ax

#endasm

   /* Rest are big memory for 80386+ */
   if( x86 < 3 ) return;

   /* Try int $15 EAX=$E820 */
   {
      struct e820_dat {
	 unsigned long base_lo, base_hi;
	 unsigned long len_lo, len_hi;
	 long addr_type;
      } e820_item;
      long epoll = 0;

      do
      {
	 e820_item.addr_type = 0;
#asm
	 mov eax,#$E820
	 mov ebx,.mem_check.epoll[bp]
	 mov ecx,#20
	 mov edx,#$534D4150
	 push ds
	 pop es
	 lea di,.mem_check.e820_item[bp]
	 int $15
	 jnc got_e820
	 xor ebx,ebx
got_e820:
	 mov .mem_check.epoll[bp],ebx
#endasm
	 if (e820_item.addr_type == 1
	       && e820_item.base_hi == 0
	       && e820_item.base_lo == 0x100000L)
	 {
	    /* XXX Later ... */
	    if (e820_item.len_hi) main_mem_top = 0x40000;
	    else
	       main_mem_top = (e820_item.len_lo >> 10);
	    return;
	 }
      }
      while(epoll);
   }

   /* Try int $15 EAX=$E801 */
   {
      unsigned int mem_64, mem_16;	/* For int $15,AX=$E801 */
#asm
      mov ax,#$E801
      int $15
      jc  no_e801
      mov .mem_check.mem_16[bp],ax
      mov .mem_check.mem_64[bp],bx
#endasm
      main_mem_top = ((unsigned long)mem_64<<6) + mem_16;
#asm
no_e801:
#endasm
   }

#endif
}

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

end of thread, other threads:[~2002-05-28 19:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-05-26  1:25 bcc question Ken Martwick
2002-05-26 12:03 ` Harry Kalogirou
2002-05-28 19:14 ` Robert de Bath

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox