PDA

Click to See Complete Forum and Search --> : Setting up function pointers ---> Need help!


Warmaster199
May 1st, 2002, 11:06 AM
Hello.

I am currently designing the ISA Plug and Play support for my operating system. I have code to detect the ISAPnP BIOS - it gets the address of the certain function...

...But how exactly do I set the function prototype to point to the address that the BIOS specifies?

It took me a while to get the BIOS detect code running, but I think that setting this pointer will be even more bothersome. There are actually 3 different prototypes for the function because it is called 3 different ways, but they ALL point to the same address(Or they are supposed to).

The following code needs to be set to the address:

int FAR (*entryPoint)(Function, NumNodes, NodeSize, BiosSelector);
int Function; /* PnP BIOS Function 0 */
unsigned char FAR *NumNodes; /* Number of nodes the BIOS will return */
unsigned int FAR *NodeSize; /* Size of the largest device node */
unsigned int BiosSelector; /* PnP BIOS readable/writable selector */

That piece gives the function prototype. Also, the funtion should not be "int FAR" because my OS is protected mode ready, so it should be "unsigned long"(It works better).

Isn't it something like:

unsigned long (*entrypointfunc)(Function, numnodes, nodesize, BIOSsel) = (unsigned long *)BIOS->pmode_entrypoint;

This is a crucial part of my OS, so I request your help as soon as possible...

parksie
May 1st, 2002, 11:14 AM
It's a lot easier if you use a typedef, for example:typedef unsigned long (*entrypointfunc)(Function, numnodes, nodesize, BIOSsel);

entrypointfunc epf = (entrypointfunc)BIOS->pmode_entrypoint;...I think :)

Warmaster199
May 1st, 2002, 03:44 PM
I still can't quite get it to work. As soon as it executes the function pointer, it writes like the whole memory after segment 0xA000(my PMode segment) to the screen. It doesn't quite look that beautiful... I just got super annoyed with the last part of it, so just take a look at this code. Maybe you will understand what I'm trying to do and maybe you can spot my error(-please-)???

CornedBee
May 2nd, 2002, 10:10 AM
I don't understand it but there's one thing...
You say you are in protected mode, yet you use a 16-bit variable as function pointer. Are you sure this works?

Warmaster199
May 2nd, 2002, 11:02 AM
Yeah, that COULD matter. I'll have to try it out. Hopefully I won't crash my computer doing this.

Hmmm... It goes Segment:offset, correct? My code gets the segment and the offset. I ran the program on this computer(@ school), and I get PMode segment 0x0000, and PMode offset 0xE2F4. So it would be like this as a 32-bit address: 0000:E2F4

On my computer it was: 0000:A000, so it really shouldn't matter as we have the lower 16-bits.

This might matter: To test this program, I need to be in protected mode. I know DOS is real mode, but is a Windows DOS box real or protected mode? I have real mode offsets, so I could need those. It was bothering me yesterday, so I'll need to look into it further today. I got "Error: Call to non-function" and it went to my line where I actually called the info. Parksie's idea did (It was a function or something), but it puts garbage on the screen right when you call it.

The actual ISAPnP document shows a psuedo-assembler version of the code and the calls. I'm not good with ASM, and I don't know the little compiler sub commands and such, but maybe I can try to just use the assembler code embedded in my C code.

If you find a solution or a better way of setting this up, it would be much appreciated.