Thinking Kernel Mode

ExAllocatePoolWithTag(KMScrapPad, sizeof(KMSCRAP), TAG_TKM);

  Home  |   Contact  |   Syndication    |   Login
  14 Posts | 0 Stories | 43 Comments | 26 Trackbacks

News

Sreejith S

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

Archives

Blogs I Read

Links

Friday, March 07, 2008 #


Writing asm code for 32 bit drivers is straightforward. You can embed the code in an __asm { } block.

void DemoFunction()
{
    __asm
    {
          mov eax, 0x01
          ; more assembly
    }
}


But writing assembly in 64 bit driver source code requires a bit more work. The 64 bit compiler will not allow inline assembly. The assembly code will have to be moved to a seperate assembly module (an .asm file).

Step 1 : Write necessary assembly routines in a seperate .asm file

Example : Test.asm
------------------------------------------

.data

; all data variables in your asm code goes here
myData1   dq   0   ; 64 bit data


.code

; all assembly routines go here

TestFunction PROC

    ; sample function/routine/procedure

    ; assembly code for the function goes here

    ret
   
TestFunction ENDP

END ; end of assembly file

Step2 :  Integrate assembly function with C

In one of your C header files declare the function:

extern void TestFunction(void);

Step 3 : Adding asm file to sources file

In the sources file of your driver you can add the .asm file along with other C files.

Example:

SOURCES = init. c \
ioctl.c \
pnp.c\
power.c\
Test.asm

You can add the same under AMD64_SOURCES or IA64_SOURCES if you required to include the same only in those specific architectures.


  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati