@@ -1106,6 +1106,14 @@ struct __attribute__((__packed__)) xmsmove {
11061106
11071107
11081108struct xmshandle xmshandles [AMOUNT_XMS_HANDLES ];
1109+ /* Handle 0 in the XMS interface is invalid
1110+ * because it refers to 86 Mode memory for
1111+ * the XMS move handling. Therefore, we check
1112+ * that handles are nonzero and then index
1113+ * into this array with handle number less one
1114+ * so that the first array entry corresponds
1115+ * to handle number 1 from the interface.
1116+ */
11091117
11101118uint8_t freexms (unsigned int ii , uint8_t force ) {
11111119 if (ii == 0 || ii > AMOUNT_XMS_HANDLES )
@@ -1204,7 +1212,7 @@ void callxms() {
12041212 uint64_t uu64 ;
12051213 void * pp ;
12061214 if (regs8 [FLAG_CF ]) { // CY, this is an XMS entrypoint call
1207- set_CF (0 );
1215+ set_CF (0 ); // signal that we support this
12081216#ifdef XMS_DEBUG
12091217 printf ("xms call ax=%04Xh dx=%04Xh bx=%04Xh\r\n" ,
12101218 regs16 [REG_AX ], regs16 [REG_DX ], regs16 [REG_BX ]);
@@ -1234,6 +1242,7 @@ void callxms() {
12341242 counter ++ ;
12351243 if (counter <= 1 ) {
12361244 set_CF (1 ); return ;
1245+ // signal failure to tinyxms
12371246 }
12381247 }
12391248#endif
@@ -1263,6 +1272,8 @@ void callxms() {
12631272 struct xmsmove * mm = (void * )mem + SEGREG (REG_DS , REG_SI , );
12641273 void * psource ;
12651274 void * pdest ;
1275+ // Odd lengths may be rejected with
1276+ // error code A7h but we support them.
12661277#ifdef XMS_DEBUG
12671278 printf ("xmsmove count=%u sourcehandle=%u sourceaddress=%08Xh"
12681279 " desthandle=%u destaddress=%08Xh\r\n" ,
@@ -1283,6 +1294,9 @@ void callxms() {
12831294 printf ("xmsmove psource=%08Xh pdest=%08Xh mem=%08Xh\r\n" ,
12841295 psource , pdest , mem );
12851296#endif
1297+ // memmove acts correctly even when memory overlaps.
1298+ // We are allowed to return error A8h if a backwards
1299+ // move is needed, but we may support it too.
12861300 memmove (pdest , psource , mm -> count );
12871301 returnxms (0 );
12881302 }
@@ -1324,6 +1338,7 @@ void callxms() {
13241338 uu64 <<= 10 ;
13251339 pp = realloc (xmshandles [regs16 [REG_DX ] - 1 ].allocation , uu64 );
13261340 if (!pp ) {
1341+ // original pointer in the handle still valid
13271342 returnxms (0xA0 );
13281343 break ;
13291344 }
@@ -1360,7 +1375,7 @@ void callxms() {
13601375 uu64 = 0xFFFF ; // maximum reportable
13611376 }
13621377 regs16 [REG_AX ] = uu64 ;
1363- set_CF (1 );
1378+ set_CF (1 ); // this means no error here
13641379 }
13651380 }
13661381}
0 commit comments