Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » 486 Emulator - Help to generate binary

This thread is locked; no one can reply to it. rss feed Print
486 Emulator - Help to generate binary
RmBeer2
Member #16,660
April 2017
avatar

I have programmed a 486 Emulator, with totally invented hardware. It interprets the basic bytecodes and it works very very well (although I suspect that it has some hidden bugs), it is still missing MMX, SSE and all the weird ones, but for the moment it is fine, I'll leave it for later.
This Emulator supports only 32 bits, I have built it following a basic guide of instructions.

I plan to use it to allow any programmer to create games and other programs using the C or C++ language (gcc/g++), although it is also possible to use ASM (as), it will be connected to the game server to consult certain information (users, players, scores, avatars, game/program resources, etc).
The programmer creates the binary file, uploads it to the server along with all datas, and then any user can download and play it online.

The problem is that I have not managed to get the gcc cross-compiling to create the pure plain binary file without format like ELF or PE.
May I ask them to create the necessary tools to compile the binary file?

At the moment I am creating a user interface using my own FS (fuse), so anyone can upload the game/program binary files directly and create their own client just by managing files and directories.

🌈🌈🌈 🌟 BlackRook WebSite (Only valid from my installer) 🌟 C/C++ 🌟 GNU/Linux 🌟 IceCream/Cornet 🌟 🌈🌈🌈

Rm Beer for Emperor 2021! Rm Beer for Ruinous Slave Drained 2022! Rm Beer for Traveler From The Future Warning Not To Enter In 2023! Rm Beer are building a travel machine for Go Back from 2023! Rm Beer in an apocalyptic world burning hordes of Zombies in 2024!

Rodolfo Lam
Member #16,045
August 2015

I don't know if this can be of any help, however it looks that you could use the guides available to make new GCC backends. I found this in the net for you:

Writing a GCC back end
Porting GCC Compiler
Anatomy of a Target Back End

You could also try with extracting the machine code from the generated *.o files. Kinda like using raw/flat binaries. I did this google search.

Again, I might be totally lost on this... It is definetly out of my league.

Good Luck with that!

Polybios
Member #12,293
October 2010

I briefly (!) dabbled with stuff like this many years ago (so take it with a grain of salt). Basically, I loaded and executed some simple ELF files. It's quite simple to write a loader for ELF if you don't need dynamic linking. The main advantage compared to flat binaries is that you can load them to any target address, but you need to process relocations when loading. I'd also strip all debug symbols before loading them at first (but you could even make use of them later...).

I'd recommend starting with a simple binary without a standard lib ("freestanding"). For compiling C files with GCC, the options -ffreestanding -fno-builtin -fno-stack-protector might be relevant.
For creating the ELF files I used ld with the option -nostdlib and a linker script. The crucial part here is SECTIONS (e.g. text, data, rodata, bss) where you specify the memory layout. This would also have to be done for producing raw binaries.

If you want a working C std lib, things become a little more complex, since you need to implement syscalls, e.g. for malloc / heap management to work, you typically need some variant of "sbrk". Basically, you need a kernel of some sort. As I understand, you aim for flat binaries to be loaded like it was a kind of ROM cartridge? So you'd probably need to link your kernel layer into every binary. Of course, you could also provide a minimal kernel that your adapted C std lib can call or you could even use dynamic linking for that, too.

Producing raw binary files is possible with ld, too, here are some hints:
https://stackoverflow.com/questions/25442242/how-do-i-produce-plain-binary-from-object-files

Here are some related resources that might be interesting:
https://wiki.osdev.org/Bare_Bones
https://wiki.osdev.org/C_Library

Edit: Forgot the first important step: you'll need to build a cross-compiler that can compile to a generic i486 target. Some advice about that here:
https://wiki.osdev.org/Why_do_I_need_a_Cross_Compiler
https://wiki.osdev.org/GCC_Cross-Compiler

Arthur Kalliokoski
Second in Command
February 2005
avatar

RmBeer2 said:

a 486 Emulator, with totally invented hardware. It interprets the basic bytecodes and it works very very well (although I suspect that it has some hidden bugs), it is still missing MMX, SSE and all the weird ones

MMX didn't come out until a couple of revs of the Pentium 1, SSE didn't come out until the Pentium 3.

They all watch too much MSNBC... they get ideas.

Chris Katko
Member #1,881
January 2002
avatar

If you haven't commited yet, implement 386 first.

486 has lots more opcodes and modes.

Ignore pentium opcodes unless you plan on supporting Windows. :D Because there's "almost" zero pentium games for DOS. Quake 1. Many games had a pentium option (Tyrain) but meh.

-----sig:
β€œPrograms should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Arthur Kalliokoski
Second in Command
February 2005
avatar

Because there's "almost" zero pentium games for DOS. Quake 1.

Actually I used to run the Quake 1 shareware episode on a 486, but it only got maybe 8 frames per second at the lowest resolution. I think the actual requirement was a real '87 chip.

They all watch too much MSNBC... they get ideas.

Chris Katko
Member #1,881
January 2002
avatar

Quake 1 doesn't require a pentium but it's ... pretty much required. John Carmack got "big" into the fact the Pentium chip had two pipelines. The integer and floating point pipelines were separate, so he coded the entire game micro optimized around that fact.

