Tuesday, July 16, 2013

HACKING JOSH OS IMPLEMENTING A COMMAND TO SHOW HARDWARE INFORMATION


The assignment given for us was to implement a new command to show hardware information. In order to achieve that goal, first I had to understand the basic structure of the given kernel (file named “kernel-3.0.asm”). Following is the structure I realized observing the kernel. I have stated the functionalities and the responsibilities of each section.

Starting part
  • Setups memory locations
  • Setups interrupt services
  • Displays welcome message
  • Calls the shell

Interrupt 0x21
  • Displays a String on the slandered output

Shell
  • Responsible for all the interactive work
  • Accepts a command (as string)
  • Manipulate it and perform action
  • Procedure to Display the version of the OS (a basic functionality which was already given)
  • Procedure to exit/restart (a basic functionality which was already given)
  • Procedure to display a message when unknown command was given
  • Procedure to accept the as a string and to store it
  • Procedure to split the command
  • Procedure to display space, a new line and the prompt

Data
  • The strings and number constants used in the kernel
First I implemented a command to display my information. Command “about” will display my information. Following is a snapshot of the command.

Following is the code used to implement it

Then I implemented a procedure to display a list of available commands. Command ‘help’ is used.


Then I implemented the command to display hardware information. The command ‘info’ displays the hardware information.


To implement this command, it is divided into separate procedures, which will display each detail separately. Each of them are explained separately


Display processor information






The CPUID opcode is a processor supplementary instruction (its name derived from CPU IDentification) for the x86 architecture. It was introduced by Intel in 1993 when it introduced the Pentium and SL-Enhanced 486 processors.By using the CPUID opcode, software can determine processor type and the presence of features (like MMX/SSE). The CPUID opcode is 0FA2h and the value in the EAX register specifies what information to return. [1]

In order to load the vender ID of then cpu CPUID has to called with EAX =0. To set the value 0 in EAX, the instruction “xor eax, eax” is used (xor of the same value will result 0).
The above instruction returns then CPU manufacturer’s ID string – a twelve character ASCII string stored in EBX, ECX and EDX – in that order. The highest basic calling parameter (largest value that EAX can be set to before calling CPUID) is returned in EAX.[1]
Then the value of then EBX, ECX and EDX has to be stored in a single string in order to display the vender ID. I have used the string ‘strCPUID’ to store the vender ID.

Then I have used the following instruction to get the processor bran string
EAX=80000002h,80000003h,80000004h: Processor Brand String
These return the processor brand string in EAX, EBX, ECX and EDX. CPUID must be issued with each parameter in sequence to get the entire 48-byte null-terminated ASCII processor brand string. I have used the ‘_string_store’ subroutine to store those values each time.