LD not giving correct references to the function

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
sharkwikios
Posts: 7
Joined: Tue Nov 20, 2012 8:25 am

LD not giving correct references to the function

Post by sharkwikios »

Hi,

I am writing a new kernel and is at very early stage of development.
I have attached the MY.img file as a reference for the help that i am seeking.

after puts("LILLYPUTS Loading I/O system...\r\n"); is called i supposed the to execute monitor_clear();
But it is not executing the same. [ pasted below is code sequence ]

while i have debugged on what is happening.., i have observed is the corresponding call instruction is branching just 2 bytes before where monitor_clear() corresponding object is resided in the object file.

In essence,

(0) [0x000400e4] 4000:00e4 (unk. ctxt): call .+0x02c2 (0x000403a9) ; e8c202 --> this referring to an offset of 5a9, but the monitor_clear code is at 5ab.

because of that my monitor_clear() is not picking up.

any suggetions or help is greatly appreciated.


The corresponding source code is :

void setup(void)
{
puts("-----LILLYPUTS Kernel Setup -----\r\n");
puts("LILLYPUTS krnl_level=1\r\n");
puts("LILLYPUTS Loading I/O system...\r\n");
//ch=sayhi();
//ch=getch();
>>>> monitor_clear(); <<<<<<<<<<<<<<<<<<<<<<<
monitor_write("Hello, world!");
puts("LILLYPUTS - DEBUG: HALT\r\n");
/* developing and error goes here... */
here:
goto here;
return;
}



(0) [0x000400d7] 4000:00d7 (unk. ctxt): push 0x0064 ; 686400
<bochs:58> n
Next at t=14419105
(0) [0x000400da] 4000:00da (unk. ctxt): add byte ptr ds:[bx+si], al ; 0000
<bochs:59>
Next at t=14419106
(0) [0x000400dc] 4000:00dc (unk. ctxt): call .+0x036f (0x0004044e) ; e86f03
<bochs:60>
Next at t=14449555
(0) [0x000400df] 4000:00df (unk. ctxt): add byte ptr ds:[bx+si], al ; 0000
<bochs:61>
Next at t=14449556
(0) [0x000400e1] 4000:00e1 (unk. ctxt): add sp, 0x0010 ; 83c410
<bochs:62>
Next at t=14449557
(0) [0x000400e4] 4000:00e4 (unk. ctxt): call .+0x02c2 (0x000403a9) ; e8c202
<bochs:63> s
Next at t=14449558
(0) [0x000403a9] 4000:03a9 (unk. ctxt): leave ; c9
<bochs:64>
Attachments
file_to_wikidev.zip
My Imge file and consistuent binaries
(5.37 KiB) Downloaded 20 times
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: LD not giving correct references to the function

Post by Combuster »

You forgot a switch to protected mode.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
sharkwikios
Posts: 7
Joined: Tue Nov 20, 2012 8:25 am

Re: LD not giving correct references to the function

Post by sharkwikios »

i value your comment.
But , to understand more on that, how can the protected mode change can bring in the correct relocation of symbols by LD?

Thanks
Regards,
-Raveendra
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: LD not giving correct references to the function

Post by Combuster »

Your key mistake is that you blame the tools in the first place. For instance:
(0) [0x000400d7] 4000:00d7 (unk. ctxt): push 0x0064 ; 686400
(0) [0x000400da] 4000:00da (unk. ctxt): add byte ptr ds:[bx+si], al ; 0000
Is actually the 16-bit interpretation of the following 32-bit code the compiler actually created:

Code: Select all

push dword 0x64 ; 6864000000
In other words, as long as the CPU is in the wrong mode, it will not execute the code you think you created, but something looking something vaguely similar.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply