Looking for 16-bit x86 compiler - c++

I am working on an embedded systems project and have run into an issue of the compiler being programatically embedded in the Paradigm C++ IDE. I would like to be able to automate building.
The processor is the AMD186ES. I am not working with the OS - just baremetal stuff.
I need to generate real-mode 16-bit 8086 machine code from C++.
My googling indicates that G++ can build such code.
My questions are:
Can g++ be configured to build this machine code?
Are there other C++ compilers that can do it as well?

Your best bet is probably OpenWatcom, which includes a C++ compiler. Back in the early-to-mid 90s, I believe this was the best C/C++ compiler around. It was open-sourced a few years ago.

I am currently using gnu as (part of binutils and the assembler used for gcc) and I have successfully been assembling 16bit assembly code with the following:
as <file>
ld --oformat binary -Ttext 0x0 -e start <file>
with my assembly files starting out with:
.code16
.globl start
.text
start:
since its plain binary omitting the lines,
.globl start
start:
will simply yield an warning, even though flat binaries need no entry point.
something I learned the hard way;
-Ttext 0x0
is critical, otherwise the .text segment is pushed outside of 16bit addressing range (don't ask me why)
I am personally still learning assembly, so this is just my way, not necessarily the best way.
EDIT: If you are writing boot code, you should change
-Ttext 0x0
to
-Ttext 0x7c00
this will offset your memory addresses by 0x7c00 since boot code is usually loaded at 0x7c00 by the BIOS.

Doesn't your chip vendor (AMD, I guess) have any pointers to compilers for the chip?
If not, you may be able to use some 16-bit DOS compilers - but you'll have several potential big problems:
getting a library for the compiler that is not dependent on the BIOS or MS-DOS
debugging
linkers for embedded systems usually have specific support for locating code in specific memory regions. That's not usually included in compilers for DOS, but you may be able to find some sort of linker/locator that'll do the trick for you.
A couple of compilers that are still supported and generate 16-bit code are:
Digital Mars
Open Watcom

This google search shows a series of links for setting gcc up as a cross compiler. To get it to target something other than a standard ELF binary you can frig the output. This link discusses excluding the standard libraries and customising the output format. You may have to do some fiddling to get it to work.
As an alternative openwatcom.org has an open-source version of the Watcom C compiler, which might also be able to do what you want.

There's a patch for GCC 4.3: New back end ia16: 16-bit Intel x86
And here's an update for it. Note that it probably doesn't work very well, for example, the updated post says: "Constructors and destructors are now supported, but for some reason they
only work on the elks configuration."
This Docker container has a build of it: https://registry.hub.docker.com/u/ysangkok/ia16-gcc-rask
I didn't manage to make DOS binaries yet: How do I assemble GAS assembly and link it with the Open Watcom C library?

Take a look at bcc, which is a 16-bit x86 C compiler. For example, there are also Debian packages for it.

The most recent as per 2014 is Dev86.

Not sure but I think old version of borland c++ was able to do that.
you can download version 5.5 t : here
good luck

80186 free C compiler:
http://coding.derkeiler.com/Archive/General/comp.arch.embedded/2005-09/msg01063.html

It has been a long time since I've looked at Paradigm stuff (are they still around?) -- are you sure they don't have command-line equivalents for the compiler? My recollection is that they were built on top of Borland's compiler toolchain... So maybe an old copy of Borland compilers might do the trick?
--
Ah, looking a little futher, I find that Paradigm is still around (www.devtools.com) selling X86 tools. (Must be a cash cow!)
Their professional product includes scripting... Depending on the amount of work you plan to do, it just might be worth it to bite the bullet and buy their full offering...
Good luck.

Related

How to install a simple Intel C/C++ compiler on a 64-bit Ubuntu system?

I need to compile c/c++ code, by running a build.sh file.
The instruction on the program (that i want to run) says it needs to be compiled by a Intel's compiler1.
After searching on the net I came across information on what to do.
Some people said that we must install first a 32-bit libraries:
https://help.ubuntu.com/community/InstallingCompilers
Others said that we must, first of any installation, change some things:
http://software.intel.com/en-us/articles/using-intel-compilers-for-linux-with-ubuntu
In the other hand, Intel's page show many suites:
http://software.intel.com/en-us/c-compilers
while the only thing that I want is simply Intel's C/C++ compiler.
Can somebody be so gentle to give me the directions on how to install a Intel's compiler on a 64-bit Ubuntu system?
Footnote 1 / Editor's note: other x86 compilers including GCC and clang (and MSVC on Windows), support Intel's SSE/AVX intrinsic functions, but Intel's compiler comes with some libraries such as SVML (e.g. SIMD sin and exp) and MKL which some code might need. Other compilers can be used with SVML if you have it installed separately.
In short, it's worth trying with other compilers, especially if you understand why something says it needs to be compiled by ICC, if getting ICC would be inconvenient. But you might (or might not) be missing out on performance for packages that detect what's available instead of just erroring.
for non commercial use you can download it from Intel
EDIT:
the IntelĀ® System Studio 2016 includes a c++ compiler.
I've tried the 32-bit version of it, the non-commecial one. I don't think it differ from the 32-bit on basic stuff related to installation. Open this and go to compilers and libraries section and you will see the C/C++ compiler. After download it read the files in doc folder; it includes how to install/use/get a key to compiler etc.
You need to install gcc compiler through apt-get install gcc
Look on example here: Install GCC

does c++11 programs work on any CPU?

note:before down vote or anything like this,this is a general question to understand more how everything is going
the question simply is:
assume I compiled a program with c++11 features (using VS2012 on windows) is there a guarantee that this program will run on older processors?(like core 2 duo;as most laptops got this)
I'm currently working with VS2010,but found libraries that needs C++11 features.
so I want to port the whole work to VS2012,but my knowledge is limited about how this gonna work
correct anything wrong in the question
edit:
another 2 questions:
1 -can I "mix" a compiled c++11 program with older one?
like calling functions which are inside the new version (.dll) from an old version(.exe) so I got 2 files:
1 is compiled with VS2010 the other 1 is compiled with VS2012,with DLL EXPORT can they work like that?
2 -suggest a better environment than VS2012 for windows
As long as the architecture for which the target is built is the same (x86 for 32 bits or amd64 for 64 bits) you shouldn't have any issue.
Of course you will need to provide the older machine with the correct runtime library to run your program (for the current architecture).
Yes, The compiler requires additional libraries to build the program. But this shouldn't affect the ability to run on older processors. The only time this changes is when your trying to run a 64 bit program on a 32 bit processor.
Porting to VS2012 is simple, open the solution in VS2012, and save it as a vs2012 solution. It should all be fine.
Edit: odds are, if your new to programming, all of your programs are compiled for 32 bit processors by default unless you code to change this, so you shouldn't worry. You can run 32 bit programs on 64 bit processors, just not the other way around. If you really want to step it up, you can make a program that can run on both processors ;)
given a compiled executable the usual requirements to run it are:
ABI
platform
libraries
and since Windows is a commercial product, depending on what are you doing, you could add another factor
environment
which means that sometimes a software house intentionally breaks the compatibility with other products to sell more stuff.
In general VS it's not that good, certainly it's not the best the compiler I have ever used and basically anything from GCC to Clang to MinGW can supersede VS easily, but VS it's the official compiler and environment for Windows so this is what you have to deal with most of the time.
If you have fulfilled the listed requirements you are good to go.
By the way a Core 2 Duo it's not that old, and the actual iCore generation it's not that different either.

Developing C++ applications to run on embedded Linux setup

I am required to write a C++ application to run on an embedded Linux setup (DMP Vortex86DX processor). The vendor provides a minimal linux installation image that can be installed to the board and contains appropriate hardware drivers. My question is motivated by the answer to my previous question about writing Linux software on a particular kernel to run on a different kernel . I don't really know where to start when it comes to writing the software with regards to ensuring compatibility.
My instinctive approach would be to install the same versions of g++ on the embedded device and on my desktop development machine, write the application on the dev maching, copy to the board and compile it there. This seems madness though and I find it hard to believe that this is how embedded software is developed. With regards to the answer to my previous question, is there a way I can simply build on my desktop but use the version of glibc that exists on the embedded device - if so how can enforce linkage to a specific version? Or is it possible to build everything statically so that the application doesn't link to anything dynamically (I doubt this is possible).
I am a total novice to embedded development, and foresee months of frustration unless I can get hold of some good advice or resources. Any pointers or suggestion of where to start will be very gratefully received no matter how simple or trivial they seem - I really am starting at the very bottom with regards to embedded stuff.
OK, given the fact that the Vortex86SX/DX/MX claims to be x86 compatible, a small set of compiler switches should enable you to compile code for your target machine: -m32 to ensure 32bit code, and no -march switch targeting a specific CPU.
Then you'll need to link your code. As long as you don't use anything fancy, but simple established glibc functions, I'd expect the ABI to be the same on your development machine and the embedded system. In other words, you compile against your host libraries, copy the binary to the embedded system, and it should simply run using the libraries available there.
If X-Linux were to use some other libc, like uclibc or similar, then you'd need a cross compiler on your host. I have little experience with Ubuntu in that regard, but I know that the sys-devel/crossdev package for Gentoo linux makes generation of cross-compilers very easy. This can be both for different architectures (not needed in your case) and different libraries (like e.g. uclibc).
I'd say simply give copying the binaries a try, and report back if you encounter any problems there.

How do I determine which C/C++ compiler to use?

I am trying to figure out which C/C++ compiler to use. I found this list of C/C++ compilers at Wikipedia:
http://en.wikipedia.org/wiki/List_of_compilers#C.2FC.2B.2B_compilers
I am fairly certain that I want to go with an open source compiler. I feel that if it is open source then it will be a more complete compiler since many programmer perspectives are used to make it better. Please tell me if you disagree.
I should mention that I plan on learning C/C++ mainly to program 2D/3D game applications that will be compatible with Windows, Linux, MAC and iPhone operating systems. I am currently using Windows Vista x64 OS.
First of all, IMHO as a beginner your development environment (IDE) matters a lot more than the compiler.
I think that people place too much emphasis on compiler choice early on. While it is not Java, C++ is meant to be portable.
If the program you're writing only works with specific compilers, you're probably doing the wrong thing or can work a little on making it more portable.
If you get to a point where compiler choice makes a significant performance impact for you, then you've already perfected everything else in your program and you're in a good state and you are also quite advanced in your abilities. We used to teach the differences between compilers at fairly advanced stages in the CS curriculum.
If you use a UNIX based machine (Linux, Mac, actual Linux), then pretty much GNU (g++) is the way to go and is fairly much standard. If it's good enough to compile your OS, it's probably good enough for you. On a mac you can use XCode as your IDE, and it interfaces well with g++. On Linux some people prefer command line tools, though you might like the Eclipse C++ support, it is much better today than it was 3-4 years ago.
Things on Windows are trickier. If you can afford it, have access to, or are eligible for one of the free editions (e.g., via a school), I think the Microsoft Visual C++ Environments (or whatever they are called now) are pretty good for learning and they are used in production. I think there's actually a lightweight visual studio now with an emphasis on C++ that could be a good start. If you don't, you can probably find a distribution of Eclipse that is specific for C++ and includes an implementation of the GNU compilers.
Use gcc and g++ while you're still learning these languages, a big enough task for now. If you need a specialized compiler down the road, you'll want to have much deeper understanding of the language and your problem domain to properly evaluate candidates.
I feel that if it is open source then it will be a more complete compiler since many programmer perspectives are used to make it better.
That's not necessarily true. You could also say that if you use Microsoft's compiler, it will be optimal for Windows, since Microsoft knows best how to optimize a compiler for Windows.
Microsoft has Visual C++ Express Edition which is free and ofcourse includes a nice IDE that's very well suited for Windows development.
But if you're interested in making portable software, look at GCC, which is the default compiler on Linux and which is also available on the Mac. (The iPhone works totally different and requires special tools that only run on Mac OS X). You can get GCC for Windows with Cygwin or MinGW.
Get the Visual Studio Express (easier and quicker IMO, to setup) and learn with it; when you think you know enough about C++ and how "things" work, you could start using something like QT or GCC (with cygwin) and learn to port to different platforms.
For windows u can use CodeBlocks I believe it uses gcc and its pretty user friendly
I strongly suggest going with MinGW.
It is:
Open-source
Available on all major platforms
Comes with standard Win32 headers and libraries
The key to writing portable C++ code is:
Use a cross-platform version control system (subversion is a great choice), because this makes it easier to
Compile and test your code on other platforms early and often

C++ code coverage tool for weird target platform

Anyone knows c++ code coverage tool usable under the following conditions:
Target platform is PowerPC CPU inside Nintendo WII dev.kit, that runs custom embedded OS. The only way to exchange data with the PC is to use custom proprietary API (sorry for my NDA).
Compiler is not Microsoft, not GCC, not even command line. Namely it's Metrowerks IDE (running on Windows, of course).
Thanks in advance!
Do you know about BullseyeCoverage. It is a commercial tool, which supports really big number of platforms and compilers. If you don't see you compiler you can write them an inquiry. I did not find the Metrowerks Compiler in the list.
Hope that helps,
Ovanes
See Cpp Test Coverage. This tool can be configured to collect data in embedded systems; you have to figure out how to export an array of bits from inside that system to an external file system, and if you can do that, it can show you precise test coverage.
Does the Metrowerks compiler have special syntax that is not ANSI standard?
My shop has been using a customized version of Covtool. Perhaps that could be ported to your environment.
I have used Cantata. It works with Metroworks. It instruments your code so your application will no run at full speed. You just need rewrite the IO functions so output happens using the custom proprietary API.