Need help with Evil 16bit code.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
astrocrep

Need help with Evil 16bit code.

Post 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
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Need help with Evil 16bit code.

Post 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 ?
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:Need help with Evil 16bit code.

Post 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?
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
astrocrep

Re:Need help with Evil 16bit code.

Post 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
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Need help with Evil 16bit code.

Post 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.
astrocrep

Re:Need help with Evil 16bit code.

Post 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
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Need help with Evil 16bit code.

Post 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)
Post Reply