ftp.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/04/17/06:13:42

Message-Id: <199604171008.GAA10619@delorie.com>
Date: Wed, 17 Apr 96 12:36:38 LIT
From: Martutis <martynas DOT kunigelis AT VM DOT KTU DOT LT>
Subject: far jumps
To: DJGPP mailing list <djgpp AT delorie DOT com>

 Hi there. I am trying to implement something like a home-made DLL, but
there is some unexpected trouble coming out of I dunno where. Here's the
pseudo-source:

typedef struct
{
  unsigned long  ofs;
  unsigned short sel;
} faraddr;

faraddr start, exit;

void main()
{
  char *image;

  image = malloc(IMGSIZE);
  load_image(image);
  start.sel = setup_selector();
  start.ofs = 0;

  exit.sel = _my_cs();
  exit.ofs = &terminate;

  asm ("leal %0,%%edx
        ljmp %1"
        :
        : "g"(exit), "g"(start)
  );
}

void terminate()
{
  ...<some harmless stuff>
  exit(0);
}
The load_image() routine loads a raw peace of code, linked with
respect to base 0 and with entry point at zero. The setup_selector()
routine allocates a code selector, sets it access rights in a way similar
to that in STUB.ASM, sets its base addrress to __djgpp_base_address+image,
and limit to something larger than 64K. Actually, all the image code does
is "ljmp (%edx)". Well, in the beginning everything works ok, but when the
"terminate" function receives the controll, things go crazy. Looks like
different selectors (es, ss or ds) get invalid, since I'm getting protection
violations and page faults at random points of terminate() or sometimes
inside exit(). What gives? The overlay doesn't mess with seg regs at all.
Where COULD be the problem with far jumps? Maybe I set the descriptor access
rights is somewhat wrong way? Maybe I should allocate an alias to cs instead?
The issue here is not a workaround (I could use DXEs), but the right way to
do this. Thanks in advance to anyone willing to help.

Martynas

- Raw text -


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