Revision | 204 (tree) |
---|---|
Time | 2020-12-26 17:50:37 |
Author | ![]() |
added low-level notes about DOS memory management
@@ -893,6 +893,17 @@ | ||
893 | 893 | int errflag; |
894 | 894 | #ifdef REALDOS |
895 | 895 | static char staticbuff[50 * 1024u]; /* can't have full 64K in a COM file, sorry */ |
896 | + /* DOS note: When DOS loads a COM file, it tries to find a 64K block of available | |
897 | + * memory, copies there the 256-bytes PSP followed by the COM file, sets CS=DS=SS to | |
898 | + * the segment where PSP starts, sets SP to 64K-2 and sets IP to 0x100. | |
899 | + * This means that 64K of memory is wasted anyway - so better filling it up | |
900 | + * with something useful (like the above buffer). The memory map produced by TCC | |
901 | + * might suggest something different, but examining the values held by _DS, _SS and | |
902 | + * _SP registers at runtime leaves no doubt. | |
903 | + * One could think that using an EXE instead would be more efficient, but my tests | |
904 | + * show that Turbo C 2.01 does not behave much differently when creating an EXE | |
905 | + * binary (checked under small memory model): only difference is that CS gets its | |
906 | + * own segment, but DS=SS still and SP is set at the end of the segment (65xxx). */ | |
896 | 907 | char far *ama = staticbuff; |
897 | 908 | #else |
898 | 909 | static char ama[65536u]; |