Use of #pragma data_seg

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

Reply to
Peter Mueller
Loading thread data ...

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?

Reply to
Lewin A.R.W. Edwards

Hi Lewin,

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.

I just want to cross compile and using win32 to simulate and debug the hardware independant parts of the device.

Peter

Reply to
Peter Mueller

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!

Reply to
Lewin A.R.W. Edwards

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.)

Reply to
Robert Scott

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.