Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full implementation of aditional 8086 compatibility mode #34

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

humbertocsjr
Copy link

@humbertocsjr humbertocsjr commented Sep 17, 2022

My code is based on Pull request 33 from aleexmaftei.

Changes:

  • Implementation of "-8086" flag on smlrc and smlrcc
  • Implementation of macro __SMALLER_C_8086__, setted by "-8086" flag
  • This new flag can be used with 32-bit modes, but generate bigger code without 386 otimizations on 16 bits.
  • Create a alternative lcds.a library with 8086 code only, named lcds86.a
  • When "-8086" and "-tiny"/"-dost" flags active, use new "lcds86.a" instead "lcds.a"
  • Creation of "Use8086InstrOnly" global variable on smlrc and smlrcc, setted by "-8086" flag
  • When activated change generation of (MOVZX, MOVSX, Bit operations, SETxx instructions, etc) to 8086 compatible equivalents.

@humbertocsjr humbertocsjr changed the title Full implementation of aditional 8086 compatiblitily mode Full implementation of aditional 8086 compatibility mode Sep 17, 2022
@humbertocsjr
Copy link
Author

I fixed the code errors that prevented it from compiling.

Now I've split CodeGen from the 8086 into a separate executable, and compressed the code enough so that it generates an smlrc using -doss exe

@humbertocsjr
Copy link
Author

Usage of my modifications:

smlrcc -8086 -doss -o hw.exe hw.c

generate executable compatible with Intel 8086

If omit -8086 flag, compiler will ignore all my modifications, generating 386 code in 16 Bits

@humbertocsjr
Copy link
Author

SMLRC86 in DOS Small and DOS Huge, has a limitation (only compiles with NO_EXTRAS flag)

v0100/smlrc.c Outdated
@@ -2886,7 +2890,7 @@ int exprUnary(int tok, int* gotUnary, int commaSeparator, int argOfSizeOf)
{
tok = GetToken();
tok = expr(tok, gotUnary, 0);
if (!*gotUnary)
if (!*gotUnary || tok != ']')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change ended up in the final Commit, it was part of a unification test with the next IF, to decrease the final size of the executable, can be restored to the previous state.

@alexfru
Copy link
Owner

alexfru commented Jul 29, 2023

Now I've split CodeGen from the 8086 into a separate executable, and compressed the code enough so that it generates an smlrc using -doss exe

Such a smlrc isn't any more useful than the full one that uses 80386 instructions/registers and supports 32-bit types.
At least, it's not any more useful alone. The rest of the binaries, e.g. the linker (smlrl) and assembler (nasm), would need to be 16-bit too so they can run on the purely 16-bit 8086 CPU. Right?

@humbertocsjr
Copy link
Author

Now I've split CodeGen from the 8086 into a separate executable, and compressed the code enough so that it generates an smlrc using -doss exe

Such a smlrc isn't any more useful than the full one that uses 80386 instructions/registers and supports 32-bit types. At least, it's not any more useful alone. The rest of the binaries, e.g. the linker (smlrl) and assembler (nasm), would need to be 16-bit too so they can run on the purely 16-bit 8086 CPU. Right?

I just made this compaction to keep the "-doss" version compilable, I also think I find it unnecessary if you think we can discard a "-doss" version of the compiler, I can return the 8086 code generator code for a version more readable, I intend to gradually implement the 32-bit calculation in 8086, once again it will generate a much larger code than pure 32-bit equivalent, but it will be an alternative for those who want to compile the 8086/8088 as a target.

- Clean 8086 CodeGen code
- Remove irrelevant code from 8086
- Update base code from current main project
- Fix 8086 bugs
@humbertocsjr
Copy link
Author

I cleaned up the 8086 code, and removed all the unnecessary extensions I had made to fit the compiler into the small model. I updated the code base to the most recent one from your project, for now the only output that this CodeGen generates is Tiny and Small, I'm seeing how I will implement a version of Large with multi segments for future versions.

@humbertocsjr humbertocsjr reopened this May 10, 2024
- Remove shortcuts for Small Model version of compiler
- Changed the names of cg8086 constants
- Added error when trying to compile 8086 in unsupported formats
@humbertocsjr
Copy link
Author

I corrected the naming of the constants to be compatible with the format you use in other CodeGen, I added an error when trying to use OutputFormat incompatible with the -8086 flag, avoiding misuse, I imagine the code is now ready for production. I'm going to start a new branch to test 32-bit integer calculations using 16-bit commands and pointers with segments, I want to do it in a way that uses only CodeGen and not have to change the syntax (I don't intend to add the "far" modifier or do anything different, at most add the MK_FP macro used in old Turbo C/Microsoft C to set the segment).
But the 16-bit integer code is ready.

…nd of Heap

- Add (optional) custom Heap+Stack configuration on Small DOS EXE, generating really small footprint for limited environvments (HP 95LX or IBM PC with < 256K RAM)
@humbertocsjr humbertocsjr requested a review from alexfru May 13, 2024 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants