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; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708724928; x=1709329728; darn=delorie.com; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=e0Ktp+9E++OoQqhXFHbWndevyPgGcMu82cA7yfsOg3c=; b=nO2+rkMOWQclposCildwoN/zWfgavfDtjKHub4+e5tzsvIAi6xO26aUtrKnmWFQlL6 KmGsIEQJN1CvjeGYEQdht4o6CJAP1NLE2z/dPMHRlwwECVuwNN8zrNEwjb5ha2Up0090 OvxP8hBAWTQRKU7oWEMqJp3L5BzBrh32am041vKnkBHERV7AHDGZsf0c6X6IqHFO4+Oy xngs5pPBJyBAFsao1cIpeLGpTy6T9blr7m2ifyYC1hKro/ZvEHcsxPievy2Pt5OIHuzw nmOXTG3pIxZuz5HWCHxpzyxckY4k2AH21HePhrBIKi98NVi7qrzvo5tCEPmrGk+Qt7Ts NGcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708724928; x=1709329728; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=e0Ktp+9E++OoQqhXFHbWndevyPgGcMu82cA7yfsOg3c=; b=q08JklzCAr2JrrmpQEl2IYg98v6lzmQET5fAY0dGyO0H+wlIZSGv4ibZO1qH4qnqJ3 LFIrFX7WrKneuHaxO2B3zEIF7Oce36cgYjQ606adJBzBEAM6kpxch9Fe5I+WlsBxiTrT EYjvBRL/01AEHQD1co/3ZibY9CBHfgJCmhPomSCFUdZdcRqOF6KiHquCKW52C0Vwyizx Fx7Ib6y5phB2vqTCF9/bV5VeGf0Kkw1kJQ7yL1kJivUffw6cExoRpiqqk6gMpIp6EF96 5GI0HsB9OSVfSXEFwLmyKaAm6vwTcW+VOJS7mt7QnDcQxfaAzmZlqSyYpzpqdDEC1q9u 09EQ== X-Gm-Message-State: AOJu0YyVaaF0OAXd6fS7cbou6RMwlGfiow9YyLqk+EmNUwcGomWqLRb0 0ond7NLjYZBPLR8GR4MHn7TBc9dObkvc/RgzTIVasu69WVT7IqLRUKWv5fhM X-Google-Smtp-Source: AGHT+IHvP5h4CU2rrCnnEscOPYV2DYZIi18Sl9na2xm1USz6CrGTSFmb9/s5ya6TCA8ifEDcY8GfOQ== X-Received: by 2002:a17:906:f80d:b0:a3f:4ec0:128e with SMTP id kh13-20020a170906f80d00b00a3f4ec0128emr613306ejb.13.1708724928044; Fri, 23 Feb 2024 13:48:48 -0800 (PST) Message-ID: Date: Fri, 23 Feb 2024 22:48:47 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: checking int2d amis appstring with djgpp To: djgpp AT delorie DOT com References: Content-Language: en-US From: "J.W. Jagersma (jwjagersma AT gmail DOT com) [via djgpp AT delorie DOT com]" In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk Hi! On 2024-02-23 22:11, Ozkan Sezer (sezeroz AT gmail DOT com) [via djgpp AT delorie DOT com] wrote: > Hi everyone: > > Does the following DJGPP port of SBEMU detection look correct? > It is an adaptation from a WatcomC (32 bit flat) code in here: > https://github.com/wbcbz7/sndlib-watcom/blob/master/sndlib.cpp#L41-L71 > > (I'm fairly rusty in gcc inline asm and djgpp address mapping, etc, > thanks in advance.) > > int sndlib_sbemu_detect(void) > { > __dpmi_raddr addr; > uint32_t r_addr; > 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; > > /* scan all multiplexes of INT 2D */ > for (mx = 0; mx < 256; mx++) > { > __asm__ __volatile__ ("movb %0,%%ah"::"m"(mx)); > __asm__ __volatile__ ( > "xorb %al, %al\n" > "int $0x2d\n" > "cmpb $0xFF, %al\n" /* is this a free multiplex? */ > "jz _found\n" > "xorw %dx, %dx\n" /* it is, return NULL pointer */ > "xorw %di, %di\n" > "_found:\n"); > __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. But this is a real-mode interrupt, no? So you would have to do it via __dpmi_int() here anyway, no asm involved. > > /* check for SBEMU application string */ > r_addr = ((uint32_t)addr.segment<<4) + (uint32_t)addr.offset16; > if (!r_addr) continue; > appstring = (char *)real2ptr(r_addr); > if (memcmp(appstring + 8,"SBEMU",5) == 0) > return mx; > } > > return -1; > } > > > P.S.: real2ptr() in there actually returns > (void *) (real += __djgpp_conventional_base) > after a successful __djgpp_nearptr_enable() > > -- > O.S.