The present invention relates to a data processing apparatus capable of executing a virtual machine instruction by using the native instruction of a CPU, and an effective technique which is applied to a microcomputer for an IC card, for example.
A technique capable of executing a virtual machine instruction by using the native instruction of a CPU, that is, a technique for executing a virtual machine instruction over a CPU having an inherent instruction set includes an implementing technique using an interpreter software. The executing method using the interpreter software loads a virtual instruction onto a CPU, recognizes the virtual instruction thus loaded and calls the function of an execution routine corresponding thereto, thereby executing the execution routine to implement a processing specified by the virtual instruction. In the execution routine, the operation of the corresponding virtual machine instruction is described in an instruction (the native instruction of the CPU) included in an instruction set which is peculiar to the CPU. When the processing of one execution routine is ended, a jump to a processing of loading the virtual machine instruction is carried out. By repeating this operation, a virtual machine program described in the virtual machine instruction can be executed by using the native instruction of the CPU. In this technique, the processing of loading the virtual machine instruction, deciding the virtual machine instruction thus loaded and calling the function of the execution routine corresponding to the virtual machine thus decided causes an overhead.
JP-P2001-508907A and JP-P2001-508908A have described a technique for reducing the overhead of the execution routine call. More specifically, there is employed a hardware for loading a virtual machine instruction by using a program counter for loading the virtual machine instruction and calculating an execution routine address from the virtual machine instruction thus loaded when the instruction fetching address of the CPU is output by utilizing a part of the instruction fetching address of the CPU for the program counter.
It was proved by the inventor that a processing of loading a virtual machine instruction and a processing of calculating an execution routine address are carried out in series to an instruction execution processing in accordance with an execution routine by using the hardware described in the Patent Documents so that the load processing and the address calculation processing still cause an overhead for the instruction execution processing in accordance with the execution routine.
It is an object of the invention to reduce the overhead of an instruction execution processing in accordance with an execution routine which is caused by a processing of loading a virtual machine instruction and an address calculation processing based thereon.
It is another object of the invention to increase the speed of a data processing based on a virtual machine program described in a virtual machine instruction.
The above and other objects and novel features of the invention will be apparent from the following description and the accompanying drawings.
A data processing apparatus according to the invention can implement an execution of a virtual machine instruction based on an execution routine specified by a native instruction of a CPU and has an address converting unit capable of sequentially converting an address output from the CPU into an address of the native instruction by utilizing an address of a prepared execution routine in response to an application of a prescribed condition. The address converting unit reads a virtual machine instruction to be executed next and prepares an address of an execution routine corresponding thereto in parallel with an execution of the execution routine by the CPU based on the address of the native instruction which is sequentially converted. In brief, the data processing apparatus according to the invention carries out the processing of loading the next virtual machine instruction and the processing of preparing the address of the execution routine corresponding to the virtual machine instruction thus loaded in parallel with the processing of executing the execution routine based on the CPU instruction set corresponding to the virtual machine instruction. Accordingly, it is possible to reduce the overhead of the instruction execution processing in accordance with the execution routine which is caused by the processing of loading the virtual machine instruction and the address calculation processing based thereon. Consequently, it is possible to increase the speed of the data processing based on the virtual machine program described in the virtual machine instruction.
The address converting unit exactly outputs an address input from the CPU in response to a non-application of the prescribed condition. More specifically, when the prescribed condition is not applied, the CPU fetches and executes the instruction from the program described in the native instruction other than the execution routine.
The prescribed condition is an output of a predetermined address by the CPU, for example. The predetermined address is a starting address of a predetermined address space assigned to the execution of the virtual machine instruction, for example. At this time, for example, the execution routine includes a native instruction of a return processing of returning a program counter of the CPU to a head of the predetermined address space assigned to the execution of the virtual machine instruction at an end thereof. When the return to the head of the predetermined address space is carried out at the end of the execution routine, the address of the execution routine corresponding to the virtual machine instruction to be executed next has already been prepared, and the CPU carries out the processing of giving access to the starting address of the predetermined address space again. Consequently, it is possible to carry out a transition to the execution of the execution routine of the prepared address.
For a desirable mode, the apparatus has a conversion table for defining a correspondence of an instruction length to an address of an execution routine for the virtual machine instruction. The address converting unit acquires the instruction length of the corresponding virtual machine instruction and the address of the execution routine from the conversion table by setting the read virtual machine instruction as a retrieval key. The instruction length is utilized for generating the address of a virtual machine instruction to be read next. This is carried out in order to cope with the case in which the instruction word length of the virtual machine instruction is different for each instruction. The address of the execution routine which is retrieved is set to be an address on a high order side for specifying the storage area of the execution routine, and is utilized for generating an address to fetch the native instruction of a next execution routine. In the case in which they are utilized, it is desirable to have a first register for holding the retrieved instruction length and a second register for holding the address of the retrieved execution routine. For example, the address converting unit has a virtual machine program counter for outputting an address to read a virtual machine instruction from a memory and an amount of an increment of the virtual machine program counter can be controlled based on a value of the first register. It is sufficient that the increment of the virtual machine program counter is carried out synchronously with an execution end timing of a current execution routine. Moreover, it is preferable that the address converting unit should have an execution routine address generating circuit for reading a native instruction of an execution routine from a memory, and the execution routine address generating circuit should have a third register for inputting an address of an execution routine held by the second register and an adder for adding a value of the third register to a plurality of bits on a low order side of an address output from the CPU, and an output of the adder should be set and utilized to be an address of a native instruction of an execution routine.
When a virtual machine instruction which is read is a branch instruction, the address converting unit can read a virtual machine instruction of a branch destination and can prepare an address of an execution routine corresponding thereto. In case of the branch of the condition when the read virtual machine instruction is a conditional branch instruction, it is preferable that the address converting unit should read a virtual machine instruction of a branch destination and should separately prepare an address of an execution routine corresponding thereto, and should select an address of an execution routine to be utilized for an address calculation depending on a presence of a branch. A transition to a next execution routine can be carried out instantly irrespective of the application of the condition.
The data processing apparatus may comprise a first memory for storing a virtual machine program constituted by a virtual machine instruction and a second memory for storing an execution routine thereof for each virtual machine instruction and may be formed on a semiconductor chip. Moreover, the first memory and the second memory may be a separate chip from the CPU and the address converting unit.
It is desirable that the first memory should be a rewritable non-volatile memory. The main reason why the virtual machine instruction is used is the portability of a program to a data processing apparatus (platform) having a different architecture. A program expressed in the virtual machine instruction can easily be executed over plural kinds of data processing apparatuses by substituting the virtual machine instruction with the execution routine based on the instruction set which is peculiar to the data processing apparatus. Such an execution routine can easily be made constant irrespective of a virtual machine program over the data processing apparatus having the same architecture. If the first memory for storing the virtual machine program is set to be rewritable, therefore, the second memory does not need to be rewritable.
The data processing apparatus can be applied to an IC card mounted on a card board together with an input/output circuit. The input/output circuit to be employed may have a contact interface form or a non-contact interface form using a radio wave. In the case in which the virtual machine program is encrypted and supplied from an outside, and is decoded on an inside and is stored in a memory in the IC card, it is desirable that the first memory should be a rewritable non-volatile memory.
The CPU 2 has a predetermined instruction set, and the instruction set includes a plurality of prescribed native instructions. The CPU 2 has an instruction control unit CNT and an executing unit EXC. The instruction control unit CNT controls the order of execution of an instruction, and furthermore, fetches an instruction to an instruction register IR from an instruction address specified by a program counter PC and decodes the fetched instruction by means of a decoder DEC to generate a control signal. The executing unit EXC has the program counter PC, a general purpose register REG and an arithmetic logic unit ALU, and operates the general purpose register REG and the arithmetic logic unit ALU based on the control signal generated by the instruction control unit CNT, thereby executing an instruction.
The microcomputer 1 can implement the execution of a virtual machine instruction in accordance with an execution routine prescribed in the native instruction of the CPU 2. The virtual machine instruction is an instruction constituting a language in an application execution form over an IC card operating system referred to as an MULTOS®, for example. A virtual machine program based on the virtual machine instruction is held in the memory 4 containing virtual machine instructions. The execution routine is held in the memory 5 containing execution routines. A part of the address space of the CPU 2 is assigned to the execution of the virtual machine instruction, which is not particularly restricted. The space will be referred to as a virtual machine instruction execution space. The address converting unit 3 decides that a prescribed condition is applied when an instruction address output from the CPU 2 indicates a predetermined address of the virtual machine instruction execution space, for example, a starting address thereof.
The address converting unit 3 has a control unit 10 for deciding whether or not the prescribed condition is applied and controlling the whole address converting unit 3, and an execution address generating unit (an example of an execution routine address generating unit) 15. The execution address generating unit (VPC unit) 15 sequentially converts an instruction address output to a bus cp_iab by the CPU 2 into the address of a native instruction by utilizing the address of an execution routine prepared for an execution routine starting address register VPC in response to the fact that the prescribed condition is applied, and outputs the same address to the bus iab. When the prescribed condition is not applied, the execution address generating unit 15 exactly outputs the instruction address sent to the bus cp_iab by the CPU 2 to the bus iab. The CPU 2 inputs the native instruction read from the memory 5 containing execution routines based on the address of the native instruction converted sequentially through data buses idb and cp_idb, and executes the native instruction. The address converting unit 3 reads a virtual machine instruction to be executed next from the memory 4 containing virtual machine instructions in parallel with the execution of the execution routine of the virtual machine instruction in response to the fact that the prescribed condition is applied, and prepares the address of an execution routine corresponding thereto for a register VPC0 (an example of a second register). A virtual machine program counter unit (VIPC unit) 11 generates an address for giving access to the memory 4 containing virtual machine instructions and outputs the same address to the address bus iab via the VPC unit 15.
The amount of an address increment in the virtual machine program counter unit 11 is determined by the set value of a register DISP0 (an example of a first register) of an increment control unit (DISP unit) 14.
A data access unit 12 inputs the virtual machine instruction read from the memory 4 containing virtual machine instructions onto the bus idb. The address converting unit 3 has a conversion table 13 which defines the correspondence of an instruction code (byte code), an instruction length (disp) and an execution routine address every virtual machine instruction. The data access unit 12 sets the instruction code of the input virtual machine instruction as a retrieval key and retrieves an instruction length and an execution routine address for the instruction code. The instruction length thus retrieved is set to the register DISP0, and the execution routine address thus retrieved is set to the register VPC0. The execution routine address set to the register VPC0 is transferred to the register VPC in response to the fact that the prescribed condition is applied subsequently to the end of the execution of the execution routine which is being carried out, and is utilized for generating an access address (execution routine instruction address) of the execution space of the execution routine prescribed by the execution routine address.
The execution routine includes a native instruction for a return processing of returning the program counter PC of the CPU 2 to the head of a predetermined address space (a virtual machine instruction execution space) assigned to the execution of a virtual machine instruction at an end thereof, for example, which is not particularly restricted. When the return to the head of the virtual machine instruction execution space is carried out at the end of the execution routine, the address of an execution routine corresponding to a virtual machine instruction to be executed next has already been prepared in the VPC0. When the CPU 2 is to carry out a processing of giving access to the starting address of the virtual machine instruction execution space again, the address of the register VPC0 is transferred to the register VPC so that the execution of an execution routine indicated by the register VPC0 can be started.
The selector 21 selects the native instruction address of an execution routine output from the adder 20, the virtual machine instruction address (VIPC0+DISP0) output from the VIPC unit 11 or the address of the address bus cp_iab and outputs one of them to the bus iab. The selecting operation of the selector 21 is controlled by the control unit 10. The control unit 10 inputs a flag for a conditional branch of the CPU 2, a bus ready signal, a bus acknowledge signal and an address signal sent from the CPU 2. The control unit 10 causes the selector 21 to select the address of the address bus cp_iab when the instruction fetch address output from the CPU 2 does not specify the virtual machine instruction execution space, and causes the selector 21 to select the output address of the adder 20 when the instruction fetch address specifies the virtual machine instruction execution space. The control unit 10 causes the selector 21 to select a virtual machine instruction address to be processed next in a predetermined timing in the middle when the selector 21 is caused to select the output address of the adder 20. The predetermined timing is not particularly restricted but may be a uniform timing, that is, the next to the head instruction fetch of the execution routine. As described above, the value of the register VPC0 is acquired in parallel with the processing of the current execution routine of the virtual machine instruction by the CPU 2. When the processing of the current virtual machine instruction is ended, it is possible to instantly carry out a transition to the processing of an execution routine corresponding to a next virtual machine instruction.
The conditional branch instruction of the virtual machine instruction has a relative position (target) of a branch destination written next to a conditional branch instruction code. The VIPC unit 11 has three registers VIPC, VIPC0 and VIPC1 and a selector 20 thereof. The register VIPC is an address register for loading data on an operand portion in a virtual machine instruction which is being executed. The register VIPC does not influence an operation for the program counter PC, and an update to a value indicative of the position of an operand which is obtained by adding 1 to the VIPC0 is carried out when the execution routine of the virtual machine instruction is started to be executed from a head. The conditional branch instruction of the virtual machine instruction employs a technique for a relative branch to obtain a branch destination on the basis of the address position of a current virtual machine instruction. For this reason, information about the address position of the current virtual machine instruction is required. In order to increase the speed of the conditional branch instruction, the branch destination and a virtual machine instruction to be a next instruction are loaded. When the register VIPC0 loads a next virtual machine instruction code, therefore, the address value of the current virtual machine instruction is updated to the address value of the next virtual machine instruction. In this case, it is necessary to know the address value of the current virtual machine instruction when a branch destination address is to be calculated in the load of a branch destination virtual machine instruction. Therefore, the register VIPC1 for storing the address value of the current virtual machine instruction is added.
By outputting an address held in the VIPC, it is possible to obtain the relative position (the branch destination target) for a branch to be operand data in the conditional branch instruction of the virtual machine instruction, and the register DISP1 for storing the value is provided. The registers DISP0 and DISP1 are selected by the selector 21. VIPC1+DISP1 indicates the address position of the virtual machine instruction of a branch destination, and the value is output as an address so that the virtual machine instruction of the branch destination can be loaded. In this case, the VIPC1 is updated by the branch destination address.
Consequently, the retrieval table 13 is accessed by setting, as a retrieval key, the virtual machine instruction of the loaded branch destination, and an instruction length and an execution routine address of the branch destination are obtained and stored in the register DISP1 of
As a result of the decision of the branch condition, the registers VIPC0, DISP0 and VPC0 are selected if the branch is not carried out (the disable state of a branch flag Bflg). The registers VIPC1, DISP1 and VPC1 are selected in the case in which the branch is carried out (the enable state of the branch flag Bflg). Consequently, it is possible to perform a transition to the processing of the execution routine of the branch destination virtual machine instruction through the conditional branch. 22 denotes a selector for VPC1 or VPC0. The control unit 10 has the branch flag Bflg for determining the presence of a branch in the conditional branch instruction of the virtual machine instruction.
From the foregoing, it is possible to load the branch destination before fixing the branch condition and to acquire the instruction length of the branch destination and the address of the execution routine in parallel with the processing of executing the current virtual machine instruction of the CPU 2.
As illustrated in a timing TA, in an initial state, the memory address of the V code [1], a relative position to the next V code [2] and the execution routine address of the V code [1] are initialized to the registers VIPC0, DISP0 and VPC0 by the CPU 2, respectively.
When the starting address V_0 of the virtual machine instruction execution space is output from the CPU 2 to the address bus cp_iab (timing TB), the address converting unit 3 detects the same address and transfers the value of the register VPC0 to the register VPC and outputs, to the address bus iab, a native instruction address [1 ]_0 constituting the execution routine of the V code [1] of the register VPC which is obtained by adding the low order offset of the address V_0 to the execution routine address of the V code [1]. A native instruction [[1]_0] is output from the memory 5 containing execution routines to the data bus idb based on an address thereof (timing TC). This is fetched to the CPU 2 through the bus cp_idb and is executed. Every time the addresses V_1 to V_3 of the virtual machine instruction execution space are sequentially output from the CPU 2 to the address bus cp_iab, succeeding native instructions [[1]_1] to [[1]_3] of the execution routines corresponding to the V codes are sequentially supplied to the CPU 2.
In the example of
In
When the CPU 2 is processing the execution routine of the V code, accordingly, the address converting unit 3 fetches a next V code from the memory 4 in parallel with the processing and acquires the starting address and instruction length of the execution routine from the conversion table 13 by setting the fetched V code to be an address. Accordingly, a jump instruction to return to the head to the virtual machine instruction execution space is executed at the end of the execution routine so that the CPU 2 can execute a necessary execution routine sequentially and continuously.
The microcomputer 1 has the CPU 2, the address converting unit 3 (VEM 3), an EEPROM 30 which is electrically rewritable, a mask ROM 31, an RAM (Random Access Memory) 32, an input/output circuit (I/O) 33, an encrypting circuit 34 and an internal bus 35. The input/output circuit 33 is utilized for the interface of an I/O signal such as an address, data or a command, a reset signal and a clock signal.
As illustrated in an address map in
While the invention made by the inventor has been specifically described above based on the example, the invention is not restricted thereto but various changes can be made without departing from the scope of the invention.
A specified condition that an address conversion is carried out by the address converting unit is not restricted to the output of the starting address of the virtual machine instruction execution space. For example, the starting address is not always required. Moreover, a specific address is not always required but other specific output states of the CPU may be brought. In addition, the memory containing virtual machine instructions and the memory containing execution routines are not restricted to non-volatile memories but they may be constituted by volatile memories if the stored data can be held. Furthermore, the memory containing virtual machine instructions may be connected to a separate bus from the memory containing execution routines, for example, a dedicated bus in the same manner as in the conversion table. It is possible to prevent the access of the execution routine from being temporarily broken by the access of a virtual machine instruction. Moreover, the address converting unit can also be constituted in the same unit as an instruction control unit and an executing unit which form a CPU in the same manner as a memory management unit. Furthermore, the microcomputer can also be applied to a PDA (Personal Digital Assistant) and a cell phone as well as an IC card.
The invention can be widely applied to a data processing apparatus which is referred to as a microcomputer, a data processor, a microprocessor or a single chip data processor to be the platform of a virtual machine program constituted by a virtual machine instruction, and furthermore, an electronic apparatus such as an IC card mounting the data processing apparatus.
Filing Document | Filing Date | Country | Kind | 371c Date |
---|---|---|---|---|
PCT/JP02/08843 | 8/30/2002 | WO | 11/9/2005 |