Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > alt.os.development > #8339
| From | "Benjamin David Lunt" <zfysz@fysnet.net> |
|---|---|
| Newsgroups | alt.os.development |
| Subject | Re: 64-bit detection |
| Date | 2015-07-10 10:52 -0700 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <mnp0ob$c64$4@speranza.aioe.org> (permalink) |
| References | <mnn174$dd$1@speranza.aioe.org> <op.x1jgivqzyfako5@localhost> <mnns78$v0t$1@dont-email.me> |
"James Harris" <james.harris.1@gmail.com> wrote in message
news:mnns78$v0t$1@dont-email.me...
>
> I didn't know either but found that there is a CPUID bit for it.
>
> CPUID[0x8000_0001].EDX[29]
>
> Almost by chance I found the following snippet in an AMD manual
> (24593-Rev. 3.23-May 2013).
>
For future reference and for those who might be looking for the
same answer, here is my code to check for a 64-bit machine.
// Use CPUID to determine if the processor supports long mode:
// reference:
// - AMD manual (24593-Rev. 3.25-June 2015)
// http://support.amd.com/TechDocs/24593.pdf
// - Intel manual Vol 3C, page 34-6, section 34.4.1.1
// (325384-055US, June 2015)
// "Support for Intel 64 architecture is reported by:
// CPUID.80000001:EDX[29] = 1"
// - Intel manual Vol 2A, page 3-186, Table 3-17
// (253666-055US, June 2015)
_naked bool is_64bit_cpu() {
_asm (
" mov eax,80000000h ; Get highest extended function\n"
" cpuid ; \n"
" cmp eax,80000001h ; is at least 80000001h allowed?\n"
" jb short @f ; If not, long mode not support\n"
" mov eax,80000001h ; Get extended function 8000001h flags\n"
" cpuid ; EDX = extended-features flags\n"
" bt edx,29 ; If bit 29 is set, long mode is
supported\n"
" jnc short @f ; \n"
" mov eax,1 ; return TRUE\n"
" ret ; we're done\n"
"@@: ; \n"
" xor eax,eax ; return FALSE\n"
" ret ; we're done\n"
);
}
Notes:
- I use Alex's SmallerC to compile this to .asm
https://github.com/alexfru/SmallerC
- Then I use my NBASM to assemble to binary
http://www.fysnet.net/newbasic.htm
- The _naked keyword tells SmallerC not to include
the epilog and prolog (an addition I made to SmallerC)
Thanks guys for your comments.
Ben
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Forever Young Software
http://www.fysnet.net/index.htm
http://www.fysnet.net/osdesign_book_series.htm
To reply by email, please remove the zzzzzz's
Batteries not included, some Assembly required.
Back to alt.os.development | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
64-bit detection "Benjamin David Lunt" <zfysz@fysnet.net> - 2015-07-09 16:47 -0700
Re: 64-bit detection "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-07-09 23:41 -0400
Re: 64-bit detection "James Harris" <james.harris.1@gmail.com> - 2015-07-10 08:30 +0100
Re: 64-bit detection "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-07-10 05:17 -0400
Re: 64-bit detection "James Harris" <james.harris.1@gmail.com> - 2015-07-10 13:41 +0100
Re: 64-bit detection "James Harris" <james.harris.1@gmail.com> - 2015-07-12 19:04 +0100
Re: 64-bit detection "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-07-13 02:30 -0400
Re: 64-bit detection "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-07-13 02:07 -0700
Re: 64-bit detection "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-07-13 23:10 -0400
Re: 64-bit detection "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-07-14 01:23 -0700
Re: 64-bit detection "James Harris" <james.harris.1@gmail.com> - 2015-07-13 12:34 +0100
Re: 64-bit detection "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-07-13 22:50 -0400
Re: 64-bit detection "James Harris" <james.harris.1@gmail.com> - 2015-07-14 08:37 +0100
Re: 64-bit detection "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-07-14 01:41 -0700
Re: 64-bit detection "James Harris" <james.harris.1@gmail.com> - 2015-07-14 10:04 +0100
Re: 64-bit detection "Benjamin David Lunt" <zfysz@fysnet.net> - 2015-07-10 08:44 -0700
Re: 64-bit detection "Benjamin David Lunt" <zfysz@fysnet.net> - 2015-07-10 10:52 -0700
Re: 64-bit detection "Benjamin David Lunt" <zfysz@fysnet.net> - 2015-07-10 08:38 -0700
Re: 64-bit detection "Benjamin David Lunt" <zfysz@fysnet.net> - 2015-07-10 10:58 -0700
Re: 64-bit detection CN <qmbmnp3799@pacbell.net> - 2015-07-09 23:00 -0700
Re: 64-bit detection "Benjamin David Lunt" <zfysz@fysnet.net> - 2015-07-10 08:40 -0700
Re: 64-bit detection "James Harris" <james.harris.1@gmail.com> - 2015-07-10 21:29 +0100
csiph-web