public inbox for linux-8086@vger.kernel.org
 help / color / mirror / Atom feed
From: Robert de Bath <robert$@mayday.cix.co.uk>
To: Ken Martwick <kenm@efn.org>
Cc: Linux 8086 <linux-8086@vger.kernel.org>
Subject: Re: bcc question
Date: Tue, 28 May 2002 20:14:52 +0100 (BST)	[thread overview]
Message-ID: <83142d34a58c4005@mayday.cix.co.uk> (raw)
In-Reply-To: <Pine.GSU.4.21.0205251824160.6484-100000@garcia.efn.org>

[-- 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
}

      parent reply	other threads:[~2002-05-28 19:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83142d34a58c4005@mayday.cix.co.uk \
    --to=robert$@mayday.cix.co.uk \
    --cc=kenm@efn.org \
    --cc=linux-8086@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox