From: Rymfax on
Hello,

I'm attempting to create a 16-bit C++ DOS application that can look at
the CPUID (if its present) and check the APIC() bit in the features to
see if the Processor can handle APIC. I have Win32 C++ code that does
this already, but the Borland C++ 5.0.2 compiler I'm using to make the
DOS app doesn't like the code that in the _asm block. So I'm trying
to just make a .ASM file with the needed code in it that just returns
a 0 if APIC is enabled and -1 if it's not.

I'm not having ANY success with this. I've got some code that shows
how to check if the CPUID is present, but every attempt I've made at
converting it to do what I need has failed horribly. This is mostly
because I know nothing about Assembly and am trying to learn as I go.

Could someone please post some code that will do what I've described
above. I would be MOST appreciative.

TIA!

Chris
From: Rod Pemberton on

"Rymfax" <cwalker(a)bigbangllc.com> wrote in message
news:480dc03d-7a6b-46f9-8089-ce1f086a5809(a)o6g2000hsd.googlegroups.com...
> Hello,
>
> I'm attempting to create a 16-bit C++ DOS application that can look at
> the CPUID (if its present) and check the APIC() bit in the features to
> see if the Processor can handle APIC. I have Win32 C++ code that does
> this already, but the Borland C++ 5.0.2 compiler I'm using to make the
> DOS app doesn't like the code that in the _asm block. So I'm trying
> to just make a .ASM file with the needed code in it that just returns
> a 0 if APIC is enabled and -1 if it's not.
>
> I'm not having ANY success with this. I've got some code that shows
> how to check if the CPUID is present, but every attempt I've made at
> converting it to do what I need has failed horribly. This is mostly
> because I know nothing about Assembly and am trying to learn as I go.
>
> Could someone please post some code that will do what I've described
> above. I would be MOST appreciative.
>

Note that cpuid uses 32-bit registers and you want 16-bit code. That means
mixing 32-bit and 16-bit code. The basic 16-bit code for NASM should be
close to this code below (untested). I compiled the NASM code for .obj and
disassembled with OpenWatcom's WDIS and the code is the same. (WDIS is their
disassembler for WASM which is TASM like).

; insert code to only execute if pentium or later
push bx
push cx
push dx
xor eax,eax ; must be eax for cpuid input
inc al ; set eax to one
cpuid
and dh,02h ; APIC status in bit 9 of edx/dx, bit 2 of dh
cmp dh,byte 1 ; set carry for 0 (no APIC)
sbb ax,ax ; -1 (no APIC) or 0
pop dx
pop cx
pop bx

If Borland doesn't assemble the 'xor eax,eax' sequence for 16-bit, you
should be able to simulate it with 'db 066h' and 'xor ax,ax'.


Rod Pemberton

From: Rymfax on
On Dec 5, 2:24 pm, "Rod Pemberton" <do_not_h...(a)nohavenot.cmm> wrote:
> "Rymfax" <cwal...(a)bigbangllc.com> wrote in message
>
> news:480dc03d-7a6b-46f9-8089-ce1f086a5809(a)o6g2000hsd.googlegroups.com...
>
>
>
>
>
> > Hello,
>
> > I'm attempting to create a 16-bit C++ DOS application that can look at
> > the CPUID (if its present) and check the APIC() bit in the features to
> > see if the Processor can handle APIC. I have Win32 C++ code that does
> > this already, but the Borland C++ 5.0.2 compiler I'm using to make the
> > DOS app doesn't like the code that in the _asm block. So I'm trying
> > to just make a .ASM file with the needed code in it that just returns
> > a 0 if APIC is enabled and -1 if it's not.
>
> > I'm not having ANY success with this. I've got some code that shows
> > how to check if the CPUID is present, but every attempt I've made at
> > converting it to do what I need has failed horribly. This is mostly
> > because I know nothing about Assembly and am trying to learn as I go.
>
> > Could someone please post some code that will do what I've described
> > above. I would be MOST appreciative.
>
> Note that cpuid uses 32-bit registers and you want 16-bit code. That means
> mixing 32-bit and 16-bit code. The basic 16-bit code for NASM should be
> close to this code below (untested). I compiled the NASM code for .obj and
> disassembled with OpenWatcom's WDIS and the code is the same. (WDIS is their
> disassembler for WASM which is TASM like).
>
> ; insert code to only execute if pentium or later
> push bx
> push cx
> push dx
> xor eax,eax ; must be eax for cpuid input
> inc al ; set eax to one
> cpuid
> and dh,02h ; APIC status in bit 9 of edx/dx, bit 2 of dh
> cmp dh,byte 1 ; set carry for 0 (no APIC)
> sbb ax,ax ; -1 (no APIC) or 0
> pop dx
> pop cx
> pop bx
>
> If Borland doesn't assemble the 'xor eax,eax' sequence for 16-bit, you
> should be able to simulate it with 'db 066h' and 'xor ax,ax'.
>
> Rod Pemberton- Hide quoted text -
>
> - Show quoted text -

Thanks you VERY much for the help, I REALLY appreicate it.

