{"id":6113,"date":"2026-07-01T14:33:17","date_gmt":"2026-07-01T05:33:17","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=6113"},"modified":"2026-07-01T14:39:12","modified_gmt":"2026-07-01T05:39:12","slug":"os-minios-8-1","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2026\/07\/01\/os-minios-8-1\/","title":{"rendered":"[OS]miniOS-8"},"content":{"rendered":"\n<p>\ud83d\udc49\ufe0f 32\ube44\ud2b8 \ubcf4\ud638\ubaa8\ub4dc(\uadf8\ub798\ud53d\ubaa8\ub4dc)\uc5d0\uc11c \ud654\uba74\uc5d0 \uc0ac\uac01\ud615\uc744 \ubcf4\uc5ec\uc8fc\ub294 \ucf54\ub4dc\uc785\ub2c8\ub2e4.<br>This is code that displays a rectangle on the screen in 32-bit protected mode (graphics mode).<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \uc774\uc804 miniOS-7\uc5d0\uc11c \ucf54\ub4dc\uc5d0\uc11c \ubc14\ub010 \ubd80\ubd84\ub9cc \uc124\uba85\ud569\ub2c8\ub2e4.<br>This section explains only the changes made to the code from the previous miniOS-7.<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \ucf54\ub4dc \/ Code<\/p>\n\n\n\n<p>\u2714\ufe0f boot.asm<\/p>\n\n\n\n<p>&#8212; boot.asm\uc5d0\uc11c 2\ubc88 \uc139\ud130 \ucf54\ub4dc\ub97c 1\uc5d0\uc11c 10\uc73c\ub85c \uc218\uc815\ud569\ub2c8\ub2e4.<br>In boot.asm, change the sector code from 1 to 10.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    mov al, 10          ; \u2705 1\uc5d0\uc11c 10\uc73c\ub85c \uc218\uc815 (\ub109\ub109\ud558\uac8c \uc77d\uc5b4\uc634)\n                        ; Adjusted from 1 to 10 (read with a generous margin)<\/code><\/pre>\n\n\n\n<p>1)\uae30\uc874 \uc5b4\uc148\ube14\ub9ac \ucf54\ub4dc\uc678\uc5d0 c\uc5b8\uc5b4 \ucf54\ub4dc\ub97c \ucd94\uac00\ud558\uba74 \uc6a9\ub7c9\uc774 \uc99d\uac00\ud558\uae30 \ub54c\ubb38\uc5d0 c\uc5b8\uc5b4 \ucf54\ub4dc\uc6a9\ub7c9\uae4c\uc9c0 \uace0\ub824\ud574\uc11c 10\uc139\ud130\uae4c\uc9c0 \uc77d\uc5b4 \uc624\ub3c4\ub85d \ud569\ub2c8\ub2e4.<br>Since adding C code alongside the existing assembly code increases the total size, the system is configured to read up to 10 sectors to accommodate the C code.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>10\uac1c \uc139\ud130 \ud06c\uae30: 512\ubc14\uc774\ud2b8 \u00d7 10 = 5,120\ubc14\uc774\ud2b8 (\uc57d 5KB)\nSize of 10 sectors: 512 bytes \u00d7 10 = 5,120 bytes (approx. 5 KB)<\/code><\/pre>\n\n\n\n<p>2) 10\uac1c \uc139\ud130\ub85c \ub109\ub109\ud558\uac8c \uc9c0\uc815\ud574 \ub450\uba74 \ucf54\ub4dc\uac00 \uc798\ub9ac\ub294 \uc77c \uc5c6\uc774 \uc548\uc815\uc801\uc73c\ub85c \uba54\ubaa8\ub9ac\uc5d0 \ub2e4 \ub85c\ub4dc\ub429\ub2c8\ub2e4.<br>By generously allocating 10 sectors, the code loads reliably into memory in its entirety without being truncated.<\/p>\n\n\n\n<p>\u2714\ufe0f sector2.asm<\/p>\n\n\n\n<p>&#8212; [org 0x8000]\ub97c \uc8fc\uc11d\ucc98\ub9ac \ud558\uac70\ub098 \uc81c\uac70\ud569\ub2c8\ub2e4.<br>Comment out or remove [org 0x8000].<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>; \u2705 \ucf54\ub4dc \uc81c\uac70 \/ Remove code\n;&#91;org 0x8000] <\/code><\/pre>\n\n\n\n<p>1)[org 0x8000]  \uc774 \ucf54\ub4dc\ub294 \uc21c\uc218 \ubc14\uc774\ub108\ub9ac\uc6a9 \uc785\ub2c8\ub2e4.<br>[org 0x8000] This code is for a raw binary.<\/p>\n\n\n\n<p>2) \uadf8\ub798\uc11c \ucf54\ub4dc \uc548\uc5d0 \uc788\ub294 \ubcc0\uc218\ub098 \ud568\uc218\ub4e4\uc758 \uc8fc\uc18c\ub97c \ubbf8\ub9ac 0x8000 \uae30\uc900\uc73c\ub85c \uc804\ubd80 \uace0\uc815\ud574\uc11c \ud558\ub098\uc758 \uc644\uc131\ub41c \ubc14\uc774\ub108\ub9ac(.bin) \ud30c\uc77c\ub85c \ucef4\ud30c\uc77c\ud569\ub2c8\ub2e4.<br>Therefore, the addresses of all variables and functions within the code are fixed in advance based on the 0x8000 address, and the code is compiled into a single, complete binary (.bin) file.<\/p>\n\n\n\n<p>3)C\uc5b8\uc5b4\ub97c \uc0ac\uc6a9\ud558\uac8c \ub418\uba74 C\uc5b8\uc5b4 \ud30c\uc77c(kernel.c)\uacfc \uc5b4\uc148\ube14\ub9ac \ud30c\uc77c(sector2.asm)\uc744 \ud568\uaed8 \ubb36\uc5b4\uc57c \ud569\ub2c8\ub2e4.<br>When using the C language, you must combine the C source file (kernel.c) and the assembly file (sector2.asm).<\/p>\n\n\n\n<p>4)\uadf8\ub798\uc11c \uc21c\uc218 \ubc14\uc774\ub108\ub9ac\uac00 \uc544\ub2cc, \uc870\ub9bd\uc6a9 \ubd80\ud488 \uc0c1\ud0dc\uc778 \uc624\ube0c\uc81d\ud2b8 \ud30c\uc77c(.o)\ub85c \ucef4\ud30c\uc77c\ud558\uac8c \ub429\ub2c8\ub2e4.<br>Therefore, instead of a pure binary, it is compiled into object files (.o)\u2014components intended for assembly.<\/p>\n\n\n\n<p>5) \uadf8\ub7ec\uba74 \ub2e4\uc74c\uacfc \uac19\uc774 \ucef4\ud30c\uc77c\uc744 \uc2e4\ud589\ud569\ub2c8\ub2e4.<br>Then, run the compilation as follows.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ld -m elf_i386 -Ttext 0x8000 -o sector2.bin sector2.o kernel.o --oformat binary<\/code><\/pre>\n\n\n\n<p>6)\uc774\ub54c \uc774\ubbf8 \ucef4\ud30c\uc77c\ud588\ub358 sector2.o\uc640 kernel.o\ub97c \ubb36\uc5b4\uc11c sector2.bin\ud30c\uc77c\uc744 \uc0dd\uc131\ud558\uba70 text \uc139\uc158 0x8000 \uc8fc\uc18c\ub85c \uc815\ub82c\ud569\ub2c8\ub2e4.<br>At this stage, the previously compiled <code>sector2.o<\/code> and <code>kernel.o<\/code> are linked to generate the <code>sector2.bin<\/code> file, with the text section aligned to address 0x8000.<\/p>\n\n\n\n<p>&#8212; text \uc139\uc158\uc740 sector2.bin\uc0dd\uc131\uc2dc -Ttext 0x8000  \uc774\ubd80\ubd84\uc5d0\uc11c text\ub85c \uc139\uc158 \ub124\uc784\uc744 \uc9c0\uc815\ud588\uae30 \ub54c\ubb38\uc785\ub2c8\ub2e4.<br>The &#8216;text&#8217; section is named as such because &#8216;text&#8217; was specified as the section name using <code>-Ttext 0x8000<\/code> when generating <code>sector2.bin<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>section .text           ;  ELF \ud3ec\ub9f7 \ucef4\ud30c\uc77c\uc744 \uc704\ud574 \ucf54\ub4dc \uc139\uc158\uc784\uc744 \uba85\uc2dc\ud569\ub2c8\ub2e4.\n                        ;  Specifies that it is a code section for ELF format compilation.\n<\/code><\/pre>\n\n\n\n<p>&#8212;  ld\uba85\ub839\uc744 \uc0ac\uc6a9\ud560\ub54c \ub9c1\ucee4\uac00 \uc778\uc2dd\ud558\uac8c \ud558\ub824\uba74 global\ub85c \uc120\uc5b8\ud574\uc11c \uc678\ubd80\uc5d0 \uacf5\uac1c\ud574\uc57c \ud569\ub2c8\ub2e4.<br>To ensure the linker recognizes it when using the <code>ld<\/code> command, you must declare it as <code>global<\/code> to make it externally visible.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>global start            ;  \ub9c1\ucee4\uac00 \uc778\uc2dd\ud560 \uc218 \uc788\ub3c4\ub85d start \ub808\uc774\ube14\uc744 \uc678\ubd80\uc5d0 \uacf5\uac1c\ud569\ub2c8\ub2e4.\n                        ;  Expose the `start` label so that the linker can recognize it.\nglobal protected_start  ;  \uba40\ub9ac\ub6f0\uae30 \ubaa9\uc801\uc9c0 \ub808\uc774\ube14\ub3c4 \uc678\ubd80\uc5d0 \uacf5\uac1c\ud569\ub2c8\ub2e4.\n                        ;  We are also making the long-jump destination labels publicly available<\/code><\/pre>\n\n\n\n<p>&#8212; C\uc5b8\uc5b4 \ubcc0\uc218 \ubc0f \ud568\uc218 \ud638\ucd9c\uc744 \uc704\ud55c \uc2a4\ud0dd\uc601\uc5ed\uc744 \uc9c0\uc815\ud569\ub2c8\ub2e4.<br>It designates the stack area for C language variables and function calls.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mov esp, 0x90000<\/code><\/pre>\n\n\n\n<p>&#8212; C\uc5b8\uc5b4\uc758 kernel_main\ud568\uc218\ub97c \ud638\ucd9c\ud569\ub2c8\ub2e4.<br>It calls the C language&#8217;s <code>kernel_main<\/code> function.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>call kernel_main    ; \u2705 kernel_main\uc73c\ub85c \uc810\ud504!\n                    ; Jump to kernel_main!<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f kernel.c<\/p>\n\n\n\n<p>&#8211;\uc774 \ucf54\ub4dc\uc5d0\uc11c \uc2e4\uc81c\ub85c \uc0ac\uac01\ud615\uc744 \uadf8\ub9bd\ub2c8\ub2e4.<br>This code actually draws the rectangle.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>typedef unsigned char byte;\n\n\/\/ 1. \uc6d0\ud558\ub294 \uc704\uce58(x, y)\uc5d0 \uc6d0\ud558\ub294 \uc0c9\uc0c1(color)\uc758 \uc810\uc744 \ucc0d\ub294 \ud568\uc218\n\/\/ 1. A function that plots a point of a specified color at a desired location (x, y).\nvoid draw_pixel(int x, int y, byte color) {\n    byte *vram = (byte *)0xA0000;\n    \/\/ 320x200 \ud574\uc0c1\ub3c4\uc758 1\ucc28\uc6d0 \ubc30\uc5f4 \uc704\uce58 \uacc4\uc0b0: (y * 320) + x\n    \/\/ Calculation of 1D array position for 320x200 resolution: (y * 320) + x\n    vram&#91;(y * 320) + x] = color;\n}\n\n\/\/ 2. \uc6d0\ud558\ub294 \uc704\uce58, \ud06c\uae30, \uc0c9\uc0c1\uc73c\ub85c \uc0ac\uac01\ud615\uc744 \uadf8\ub9ac\ub294 \ud568\uc218\n\/\/ 2. Function to draw a rectangle at a desired position, size, and color\nvoid draw_rect(int start_x, int start_y, int width, int height, byte color) {\n    for (int y = 0; y &lt; height; y++) {\n        for (int x = 0; x &lt; width; x++) {\n            \/\/ \uc704\uc5d0\uc11c \ub9cc\ub4e0 \uc810 \ucc0d\uae30 \ud568\uc218\ub97c \ud65c\uc6a9\n            \/\/ Utilize the point-plotting function created above\n            draw_pixel(start_x + x, start_y + y, color);\n        }\n    }\n}\n\n\/\/ 3. \ucee4\ub110 \uba54\uc778 \ud568\uc218\n\/\/ 3. Kernel main function\nvoid kernel_main(void) {\n    \/\/ \uc608\uc2dc 1: X=100, Y=50 \uc704\uce58\uc5d0 \uac00\ub85c 50, \uc138\ub85c 30 \ud06c\uae30\uc758 \uac08\uc0c9(6) \uc0ac\uac01\ud615\n    \/\/ Example 1: A brown (6) rectangle with a width of 50 and a height of 30 at position X=100, Y=50\n    draw_rect(100, 50, 50, 30, 6);\n\n    \/\/ \uc608\uc2dc 2: \ub2e4\ub978 \uc704\uce58\uc5d0 \ud30c\ub780\uc0c9(9) \uc0ac\uac01\ud615 \ucd94\uac00\ub85c \uadf8\ub9ac\uae30 (\uc0c9\uc0c1 \ubcc0\uacbd \ud14c\uc2a4\ud2b8)\n    \/\/ Example 2: Draw an additional blue (9) rectangle at a different location (color change test)\n    draw_rect(200, 100, 40, 40, 9);\n    \n    \/\/ \uc608\uc2dc 3: \ub2e4\ub978 \uc704\uce58\uc5d0 \ucd08\ub85d\uc0c9(10) \uc0ac\uac01\ud615 \ucd94\uac00\ub85c \uadf8\ub9ac\uae30\n    \/\/ Example 3: Draw an additional green (10) rectangle at a different location.\n    draw_rect(30, 120, 60, 20, 10);\n\n    \/\/ \uc791\uc5c5 \uc644\ub8cc \ud6c4 CPU \ub300\uae30\n    \/\/ Wait for CPU after task completion\n    while (1) {\n        __asm__ __volatile__(\"hlt\");\n    }\n}\n<\/code><\/pre>\n\n\n\n<p>\ud83d\udc49\ufe0f \ucef4\ud30c\uc77c \/ Compiling<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># 1. 1\ubc88 \uc139\ud130 \ubd80\ud2b8\ub85c\ub354 \ucef4\ud30c\uc77c\n# Compile Sector 1 Bootloader\n\nnasm -f bin boot.asm -o boot.bin\n\n# 2. 2\ubc88 \uc139\ud130 \ubcf4\ud638\ubaa8\ub4dc \uc9c4\uc785\ubd80 \ucef4\ud30c\uc77c\n# Compiling the Sector 2 protection mode entry section\n\nnasm -f elf32 sector2.asm -o sector2.o\n\n# 3. GCC \ucef4\ud30c\uc77c \uc2dc \uc704\uce58 \ub3c5\ub9bd\uc801 \ucf54\ub4dc(PIC)\ub97c \uc0dd\uc131\ud558\uc9c0 \uc54a\ub3c4\ub85d \uc635\uc158 \ucd94\uac00\n# Add an option to prevent the generation of position-independent code (PIC) when compiling with GCC.\n\ngcc -m32 -c kernel.c -o kernel.o -nostdlib -fno-builtin -fno-stack-protector -fno-pic -fno-PIE\n\n# 4. \ub9c1\ucee4(ld)\uc5d0\uac8c \ucf54\ub4dc\uc758 \uc2dc\uc791\uc810(Entry)\uc774 '_start'\uac00 \uc544\ub2c8\ub77c 'start' \uc784\uc744 \uba85\uc2dc\n# Specify to the linker (ld) that the code entry point is 'start' instead of '_start'\n\nld -m elf_i386 -Ttext 0x8000 -e start -o sector2.bin sector2.o kernel.o --oformat binary\n\n# 5. \uae30\uc874 \ubc29\uc2dd\ub300\ub85c \ub514\uc2a4\ud06c \uc774\ubbf8\uc9c0 \ubcd1\ud569 \ubc0f QEMU \uc2e4\ud589\n# # 5. Merging Disk Images and Running QEMU Using the Existing Method\n\ncat boot.bin sector2.bin &gt; temp.bin\ndd if=temp.bin of=os.img bs=512 count=2880 conv=sync\nqemu-system-x86_64 -drive file=os.img,format=raw,if=floppy -boot a\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"687\" height=\"484\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/07\/miniOS-8.jpg\" alt=\"\" class=\"wp-image-6118\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/07\/miniOS-8.jpg 687w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/07\/miniOS-8-300x211.jpg 300w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/07\/miniOS-8-400x282.jpg 400w\" sizes=\"auto, (max-width: 687px) 100vw, 687px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\ud83d\udc49\ufe0f 32\ube44\ud2b8 \ubcf4\ud638\ubaa8\ub4dc(\uadf8\ub798\ud53d\ubaa8\ub4dc)\uc5d0\uc11c \ud654\uba74\uc5d0 \uc0ac\uac01\ud615\uc744 \ubcf4\uc5ec\uc8fc\ub294 \ucf54\ub4dc\uc785\ub2c8\ub2e4.This is code that displays a rectangle on the screen in 32-bit protected mode (graphics mode). \ud83d\udc49\ud83c\udffb \uc774\uc804 miniOS-7\uc5d0\uc11c \ucf54\ub4dc\uc5d0\uc11c \ubc14\ub010 \ubd80\ubd84\ub9cc \uc124\uba85\ud569\ub2c8\ub2e4.This section explains only the changes made to the code from the previous miniOS-7. \ud83d\udc49\ud83c\udffb \ucf54\ub4dc \/ Code \u2714\ufe0f boot.asm &#8212; boot.asm\uc5d0\uc11c 2\ubc88 \uc139\ud130 \ucf54\ub4dc\ub97c 1\uc5d0\uc11c 10\uc73c\ub85c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,1],"tags":[],"class_list":["post-6113","post","type-post","status-publish","format-standard","hentry","category-os","category-uncategorized","missing-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/6113","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=6113"}],"version-history":[{"count":6,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/6113\/revisions"}],"predecessor-version":[{"id":6120,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/6113\/revisions\/6120"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=6113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=6113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=6113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}