Simple OS to Display Hardware Information(Extend of Josh OS).

Dineth Shan Gimhana
5 min readJul 25, 2020

--

Boot loader

First you should have boot-strap loader (which can understand the FAT12 structure and load the FAT file into memory) to load the OS from raw sectors from the floppy disk into RAM and execute.Here you can get the boot-strap code easily.

Save it as boot.asm (boot-strap loader assembly file).Then run the following command on Linux terminal (“boot.asm” file path and terminal directory should be same” to run following code”).

nasm boot.asm -o boot.bin -f bin

Kernel

The kernel is the core of the Operating System performing most of the work and providing the applications with a good set of functionality. The kernel (or its functionality) should be available always and applications should have a way of interacting with the kernel in a seamless manner. JOSH will provide all the functionality to applications through interrupts.

Retrieving Hardware information

1. Display No.of Serial Ports

strSerial is a string that is used to store a string to be displayed. xor ax,ax clears all the bits in the ax register. When interrupt 0x11 is the bios equipment list flags are stored in ax register. And ax, 0xe00 is used to mask out bits 9,10 and 11 which are used to indicate the number of serial ports available in the computer. Then ax is right shifted by 9 bit positions so that only required bits are remaining in the ax register. 48 is added to ax to get the ASCII value of the value stored in ax. Then it is displayed.

2.Display No.of Floppy Disks

Same as Above process.

Following function, if there is no floppy drives are available it will print 0

In following function will send interrupt 11h and read the 6–7 bits from the ax register to read the available number of floppy drives if there is floppy disks

3.Display No.of Hard drives

Number of hard drives in the system can be extracted from memory locations 0x0040 to 0x0075. Interrupt 0x10 with 0x0e in the ah register prints the text in al.

4.Display CPU Vendor ID and Processor

The CPUID opcode is a processor supplementary instruction for the x86 architecture that gives information about the CPU. By using the CPUID opcode, software can determine processor type. The value in the EAX register specifies what information to return when CPUID is executed. With 0x00 in the EAX register, CPUID stores the vendor name of the CPU in registers EBX, EDX and ECX.

5.Display Memory information

Memory details can get by using the INT 0x15, EAX = 0xE801 command. There stores the extended memory between 1MB and 16MB in kilobytes in AX or BX and extended memory >16MB as no of pages of 64KB in CX or DX. The purpose of comparing ah with 0x86 is to check whether the function is supported on the system and comparing ah with 0x80 is to check whether it is an invalid command. Some systems, when called the interrupt 0x15, returns that CX=DX=0. If so we have to copy AX and BX to CX and DX. It is don’t by _cx_zero. Detected memory has to be calculated MB and has to be converted to decimal from hexadecimal.

After the finishing of the kernel code then you can compile kernel code by using nasm again.

nasm kernel.asm -o kernel.bin -f bin

Create Bootable Floppy Image

Then you simply create a floppy disk image by using following command.

cd /media
sudo mkdir floppy

mkfs.msdos -C floppy.img 1440

Then mount the floppy disk image to above directory which is /media/floppy/ by using following command.

sudo mount -o loop floppy.img /media/floppy/

Then copy the kernel.bin file to above mounted directory.

sudo cp kernel.bin /media/floppy/

Using command df -h you can get the directory of bootable area of floppy image.In my case it is /dev/loop42/. Now you can move boot.bin file to bootable section using following command.

sudo dd if=Bootloader/boot.bin of=/dev/loop42

Then unmount floppy image and remove the directory that we created in /media.

sudo umount /media/floppy/
sudo rm -rf /media/floppy/

Now you can run extended josh os using a virtual machine by using the floppy image disk.

Thank you.

Code Base:

References:

--

--

Dineth Shan Gimhana

Software Engineering Undergraduate | University of Kelaniya