Message-Id: <199604171008.GAA10619@delorie.com> Date: Wed, 17 Apr 96 12:36:38 LIT From: Martutis Subject: far jumps To: DJGPP mailing list 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() { ... 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