Application Software For Learning CPU Process of Interrupt and I/O Operation

,


INTRODUCTION
Central Processing Unit (CPU), play a role as the "brain" of the computer and It handles all the instructions where all of the activities in a computer are arranged inside the CPU.The processing of instructions given to the CPU is processed in a cycle known as instruction cycle.This instruction cycle consisting of three steps: fetch, decode, and execute.In carrying out these steps, processor also involves memory and I/O devices.It is impossible to see in live how the process happened in hardware.What can be done is to try to visualize the process into software in the form of simulation.The simulation program cannot give a perfect detail of the process of the hardware because of the complexity of the process.The simulation software can give a simple picture of the interaction between processor, memory and the peripheral devices.
The purpose of this research is to have simulation software capable of processing interrupt instruction and I/O operation that in the future it can contribute in developing a kernel.This is because of the frequency of using the interrupt instruction and I/O operation is quite often in developing software.Other purpose of this research is to have simulation software that can represent more of the work of memory and the process of instruction cycle so that it can reflect of the process in the CPU in a more complete way.

A. Components and Classifications in Computer System
A computer system can do the data processing properly if it has five units or main components that functioning independently.These components are input unit, processing unit, output unit, storage unit, and communication unit [1].CPU is a main component in a computer system, where the main function of CPU is to carry out instruction or program stored in memory by performing the instruction cycle that is fetch, decode, and execute.CPU consist of two main components, that is Arithmetic and Logic Unit (ALU) which carries out arithmetic operation and logic on data, and Control Unit which responsible for directing the flow of instruction and data in CPU.Besides that, in CPU there are also several registers that functioning as temporary data storage in CPU.Register divided into main registers like Instruction Register (IR), Program Counter (PC), Memory Address Register (MAR), and Memory Buffer Register (MBR), and general purpose register which consist of operand register and accumulator [1].

B. Instruction Set and Instruction Cycle
In a computer system, there is collection of instructions able to be carried out by processor in the system.That collection of instructions is known as Instruction set.Those instructions when executed, will ISSN 2354-0082 experience a cycle started from fetch, decode, and execute.The instruction cycle will always looped in a computer.Instruction set in a microprocessor is a collection of instruction and basic operation able to be carried out by device to be used by programmer.Instruction set is divided into several categories which connected functionally, which is data transfer instruction, arithmetic instruction, logic instruction, shift instruction, and rotate instruction [2].
Instruction cycle consist of several read or write process (machine cycle) in doing the execution of microprocessor/microcontroller instruction.Three machine cycle which are done for one instruction cycle consist of reading the instruction (fetch), decoding the instruction (decode), and executing the instruction (execute).Decode process usually merged with the fetch process [3].

C. Interrupt Handling
Interrupt is an event which indicate that there is a condition somewhere in system, processor, or in program which is currently executed that needs attention from processor.Interrupt usually have the impact on forcefully transfer the execution from the running program to a routine or special task called interrupt handler [4] .To help handling the interrupt, every interrupt in IA-32 architecture that needs special handling by the processor is given a unique identification number, called vector.Processor used the vector assigned to every interrupt as index in Interrupt Descriptor Table (IDT) to determine the starting point of interrupt handler [5].
Processor can receive interrupt from two sources, that is external interrupt and software generated interrupt.External interrupt is received from pin in processor or from local Advanced Programmable Interrupt Controller (APIC) [5].Software generated interrupt is generated from instruction INT n from the software and provide the interrupt vector number as operand.Example, instruction INT 7 will force a definite call to interrupt handler for interrupt 7 [5].

D. Input and Output
Processor enables an application to access I/O port in two ways, which is from distinct I/O address space and from memory-mapped I/O.Accessing I/O port from I/O address space is handled by string of I/O instruction and special I/O protection mechanism.Accessing I/O port from memory mapped I/O is handled by move or string instruction from processor, with protection provided by segmentation or paging [6].
Besides able to transfer data from and to external memory, a processor is also capable to transfer data from and to the I/O port.I/O port is made in hardware system from string that do decodes about the control, data, and address pin in processor.I/O port then configured to communicate with surrounding device.I/O port can be an input port, output port, or bidirectional port [5].I/O device that responds like memory component can be accessed from physical memory address.When using memory mapped I/O, all processor instruction involving the memory can be used to accessed I/O port placed in physical memory address.As an example, MOV instruction can move the data between register and memory-mapped I/O port.AND and OR instruction can also be used to access I/O port [6].