One more question for you please....You are correct that Borland
doesn't assemble eax, I'm getting a 'Undefined symbol' error for
'eax'. Could you explain in alittle greater detail how I should use
the db and xor to simulate? Is that two lines of code in place of the
other line?

Also, if it isn't too much trouble, could you put some comments on
each line so I know what that code is doing? That will go a long way
in helping me learn what's going on.

Again...thank you very, VERY much!
From: Rymfax on
On Dec 5, 2:59 pm, Rymfax <cwal...(a)bigbangllc.com> wrote:
> On Dec 5, 2:24 pm, "Rod Pemberton" <do_not_h...(a)nohavenot.cmm> wrote:
>
>
>
>
>
> > "Rymfax" <cwal...(a)bigbangllc.com> wrote in message
>
> >news:480dc03d-7a6b-46f9-8089-ce1f086a5809(a)o6g2000hsd.googlegroups.com...
>
> > > Hello,
>
> > > I'm attempting to create a 16-bit C++ DOS application that can look at
> > > the CPUID (if its present) and check the APIC() bit in the features to
> > > see if the Processor can handle APIC. I have Win32 C++ code that does
> > > this already, but the Borland C++ 5.0.2 compiler I'm using to make the
> > > DOS app doesn't like the code that in the _asm block. So I'm trying
> > > to just make a .ASM file with the needed code in it that just returns
> > > a 0 if APIC is enabled and -1 if it's not.
>
> > > I'm not having ANY success with this. I've got some code that shows
> > > how to check if the CPUID is present, but every attempt I've made at
> > > converting it to do what I need has failed horribly. This is mostly
> > > because I know nothing about Assembly and am trying to learn as I go.
>
> > > Could someone please post some code that will do what I've described
> > > above. I would be MOST appreciative.
>
> > Note that cpuid uses 32-bit registers and you want 16-bit code. That means
> > mixing 32-bit and 16-bit code. The basic 16-bit code for NASM should be
> > close to this code below (untested). I compiled the NASM code for .obj and
> > disassembled with OpenWatcom's WDIS and the code is the same. (WDIS is their
> > disassembler for WASM which is TASM like).
>
> > ; insert code to only execute if pentium or later
> > push bx
> > push cx
> > push dx
> > xor eax,eax ; must be eax for cpuid input
> > inc al ; set eax to one
> > cpuid
> > and dh,02h ; APIC status in bit 9 of edx/dx, bit 2 of dh
> > cmp dh,byte 1 ; set carry for 0 (no APIC)
> > sbb ax,ax ; -1 (no APIC) or 0
> > pop dx
> > pop cx
> > pop bx
>
> > If Borland doesn't assemble the 'xor eax,eax' sequence for 16-bit, you
> > should be able to simulate it with 'db 066h' and 'xor ax,ax'.
>
> > Rod Pemberton- Hide quoted text -
>
> > - Show quoted text -
>
> Thanks you VERY much for the help, I REALLY appreicate it.
>
> One more question for you please....You are correct that Borland
> doesn't assemble eax, I'm getting a 'Undefined symbol' error for
> 'eax'. Could you explain in alittle greater detail how I should use
> the db and xor to simulate? Is that two lines of code in place of the
> other line?
>
> Also, if it isn't too much trouble, could you put some comments on
> each line so I know what that code is doing? That will go a long way
> in helping me learn what's going on.
>
> Again...thank you very, VERY much!- Hide quoted text -
>
> - Show quoted text -

I put in those two lines (db and xor) to test and it seems to have
worked (meaning the error went away). However, I'm getting an error
on the 'cmp dh, byte 1' line that says 'Extra characters on line'.
What would be causing that?
From: Mike Gonta on
On Dec 5, 12:58 pm, Rymfax <cwal...(a)bigbangllc.com> wrote:

> I've got some code that shows how to check if the CPUID
> is present, but every attempt I've made at converting it to
> do what I need has failed horribly. This is mostly because
> I know nothing about Assembly and am trying to learn as I go.
>
>Could someone please post some code

; cpuid.asm
; original code by Mike Gonta, Public Domain 2007
; assemble with FASM, requires aeBIOS

use32
org 100000h
; 32 bit protected mode, high memory with
; full industry standard bios support

xor eax, eax
cpuid
mov [buffer], ebx
mov [buffer+4], edx
mov [buffer+8], ecx
mov esi, buffer ; zero terminated string
call print_string
mov eax, 1
cpuid
bt edx, 9
jnc .1
mov esi, apic_yes
jmp .2
..1:
mov esi, apic_no
..2:
call print_string
xor eax, eax
int 16h
int 20h

print_string:
pusha
mov ah, 0Eh
mov ebx, 0Fh
@@:
mov al, [esi]
lea esi, [esi+1]
test al, al
je @F
int 10h
jmp @B
@@:
popa
ret
buffer: db " ", 0Dh, 0Ah, 0
apic_yes: db "APIC present", 0
apic_no: db "APIC not present", 0


Mike Gonta

look and see - many look but few see

http://mikegonta.com/aeBIOS
 |  Next  |  Last
Pages: 1 2
Prev: Tasm IDE
Next: simple read char app return wrong value?