X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f X-Recipient: djgpp AT delorie DOT com X-Original-DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=nMkoXvZqrWJCANkTEFu9sKVv+sBtex8yJ4jUaSSilMw=; b=g+gwU2E05VAYnkAMp112 ZKTww3esDklLq9d2nNH9gwDjzcV3fd5pYY8jdRWe+Z23uNtorJFqG67CnL8APRNwQe3wqdIGz2g2v YZyslerO0I/EOHoEm79Gy7Wk7TQGOuoQM1OfAQABdjNk41Hrb3EhaA3Xtb1JnyheRcfFKPCCsRCfJ 7UUlncmeu9fi7TPwOINQ6sN5lVFuZCffSwRg3qm2TPk7lJx/YmHMtuhJh0mrj4inbtHK7cT6Rs5OH DrVZOlv07tyrvL6p3Pzdb+arqgdrOVlW2ZGeM/1bwnLx0Xf0WEAk18NBbvkAcpeZukCvdg7pIUUEe k1tgL/Gk5XE6uA==; Date: Sat, 24 Feb 2024 09:02:23 +0200 Message-Id: <86y1baz6o0.fsf@gnu.org> From: "Eli Zaretskii (eliz AT gnu DOT org) [via djgpp AT delorie DOT com]" To: djgpp AT delorie DOT com In-Reply-To: (djgpp AT delorie DOT com) Subject: Re: checking int2d amis appstring with djgpp References: MIME-version: 1.0 Content-type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Reply-To: djgpp AT delorie DOT com > From: "Ozkan Sezer (sezeroz AT gmail DOT com) [via djgpp AT delorie DOT com]" > Date: Sat, 24 Feb 2024 03:08:59 +0300 > > On Sat, Feb 24, 2024 at 12:49 AM J.W. Jagersma (jwjagersma AT gmail DOT com) > [via djgpp AT delorie DOT com] wrote: > [...] > > > __asm__ __volatile__ ("movw %%dx,%0":"=m"(addr.segment)); > > > __asm__ __volatile__ ("movw %%di,%0":"=m"(addr.offset16)); > > > > This doesn't look right - you can't assume gcc preserves registers > > between asm blocks. > > OK, should have been like this then, yes? It is better to avoid inline assembly at all. I'm guessing Watcom did that for speed or something, but does speed really matter here? > Is the following correct ?? > > int sndlib_sbemu_detect(void) > { > __dpmi_raddr addr; > uint32_t r_addr; > __dpmi_regs regs; > char* appstring; > int mx; > > /* check for INT2D vector == NULL */ > __dpmi_get_real_mode_interrupt_vector(0x2D, &addr); > r_addr = ((uint32_t)addr.segment<<4) + (uint32_t)addr.offset16; > if (!r_addr) return -1; Instead of the above bit juggling to get r_addr, you could simply test both segment and offset to be zero. After all, how else you'd get zero in the linear address? > /* scan all multiplexes of INT 2D */ > for (mx = 0; mx < 256; mx++) > { > memset(®s, 0, sizeof(regs)); > regs.h.ah = mx; > __dpmi_int(0x2D, ®s); > if (regs.h.al != 0xFF) > continue; > > /* check for SBEMU application string */ > r_addr = ((uint32_t)regs.x.dx<<4) + (uint32_t)regs.x.di; > if (!r_addr) continue; > appstring = (char *)real2ptr(r_addr); > if (memcmp(appstring + 8,"SBEMU",5) == 0) > return mx; You cannot access conventional (below 1MB) memory like that. You need to use one of the techniques described in the node "Xfer" in the DJGPPFAQ Info manual, to fetch the 5 bytes to protected-mode memory first. In your case, _dosmemget seems to be the best method.