EmbeddedRelated.com
Forums

Use of #pragma data_seg

Started by Peter Mueller May 5, 2004
Hi all,

I know this questions a littel bit off topic, but maybe someone
already came across this problem.

I want to run software from an embedded project on windows. The
software defines some segments and stores data into
these segments. The content of the segments is stored non-volatile
later on.

I want to emulate a similar behaviour on Windows by just saving all
data in a segment to a file. I can create my onw data segments without
no problem so far.
The problem is how can I find out where the segment start address is
and where it ends?

Any idea?

Thanks a lot,
Peter
> I want to run software from an embedded project on windows. The > software defines some segments and stores data into > these segments. The content of the segments is stored non-volatile > later on. > I want to emulate a similar behaviour on Windows by just saving all > data in a segment to a file. I can create my onw data segments without > no problem so far. > The problem is how can I find out where the segment start address is > and where it ends?
Huh? If you are emulating this item by mallocing a buffer to store the data segment(s), then all you do is write out the buffer. It starts at the address given to you by malloc, and ends at the address of (start + length). Is this a trick question? Are you somehow asking to obtain the physical address of a virtual address within Windows? There are mechanisms to do it, but it doesn't serve any purpose for the application you've described. Is this device x86-based, i.e. are you running the code natively inside a DOS box, or are you also emulating the instruction set? Or did you just cross-compile the C code?
Hi Lewin,


larwe@larwe.com (Lewin A.R.W. Edwards) wrote in message news:<608b6569.0405051145.272fffd3@posting.google.com>...
> > I want to run software from an embedded project on windows. The > > software defines some segments and stores data into > > these segments. The content of the segments is stored non-volatile > > later on. > > I want to emulate a similar behaviour on Windows by just saving all > > data in a segment to a file. I can create my onw data segments without > > no problem so far. > > The problem is how can I find out where the segment start address is > > and where it ends? > > Huh? If you are emulating this item by mallocing a buffer to store the > data segment(s), then all you do is write out the buffer. It starts at > the address given to you by malloc, and ends at the address of (start > + length). Is this a trick question? Are you somehow asking to obtain > the physical address of a virtual address within Windows? There are > mechanisms to do it, but it doesn't serve any purpose for the > application you've described.
The problem is that the code looks in principle like: #segment abc several variables defined #segment default There is no chance for malloc if I won't change the exsiting code too much. At least I do not see it.
> > Is this device x86-based, i.e. are you running the code natively > inside a DOS box, or are you also emulating the instruction set? Or > did you just cross-compile the C code?
I just want to cross compile and using win32 to simulate and debug the hardware independant parts of the device. Peter
> The problem is that the code looks in principle like: > > #segment abc > > several variables defined > > #segment default > > There is no chance for malloc if I won't change the exsiting code too > much. At least I do not see it.
Why does the compiler care about these unrecognized pragmas? Are you experiencing some kind of namespace collision between variable "A" defined in segment abc, then a different variable "A" defined in some other segment? Or are you trying to emulate some kind of overlap, where certain parts of one segment are mapped into all other segments? These segments presumably have something to do with RAM banking or I/O mapping in the real hardware. Well, since you're not running on the real hardware, RAM is RAM and "a=123" sets a=123 regardless of what segment it lived in on the original platform - so I still don't understand the problem, sorry!
I think that the OP wanted to find a way to emulate an embedded system
on a PC.  In particular, he wanted to emulate the non-volatile RAM by
saving a specific segment to disk between program invocations.

From what I have seen from linker maps on PC-targetted compilers, data
segments are given special symbols to define their beginning and
ending.  Even if they are not given these special symbols, you can
define your own by defining an "int" before and another "int" after
all the variables that your application needs.  Check the linker map
to make sure that the variables you defined really do end up
bracketing the application variables.  Then write some start-up code
and shut-down code to fill the memory thusly bracketted by a binary
file read and start-up, and a similar binary file write on shut-down.
If seg_start is a variable at the start of the segment and seg_end is
a variable at the end, then the number of bytes read or written should
be

  ((char*)(&seg_end))-((char*)(&seg_start))

and of course the starting address is &seg_start.

-Robert Scott
 Ypsilanti, Michigan
(Reply through this forum, not by direct e-mail to me, as automatic reply address is fake.)