basic problem to start with an OS project
Posted: Sat Oct 23, 2004 11:00 pm
Hi,
My name is Prajwal....
I'v a problem in generating flat binary file in Linux....
Please try to solve my problem with Patience...
It'll be easy for me to explain this with an example....
1 ***************************
ASM CODE: start.asm
[BITS 32]
[EXTERN main1]
[GLOBAL _start]
_start:
call main1
2 ****************************
C CODE: test.c
extern void main1();
void display()
{
}
void main1()
{
display();
}
3 ******************************
nasm -f aout start.asm -o start.o // runs successfully
gcc -c test.c -o test.o // runs successfully
Now I try to link these two using ld - linker
ld -o final.bin --oformat binary start.o test.o // runs successfully
I get "final.bin"....
But when I disassemble it using "ndisasm"... I observe that
function calls are not properly resovled....
what I mean is... the disassembled code would look like this:
01 call 0xb
04 nop // why these nops....
05 nop
06 nop
07 push ... // display function
09 ...
0a leave
0b ret
0c push ... // main1 function
0d sub...
0e call 0x5
10 leave
11 ret
The addresses used may not be correct but all function calls to
some address which is always some 2 bytes or 1 byte less than
what it should have been...
Also the call to display which is part of c program is also improper...
I got some Kernel code in C from websites... which had similar kind
of scenario when compiling and linking...
I followed same procedure to compile them as specified in their readme..
but even there the bin code generated had this problem....
Please help me out of this problem....
Thanks for reading with patience,
-Prajwal
In the above case call is to 0b but should have been to 0c
My name is Prajwal....
I'v a problem in generating flat binary file in Linux....
Please try to solve my problem with Patience...
It'll be easy for me to explain this with an example....
1 ***************************
ASM CODE: start.asm
[BITS 32]
[EXTERN main1]
[GLOBAL _start]
_start:
call main1
2 ****************************
C CODE: test.c
extern void main1();
void display()
{
}
void main1()
{
display();
}
3 ******************************
nasm -f aout start.asm -o start.o // runs successfully
gcc -c test.c -o test.o // runs successfully
Now I try to link these two using ld - linker
ld -o final.bin --oformat binary start.o test.o // runs successfully
I get "final.bin"....
But when I disassemble it using "ndisasm"... I observe that
function calls are not properly resovled....
what I mean is... the disassembled code would look like this:
01 call 0xb
04 nop // why these nops....
05 nop
06 nop
07 push ... // display function
09 ...
0a leave
0b ret
0c push ... // main1 function
0d sub...
0e call 0x5
10 leave
11 ret
The addresses used may not be correct but all function calls to
some address which is always some 2 bytes or 1 byte less than
what it should have been...
Also the call to display which is part of c program is also improper...
I got some Kernel code in C from websites... which had similar kind
of scenario when compiling and linking...
I followed same procedure to compile them as specified in their readme..
but even there the bin code generated had this problem....
Please help me out of this problem....
Thanks for reading with patience,
-Prajwal
In the above case call is to 0b but should have been to 0c