_asm in IA64 & x64??

Discussion in 'Windows Vista Drivers' started by Sathyanarayanan, Feb 20, 2006.

  1. I badly need to use some assembly instructions in my driver & application.
    Compiling these codes with _asm keyword works fine for x86, but throws error
    for x64 & IA64. Then I learnt that _asm is not supported keyword for these 2
    architectures. How else can I call assembly instructions that can work for
    these architectures???
    Sathyanarayanan, Feb 20, 2006
    1. Advertisements

  2. Sathyanarayanan

    Don Burn Guest

    You will have to get assemblers for these architectures and put the
    instructions in seperate routines. I am very curious what instructions you
    think you need?
    Don Burn, Feb 20, 2006
    1. Advertisements

  3. You cannot use any assembler instructions on X64.
    Maxim S. Shatskih, Feb 20, 2006
  4. Sathyanarayanan

    Skywing Guest

    You can put your assembler in a separate raw assembler module and link the
    resultant object file in. There are also a great many new intrinsics
    supported by the x64 compiler (e.g. _writecr0) to do some things you used to
    need inline asm for.

    (Certainly, you should avoid assembler in NT drivers where possible - but
    there are a couple of legitimate scenarios where it is necessary.)
    Skywing, Feb 20, 2006
  5. I needed to read few MSRs of CPU, for which I had to use assembly code.

    ----- contents of assembly.asm ------
    ..model SMALL, C
    push ecx
    mov ecx, MsrAddr
    pop ecx
    ReadCPUMsr ENDP
    ----- contents assembly ends --------

    1. When i compile this .asm file separately in makefile.inc (ml /c /Cx /coff
    /Fo$(O)\assembly.obj assembly.asm) it generates .obj, but I didn't know how
    to instruct BUILD utility to link this obj file along with my driver code -
    any inputs?
    2. Alternately, I tried to include this .asm file name under SOURCES macro
    in sources file, but NMAKE returns error "NMAKE : fatal error U1073: don't
    know how to make 'objchk_wnet_x86\i386\assembly.obj'

    How do I successfully link my driver code with this assembly?
    Sathyanarayanan, Feb 23, 2006
  6. Sathyanarayanan

    Skywing Guest

    You can use the new __readmsr() intrinsic to do this without separate
    assembler code.

    Skywing, Feb 23, 2006
  7. Folks,
    1. I couldn't find __readmsr() declaration anywhere in DDK headers (I am
    using Win 2003 SP1 DDK). Which header & library have this intrinsic?
    2. I also tried specifying PRECOMPILED_OBJ build macro for assembly code obj
    file, but still linker cribs unresolved external symbol for this PROC....The
    log generated by build.exe does NOT contain this obj in list of linking. Also
    looks like this build macro is needed for overriding default pre-compiled obj
    file - is it right to use?
    3. Also do we have __writemsr() too??
    Sathyanarayanan, Feb 23, 2006
  8. Sathyanarayanan

    Skywing Guest

    These might only be available with the x64 compiler in the DDK - it's new to
    CL 14, and the x86 DDK compiler is still CL 13 as I recall.
    Skywing, Feb 24, 2006
  9. Sathyanarayanan

    Skywing Guest

    I believe that you should be able to use these intrinsics with the current
    x64 DDK compiler, just not the current x86 one.
    Skywing, Feb 24, 2006
  10. Sathyanarayanan

    Tim Roberts Guest

    Create a subdirectory called i386. Move your "assembly.asm" into the i386
    subdirectory. Now, in your "sources", add:

    I386_SOURCES = i386\assembly.asm

    That's all it takes. Build will assemble and link it.

    The same thing works with:

    IA64_SOURCES = ia64\assembly.s

    AMD64_SOURCES = amd64\assembly.asm
    Tim Roberts, Feb 25, 2006
  11. Cool !!
    I just used below declarations for x64 (kept same _asm code for x86) and it
    successfully builds :). I will test and update if it works/any issues, etc.
    Thanks a lot folks!!

    BTW, I am also gonna try I386_SOURCES macro addition and will let you know.

    extern unsigned __int64 __readmsr(int);
    extern void __writemsr(int,unsigned __int64);

    (extern "C" - declaration throws compiler error).
    Sathyanarayanan, Feb 27, 2006
  12. It works :).
    Thanks Tim!!

    Sathyanarayanan, Mar 3, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.