<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="https://scientiac.space/feed.xsl" type="text/xsl"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>scientiac::syntropy</title>
    <subtitle>A Computer Engineering student who loves FOSS and is learning about privacy, the Internet and languages writing about the things he does.</subtitle>
    <link href="https:&#x2F;&#x2F;scientiac.space"/>
    <link href="https://scientiac.space/atom.xml" rel="self" type="application/atom+xml"/>
    <updated>2026-01-05T00:00:00+00:00</updated>
    <id>https:&#x2F;&#x2F;scientiac.space</id>
    <entry>
        <title>KL-OS: File System</title>
        <link href="https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2026-01-05&#x2F;"/>
        <updated>2026-01-05T00:00:00+00:00</updated>
        <author><name>scientiac</name></author>
        <id>https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2026-01-05&#x2F;</id>
        <content type="html"><![CDATA[
          <a class="u-bridgy-fed" href="https://fed.brid.gy/" hidden="from-humans"></a>
<p><a rel="external" href="https://codeberg.org/scientiac/KL-OS/src/branch/main/progress/day-15.md">Day 15</a> was about File System.</p>
<p>The <a rel="external" href="https://operating-system-in-1000-lines.vercel.app/en/">book</a> that I am following has come to an end with <strong>File System</strong> as the final chapter where it teaches to implement <code>tar</code> file as a filesystem.</p>
<p><code>tar</code> is an archive format (like zip) that can contain multiple files. It contains file contents, filenames, creation dates, and other information necessary for a filesystem. Compared to common filesystem formats like FAT or ext2, tar has a much simpler data structure.</p>
<p>First a simple directory with two files is made as an example which is then archived/compressed into the <code>tar</code> format using the command line <code>tar</code> tool. Which, also is added to the <code>buildscript</code> before launching the <code>qemu</code> VM.</p>
<pre class="giallo" style="color: #EBDBB2; background-color: #282828;"><code data-lang="shellscript"><span class="giallo-l"><span style="color: #A89984;">(</span><span style="color: #FE8019;">cd</span><span style="color: #B8BB26;"> disk</span><span style="color: #A89984;"> &amp;&amp;</span><span style="color: #FABD2F;"> tar</span><span style="color: #B8BB26;"> cf ../disk.tar</span><span style="color: #D3869B;"> --format=ustar</span><span style="color: #83A598;"> *</span><span style="color: #B8BB26;">.txt</span><span style="color: #A89984;">)</span></span>
<span class="giallo-l"></span>
<span class="giallo-l"><span style="color: #928374;font-style: italic;"># The following flag is also added to qemu.</span></span>
<span class="giallo-l"><span style="color: #FABD2F;">-drive</span><span style="color: #B8BB26;"> id=drive0,file=disk.tar,format=raw,if=none</span><span style="color: #D3869B;"> \</span></span></code></pre>
<p>To read the filesystem, first, the data structures related to the tar filesystem is defined in <code>kernel.h</code>. This implementation has all files read from the disk at boot.</p>
<p>To write to the disk, the contents of the <code>files</code> variable is written back to the disk in the tar file format. The <code>files</code> variable contains the copy of the <code>disk</code> variable declared as a static variable (It is a temporary buffer and, since the stack has a limited size it is preferred to use static variable instead of local <code>stack</code> variable.) which contains the disk image.</p>
<p>File read/write system calls are then designed in the <code>user.c</code> and <code>user.h</code> files and then the system calls are implemented on the kernel files and then the system calls are implemented in the kernel. We also add the read and write commands to the shell.</p>
<p>But, we still have to address the user pointers.</p>
<p>In RISC-V, the behaviour of <code>S-Mode</code> (kernel) can be configured through <code>sstatus</code> <code>CSR</code>, including SUM (permit Supervisor User Memory access) bit. When SUM is not set, <code>S-Mode</code> programs (i.e. kernel) cannot access U-Mode (user) pages.</p>
<p>All we need to do is to set the SUM bit when entering user space and voila! Our OS with a filesystem implementation is now ready.</p>

          <hr/>
          <p><i>You might be wondering how I know that you're awesome!</i><br/> Because I know you read this via RSS.</p>
        ]]></content>
    </entry>
    <entry>
        <title>KL-OS: Disk I&#x2F;O</title>
        <link href="https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2026-01-04&#x2F;"/>
        <updated>2026-01-04T00:00:00+00:00</updated>
        <author><name>scientiac</name></author>
        <id>https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2026-01-04&#x2F;</id>
        <content type="html"><![CDATA[
          <a class="u-bridgy-fed" href="https://fed.brid.gy/" hidden="from-humans"></a>
<p><a rel="external" href="https://codeberg.org/scientiac/KL-OS/src/branch/main/progress/day-14.md">Day 14</a> was about Disk <code>I/O</code>.</p>
<p>A device driver for the <code>virtio-blk</code>, a virtual disk device was implemented.</p>
<p><code>Virtio</code> is one of the APIs for device drivers to control devices. It is widely used in virtualization environments such as QEMU.
The <code>virtio</code> devices have a structure called <code>virtqueue</code> and it is a queue shared between the driver and the device.
It consists of <code>Discriptor Table</code>, <code>Available Ring</code> and <code>Used Ring</code>.</p>
<p>First we enable <code>virtio</code> drivers in our <code>buildscript</code> which is <code>run.sh</code>. We use the following flags for <code>qemu</code>:</p>
<pre class="giallo" style="color: #EBDBB2; background-color: #282828;"><code data-lang="shellscript"><span class="giallo-l"><span style="color: #FABD2F;">    -drive</span><span style="color: #B8BB26;"> id=drive0,file=lorem.txt,format=raw,if=none</span></span>
<span class="giallo-l"><span style="color: #FABD2F;">    -device</span><span style="color: #B8BB26;"> virtio-blk-device,drive=drive0,bus=virtio-mmio-bus.0</span></span></code></pre>
<p>Here, <code>lorem.txt</code> is a file made for testing purposes beforehand.</p>
<p>Then, the definition of <code>c</code> structs and macros is done in <code>kernel.h</code>. To access the <code>MMIO</code> registers we add that functionality in <code>kernel.c</code>.</p>
<p>The <code>create_process</code> function is modified to map the <code>virtio-blk</code> <code>MMIO</code> region to the page table so the kernel can access the <code>MMIO</code> registers. <code>MMIO</code> region to the page table so the kernel can access the <code>MMIO</code> registers.</p>
<p>Then the <code>Virtio Device Initialization</code> and <code>Virtqueue Initialization</code> is done with the process described in the <a rel="external" href="https://ozlabs.org/~rusty/virtio-spec/virtio-0.9.5.pdf">spec</a>.</p>
<p><code>I/O</code> requests to the disk is implemented by "adding processing requests to the <code>virtqueue</code>".</p>
<p>A request is sent in the following steps:</p>
<ol>
<li>Construct a request in <code>blk_req</code>. Specify the sector number you want to access and the type of read/write.</li>
<li>Construct a descriptor chain pointing to each area of <code>blk_req</code> (see below).</li>
<li>Add the index of the head descriptor of the descriptor chain to the Available Ring.</li>
<li>Notify the device that there is a new pending request.</li>
<li>Wait until the device finishes processing (aka busy-waiting or polling).</li>
<li>Check the response from the device.</li>
</ol>
<p>To test, we initialize the <code>virtio</code> device in the kernel main and try reading and writing to the disk with the implemented functions.</p>
<blockquote>
<p>Device drivers are just "glue" between the OS and devices. Drivers don't control the hardware directly; drivers communicate with other software running on the device (e.g., firmware). Devices and their software, not the OS driver, will do the rest of the heavy lifting, like moving disk read/write heads.</p>
</blockquote>

          <hr/>
          <p><i>You might be wondering how I know that you're awesome!</i><br/> Because I know you read this via RSS.</p>
        ]]></content>
    </entry>
    <entry>
        <title>KL-OS: System Call</title>
        <link href="https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2026-01-03&#x2F;"/>
        <updated>2026-01-03T00:00:00+00:00</updated>
        <author><name>scientiac</name></author>
        <id>https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2026-01-03&#x2F;</id>
        <content type="html"><![CDATA[
          <a class="u-bridgy-fed" href="https://fed.brid.gy/" hidden="from-humans"></a>
<p><a rel="external" href="https://codeberg.org/scientiac/KL-OS/src/branch/main/progress/day-13.md">Day 13</a> was about system call.</p>
<p>Similar to <code>SBI Call</code> implementation, the system calls are invoked in a similar way.</p>
<p>The <code>syscall</code> function sets the system call number in the <code>a3</code> register and the system call arguments in the <code>a0</code> to <code>a2</code> registers, then executes the <code>ecall</code> instruction. The <code>ecall</code> instruction is a special instruction used to delegate processing to the kernel. When the <code>ecall</code> instruction is executed, an exception handler is called, and control is transferred to the kernel. The return value from the kernel is set in the <code>a0</code> register.</p>
<p>The first <code>systemcall</code> implemented is <code>putchar</code>. It takes a character as the first argument and the second and subsequent unused arguments are set to 0.</p>
<p>Then the <code>ecall</code> instruction is handled in the kernel. The calling of <code>ecall</code> can by determined by checking the value of <code>scause</code>. Before calling the <code>handle_syscall</code> function we also add the size of <code>ecall</code> instruction (4) to the value of <code>sepc</code>.</p>
<p>This is because <code>sepc</code> points to the program counter that caused the exception, which points to the <code>ecall</code> instruction. If we don't change it, the kernel goes back to the same place, and the <code>ecall</code> instruction is executed repeatedly.</p>
<p>Then a <code>system call</code>  handler is made and is called from trap handler. It receives a
structure of registers at the time of exception that was saved in the trap handler. It determined the type of system call by checking the value of <code>a3</code> register.</p>
<p>The system call was then tested with a main print function in <code>shell.c</code>.</p>
<p>An <code>exit</code> system call is also implemented where it takes the first argument as <code>3</code> which is defined as <code>SYS_EXIT</code>.</p>
<p>The system call changes the process state to <code>PROC_EXITED</code>, and calls yield to give up the CPU to other processes. The scheduler will only execute processes in <code>PROC_RUNNABLE</code> state, so it will never return to this process. However, <code>PANIC</code> macro is added to cause a panic in case it does return.</p>
<p>A bare-bones shell was then implemented to use the syscalls to perform actions from the user mode.</p>

          <hr/>
          <p><i>You might be wondering how I know that you're awesome!</i><br/> Because I know you read this via RSS.</p>
        ]]></content>
    </entry>
    <entry>
        <title>KL-OS: User Mode</title>
        <link href="https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2026-01-02&#x2F;"/>
        <updated>2026-01-02T00:00:00+00:00</updated>
        <author><name>scientiac</name></author>
        <id>https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2026-01-02&#x2F;</id>
        <content type="html"><![CDATA[
          <a class="u-bridgy-fed" href="https://fed.brid.gy/" hidden="from-humans"></a>
<p><a rel="external" href="https://codeberg.org/scientiac/KL-OS/src/branch/main/progress/day-12.md">Day 12</a> was about user mode.</p>
<p>The application that we had made had to be run on the user mode. And since, the execution
image is a raw binary, it needs to be prepared with a fixed binary.</p>
<pre class="giallo" style="color: #EBDBB2; background-color: #282828;"><code data-lang="c"><span class="giallo-l"><span style="color: #A89984;">#</span><span style="color: #8EC07C;">define</span><span style="color: #FABD2F;"> USER_BASE</span><span style="color: #B8BB26;"> 0x</span><span style="color: #D3869B;">1000000</span></span></code></pre>
<p>After defining the symbols to use in the embedded raw binary, the create process function is updated to start the application from the <code>user_entry</code>.</p>
<p>The <code>create_process</code> is modified to take the pointer to the execution image and image size as arguments. It copies the execution image page by page for the specified size and maps it to the process page table.</p>
<p>Finally, the <code>create_process</code> function is modified to create a user process.</p>
<p>After checking if the execution image is mapped as expected, to run applications we must transition the CPU to the user mode. Or, in RISC-V, the U-Mode.</p>
<p>This switch from <code>S-Mode</code> to <code>U-mode</code> is done with the <code>sret</code> instruction. It does two writes to CSRs while switching:</p>
<ul>
<li><code>PC</code> is set for when transitioning in U-Mode in the <code>sepc</code> register where <code>sret</code> jumps to.</li>
<li>Then, setting <code>SPIE</code> bit in the <code>sstatus</code> register enables hardware interrupts and the handler set in the <code>stvec</code> register will be called while entering the <code>U-Mode</code>.</li>
</ul>

          <hr/>
          <p><i>You might be wondering how I know that you're awesome!</i><br/> Because I know you read this via RSS.</p>
        ]]></content>
    </entry>
    <entry>
        <title>KL-OS: Application</title>
        <link href="https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2026-01-01&#x2F;"/>
        <updated>2026-01-01T00:00:00+00:00</updated>
        <author><name>scientiac</name></author>
        <id>https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2026-01-01&#x2F;</id>
        <content type="html"><![CDATA[
          <a class="u-bridgy-fed" href="https://fed.brid.gy/" hidden="from-humans"></a>
<p><a rel="external" href="https://codeberg.org/scientiac/KL-OS/src/branch/main/progress/day-11.md">Day 11</a> was about application.</p>
<p>First, a linker script named <code>user.ln</code> was made this time starting at address <code>1000000</code> so that the application doesn't overlap with the kernel space.</p>
<p>Then a simple <code>userland</code> library is created with minimal features just enough to indicate the existence of a userland application.
A header file for the userland library is also made.</p>
<p>Then an application is made, very <code>barebones</code>, it is just an infinite loop for now since there is no way to print characters at the moment.</p>
<p>To build the application, we first compile it with cc to get an executable in a <code>ELF</code> format. The executable is then converted to raw binary format with the <code>objcopy</code> tool.
Then the raw binary executable format is then again converted to a format that can be embedded in the C language.</p>
<p>Lastly, the <code>shell.bin.o</code> output is then passed to <code>clang</code> (kernel build section of the script) which gets embedded into the kernel image.</p>

          <hr/>
          <p><i>You might be wondering how I know that you're awesome!</i><br/> Because I know you read this via RSS.</p>
        ]]></content>
    </entry>
    <entry>
        <title>KL-OS: Examining Pages</title>
        <link href="https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2025-12-31&#x2F;"/>
        <updated>2025-12-31T00:00:00+00:00</updated>
        <author><name>scientiac</name></author>
        <id>https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2025-12-31&#x2F;</id>
        <content type="html"><![CDATA[
          <a class="u-bridgy-fed" href="https://fed.brid.gy/" hidden="from-humans"></a>
<p><a rel="external" href="https://codeberg.org/scientiac/KL-OS/src/branch/main/progress/day-10.md">Day 10</a> was about testing and debugging paging and page table contents.</p>
<p>Running the <code>buildscript</code> should give us the exact same output of repeating letters similar to how it was before paging was implemented.</p>
<p>Then the page table contents were examined. To check about the registers, following command was run on the <code>qemu</code> console.</p>
<pre class="giallo" style="color: #EBDBB2; background-color: #282828;"><code data-lang="shellscript"><span class="giallo-l"><span style="color: #A89984;">(</span><span style="color: #FABD2F;">qemu</span><span style="color: #A89984;">)</span><span style="color: #FABD2F;"> info</span><span style="color: #B8BB26;"> registers</span></span></code></pre>
<p>Then the value of <code>satp</code> register is read and then interpreted by doing the following hexadecimal math:</p>
<pre class="giallo" style="color: #EBDBB2; background-color: #282828;"><code data-lang="python"><span class="giallo-l"><span style="color: #FE8019;">hex</span><span style="color: #A89984;">((</span><span style="color: #CC241D;">0x</span><span style="color: #8EC07C;">&lt;</span><span style="color: #D5C4A1;">val of satp</span><span style="color: #8EC07C;">&gt; &amp;</span><span style="color: #FE8019;"> 0x</span><span style="color: #D3869B;">3fffff</span><span style="color: #A89984;">)</span><span style="color: #8EC07C;"> *</span><span style="color: #D3869B;"> 4096</span><span style="color: #A89984;">)</span></span></code></pre>
<p>Then the <code>VPN[1]</code> and <code>VPN[0]</code> physical addressed were also examined.</p>
<p>The consequences of forgetting to set the paging mode, specifying physical address instead of physical page number was also seen. <code>qemu</code> logs were also enabled.</p>

          <hr/>
          <p><i>You might be wondering how I know that you're awesome!</i><br/> Because I know you read this via RSS.</p>
        ]]></content>
    </entry>
    <entry>
        <title>KL-OS: Page Table</title>
        <link href="https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2025-12-30&#x2F;"/>
        <updated>2025-12-30T00:00:00+00:00</updated>
        <author><name>scientiac</name></author>
        <id>https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2025-12-30&#x2F;</id>
        <content type="html"><![CDATA[
          <a class="u-bridgy-fed" href="https://fed.brid.gy/" hidden="from-humans"></a>
<p><a rel="external" href="https://codeberg.org/scientiac/KL-OS/src/branch/main/progress/day-9.md">Day 9</a> was about memory management and virtual addressing.</p>
<p>The structure of the virtual address is defined by the RISC-V paging mechanism called <code>Sv32</code>.
It uses a two level page table where the 32 bit virtual address  is divided into a first-level page table index, a second level and a page offset. The tables are named <code>VPN[1]</code> and <code>VPN[0]</code> respectively.</p>
<p>First the macros for the construction of the page table are defined. Then the function to map pages <code>map_page</code> is made which is utilized in process creation. For that we also add an element called <code>page_table</code> on the <code>struct</code> of process. And to make everything work we define the starting address of the kernel space <code>__kernel__base</code> in the linker script just after boot.</p>
<p>To utilize the above setup of page tables and switch them, we specify the first-level page table in <code>satp</code> (Supervisor Address Translation and Protection) register.</p>
<p>I still need to understand more about this. I am not satisfied with the explanation from the resource.</p>

          <hr/>
          <p><i>You might be wondering how I know that you're awesome!</i><br/> Because I know you read this via RSS.</p>
        ]]></content>
    </entry>
    <entry>
        <title>KL-OS: Process</title>
        <link href="https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2025-12-29&#x2F;"/>
        <updated>2025-12-29T00:00:00+00:00</updated>
        <author><name>scientiac</name></author>
        <id>https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2025-12-29&#x2F;</id>
        <content type="html"><![CDATA[
          <a class="u-bridgy-fed" href="https://fed.brid.gy/" hidden="from-humans"></a>
<p><a rel="external" href="https://codeberg.org/scientiac/KL-OS/src/branch/main/progress/day-8.md">Day 8</a> was about Process. Though, modern operating systems use the concept of threads to provide execution context. We treat processes like individual threads being run for our implementation.</p>
<p>First we define a structure for PCB (Process Control Block). We first define <code>PROC_UNUSED</code> and <code>0</code> and <code>PROC_RUNNABLE</code> as <code>1</code>. Then we create a structure for a unit process with the following slots:</p>
<ul>
<li>Process ID as an Integer.</li>
<li>State (<em><code>PROC_UNUSED </code>or <code>PROC_RUNNABLE</code></em>) as an Integer as defined before.</li>
<li>Stack Pointer as a <code>vaddr_t</code> (Virtual Address Type).</li>
<li>Kernel Stack as a list of unsigned <code>8bit</code> Integers.</li>
</ul>
<p>The Kernel Stack is essential for saving the registers while context switching.</p>
<p>Then, we defined the <code>switch_context</code> function that does the context switching. It takes
the previous and next stack pointer as arguments and then switches them during execution.
It saves the callee-saved registers into the stack, switches the stack pointer then restores the callee-saved registers from the stack. <em>The execution context is saved as a temporary local variable on the stack.</em></p>
<p>Then, we work on process creation. The process creation function <code>create_process</code> takes
in the entry point of the process as a parameter and then returns the process struct.</p>
<p>The <code>delay</code> function is also created to act as a sleep style function which just does <code>nop</code> (Nothing) for 30000000 clock pulses.</p>
<p>Then a <strong>scheduler</strong> is made to make the context switching more autonomous.
A scheduler is basically a Kernel program which decides the next process.</p>
<p>Then, in the exception handler, we make it so that each process has it's own independent kernel stack. While switching, the contents of <code>sscratch</code> are switched too to resume the execution of process from where it was interrupted as if nothing had happened.</p>

          <hr/>
          <p><i>You might be wondering how I know that you're awesome!</i><br/> Because I know you read this via RSS.</p>
        ]]></content>
    </entry>
    <entry>
        <title>KL-OS: Memory Allocation</title>
        <link href="https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2025-12-28&#x2F;"/>
        <updated>2025-12-28T00:00:00+00:00</updated>
        <author><name>scientiac</name></author>
        <id>https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2025-12-28&#x2F;</id>
        <content type="html"><![CDATA[
          <a class="u-bridgy-fed" href="https://fed.brid.gy/" hidden="from-humans"></a>
<p><a rel="external" href="https://codeberg.org/scientiac/KL-OS/src/branch/main/progress/day-7.md">Day 7</a> was about Memory Allocation. First the memory regions were defined in the linker script so that it can determine the position to avoid overlapping the memory to kernel's static data.</p>
<p>The size of the memory space was <code>64 * 1024 * 1024</code> bytes or <code>64MB</code> and it is aligned to a <code>4KB</code> boundary.</p>
<p>Then a function <code>alloc_pages</code> was implemented which allocated <code>n</code> pages of memory and returned it's starting address.</p>

          <hr/>
          <p><i>You might be wondering how I know that you're awesome!</i><br/> Because I know you read this via RSS.</p>
        ]]></content>
    </entry>
    <entry>
        <title>KL-OS: Exceptions</title>
        <link href="https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2025-12-27&#x2F;"/>
        <updated>2025-12-27T00:00:00+00:00</updated>
        <author><name>scientiac</name></author>
        <id>https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2025-12-27&#x2F;</id>
        <content type="html"><![CDATA[
          <a class="u-bridgy-fed" href="https://fed.brid.gy/" hidden="from-humans"></a>
<p><a rel="external" href="https://codeberg.org/scientiac/KL-OS/src/branch/main/progress/day-6.md">Day 6</a> was about Exceptions and handling those Exceptions in the kernel.</p>
<p>In RISC-V the CPU first checks <code>medeleg</code> register to determine which operation mode should handle the exception.
In our case <code>U-mode/S-mode</code> is already handled by <code>OpenSBI</code>.
Then, the CPU saves states into various <code>CSRs</code>.
<code>stvec</code> register is set to <code>pc</code> then the exception is handled using the handler. Then <code>sret</code> is called to resume execution from the point where exception occurred.</p>
<p>The <code>handle_trap</code> function reads why the exception occurred and triggers the kernel panic. Which was implemented yesterday.</p>

          <hr/>
          <p><i>You might be wondering how I know that you're awesome!</i><br/> Because I know you read this via RSS.</p>
        ]]></content>
    </entry>
    <entry>
        <title>KL-OS: PANIC</title>
        <link href="https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2025-12-26&#x2F;"/>
        <updated>2025-12-26T00:00:00+00:00</updated>
        <author><name>scientiac</name></author>
        <id>https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2025-12-26&#x2F;</id>
        <content type="html"><![CDATA[
          <a class="u-bridgy-fed" href="https://fed.brid.gy/" hidden="from-humans"></a>
<p>Perfect topic for today because early morning I was shown why It was a stupid decision to do something, then at afternoon I got into a bike accident. Though it was minor with no injuries to both parties except some scratches on the bikes. It could have caused huge consequences. Then I did another mistake and then another.</p>
<p>PANIC!</p>
<p>It is <a rel="external" href="https://codeberg.org/scientiac/KL-OS/src/branch/main/progress/day-5.md">day 5</a>. Implementing panic was very easy, it is implemented as a macro because if we defined it as a function it would have printed the <code>__LINE__</code> and <code>__FILE__</code> where <code>PANIC</code> is defined and not where it is called. And to halt the kernel it uses a <code>while true</code> loop which goes on infinitely.</p>

          <hr/>
          <p><i>You might be wondering how I know that you're awesome!</i><br/> Because I know you read this via RSS.</p>
        ]]></content>
    </entry>
    <entry>
        <title>KL-OS: C Standard Library</title>
        <link href="https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2025-12-25&#x2F;"/>
        <updated>2025-12-25T00:00:00+00:00</updated>
        <author><name>scientiac</name></author>
        <id>https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2025-12-25&#x2F;</id>
        <content type="html"><![CDATA[
          <a class="u-bridgy-fed" href="https://fed.brid.gy/" hidden="from-humans"></a>
<p>To make a useful kernel we require it to perform tasks like setting a memory chunk to zero,
or copying the memory from a source address to destination address. It may have to understand
what a boolean is or what NULL is. So, for that we require the "C Standard Library" and hence
we need to implement it (or the functions it contains as abstractions to commonly used functions).</p>
<p>For this, in <a rel="external" href="https://codeberg.org/scientiac/KL-OS/src/branch/main/progress/day-4.md">day 4</a> I utilized <code>clang</code>'s internal C library as well as resorted to writing the functions all by myself.</p>

          <hr/>
          <p><i>You might be wondering how I know that you're awesome!</i><br/> Because I know you read this via RSS.</p>
        ]]></content>
    </entry>
    <entry>
        <title>KL-OS: Printing</title>
        <link href="https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2025-12-24&#x2F;"/>
        <updated>2025-12-24T00:00:00+00:00</updated>
        <author><name>scientiac</name></author>
        <id>https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2025-12-24&#x2F;</id>
        <content type="html"><![CDATA[
          <a class="u-bridgy-fed" href="https://fed.brid.gy/" hidden="from-humans"></a>
<p>As the days progress the journey is getting more fun and interesting.
It was the part where actual text was going to be printed.
It was a kernel <code>hello-world</code>.</p>
<p><a rel="external" href="https://codeberg.org/scientiac/KL-OS/src/branch/main/progress/day-3.md">Day 3</a> focused on printing characters on the console by talking to SBI finally implementing <code>putchar</code> and eventually <code>printf</code>.</p>

          <hr/>
          <p><i>You might be wondering how I know that you're awesome!</i><br/> Because I know you read this via RSS.</p>
        ]]></content>
    </entry>
    <entry>
        <title>KL-OS: Boot</title>
        <link href="https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2025-12-23&#x2F;"/>
        <updated>2025-12-23T00:00:00+00:00</updated>
        <author><name>scientiac</name></author>
        <id>https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2025-12-23&#x2F;</id>
        <content type="html"><![CDATA[
          <a class="u-bridgy-fed" href="https://fed.brid.gy/" hidden="from-humans"></a>
<p>The actual development of OS started with making the build script <code>run.sh</code> in bash to setup and launch a <code>qemu</code> RISC-V virtual machine with <code>OpenSBI</code> as bios for QEMU.</p>
<p>Then a linker script <code>kernel.ld</code> was made and a basic kernel process <code>kernel.c</code> was written. Finally, the build script was updated to include compiler and execution commands and flags to properly boot the kernel.</p>
<p><a rel="external" href="https://codeberg.org/scientiac/KL-OS/src/branch/main/progress/day-2.md">Day 2</a> focused on writing a basic starting process of a kernel and running it in a virtual machine.</p>

          <hr/>
          <p><i>You might be wondering how I know that you're awesome!</i><br/> Because I know you read this via RSS.</p>
        ]]></content>
    </entry>
    <entry>
        <title>KL-OS: Setting Up</title>
        <link href="https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2025-12-22&#x2F;"/>
        <updated>2025-12-22T00:00:00+00:00</updated>
        <author><name>scientiac</name></author>
        <id>https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2025-12-22&#x2F;</id>
        <content type="html"><![CDATA[
          <a class="u-bridgy-fed" href="https://fed.brid.gy/" hidden="from-humans"></a>
<p>I have set up the environment required to run RISC-V 64 toolchain using <code>QEMU</code>.</p>
<p>Installed a <code>debian</code> RISC-V 64 <code>iso</code> and set it up to my liking with <code>autologin</code> and proper terminal emulation and <code>sudo</code>. I then installed <code>gcc</code>, <code>gdb</code> and <code>neovim</code> for writing and compiling programs.</p>
<p>Details of what happened on <a rel="external" href="https://codeberg.org/scientiac/KL-OS/src/branch/main/progress/day-1.md">Day 1</a> is tracked using <code>git</code> with <code>codeberg</code> as a remote.</p>
<p>I have decided to use <a rel="external" href="https://operating-system-in-1000-lines.vercel.app/">Operating System in 1000 Lines</a> as the learning material because it was featured as a beginner level learning material in <a rel="external" href="https://github.com/riscv/learn">github:riscv/learn</a>.</p>

          <hr/>
          <p><i>You might be wondering how I know that you're awesome!</i><br/> Because I know you read this via RSS.</p>
        ]]></content>
    </entry>
    <entry>
        <title>KL-OS: Checkpoint</title>
        <link href="https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2025-12-21&#x2F;"/>
        <updated>2025-12-21T00:00:00+00:00</updated>
        <author><name>scientiac</name></author>
        <id>https:&#x2F;&#x2F;scientiac.space&#x2F;syndications&#x2F;kl-os-2025-12-21&#x2F;</id>
        <content type="html"><![CDATA[
          <a class="u-bridgy-fed" href="https://fed.brid.gy/" hidden="from-humans"></a>
<p>I want to learn systems programming and I thought why not go with the open source one which is currency in development.
So, I chose the RISC-V architecture.
That way if I decide to keep pursuing it, I can grow along with the ISA slowly catching up to it.</p>
<p>I want to keep a streak by posting here every day about what I learn. Let's hope it goes well.</p>

          <hr/>
          <p><i>You might be wondering how I know that you're awesome!</i><br/> Because I know you read this via RSS.</p>
        ]]></content>
    </entry>
</feed>
