How can I use CALL?

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
Unspoken_Magi

How can I use CALL?

Post 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? ???
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:How can I use CALL?

Post by Pype.Clicker »

mov bx,[where_is_pointer_to_cputs_stored]
call [bx]
Unspoken_Magi

Re:How can I use CALL?

Post 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.
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:How can I use CALL?

Post 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]
Unspoken_Magi

Re:How can I use CALL?

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