0x402000

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
Lovmy
Posts: 17
Joined: Fri Oct 05, 2007 5:58 am

0x402000

Post by Lovmy »

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:
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:

Post by Combuster »

"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 ]
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Actually Combuster, can you explain it as I'm not certain why it's happening either :P
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:

Post by Combuster »

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.
"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 ]
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Combuster: That's what I initially thought, but if that's the case why are the addresses in the .data section at 0x600 etc?
Lovmy
Posts: 17
Joined: Fri Oct 05, 2007 5:58 am

Hox to load data into memory ?

Post by Lovmy »

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 !
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Use a linker script. Look at the wiki. Search old posts on this forum.
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:

Post by Combuster »

JamesM wrote:Use a linker script. Look at the wiki. Search old posts on this forum.
Which essentially means, don't use TLink :cry:
"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 ]
Lovmy
Posts: 17
Joined: Fri Oct 05, 2007 5:58 am

How to use with TLINK32

Post by Lovmy »

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 !
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: How to use with TLINK32

Post by Solar »

Lovmy wrote:how to specify linker script file to TLINK32 ?
It's your tool of choice, so I assume you have the according documentation installed alongside. I don't.
What's best compiler and linker to compil C source file with ASM include ?
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.
Every good solution is obvious once you've found it.
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:

Post by Combuster »

how to specify linker script
A website wrote:If you run either of the compiler, bcc32.exe, or the linker, ilink32.exe, with no command line parameters, a summary of how to use them will be shown. The summary shows how the command line is constructed and the options that can be used.
"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