Page 1 of 1

How can I use CALL?

Posted: Mon Mar 10, 2003 6:53 pm
by Unspoken_Magi
STAGE1 of my bootloader loads at 0x0070:0x0000.
STAGE2 of my bootloader loads at 0x0090:0x0000.
There is a function in there (cputs) that I want to use in the STAGE2 bootloader.

cputs does use short jumps, but does that make a difference?

STAGE1 puts the pointer to cputs (Linear address) into a location in memory with some other variables.
STAGE2 reads the value into ax, (the value ends up being 0x7b0(the value is correct)).

How can I use CALL to run the function from STAGE2? ???

Re:How can I use CALL?

Posted: Tue Mar 11, 2003 2:03 am
by Pype.Clicker
mov bx,[where_is_pointer_to_cputs_stored]
call [bx]

Re:How can I use CALL?

Posted: Tue Mar 11, 2003 1:47 pm
by Unspoken_Magi
Pype.Clicker wrote: mov bx,[where_is_pointer_to_cputs_stored]
call [bx]
That doesn't work, it's in a different segment.

Re:How can I use CALL?

Posted: Tue Mar 11, 2003 3:34 pm
by Pype.Clicker
then you should make your variable hold a far pointer (check intel manuals to know whether it starts with segment or offset, but i think it is offset first), and use

Code: Select all

fputs_pointer:
   dw fputs
   dw segment_of_fputs

mov bx,fputs_pointer
call WORD FAR [bx]
if you know that your pointer is, say, located at 0x1234:0x5678, then

Code: Select all

mov bx,0x5678
mov es,0x1234 ;; i assume you don't want to touch ds.
call WORD FAR [es:bx]

Re:How can I use CALL?

Posted: Tue Mar 11, 2003 5:51 pm
by Unspoken_Magi
Well, I got it to work.

I used:

Code: Select all

   push   cs            ; push return cs
   push   word $+0xb         ; push return ip
   push   word [CPUTS_SEG_POINTER]   ; push function cs
   push   word 0x0000         ; push function ip
   retf
I also changed the ret at the end of cputs to a retf.