OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Mar 19, 2024 2:19 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Linking and addressing issues
PostPosted: Wed Jan 04, 2023 9:18 am 
Offline
Member
Member
User avatar

Joined: Wed Nov 02, 2005 12:00 am
Posts: 110
Location: The Netherlands
Hello everybody.

Thank you for your time reading this topic.

A few days ago, I decided to pick up my old hobby, writing an Operating System. And although I was very far with the previous OS I wrote, I decided it
would be fun to start all over. Besides, having more knowledge and experience now should make it a breeze, shouldn't it?
Well, I was (very very) wrong). But that is a topic for another day...
At this moment, I am writing my secondary bootloader. This loader is loaded by the primary bootloader. My toolchain for writing this piece of software
is nasm, combined with the Borland turbo c++ 3.0 compiler and the turbo linker.
Everything compiles and links well(ish). I try to link all source files into one com/binary executable. Luckely, the linker understands that the entrypoint
has to be at 0x0000.
The loader executes fine, until a string is passed to the print_string function. Looking in my bochs debugger, it seems that a totally wrong offset is passed to
the print_string function. Looking at my map-file I understand what's going wrong; the linker is handling the data segment as a separate segment, while I always
thought that a com-file has only one segment.
The question now is, how do I circumvent this kind of segment handling? Below the output of the linker in map-format:

Start Stop Length Name Class

00000H 00089H 0008AH _TEXT CODE
0008AH 000B0H 00027H _DATA DATA
000B2H 000B2H 00000H _BSS BSS


Detailed map of segments

0000:0000 0050 C=CODE S=_TEXT G=(none) M=LOADHEAD.ASM ACBP=28
0000:0050 003A C=CODE S=_TEXT G=(none) M=LOADER.C ACBP=28
0008:000A 0027 C=DATA S=_DATA G=DGROUP M=LOADER.C ACBP=48
0008:0032 0000 C=BSS S=_BSS G=DGROUP M=LOADER.C ACBP=48

Address Publics by Name

0000:0003 _CLEAR_SCREEN
0000:0069 _MAIN
0000:0021 _PRINT_CHAR
0000:0050 idle _PRINT_STRING
0000:0037 _SET_CURSOR
0000:0000 idle _START

Address Publics by Value

0000:0000 idle _START
0000:0003 _CLEAR_SCREEN
0000:0021 _PRINT_CHAR
0000:0037 _SET_CURSOR
0000:0050 idle _PRINT_STRING
0000:0069 _MAIN


Top
 Profile  
 
 Post subject: Re: Linking and addressing issues
PostPosted: Wed Jan 04, 2023 9:35 am 
Offline
Member
Member
User avatar

Joined: Wed Nov 02, 2005 12:00 am
Posts: 110
Location: The Netherlands
Because this problem was driving me crazy, I did some experimenting - a sort of desperado move.

The following commandline parameters (turbo c++) did the trick:
-zR_TEXT -zTCODE
With the parameters I tried to give the datasegment the same name and class as the code segment.
And this worked! I finally see the string on screen that my loader is supposed to show.

I hope this will help anybody else in the future. Thanks for reading!


Top
 Profile  
 
 Post subject: Re: Linking and addressing issues
PostPosted: Wed Jan 04, 2023 12:14 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5069
Sounds like you're using the wrong memory model. Try using "-mt" to specify the tiny memory model.


Top
 Profile  
 
 Post subject: Re: Linking and addressing issues
PostPosted: Wed Jan 04, 2023 12:49 pm 
Offline
Member
Member
User avatar

Joined: Wed Nov 02, 2005 12:00 am
Posts: 110
Location: The Netherlands
Thanks for thinking along. :) I knew I had to try at least mt or ms, but none of these worked... Strange enough...
I know masm doesn't care that much, so that wasn't the problem. For now, my commandline parameters work
like a charm.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: SemrushBot [Bot] and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group