Page 1 of 1

Need help with Evil 16bit code.

Posted: Tue Nov 16, 2004 4:06 pm
by astrocrep
My os has a loader that checks for the capabilities of the videocard and then setups up vesa lfb (and then loads 32bit kernel, goes to pmode and such...)

Anyway,

I need to set my struct the ES:DI in C.

I hate asm this is what I am tring to adapt:

Code: Select all

  

/*Copied this from Turbo C dos.h file*/

#define FP_OFF(fp)   ((unsigned)(fp))
#define FP_SEG(fp)   ((unsigned)((unsigned long)(fp) >> 16))

void vesa()
{

  int temp;
    _AX = 0x4F00;
    _ES = FP_SEG(&info);
   _DI = FP_OFF(&info);
    
    asm int 10h;
    
    temp = _AX;
    
    if (temp != 0x004f) { printf("Failed"); }
}
Thats my disgusting attempt to convert this,

Code: Select all

    reg.r_ax = 0x4F00;
    reg.r_es = FP_SEG(&info);
   reg.r_di = FP_OFF(&info);
    intr(0x10, &reg);

    if (reg.r_ax != 0x004f) { printf("Fail"); }

My compiler is Turbo C 2.02 (Free)

The original passes on my computer, and my version fails, I have no clue why, you guys see anything ?

Thanks in advance,

Rich

Re:Need help with Evil 16bit code.

Posted: Wed Nov 17, 2004 3:13 am
by Pype.Clicker
what exactly are _AX, _ES and _DI macro expected to do ? The regs.ax was changing a member of a structure that intr(...) function was using to set/save registers before calling the interrupt. What about yours ?

Re:Need help with Evil 16bit code.

Posted: Wed Nov 17, 2004 4:18 am
by distantvoices
@astrocrep:

what is happening inside your intr() function? Do you pass the data inside the regs structure to the according regsters ere you issue

Code: Select all

__asm__("int 0x10");
- assuming you are still in 16 bit environment.

Without passing the data to the registers and fetching it from the registers in reply, your approach won't work. I'm using a similar way to issue bios interrupts via vm86.

To clear things, just show the intr() code, hm? Maybe there is a secret hidden we can find together?

Re:Need help with Evil 16bit code.

Posted: Wed Nov 17, 2004 7:18 am
by astrocrep
Thanks guys for the responses,

I was pretty sure that TurboC allows for direct access to the registeres via _AX, _BX, etc. and when you throw an interrupt

Code: Select all

asm int 10h;
It has the registers, however maybe I was wrong about that, it does seem to make sense. I guys I will need to include the whole chunk in

Code: Select all

asm {
...
}
Or export it to an extern file. Any advice on either of those?

Thanks

Rich

Re:Need help with Evil 16bit code.

Posted: Wed Nov 17, 2004 10:51 am
by Pype.Clicker
honestly, i'd rather have the int 0x10 wrapped in an ASM file. picking arguments on the stack with [ebp+*] and returning the value with dx:ax isn't that complicated.

Re:Need help with Evil 16bit code.

Posted: Wed Nov 17, 2004 12:34 pm
by astrocrep
ive been thinking about that while I was at work today, I think thats exactly how I am going to do it, Isn't the return value of a function stored in ax? I don't remember, ill have to google it later on.

Thanks alot for the help though,

Rich

Re:Need help with Evil 16bit code.

Posted: Wed Nov 17, 2004 1:25 pm
by Pype.Clicker
that'll be AX if the value fits 16 bits and dx:ax if the value is larger (like for long ints and far pointer, afaik)