3

Just out of curiosity I'm fiddling around with some demoscene 256 byte intros. I came around one production which ran fine under MS-DOS 6.22 but crashes under FreeDOS 1.3 - "sometimes". It turned out that it ran fine when executed after some other small intro but crashed when it was the first application started after booting. Both used FPU code for generation of cosine tables.

Lengthy disassembly and investigation turned out that the "good" intro was using the FINIT instruction as documented here

https://c9x.me/x86/html/file_module_x86_id_97.html

which was missing in the "bad" intro. Including the FINIT instruction and reassembly with TASM 2.0 resolved the issue (which somehow made me proud of accepting to start the rather extensive journey).

Now my question is - was it expected that under DOS every application did a proper initialization of the FPU with the instructions mentioned above? If so, why did I not encounter problems on MS-DOS but only on FreeDOS? Is this some unspecified behaviour and I have just been lucky in the past or is something documented about this regarding MS-DOS and FreeDOS?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Codor
  • 17,447
  • 9
  • 29
  • 56
  • Quite honestly I've never seen a DOS program do `FINIT`. Sounds like a strange issue. – fuz Jan 10 '22 at 19:20
  • 1
    Perhaps some other program left the x87 stack non-empty? Does DOS itself not `finit` between programs to make sure programs start with a fresh FP environment? (@fuz). I guess that could depend on the specific DOS kernel, e.g. FreeDOS vs. MS-DOS? – Peter Cordes Jan 10 '22 at 21:27
  • 1
    Hmm… it seems to be an issue under FreeDOS on one particular notebook. Strange. I mean this is just hobby stuff and not production code (in fact it is not even my own code), but still I would like to clarify it. – Codor Jan 10 '22 at 21:32
  • @PeterCordes It would surprise me if DOS did an `finit`, but it could be. The BIOS certainly should. – fuz Jan 10 '22 at 22:52
  • Did DOS even _assume_ a FPU? Or was it like sound cards something that DOS left entirely to programs? In other words, DOS might not _have_ expectations. – MSalters Jan 10 '22 at 23:05
  • @MSalters DOS is aware of the FPU (e.g. DEBUG can assemble and disassemble FP instructions) but does not use it as far as I'm concerned. – fuz Jan 10 '22 at 23:19
  • Only hit for `FINIT` in [MS-DOS 2.0](https://github.com/microsoft/MS-DOS) is in DEBUG, so at least at that point, you couldn't rely on DOS to do it for you. (I'm not sure that it even bothered to detect if there was an FPU, so it might not even know whether it could safely execute FINIT at all. To @MSalters' point, for almost all of MS-DOS's lifetime, nearly every user would have had a computer for which an FPU was at best an optional add-on, so it certainly couldn't *assume* one.) – Nate Eldredge Jan 11 '22 at 05:47
  • @NateEldredge If there is no FPU, `FINIT` should still be safe to execute. It just doesn't do anything. – fuz Feb 12 '22 at 20:46

0 Answers0