Hands on to Operating Systems

Tiroshan Madushanka
setublog
Published in
4 min readApr 5, 2019

This article provides guidance to learn Operating System fundamentals and concepts which are discussed in SENG 21213 — Operating Systems & Computer Architecture. In order to be familiar with low-level Operating System concepts and hardware, students need to implement a simple Operating System (display the hardware information of the machine) as an extension of minimalOS — JOSH.

What is JOSH— minimalOS?

As you find more information in here, JOSH is a real-mode operating system which is an interrupt driven and single-tasking. JOSH is designed to boot from a floppy disk which is a FAT12 file system.

FAT12 File system — Disk Layout

Make JOSH Boot from USB Drive

Linux uses ordinary files to represent various I/O devices and these files are in /dev directory. When a USB pen is plugged in, LINUX creates the ansdb file and sdb1 file in /dev directory.

/dev
sdb -represents the device itself
sdb1 –primary partition on that device.

Steps

01. Format the USB drive as the FAT32 file system. The FAT12 file format can handle disks minimum than 32MB.

sudo /sbin/mkdosfs -F 32 -I /dev/sdb

02. Create a floppy disk image,

sudo dd if=/dev/zero bs=512 count=2880 of=./floppy.img

03. Format the floppy image,

sudo /sbin/mkdosfs –F 12 ./floppy.img

04. Override the floppy image,

sudo dd if=./floppy.img of=/dev/sdc

05. Move the boot file into the boot sector of the disk.

sudo dd if=./boot.bin of=/dev/sdc

Extend JOSH OS features

As of following, there are two basic methods that are being used in assembly language to get the hardware information.

1. Use BIOS Service interrupts

The BIOS interrupts, facilitate to get the hardware information which is stored in the BIOS data area. When an interrupt call is executed, it returns the AX register with corresponding data.
Ex: Print a word to the screen using BIOS interrupt 0x21:

mov si, strproserialmov al, 0x01int 0x21

Types of BIOS Service Interrupts

a. Processor interrupts

Interrupts 00h to 07h are called by the processor directly, but can also be called from software using the INT (int) instruction.

Processor Inputs

b. Hardware interrupts

The hardware interrupts differ from all the software interrupts. They have a direct channel to the processor through an Interrupt Request Line. The 8259 Programmable Interrupt Controller or PIC on the motherboard manages all the hardware interrupts.

2. Use special commands

The special commands are provided by the processor manufacturers. The CPUID (cpuid) command requires without any operand, but it takes an argument from the EAX register.
Ex: CPUID functions that return the basic processor information, the program should set the EAX register parameter value to “0” and then execute the CPUID instruction as follows:

MOV EAX, 00hCPUID

As an example, when a cpuid call is executed with the value of 0 to the register EAX, it returns vendor ID as 12 bytes values and stores in EBX, EDX, ECX registers.

when a cpuid call is executed with values of 0x80000002,0x80000003, 0x80000004 separately to the register EAX., it returns processor type and returns it as 12 bytes value which stores in EBX, EBX, ECX, EDX

Extension of the JOSH

Display the hardware details.

_cmd_displayHardwareInfo:call _display_endlmov si, strCPUIDmov al, 0x01int 0x21call _cmd_cpuVendorIDcall _cmd_ProcessorTypecall _cmd_ProcessorSerialNo;call _cmd_ProcessorFeature;call _cmd_MouseStatusret

Display the vendor ID of the processor

_cmd_cpuVendorID:mov eax,0cpuid; call cpuid commandmov [strcpuid],ebx; load last stringmov [strcpuid+4],edx; load middle stringmov [strcpuid+8],ecx; load first stringcall _display_endlmov si, strcpuid;print CPU vender IDmov al, 0x01int 0x21ret

Display the processor type, the speed of the processor.

_cmd_ProcessorType:mov eax,0x80000002cupid     ; call cpuid commandmov [strcputype]   ,eaxmov [strcputype+4] ,ebxmov [strcputype+8] ,ecxmov [strcputype+12],edxmov eax,0x80000003cpuid; call cpuid commandmov [strcputype+16],eaxmov [strcputype+20],ebxmov [strcputype+24],ecxmov [strcputype+28],edxmov eax,0x80000004cupid     ; call cpuid commandmov [strcputype+32],eaxmov [strcputype+36],ebxmov [strcputype+40],ecxmov [strcputype+44],edxcall _display_endl;mov si, strProcessor;mov al, 0x01;int 0x21call _display_spacemov si, strcputype           ;print processor typemov al, 0x01int 0x21ret

Help menu

cmd_displayHelpMenu:call _display_endlmov si, strHelpMsg0;print help messagemov al, 0x01int 0x21call _display_endlmov si, strHelpMsg1mov al, 0x01int 0x21call _display_endlmov si, strHelpMsg2mov al, 0x01int 0x21call _display_endlmov si, strHelpMsg3mov al, 0x01int 0x21ret

Go through step by step implementation of the JOSH Operating System referencing this guide.

References:

[1] https://www.cs.bgu.ac.il/~yagel/dolev/MinimalOS/josh/

--

--

Tiroshan Madushanka
setublog

Cloud, Distributed Systems, Data Science, Machine Learning Enthusiastic | Tech Lead- Rozie AI Inc. | Research Assistant - NII |Lecturer - University of Kelaniya