Page 1 of 1

LD not giving correct references to the function

Posted: Tue Mar 26, 2013 3:48 am
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>

Re: LD not giving correct references to the function

Posted: Tue Mar 26, 2013 5:24 am
by Combuster
You forgot a switch to protected mode.

Re: LD not giving correct references to the function

Posted: Tue Mar 26, 2013 8:21 am
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

Re: LD not giving correct references to the function

Posted: Tue Mar 26, 2013 11:54 am
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.