tkchia / gcc-ia16

Fork of Lambertsen & Jenner (& al.)'s IA-16 (Intel 16-bit x86) port of GNU compilers ― added far pointers & more • use https://github.com/tkchia/build-ia16 to build • Ubuntu binaries at https://launchpad.net/%7Etkchia/+archive/ubuntu/build-ia16/ • DJGPP/MS-DOS binaries at https://gitlab.com/tkchia/build-ia16/-/releases • mirror of https://gitlab.com/tkchia/gcc-ia16
GNU General Public License v2.0
174 stars 13 forks source link

Custom memory layout for tiny model TSR #81

Open andrewbird opened 3 years ago

andrewbird commented 3 years ago

I'm looking at getting gcc-ia16 to cross compile the share.com TSR for FreeDOS. Currently the only compiler capable of building it is Turbo C 2.01. I've had some initial success with GCC using a local keep() function, see https://github.com/andrewbird/share/commit/b94094af4b5bed6efbafb6ee10a38106f7cadfb8 however the original code does some tricks to throw away the initialisation code and shrink the resident memory size. I'm wondering if I could achieve something similar or better using a custom linker script? From what I see in the memory map file, gcc-ia16 lays out the startup code, init and fini before the text of the program and consequently would still be included in the resident memory at TSR. I think that ideally I'd want something like this for tiny model .COM

(jump to real startup code)
(resident text section)
(resident data section)
        < some way of determining this point to use as the size to retain in the keep() function >
(normal startup code)
(usual init code)
(usual fini code)
(transient text section)
(transient data section)

I've never had cause to write a linker script before, so I am a complete novice. Is this sort of control possible? Is there a better solution?

Also I'm using this command line, how would I replicate that as separate compile / link ops?

ia16-elf-gcc -Wall -fpack-struct -fno-toplevel-reorder -mcmodel=tiny -o $@ $< -li86 -Wl,-Map=share.map
andrewbird commented 1 year ago

Hello @tkchia, Oh good, I'm really glad there actually was something wrong, I'll check it out when the newlib update happens to PPA.

Anyway, for flat .com files, load addresses are used for their "original" purpose

Ahh, then I guess that's why the .map file gave some odd symbol addresses when loaded into dosdebug. I wrote the parsing / interpretation there to suit the FreeDOS kernel scheme. I don't suppose there's an easy way to detect the difference though?

Thank you so very much for the very prompt fix!

andrewbird commented 1 year ago

Hello @tkchia, The PPA has updated now and my share initialisation problem seems to have gone!

Thank you!