ISSN 2354-0082
In simulation program, the contents of IDT are not gate descriptor, but direct address of the interrupt handler.To obtain the address, simulation program will multiply the vector number by two (the address length of interrupt handler is 2-byte), then added with the base address of IDT.The result is an address contains the address of interrupt handler.Interrupt handler for every vector number only filled with simple instruction that defined when the simulation program is loaded for the first time ended with an IRET instruction to return back from executing the interrupt handler and back to execute the program left because of the interrupt instruction.IRET instruction has an OpCode of 2C H.When the INT instruction is found, first, the simulation program will enter the fetch cycle, like other instruction.After the fetch cycle, simulation program will enter the execute cycle for interrupt instruction.In this cycle, the first thing to do is to store the value of register FLAG, CS and PC into the stack with PUSH instruction.Then, simulation program will take the last 16 bit of IDTR that contains the base address of IDT.Index of the IDT's base address then added with two times the vector number of interrupt.The result is stored in MAR, then from the memory address pointed by MAR the simulation program will read the base address of interrupt handler and then save it in MBR, and then moved to PC register.Simulation program will then start the execution of interrupt handler started from the address pointed by PC until the simulation program executes the IRET instruction.When the IRET instruction is found, it indicates that interrupt handler has been executed.When that happened, simulation program will load the value of FLAG, CS and PC register from stack with POP instruction, and then resume the execution of the program left behind.IRET instruction has an OpCode of 2C H and size of 1-byte

C. Design of I/O Instruction
I/O instruction (IN, OUT, INS, and OUTS) will provide access to the I/O port by means of I/O address space for processor (these instructions cannot be used to access port thorough memory-mapped I/O).There are two groups of I/O instructions [5].

A. Implementation of Class CMemory
In class CMemory, there is an array that acts as storage but has private attribute.The data in this array can only be accessed using functions or methods contained in this class.The array has the capacity of 4 KB (4096 byte).The functions or methods in this class have a function to read or write data in the array.There are four main methods in this class, methods to write and read byte like writeByte and readByte, and methods to write and read word like writeWord and readWord

B. Implementation of Instruction
The main focuses of this research are interrupt instruction (INT), interrupt return instruction (IRET) and I/O operations

1) Implementation of Interrupt and Interrupt Return
Interrupt is an instructions used to halt the running program.Based on the sources, interrupt is divided into two type, hardware generated interrupt and software generated interrupt.In simulation program, the type that can be handled is software generated interrupt, called through INT n instruction.n is the vector number of the interrupt called.Vector number is allowed only in the range from 0 to 1F H. Interrupt in simulation program is still simple, because there is no proper interrupt handler like the one in Intel processor The interrupt process in this simulation program only shows how the interrupt handler is called through INT instruction.In this simulation program there no instructions to facilitate change in FLAG from EI (Enable Interrupt) to DI (Disable interrupt) vice versa like STI (Set Interrupt Flag) and CLI (Clear Interrupt Flag).In this simulation program, the interrupt process is considered the same for all interrupt vector and FLAG changed in this instruction is IF flag.
After the process of calling the interrupt handler, the simulation program then proceeds to executing the interrupt handler.Interrupt handler in this simulation program only contains simple instructions ended with IRET instruction, to return the value of register FLAG, CS and PC back to the value before the interrupt instruction enter execute cycle.

C. Testing of Simulation Program
Testing for the simulation program is done to see if the program can run according to expectations.Testing is done by trying to execute variety of instructions that contained in file instruction set.The following is an example of instructions run by the simulation program.

Fig. 1 .Fig. 3 .
Fig. 1.Archictecture of Simulation Program In running the simulation program, there are steps that the user will encounter in.Those steps are the mechanism of the simulation program described in the following flowcharts

ISSN 2354- 0082 
Used to move one item (byte, word or double between I/O ports and general purpose register.Included in this group are IN and OUT instructions  Used to move string of item (string of byte, word or double word) between I/O ports and memory.Included in this group are INS and OUT instructions In the simulation program, group of I/O instruction able to be handled are only IN and OUT instructions IV.IMPLEMENTATION AND TESTING

I
/O instructions that can be handled by simulation program are IN, and OUT.IN instruction is an instruction to read the value of I/O address space with the address pointed by displacement or general purpose register and store it in general purpose register.And OUT Instructions will write the value of a general purpose register into I/O address space with address pointed by displacement or general purpose register.

Table Register )
, which contains base address of IDT (Interrupt Descriptor Table).

TABLE III .
Testing of Stack Operations

TABLE IV .
Testing of Compare Operations and Conditional Jump Operations