0x402000
0x402000
Hello,
Sorry i don't speak very well English, i'm French.
I try to understand how TLINK32 make my EXE program.
Example, i have this C program:
void toto();
unsigned int var = 0x1234;
unsigned int var2 = 0xABCD;
main()
{
toto();
asm {
nop
}
var = 0x4567;
asm {
nop
}
var2 = 0xCDEF;
asm {
nop
}
while(1) {}
}
void toto()
{
asm {
nop
nop
nop
}
}
I type to make exe:
TCC -c -ml TOTO.C
TLINK /n /x TOTO
NDISASM TOTO.EXE > TOTO.TXT
I have into TOTO.TXT
00000200 55 push bp
00000201 8BEC mov bp,sp
00000203 0E push cs
00000204 E81400 call 0x21b
00000207 90 nop
00000208 90 nop
00000209 C70604006745 mov word [0x4],0x4567
0000020F 90 nop
00000210 C7060600EFCD mov word [0x6],0xcdef
00000216 90 nop
00000217 EBFE jmp short 0x217
00000219 5D pop bp
0000021A CB retf
0000021B 55 push bp
0000021C 8BEC mov bp,sp
0000021E 90 nop
0000021F 90 nop
00000220 90 nop
00000221 5D pop bp
00000222 CB retf
00000223 0034 add [si],dh
00000225 12CD adc cl,ch
00000227 AB stosw
It's OK, in 16 bit mode, date 0x1234 is in 0022:0004 (mov word [0x4],0x4567 with DS=0022h) and 0xABCD in 0022:0006.
Now i try to make 32 bits exe:
BCC32 -c -tWC TOTO.C
TLINK32 -n TOTO
NDISASM -u TOTO.EXE > TOTO.TXT
Now i have into TOTO.TXT:
000005FF 00558B add [ebp-0x75],dl
00000602 EC in al,dx
00000603 E81B000000 call 0x623
00000608 90 nop
00000609 C705002040006745 mov dword [0x402000],0x4567
-0000
00000613 90 nop
00000614 C70504204000EFCD mov dword [0x402004],0xcdef
-0000
0000061E 90 nop
0000061F EBFE jmp short 0x61f
00000621 5D pop ebp
00000622 C3 ret
00000623 55 push ebp
00000624 8BEC mov ebp,esp
00000626 90 nop
00000627 90 nop
00000628 90 nop
00000629 5D pop ebp
0000062A C3 ret
for code and:
000007FF 003412 add [edx+edx],dh
00000802 0000 add [eax],al
00000804 CDAB int 0xab
for data, but why mov dword [0x402000],0x4567 ?
data is in 800h, or 200h without header of exe file, why 0x402000 ?
If i copy this file ( 600h to end of file ) into memory in real mode before swap to protected mode, how processor can found data ?
Thank you for responses !
I'm newbie :wink:
Sorry i don't speak very well English, i'm French.
I try to understand how TLINK32 make my EXE program.
Example, i have this C program:
void toto();
unsigned int var = 0x1234;
unsigned int var2 = 0xABCD;
main()
{
toto();
asm {
nop
}
var = 0x4567;
asm {
nop
}
var2 = 0xCDEF;
asm {
nop
}
while(1) {}
}
void toto()
{
asm {
nop
nop
nop
}
}
I type to make exe:
TCC -c -ml TOTO.C
TLINK /n /x TOTO
NDISASM TOTO.EXE > TOTO.TXT
I have into TOTO.TXT
00000200 55 push bp
00000201 8BEC mov bp,sp
00000203 0E push cs
00000204 E81400 call 0x21b
00000207 90 nop
00000208 90 nop
00000209 C70604006745 mov word [0x4],0x4567
0000020F 90 nop
00000210 C7060600EFCD mov word [0x6],0xcdef
00000216 90 nop
00000217 EBFE jmp short 0x217
00000219 5D pop bp
0000021A CB retf
0000021B 55 push bp
0000021C 8BEC mov bp,sp
0000021E 90 nop
0000021F 90 nop
00000220 90 nop
00000221 5D pop bp
00000222 CB retf
00000223 0034 add [si],dh
00000225 12CD adc cl,ch
00000227 AB stosw
It's OK, in 16 bit mode, date 0x1234 is in 0022:0004 (mov word [0x4],0x4567 with DS=0022h) and 0xABCD in 0022:0006.
Now i try to make 32 bits exe:
BCC32 -c -tWC TOTO.C
TLINK32 -n TOTO
NDISASM -u TOTO.EXE > TOTO.TXT
Now i have into TOTO.TXT:
000005FF 00558B add [ebp-0x75],dl
00000602 EC in al,dx
00000603 E81B000000 call 0x623
00000608 90 nop
00000609 C705002040006745 mov dword [0x402000],0x4567
-0000
00000613 90 nop
00000614 C70504204000EFCD mov dword [0x402004],0xcdef
-0000
0000061E 90 nop
0000061F EBFE jmp short 0x61f
00000621 5D pop ebp
00000622 C3 ret
00000623 55 push ebp
00000624 8BEC mov ebp,esp
00000626 90 nop
00000627 90 nop
00000628 90 nop
00000629 5D pop ebp
0000062A C3 ret
for code and:
000007FF 003412 add [edx+edx],dh
00000802 0000 add [eax],al
00000804 CDAB int 0xab
for data, but why mov dword [0x402000],0x4567 ?
data is in 800h, or 200h without header of exe file, why 0x402000 ?
If i copy this file ( 600h to end of file ) into memory in real mode before swap to protected mode, how processor can found data ?
Thank you for responses !
I'm newbie :wink:
- Combuster
- 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:
obviously you haven't read http://www.osdev.org/phpBB2/viewtopic.php?t=14961
- Combuster
- 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:
Well, I can pretty accurately guess what happens - its the default linking address. (the reason why everybody uses linker scripts - iirc if he used gcc we'd gotten a topic labeled 0x80something)
Still, he obviously hasn't read how to ask questions (obvious from the thread's title), he hasn't read the notes on the wiki (no code tags), and apparently doesnt meet the prerequisites (doesnt know the tools inside out). All of which are mentioned in the readme topic.
Still, he obviously hasn't read how to ask questions (obvious from the thread's title), he hasn't read the notes on the wiki (no code tags), and apparently doesnt meet the prerequisites (doesnt know the tools inside out). All of which are mentioned in the readme topic.
Hox to load data into memory ?
Hello,
Ok 0x402000 is forced by TLINK, but how to deal with it ?
I think:
-> In boot my boot-code (sector 0 of floppy) is loaded into 0000:7C00.
-> In this boot-code, i load 400h bytes of my 32 bits program into 0000:7E00.
-> In boot-code, i switch into protected mode and i jump to 0000:7E00, or linear adress 00007E00h. I use all memory for code and data segment in GDT configuration.
-> I copy data (linear adress 00008000 - 00008200) into 00402000h - 00404400h to be OK with mov dword [0x402000],0x4567
That's OK ? Can you help me to understand how protected mode work ?
Thank !
Ok 0x402000 is forced by TLINK, but how to deal with it ?
I think:
-> In boot my boot-code (sector 0 of floppy) is loaded into 0000:7C00.
-> In this boot-code, i load 400h bytes of my 32 bits program into 0000:7E00.
-> In boot-code, i switch into protected mode and i jump to 0000:7E00, or linear adress 00007E00h. I use all memory for code and data segment in GDT configuration.
-> I copy data (linear adress 00008000 - 00008200) into 00402000h - 00404400h to be OK with mov dword [0x402000],0x4567
That's OK ? Can you help me to understand how protected mode work ?
Thank !
How to use with TLINK32
Hello,
I have found information about linker script on http://www.delorie.com/gnu/docs/binutils/ld_9.html, but how to specify linker script file to TLINK32 ?
I use to compile:
BCC32 -c TOTO.C
TLINK32 -n TOTO
If i replace TLINK32 by
ILINK32 TOTO
And i do
NDISASM -u TOTO.EXE > TOTO.TXT
I have no comprehensif data into TOTO.TXT at 600h and 800h
What's best compiler and linker to compil C source file with ASM include ?
Thank !
I have found information about linker script on http://www.delorie.com/gnu/docs/binutils/ld_9.html, but how to specify linker script file to TLINK32 ?
I use to compile:
BCC32 -c TOTO.C
TLINK32 -n TOTO
If i replace TLINK32 by
ILINK32 TOTO
And i do
NDISASM -u TOTO.EXE > TOTO.TXT
I have no comprehensif data into TOTO.TXT at 600h and 800h
What's best compiler and linker to compil C source file with ASM include ?
Thank !
Re: How to use with TLINK32
It's your tool of choice, so I assume you have the according documentation installed alongside. I don't.Lovmy wrote:how to specify linker script file to TLINK32 ?
Define "best". Quite a lot of people use the GCC / binutils (GAS, LD) toolchain. Most tutorials assume that toolchain. So, in a way, it might be considered "best". Others disagree.What's best compiler and linker to compil C source file with ASM include ?
Every good solution is obvious once you've found it.