2010年9月9日 星期四

Dalvik Interpreter (1)

-Let's talk about how Dalvik generate interpreter for different platforms. All interpreter related files exist in dalvik/vm/mterp

1.
There exists a config file for every specific platform, e.g. config-armv5te or config-portstd. The config-portstd is a portable config file for all platforms.

2.
Every config file consists of the information needed by the gen-mterp.py. The gen-mterp.py is a python module which is used to read the platform-specific config file and generate the platform-specific interpreter.

3.
Following are currently supported platforms.
portstd
portdbg
allstubs
armv4t
armv5te
armv5te-vfp
armv7-a
x86

Every platform has its own .c and .S interpreter InterpC-$(TARGET_ARCH_EXT).c and InterpAsm-$(TARGET_ARCH_EXT).S. However, only .S or .c files has the interpreter entry point i.e. only one file is used to do interpreting.

The architecture-specific config files determine what goes into two generated out files (InterpC-$(TARGET_ARCH_EXT).c, InterpAsm-$(TARGET_ARCH_EXT).S).  The goal is to make it easy to swap C and assembly sources during initial development and testing, and to provide a way to use architecture-specific versions of some operations (e.g. making use of PLD instructions on ARMv6 or avoiding CLZ on ARMv4T).

(Config file example 1) - config-portstd

# C file header and basic definitions
import c/header.c

# simple def to specify the "standard" interp
import portable/portstd.c

# C pre-processor defines for stub C instructions
import portable/stubdefs.c

# common defs for the C opcodes
import c/opcommon.c

# entry point
# This entry point will tell the Dalvik VM where to enter the interpreter
import portable/entry.c --> InterpC-portstd is the main interpreter file

# opcode list; argument to op-start is default directory
op-start c
    # concatenate all C implementations
op-end

# "helper" code
import c/gotoTargets.c

# finish
import portable/enddefs.c

(Config file example 2) - config-armv5te
handler-size 64

# source for the instruction table stub
asm-stub armv5te/stub.S

# file header and basic definitions
import c/header.c                   --> This file will be paste in .c
import armv5te/header.S       --> This file will be paste in .S

# C pre-processor defines for stub C instructions
import cstubs/stubdefs.c        --> This file will be paste in .c

# highly-platform-specific defs
import armv5te/platform.S    --> This file will be paste in .S

# common defs for the C helpers; include this before the instruction handlers
import c/opcommon.c            --> This file will be paste in .c

# arch-specific entry point to interpreter
# This entry point will tell the Dalvik VM where to enter the interpreter
import armv5te/entry.S          --> InterpAsm-armv5te.S is the main interpreter file

# opcode list; argument to op-start is default directory
op-start armv5te
    #op OP_FILL_ARRAY_DATA c
op-end

# "helper" code for C; include if you use any of the C stubs (this generates
# object code, so it's normally excluded)
##import c/gotoTargets.c

# end of defs; include this when cstubs/stubdefs.c is included
import cstubs/enddefs.c

# common subroutines for asm
import armv5te/footer.S
import armv5te/debug.c

沒有留言:

張貼留言