Playing on a 486 "works" but is, as you've seen, dog crap slow because the 486 doesn't have two pipelines and every float basically explodes the timing.

I can't remember the source but it's burned into my memory. It might have been the Joe Rogan podcast interview, but it seems like that would have been far over Joe's head.

Fun fact: The fact that non-Intels had very poor floating point performance basically killed all competiting brands of 486's. (RIP Cyrix)

Quote:

John Carmack: The floating-point issue has really hurt them. We had
AMD and Cyrix down here while we were developing Quake, and we said,
”Look, floating point’s going to be important,” but because there weren’t
any benchmarks or any applications they’d used at that time, they brushed
it under the rug.
AMD and Cyrix both have non-pipeline FPUs, which is their Achilles’
heel. In terms of integer performance a lot of them are on par or, even
in some cases, better than Intel, but we optimize for Intel because the
Pentium’s got the FXCH change trick to pipeline all these things. And
it’s pretty tweaky but it pervades all of our assembly language code for
Quake.

[the link is broken but I could still download it. so I'll just post the PDF as an attachment]

I think the "FXCH trick" is the one that requires a pentium to load essentially two instruction streams [integer + float, "I and U" or "I and V" pipelines] at once.

https://books.google.com/books?id=Q1zSIarI8xoC&pg=PA91&lpg=PA91&dq=FXCH+pentium+trick&source=bl&ots=qs6zBLhRql&sig=ACfU3U3juTJ906s1haqLwRWv0J-fyiUfEA&hl=en&sa=X&ved=2ahUKEwiKpPW-9uPpAhWC4J4KHZLWCPwQ6AEwAHoECAoQAQ#v=onepage&q=FXCH%20pentium%20trick&f=false

[1]

-----sig:
β€œPrograms should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

RmBeer2
Member #16,660
April 2017
avatar

There are interesting documentations. But it wasn't what I was really asking for, I was letting you create the tools to create the necessary binary. After all, they are interested in making a game.

If this is not possible. Maybe later I'll do an ELF to pure binary converter.

In a few days I will release the basic header along with the interrupt guide.

=============================
At that time, using 'float' meant throwing your game away and in no way represented a competition.
Always used integers, arranged numbers (two integers, one for the integer and the other for the decimal), or arranged vectors. They were the only way to optimize, especially in 3D games.

🌈🌈🌈 🌟 BlackRook WebSite (Only valid from my installer) 🌟 C/C++ 🌟 GNU/Linux 🌟 IceCream/Cornet 🌟 🌈🌈🌈

Rm Beer for Emperor 2021! Rm Beer for Ruinous Slave Drained 2022! Rm Beer for Traveler From The Future Warning Not To Enter In 2023! Rm Beer are building a travel machine for Go Back from 2023! Rm Beer in an apocalyptic world burning hordes of Zombies in 2024!

Polybios
Member #12,293
October 2010

RmBeer2 said:

But it wasn't what I was really asking for, I was letting you create the tools to create the necessary binary. After all, they are interested in making a game.

I don't really get what you are asking. So who is "you" and "they" here?

RmBeer2
Member #16,660
April 2017
avatar

How I'm to know? there are no exact translations, especially with personal pronouns.

you == they, or "you+they" what's "tu+ellos" in "ustedes" from spanish, that "ustedes" not have translation.

also google translator confuse "I" with "you".

EDIT ==========================

I also understand that "ustedes" is a more polite way of referring to someone, which is also lost.

🌈🌈🌈 🌟 BlackRook WebSite (Only valid from my installer) 🌟 C/C++ 🌟 GNU/Linux 🌟 IceCream/Cornet 🌟 🌈🌈🌈

Rm Beer for Emperor 2021! Rm Beer for Ruinous Slave Drained 2022! Rm Beer for Traveler From The Future Warning Not To Enter In 2023! Rm Beer are building a travel machine for Go Back from 2023! Rm Beer in an apocalyptic world burning hordes of Zombies in 2024!

DanielH
Member #934
January 2001
avatar

Clearing confusion: :)

RmBeer2: he wasn't asking for translations but what "I" and "they" represent
Polybios: It was in the original post so maybe you just missed it.

"I" refers to RmBeer2
"You" or "They" refers to users who might use the emulator

bamccaig
Member #7,536
July 2006
avatar

RmBeer2
Member #16,660
April 2017
avatar

This is going to have to wait another week until I get something to talk about.

Still missing to be published. Even if it goes into production, it will still be like a demo, a beta far from being complete.

EDIT ============================

I have decided to leave FS and continue with the client of the terminal. What I want is to focus on what matters most and finish with the Emulator to be used by everyone. For several days I have also been diverted by ffmpeg. This only involves delays.

🌈🌈🌈 🌟 BlackRook WebSite (Only valid from my installer) 🌟 C/C++ 🌟 GNU/Linux 🌟 IceCream/Cornet 🌟 🌈🌈🌈

Rm Beer for Emperor 2021! Rm Beer for Ruinous Slave Drained 2022! Rm Beer for Traveler From The Future Warning Not To Enter In 2023! Rm Beer are building a travel machine for Go Back from 2023! Rm Beer in an apocalyptic world burning hordes of Zombies in 2024!

Go to: