Operating System Development from Scratch

Operating System Development from Scratch

International Journal of Advances in Electronics and Computer Science, ISSN(p): 2394-2835 Volume-6, Issue-11, Nov.-2019 http://iraj.in OPERATING SYSTEM DEVELOPMENT FROM SCRATCH SHIVAM BASIA Student, KIIT Deemed To Be University, Bhubaneswar, India E-mail: [email protected] Abstract - This research project is based on developing an operating system from scratch to demonstrate and understand how a entire computer system actually gets built and how it works internally. Our Operating System has been built by using Assembly Language only. Our Operating System in general consists of a Bootloader, a Kernel,FAT32 partition file system and a simple shell all of which has been built from scratch. Various command line features has been added in our operating system like change directory, listing and even the cat command for displaying contents of any text file. The size of our Operating System is 8 MB. The memory disk of our Operating System is divided into 16384 blocks with each block’s size being 512 bytes. The testing of our Operating System was performed in two emulators namely qemu and virtualbox. Keywords - Operating System, Bootloader, Assembly Language,Kernel,FAT32 partition file system, shell. I. INTRODUCTION Thirdly, the entire boot sector gets load at address 0000:7c00 and with that the CPU starts executing the Before the development of an operating system from very first instruction it founds at that address. So, for scratch it is important to know what is an operating building our bootloader and for ensuring that the system and what components and resources it consists kernel gets load from the FAT32 partition file system of. An operating system can be said to be a software by the boot sector we defined the first 90 bytes of the which controls the entire operation of a computer boot sector as the FAT32 BPB (BIOS Parameter Block) system as well as handles all its resources. Some and external BPB and a Disk Address Packet for functions of operating systems are to manage memory memory address handling. The details contain in BPB, and other system resources, keep the security and external BPB and the disk address packet are given in access policies in check as well as to schedule Table 1,Table 2,Table 3 respectively. After that the processes. An operating system in general consists of a bootloader loading code was written, the steps of bootloader, a kernel and a command line interface which are mentioned in Table 4. BPB, externalBPB, which we can be called as a shell. A boot loader can be disk address packet along with bootloader loading said to be a software which brings the kernel into code was enough to load the kernel at 17c0:0000 and memory and provides kernel with all the required transfer control to the kernel by using long jump. information it needs to work correctly. The kernel of an operating system is basically a software which i. Jump bit specifying the address of kernel to jump enables any other programs to execute in the computer ii. Original equipment manager id for security and system. The kernel also handles various events access policies generated by hardware and software which are also iii. Bytes per sector called as interrupts and system calls respectively. It iv. Sectors per cluster also performs the task of management of access to v. Reserved Sectors resources. A command line interface or a shell is vi. Number of File Allocation Tables typically a program that is integrated into the vii. Root Entries distribution of an operating system which basically viii. Total Sectors helps human beings in getting an interface with the ix. Media Descriptor computer. x. Sectors per File Allocation Table xi. Sectors per Track II. DEVELOPMENT OF BOOTLOADER xii. Number of Heads Firstly, a Bootloader was to be created for our xiii. Hidden Sectors Operating System. So, to create a Bootloader it was xiv. Total Sectors important to know the Booting Process. The Booting Table 1:Details contain in FAT32 BPB Process works in three ways in a computer system. i. Sectors per File Allocation Table Firstly, when a computer is switched on, the computer ii. Flags performs a Power-On Self Test (POST) which refers to if the computer system is getting enough power iii. FAT Version supply to run. Secondly, it detects if a bootable disk iv. Root Cluster has been inserted in the disk drive or not and if inserted v. File System Information Sector it loads the boot sector which is generally the first 512 vi. Backup Boot Sector bytes on the disk and will be executable if the last two vii. 12 reserved bits bytes of the boot sector are the magic value 0xaa55. viii. Drive Number Operating System Development from Scratch 59 International Journal of Advances in Electronics and Computer Science, ISSN(p): 2394-2835 Volume-6, Issue-11, Nov.-2019 http://iraj.in ix. Drive Signature vii. Restore the drive number. x. System Identifier viii. Mount the FAT32 partition. Table 2: Details contain in external BPB ix. Print the mount message. x. Since the DL register already contains the drive i. Unused sectors number, clear DH. ii. Number of sectors xi. Read the partition entry DH on drive DL. iii. Offset xii. Preserve EDX for copying the LBA number into iv. Segment EDX for printf. v. Starting Logical Block Address xiii. Restore EDX. Table 3:Details contain in disk address packet xiv. Final mount the partition. xv. Initialize the shell. i. Clear the direction flag. xvi. Jump into the shell. ii. Set Data Segment to Code Segment. Table 5:Initializing the init code of the kernel iii. Place the stack at the top of the current segment. iv. Initialize FS. Next, we had to find a way to halt if an interrupt is v. Store the current drive number. encountered. For the interrupt to work we performed vi. Find the FAT offset. the steps given in table 6. vii. Add the number of reserved sectors. viii. Store the sectors. i. Register an interrupt handler. ix. Preserve EAX. ii. Initialize BL as the interrupt number. x. Find the data cluster offset. iii. DX will be the CS offset. xi. Set CX to the number of FATs. iv. Disable interrupts by calling clear interrupt flag. xii. Perform the operation of AX*CX -> EDX:EAX. v. Create the Interrupt Vector Table(IVT) segment. xiii. Add the previous offset. vi. Initialize the BH register as 0 and multiply BX xiv. Store the data offset. register by 4. xv. Find the number of directory entries per cluster. vii. Add ES:BXoffset to DX register. xvi. Multiply CX by 16 as its the number of 32-byte viii. Move the CS register to DX register. directory entries per a 512-byte sector. ix. Enable interrupts by calling set interrupt flag. xvii. Store the value. x. Finally Return from an interrupt without xviii. Read the root clusters. restoring the original CF. xix. The buffer will be at 0050:0000. Table 6:Interrupt handling xx. Read the first cluster of the root directory. xxi. Clear DI. Next, kernel system call was to be designed. Forit,we xxii. Iterate CX times. performed the steps given in table 7. xxiii. For finding the next entries compare the file names. i. Assign BP register to specify the function to call. xxiv. Restore the registers when the entry is found. ii. Assign 0 for kalloc function. xxv. Load the number of the next cluster. iii. Assign 1 for kfree function. xxvi. Finally, load the kernel at 17c0:0000 and transfer iv. Preserve DS and set DS to the kernel segment. control to the kernel by long jump. v. Compare BP to 0 to jump to kalloc or kfree Table 4: Steps of bootloader loading function. Table 7:Kernel System Call Finally, the development of bootloader was completed. Next, The console I/O system call was to be designed. For it, we performed the steps in table 8. III. DEVELOPMENT OF KERNEL i. Assign BP register to specify the function to call. Since the bootloader was initially developed, it had ii. Assign 0 for print. already placed the kernel at 17c0:0000.Now,we had to iii. Assign 1 for printf. jump to the initcode. The steps of init code initializing iv. Assign 2 for newline. are given in table 5. v. Assign 3 for printChar. vi. Assign 4 for readLine. i. Initialize the segments. vii. Compare BP to 0,1,2,3,4 for jumping to the ii. Preserve the drive number. required I/O system call. iii. Call the Initkalloc subroutine. Table 8: Console I/O System Call iv. Clear the screen by calling console.clearscreen. v. Print the boot message. Also, interrupt service routines for console, string and shell was designed and integrated with the kernel for vi. Register the system calls by calling interrupt screen handling, keyboard handling and command line subroutines. Operating System Development from Scratch 60 International Journal of Advances in Electronics and Computer Science, ISSN(p): 2394-2835 Volume-6, Issue-11, Nov.-2019 http://iraj.in interface respectively. The steps for building console recursively. subroutine, string subroutine and console subroutine xvii. Lists the files in the current directory along with are given in table 9, table 10,table 11 respectively. their attributes and initialize the directory enumeration where DX counts the entries i. Initialize our screen width and height as 80 and printed. 25 respectively. xviii. Parse the directory entry at FS for the next entry. ii. Clear the screen and go to 0,0. xix. Set the temporary file name type of the file as '-' iii.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    5 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us