{"id":12576,"date":"2026-10-19T15:43:21","date_gmt":"2026-10-19T06:43:21","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=12576"},"modified":"2026-10-19T18:32:25","modified_gmt":"2026-10-19T09:32:25","slug":"minios-text-1","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2026\/10\/19\/minios-text-1\/","title":{"rendered":"[OS]miniOS-Text-1"},"content":{"rendered":"\n<p>\ud83d\udc49\ud83c\udffb \uc774 \ubd80\ubd84\uc740 \ubbf8\ub2c8OS \ud14d\uc2a4\ud2b8 \ubaa8\ub4dc \uc2dc\uc791 \ubd80\ubd84\uc785\ub2c8\ub2e4.<br>This section marks the beginning of the MiniOS text mode.<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb 32\ube44\ud2b8 \ubcf4\ud638 \ubaa8\ub4dc \uc9c4\uc785 \ubc0f C\uc5b8\uc5b4 kernel_maiin()\ud568\uc218\ub85c\ub4dc \uae4c\uc9c0 \uc785\ub2c8\ub2e4.<br>This covers the transition into 32-bit protected mode and the loading of the C-language <code>kernel_main()<\/code> function.<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb32\ube44\ud2b8 \ubcf4\ud638 \ubaa8\ub4dc\uc5d0\uc11c\ub294 \ub7a8\uc744 4\uae30\uac00\uae4c\uc9c0 \uc0ac\uc6a9\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<br>In 32-bit protected mode, up to 4 GB of RAM can be used.<\/p>\n\n\n\n<p>\ud83d\udcc1boot.asm<\/p>\n\n\n\n<p>\u2714\ufe0f \ub514\uc2a4\ud06c\uc77d\uae30 \/ Disk read<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:14px\"><code>    mov ah, 0x02        ; \ub514\uc2a4\ud06c \uc77d\uae30 \uae30\ub2a5 \/ Disk reading capability\n    mov al, 12          ; \uc77d\uc5b4\uc62c \uc139\ud130 \uac1c\uc218(12\uac1c) \/ Number of sectors to read (12)\n    mov ch, 0           ; \uc2e4\ub9b0\ub354 0 \/ Cylinder 0\n    mov cl, 2           ; \uc2dc\uc791 \uc139\ud130 2 \/ Starting sector 2\n    mov dh, 0           ; \ud5e4\ub4dc 0 \/ Head 0\n    mov bx, 0x8000      ; \uba54\ubaa8\ub9ac 0x8000\uc5d0 \ub85c\ub4dc \/ Loaded into memory 0x8000\n    int 0x13<\/code><\/pre>\n\n\n\n<p>1)\uc2e4\uc81c\ub85c \ud50c\ub85c\ud53c \ub514\uc2a4\ud06c\ub97c \uc77d\uc5b4 \ubcf4\ub294 \ubd80\ubd84\uc785\uc774\ub2e4.<br>This is the part where the floppy disk is actually read.<\/p>\n\n\n\n<p>\u2714\ufe0f sector2.asm\uc73c\ub85c \uc810\ud504\ud574\uc11c \ucf54\ub4dc \uc2e4\ud589<br>Jump to sector2.asm and execute the code<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> jmp 0x0000:0x8000<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \ubd80\ud2b8 \uc2dc\uadf8\ub2c8\ucc98<br>Boot signature<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>; 1\ubc88 \uc139\ud130(MBR) \ube48 \uacf5\uac04\uc744 0\uc73c\ub85c \ucc44\uc6b0\uace0 \ubd80\ud2b8 \uc2dc\uadf8\ub2c8\ucc98 \ucd94\uac00\n; Fill remaining space of sector 1 (MBR) with 0 and add boot signature\ntimes 510 - ($ - $$) db 0\ndw 0xaa55<\/code><\/pre>\n\n\n\n<p>1)\uc774 \ucf54\ub4dc\uac00 \uc5c6\uc73c\uba74 \ubd80\ud305\ud560 \uc218 \uc5c6\uc74c \/ Without this code, it cannot boot.<\/p>\n\n\n\n<p>\ud83d\udcc1 sector2.asm<\/p>\n\n\n\n<p>\u2714\ufe0f sector2.asm\uc774 0x8000\u00a0\uc774 \uc8fc\uc18c\uc5d0\uc11c \uc2e4\ud589\ub420 \uc218 \uc788\ub294 \uc774\uc720\ub294 boot.asm\uc5d0\uc11c \uc810\ud504\ud558\uace0 \ucef4\ud30c\uc77c\uc2dc \ub9c1\ucee4\uc635\uc158\uc744 \ud1b5\ud574\uc11c \uc8fc\uc18c\ub97c \uc9c0\uc815\ud588\uae30 \ub54c\ubb38\uc785\ub2c8\ub2e4.<br>The reason sector2.asm can execute at the address 0x8000 is that the code jumps there from boot.asm, and the address was specified using linker options during compilation.<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:14px\"><code># 1. boot.asm\uc758 \uc810\ud504 \ucf54\ub4dc \/ Jump code in boot.asm\njmp 0x0000:0x8000 \n\n# 2.\ucef4\ud30c\uc77c\uc2dc \ub2e8\uc77c \ubc14\uc774\ub108\ub9ac\ub85c \uacb0\ud569\uc2dc \uc635\uc158\uc73c\ub85c \uc8fc\uc18c\ub97c \uc9c0\uc815\n#   Specify addresses as an option when combining into a single binary during compilation.\ni686-elf-ld -m elf_i386 <strong>-Ttext 0x8000<\/strong> <strong>-e start<\/strong> sector2.o kernel.o -o kernel.bin --oformat binary\n<\/code><\/pre>\n\n\n\n<p>1) -e start\ub294 sector2.asm\uc758 global start \uc704\uce58\ub97c \uc758\ubbf8\ud568.<br>-e start refers to the global start location in sector2.asm.<\/p>\n\n\n\n<p>\u2714\ufe0f A20 \uac8c\uc774\ud2b8 \ud65c\uc131\ud654 (\uba54\ubaa8\ub9ac 1MB \uc774\uc0c1 \uc811\uadfc \ud5c8\uc6a9)<br>A20 gate activation (enables access to memory beyond 1MB)<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:14px\"><code>    in al, 0x92\n    or al, 2\n    out 0x92, al<\/code><\/pre>\n\n\n\n<p>1) in al, 0x92 : <br>\ub9c8\ub354\ubcf4\ub4dc\uc758 \uc2dc\uc2a4\ud15c \uc81c\uc5b4 \ud3ec\ud2b8 \uc911 \ud558\ub098\uc778 0x92\ubc88 \ud3ec\ud2b8(System Control Port A)\uc758 \ud604\uc7ac \ud558\ub4dc\uc6e8\uc5b4 \uc0c1\ud0dc \uac12\uc744 \uc77d\uc5b4\uc640\uc11c al \ub808\uc9c0\uc2a4\ud130\uc5d0 \uc800\uc7a5<br>Read the current hardware status value of port 0x92 (System Control Port A)\u2014one of the motherboard&#8217;s system control ports\u2014and store it in the AL register.<\/p>\n\n\n\n<p>2)or al, 2:<br>al \ub808\uc9c0\uc2a4\ud130\uc5d0 \ub4e4\uc5b4 \uc788\ub294 \uac12\uacfc \uc22b\uc790 2(\uc774\uc9c4\uc218\ub85c 00000010)\ub97c \ube44\ud2b8 OR \uc5f0\uc0b0<br>Perform a bitwise OR operation between the value in the al register and the number 2 (00000010 in binary).<br>0x92 \ud3ec\ud2b8\uc758 2\ubc88 \ube44\ud2b8\uac00 \ubc14\ub85c A20 \uac8c\uc774\ud2b8\ub97c \ucf1c\uace0 \ub044\ub294 \uc2a4\uc704\uce58 \uc5ed\ud560\uc744 \ud568.<br>Bit 2 of port 0x92 acts as a switch for enabling and disabling the A20 gate.<br>or al, 2\ub97c \uc218\ud589\ud558\uba74 \uae30\uc874\uc5d0 \uc5b4\ub5a4 \uac12\uc774 \ub4e4\uc5b4 \uc788\uc5c8\ub4e0 \uc0c1\uad00\uc5c6\uc774 \ub2e4\ub978 \ube44\ud2b8\ub294 \uadf8\ub300\ub85c \uc720\uc9c0\ud55c \ucc44 2\ubc88 \ube44\ud2b8\ub9cc \ubb34\uc870\uac74 1(\ucc38)\ub85c \ubc14\ub00c\uac8c \ub428.<br>Performing an OR operation with 2 will force the 2nd bit to become 1 (true), regardless of its previous value, while leaving all other bits unchanged.<\/p>\n\n\n\n<p>3)out 0x92, al<br>2\ubc88 \ube44\ud2b8\uac00 1\ub85c \uc870\uc791\ub41c al \ub808\uc9c0\uc2a4\ud130\uc758 \uac12\uc744 \ub2e4\uc2dc 0x92\ubc88 \ud3ec\ud2b8\uc5d0 \ucd9c\ub825(\uc800\uc7a5)<br>Output (store) the value of the AL register\u2014with its 2nd bit set to 1\u2014back to port 0x92.<br>\uc774 \uba85\ub839\uc5b4\uac00 \uc2e4\ud589\ub418\ub294 \uc21c\uac04 \ub9c8\ub354\ubcf4\ub4dc\uc758 \ud558\ub4dc\uc6e8\uc5b4 \ud68c\ub85c\uac00 \ubc18\uc751\ud558\uc5ec A20 \ub77c\uc778(\uc8fc\uc18c\uc120)\uc774 \uac15\uc81c\ub85c \uc5f4\ub9ac\uac8c \ub428.<br>The moment this instruction is executed, the motherboard&#8217;s hardware circuitry responds, forcing the A20 line (address line) to open.<\/p>\n\n\n\n<p>\u2714\ufe0f GDT \ub85c\ub4dc <br>Loading the GDT <\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:14px\"><code>lgdt &#91;gdt_pointer]<\/code><\/pre>\n\n\n\n<p>1)lgdt [gdt_pointer] (Load Global Descriptor Table)<br>\uba54\ubaa8\ub9ac \uc811\uadfc \uaddc\uce59\uacfc \uad8c\ud55c\uc744 \uc815\uc758\ud574 \ub454 GDT(Global Descriptor Table)\uc758 \uc704\uce58\uc640 \ud06c\uae30 \uc815\ubcf4\ub97c CPU\uc5d0\uac8c \uc54c\ub824\uc8fc\uace0 \ub4f1\ub85d\ud558\ub294 \uba85\ub839\uc5b4\uc785\ub2c8\ub2e4.<br>This is an instruction that informs the CPU of the location and size of the Global Descriptor Table (GDT)\u2014which defines memory access rules and permissions\u2014and registers it.<\/p>\n\n\n\n<p>16\ube44\ud2b8 \ubaa8\ub4dc\uc5d0\uc11c\ub294 \ub2e8\uc21c\ud788 <code>\uc138\uadf8\uba3c\ud2b8 \u00d7 16 + \uc624\ud504\uc14b<\/code> \uacc4\uc0b0\uc73c\ub85c \uc2e4\uc81c \ubb3c\ub9ac \uba54\ubaa8\ub9ac(RAM)\uc5d0 \uc9c1\uc811 \uc811\uadfc \ubc29\uc2dd\uc744 \uc0ac\uc6a9\ud588\uc2b5\ub2c8\ub2e4. \uc774 \ubc29\uc2dd\uc740 \uba54\ubaa8\ub9ac\uc5d0 \ub300\ud55c \ubcf4\ud638\uccb4\uacc4\uac00 \uc5c6\uace0 \uc6b4\uc601\uccb4\uc81c \uc601\uc5ed\uc774\ub4e0 \uc544\ubb34\uacf3\uc5d0\ub098 \uba54\ubaa8\ub9b4 \uc0ac\uc6a9 \ud560 \uc218 \uc788\uc5b4\uc11c \uc2dc\uc2a4\ud15c\uc774 \ub2e4\uc6b4\ub420 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<br>n 16-bit mode, a method was used to access actual physical memory (RAM) directly by simply calculating &#8220;segment \u00d7 16 + offset.&#8221;<br>This approach lacks a memory protection mechanism, allowing memory to be accessed anywhere\u2014including within the operating system&#8217;s own space\u2014which can cause the system to crash.<\/p>\n\n\n\n<p>32\ube44\ud2b8 \ubcf4\ud638\ubaa8\ub4dc\uc5d0\uc11c\ub294 \ucca0\uc800\ud55c \uaddc\uce59\uacfc \uac80\uc0ac\uccb4\uacc4\ub97c \ub3c4\uc785\ud568\uc73c\ub85c CPU\uac00 \uba54\ubaa8\ub9ac\ub97c \uc0ac\uc6a9\uc2dc \ub9e4\ubc88 \uc5c4\uaca9\ud558\uac8c \uac80\uc0ac\ud569\ub2c8\ub2e4.<br>In 32-bit protected mode, a system of rigorous rules and checks is implemented, ensuring that every instance of CPU memory access is strictly verified.<\/p>\n\n\n\n<p>\u2714\ufe0f GDT \ud14c\uc774\ube14 \/ GDT Table<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:14px\"><code>; GDT(Global Descriptor Table) \uc815\uc758\n; Definition of Global Descriptor Table (GDT)\nalign 4\ngdt_start:\n    dd 0, 0                     ; 1. \ub110 \ub514\uc2a4\ud06c\ub9bd\ud130 \/ Null descriptor\n    dw 0xFFFF, 0x0000           ; 2. \ucf54\ub4dc \uc138\uadf8\uba3c\ud2b8 (0x08) \/ Code segment (0x08)\n    db 0x00, 0x9A, 0xCF, 0x00\n    dw 0xFFFF, 0x0000           ; 3. \ub370\uc774\ud130 \uc138\uadf8\uba3c\ud2b8 (0x10) \/ Data Segment (0x10)\n    db 0x00, 0x92, 0xCF, 0x00\ngdt_end:\n\ngdt_pointer:\n    dw gdt_end - gdt_start - 1\n    dd gdt_start<\/code><\/pre>\n\n\n\n<p>1)\uba54\ubaa8\ub9ac \uc8fc\uc18c \ubc30\uce58 \/ Memory address layout<br>\uba54\ubaa8\ub9ac \uc8fc\uc18c\uac00 4\ub85c \ub098\ub204\uc5b4 \ub5a8\uc5b4\uc9c0\ub294 \uc704\uce58\uc5d0 GDT\uc8fc\uc18c \ubc30\uce58(\ub370\uc774\ud130\ub97c \uc77d\uc744\ub54c 4\ubc14\uc774\ud2b8 \ub2e8\uc704\ub85c \uc77d\uc74c)<br>CPU\uac00 \uba54\ubaa8\ub9ac\ub97c \ud6a8\uc728\uc801\uc774\uace0 \ube60\ub974\uac8c \uc77d\uac8c \ud558\uae30 \uc704\ud55c \uc8fc\uc18c\ubc30\uce58<br>Place the GDT address at a memory location that is a multiple of 4 (since data is read in 4-byte units).<br>Address arrangement to enable the CPU to read memory efficiently and quickly<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:14px\"><code>align 4<\/code><\/pre>\n\n\n\n<p>2)\ub110 \ub514\uc2a4\ud06c\ub9bd\ud130 \/ Null descriptor<br>GDT\uc758 \ub9e8 \uccab \ubc88\uc9f8 \uce78(\uc778\ub371\uc2a4 0\ubc88)\uc740 \ubc18\ub4dc\uc2dc 0\uc73c\ub85c \ucc44\uc6cc\uc9c4 \ube48 \uce78(Null)\uc774\uc5b4\uc57c \ud55c\ub2e4\ub294 CPU \uae30\uc900<br>CPU specification requiring the very first entry (index 0) of the GDT to be a null entry (filled with zeros).<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:14px\"><code>dd 0, 0 <\/code><\/pre>\n\n\n\n<p>3)\ucf54\ub4dc \uc138\uadf8\uba3c\ud2b8 (\ucd1d 8\ubc14\uc774\ud2b8) \u2014 \uc544\ub798 \ub450 \uc904\uc774 \ud569\uccd0\uc838\uc11c 1\uac1c \uc138\uadf8\uba3c\ud2b8<br>Code segment (8 bytes total) \u2014 the two lines below combine to form a single segment<\/p>\n\n\n\n<p>&#8212; 0xFFFF = 65535 ,\ucef4\ud4e8\ud130\uac00 \uc2e4\ud589\ud560 \uba85\ub839\uc5b4(\ucf54\ub4dc)\uac00 \ub2f4\uae34 \uc601\uc5ed\uc758 \uaddc\uce59\uc744 \uc815\uc758<br>Define the rules for the area containing the instructions (code) that a computer will execute.<\/p>\n\n\n\n<p>&#8212; dw(Define word) 2\ubc14\uc774\ud2b8(16\ube44\ud2b8) \ud06c\uae30\uc758 \ub370\uc774\ud130\ub97c \uba54\ubaa8\ub9ac\uc5d0 \ud560\ub2f9<br>Allocate 2 bytes (16 bits) of data in memory<\/p>\n\n\n\n<p>&#8212; db(Define byte) 1\ubc14\uc774\ud2b8(8\ube44\ud2b8) \ud06c\uae30\uc758 \ub370\uc774\ud130\ub97c \uba54\ubaa8\ub9ac\uc5d0 \ud560\ub2f9<br>Allocate 1 byte (8 bits) of data in memory<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:14px\"><code>dw 0xFFFF, 0x0000           ; \uc55e 4\ubc14\uc774\ud2b8 (\uba54\ubaa8\ub9ac \ud06c\uae30 \ubc0f \uc2dc\uc791 \uc8fc\uc18c \uc77c\ubd80)\n                            ; First 4 bytes (memory size and part of the start address)\ndb 0x00, 0x9A, 0xCF, 0x00   ; \ub4a4 4\ubc14\uc774\ud2b8 (\uad8c\ud55c \uc18d\uc131 \ubc0f \ub098\uba38\uc9c0 \uc8fc\uc18c)\n                            ; Last 4 bytes (permission attributes and remaining address)<\/code><\/pre>\n\n\n\n<p>4)\ub370\uc774\ud130 \uc138\uadf8\uba3c\ud2b8 (\ucd1d 8\ubc14\uc774\ud2b8) \u2014 \uc544\ub798 \ub450 \uc904\uc774 \ud569\uccd0\uc838\uc11c \ub610 \ub2e4\ub978 1\uac1c \uc138\uadf8\uba3c\ud2b8<br>Data segment (8 bytes total) \u2014 the two lines below combine to form another single segment<\/p>\n\n\n\n<p>&#8212; \uc55e 4\ubc14\uc774\ud2b8\ub294 \uac19\uace0 \ub4a4 4\ubc14\uc774\ud2b8\uc911 0x92 \uc774\uac83\ub9cc \ub2e4\ub984.<br>The first 4 bytes are the same, and among the last 4 bytes, only the 0x92 value differs.<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:14px\"><code>dw 0xFFFF, 0x0000           ; \uc55e 4\ubc14\uc774\ud2b8 (\uba54\ubaa8\ub9ac \ud06c\uae30 \ubc0f \uc2dc\uc791 \uc8fc\uc18c \uc77c\ubd80)\n                            ; ; First 4 bytes (memory size and part of the start address)\ndb 0x00, 0x92, 0xCF, 0x00   ; \ub4a4 4\ubc14\uc774\ud2b8 (\uad8c\ud55c \uc18d\uc131 \ubc0f \ub098\uba38\uc9c0 \uc8fc\uc18c)\n                            ; Last 4 bytes (permission attributes and remaining address)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:14px\"><code>\ud83d\udca1\n\ucf54\ub4dc \uc138\uadf8\uba3c\ud2b8 : \uae30\uacc4\uc5b4 \ucf54\ub4dc \uc800\uc7a5\uad6c\uc5ed(\uc5b4\uc148\ube14\ub7ec + C\uc5b8\uc5b4)\nCode segment: A storage area for machine code (assembler + C language)\n\n\ub370\uc774\ud130 \uc138\uadf8\uba3c\ud2b8(\uc2a4\ud0dd \uc138\uadf8\uba3c\ud2b8) : \ubcc0\uc218\uc800\uc7a5\uad6c\uc5ed\nData segment (stack segment): Storage area for variables<\/code><\/pre>\n\n\n\n<p>5)gdt_pointer<\/p>\n\n\n\n<p>&#8212; GDT\ud14c\uc774\ube14\uc774 \uc704\uce58\ud558\ub294 \uba54\ubaa8\ub9ac \uc8fc\uc18c\uc758 \uc2dc\uc791\uacfc \ub05d\uc744 \uae30\ub85d\ud568.<br>Records the start and end memory addresses where the GDT table is located.<\/p>\n\n\n\n<p>&#8212; dd(Define Doubleword) 4\ubc14\uc774\ud2b8(32\ube44\ud2b8) \ud06c\uae30\uc758 \ub370\uc774\ud130(\uc815\uc218\ub098 \uba54\ubaa8\ub9ac \uc8fc\uc18c)\ub97c \uba54\ubaa8\ub9ac\uc5d0 \ud560\ub2f9<br>Allocate 4-byte (32-bit) data (integers or memory addresses) in memory<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:14px\"><code>gdt_pointer:\n    dw gdt_end - gdt_start - 1\n    dd gdt_start<\/code><\/pre>\n\n\n\n<p>1)gdt_end,gdt_start\uc640 \uac19\uc740 \ub77c\ubca8\uc744 \ub9cc\ub4e4\uba74 \ub77c\ubca8\uc5d0 \ud604\uc7ac \uba54\ubaa8\ub9ac \uc704\uce58 \uac12\uc774 \uc800\uc7a5\ub428<br>Creating labels such as <code>gdt_end<\/code> and <code>gdt_start<\/code> causes the current memory location value to be stored in those labels.<\/p>\n\n\n\n<p>2)dw gdt_end &#8211; gdt_start &#8211; 1 \uc774\uc720\ub294 \uc8fc\uc18c\uac00 1\ubc88\uc774 \uc544\ub2cc 0\ubc88 \ubd80\ud130 \uc2dc\uc791\ud558\uae30 \ub584\ubb38\uc5d0 -1\uc744 \ud574\uc8fc\uc5b4\uc57c \uc815\ud655\ud55c \uc8fc\uc18c \ud655\uc778\uc774 \uac00\ub2a5\ud568<br>The reason for <code>dw gdt_end - gdt_start - 1<\/code> is that addresses begin at 0 rather than 1; therefore, subtracting 1 is necessary to obtain the correct address.<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:14px\"><code># \uc815\ud655\ud55c \uc8fc\uc18c\uac00 \uc544\ub2d8 \/ Not an accurate address\n(0x8000 + gtd_end) - (gdt_start) = 24\n\n# \uc815\ud655\ud55c \uc8fc\uc18c \/ Exact address\n(0x8000 + gtd_end) - (gdt_start) - 1 = 23<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:14px\"><code>\ud83d\udca1 \nsector2.asm\uc740 \uba54\ubaa8\ub9ac\uc758 0x8000\ubc88\uc9c0 \uc785\ub2c8\ub2e4.(\ub9c1\ucee4\uc5d0\uc11c \uc9c0\uc815\ud568.)\nsector2.asm is located at memory address 0x8000 (as specified in the linker).\n\n\uc774\ub54c GDT\ud14c\uc774\ube14\uc740 \uc704\uc758 \uc8fc\uc18c\ubd80\ud130 \ucc28\ub840\ub300\ub85c \uc22b\uc790 \ub370\uc774\ud130\ub97c \uba54\ubaa8\ub9ac\uc5d0 \uae30\ub85d\ud569\ub2c8\ub2e4.\nAt this point, the GDT table records numerical data into memory, starting from the aforementioned address and proceeding sequentially.\n\n\uae30\ub85d\uc21c\uc11c\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.\nThe order of the records is as follows.\n\n\ub110\ub514\uc2a4\ud06c\ub9bd\ud130,\ucf54\ub4dc\uc138\uadf8\uba3c\ud2b8,\ub370\uc774\ud130\uc138\uadf8\uba3c\ud2b8 gdt_pointer\uc758 dw,dd\ubd80\ubd84\nThe `dw` and `dd` components of the `gdt_pointer` for the null descriptor, code segment, and data segment.\n<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f32 \ube44\ud2b8 \ubcf4\ud638 \ubaa8\ub4dc \uc9c4\uc785 \/ Entering 32-bit protected mode<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:14px\"><code>jmp 0x08:protected_start<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0fC\uc5b8\uc5b4\uc2e4\ud589 \/ Executing C code<\/p>\n\n\n\n<p>&#8212; C\uc5b8\uc5b4 \ud568\uc218\ub97c \uc5b4\uc148\ube14\ub7ec\ub85c \uac00\uc838\uc624\uae30 \/ Importing C Functions into Assembly<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:14px\"><code>extern kernel_main <\/code><\/pre>\n\n\n\n<p>&#8212; \ubd88\ub7ec\uc628 C\uc5b8\uc5b4 \ud568\uc218 \uc2e4\ud589 \/ Execute the imported C function<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:14px\"><code>call kernel_main<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \ub370\uc774\ud130 \uc138\uadf8\uba3c\ud2b8 \ub808\uc9c0\uc2a4\ud130 \ucd08\uae30\ud654 \/ Initialization of data segment registers<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:14px\"><code>    mov ax, 0x10\n    mov ds, ax\n    mov es, ax\n    mov fs, ax\n    mov gs, ax\n    mov ss, ax<\/code><\/pre>\n\n\n\n<p>1)GDT\ud14c\uc774\ube14\uc758 \ub370\uc774\ud130 \uc138\uadf8\uba3c\ud2b8\ub97c \uc0ac\uc6a9\ud558\uae30 \uc704\ud574\uc11c \ub808\uc9c0\uc2a4\ud130 \ucd08\uae30\ud654 0x10(=16)<br>Initializing registers to use data segments from the GDT table<\/p>\n\n\n\n<p>2)\ucf54\ub4dc \uc138\uadf8\uba3c\ud2b8\ub294 0x08<br>The code segment is 0x08<\/p>\n\n\n\n<p>\u2714\ufe0f 32\ube44\ud2b8 CPU\uc758 \uc2a4\ud0dd \ud3ec\uc778\ud130 \ub808\uc9c0\uc2a4\ud130(esp)\uc5d0 \uba54\ubaa8\ub9ac \uc8fc\uc18c 0x90000\uc744 \ub300\uc785<br>Assign memory address 0x90000 to the stack pointer register (esp) of a 32-bit CPU<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mov esp, 0x90000<\/code><\/pre>\n\n\n\n<p>1)\uc55e\uc73c\ub85c \ud504\ub85c\uadf8\ub7a8(\ud2b9\ud788 C\uc5b8\uc5b4 \ucee4\ub110)\uc774 \uc0ac\uc6a9\ud560 \uc2a4\ud0dd(Stack)\uc758 \uc704\uce58\ub97c \uc9c0\uc815<br>Specifies the location of the stack that the program (especially the C language kernel) will use in the future.<\/p>\n\n\n\n<p>2)\uc2a4\ud0dd\uc758 \uc8fc\uc18c\ub97c 0x90000\ub85c \uc9c0\uc815\ud574\uc11c \ucee4\ub110 \ucf54\ub4dc\uac00 \uc788\ub294 0x8000\uc640 \uacb9\uce58\uc9c0 \uc54a\uace0 \uc0ac\uc6a9\uac00\ub2a5<br>By setting the stack address to 0x90000, it can be used without overlapping with the 0x8000 address where the kernel code resides.<\/p>\n\n\n\n<p>3)C\uc5b8\uc5b4\ub97c \uc0ac\uc6a9\ud558\ub824\uba74 \ubc18\ub4dc\uc2dc \uc2a4\ud0dd\uacf5\uac04\uc744 \uc124\uc815\ud574\uc57c\ud568<br>To use the C language, you must configure stack space.<\/p>\n\n\n\n<p>\ud83d\udcc1kernel.c<\/p>\n\n\n\n<p>\u2714\ufe0f \ube44\ub514\uc624 \uba54\ubaa8\ub9ac \uc8fc\uc18c \uc9c0\uc815 \/ Video Memory Addressing (0xB8000)<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:14px\"><code> volatile char *vram = (volatile char *)0xB8000;<\/code><\/pre>\n\n\n\n<p>1)VGA \ud14d\uc2a4\ud2b8 \ubaa8\ub4dc \ube44\ub514\uc624 \uba54\ubaa8\ub9ac \uc8fc\uc18c<br>VGA text mode video memory address<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:14px\"><code>0xB8000<\/code><\/pre>\n\n\n\n<p>2)volatile<br>\uc678\ubd80 \uc694\uc778(\ud558\ub4dc\uc6e8\uc5b4 \ub4f1)\uc5d0 \uc758\ud574 \uac12\uc774 \ubcc0\ud560 \uc218 \uc788\uc73c\ub2c8 \ub9e4\ubc88 \uc9c4\uc9dc \uba54\ubaa8\ub9ac\uc5d0 \uc9c1\uc811 \uc811\uadfc \ud558\ub3c4\ub85d\ud558\ub294 \ucd5c\uc801\ud654 \ubc29\uc9c0 \uacbd\uace0<br>A warning to prevent optimization, ensuring that the value is accessed directly from actual memory every time, as it may be altered by external factors (such as hardware).<\/p>\n\n\n\n<p>\ud504\ub85c\uadf8\ub7a8 \ubc14\uae65\uc758 \ud558\ub4dc\uc6e8\uc5b4\uc640 \uc9c1\uc811 \uc18c\ud1b5\ud558\ub294 \ubaa8\ub4e0 \uba54\ubaa8\ub9ac \uacf5\uac04\uc5d0 \ud544\uc218\uc801\uc73c\ub85c \uc0ac\uc6a9<br>Essentially used in all memory spaces that communicate directly with hardware outside the program<\/p>\n\n\n\n<p>\u2714\ufe0f \ud654\uba74\uc5d0 \uae00\uc790 \ucd9c\ub825<br>Display text on the screen<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:14px\"><code>    const char *msg = \"Shell Version = 1.0.2!\";\n    int i = 0;\n    \n    while (msg&#91;i] != '\\0') {\n        vram&#91;i * 2]     = msg&#91;i];       \/\/ \uc9dd\uc218 \ubc14\uc774\ud2b8: ASCII \ubb38\uc790 \/ Even-numbered bytes: ASCII characters\n        vram&#91;i * 2 + 1] = 0x0F;         \/\/ \ud640\uc218 \ubc14\uc774\ud2b8: \ud770\uc0c9 \uae00\uc790, \uac80\uc740 \ubc30\uacbd \uc18d\uc131 \/ Odd-numbered bytes: white text, black background attribute\n        i++;\n    }<\/code><\/pre>\n\n\n\n<p>1)*msg\ub294 \ubb38\uc790\uc5f4 \ud3ec\uc778\ud130\uc774\uc9c0\ub9cc C\uc5b8\uc5b4\uc5d0\uc11c \ubc30\uc5f4\uacfc \ub3d9\uc77c\ud558\uac8c \uc0ac\uc6a9\uac00\ub2a5(\ub0b4\ubd80\uc801\uc73c\ub85c \ub3d9\uc77c\ud558\uac8c \ub3d9\uc791\ud568)<br>*Although <code>msg<\/code> is a string pointer, it can be used in the same way as an array in C (it functions identically under the hood).<\/p>\n\n\n\n<p>2)\ube44\ub514\uc624 \uba54\ubaa8\ub9ac \ud558\ub4dc\uc6e8\uc5b4 \uba54\ubaa8\ub9ac \uad6c\uc870\uc5d0\uc11c \uc9dd\uc218 \ubc88\uc9c0\uc5d0\ub294 \uae00\uc790,\ud640\uc218\ubc88\uc9c0\uc5d0\ub294 \uc0c9\uc0c1 \uc18d\uc131\uc744 \uc800\uc7a5\ud568.<br>In the video memory hardware architecture, even-numbered addresses store characters, while odd-numbered addresses store color attributes.<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:14px\"><code>        vram&#91;i * 2] = msg&#91;i];     \n        vram&#91;i * 2 + 1] = 0x0F;   <\/code><\/pre>\n\n\n\n<p>3)VGA\ud14d\uc2a4\ud2b8 \ubaa8\ub4dc\uc758 \uae30\ubcf8\uc124\uc815\uc740 \uac80\uc740 \ubc14\ud0d5\uc5d0 \ud770\uc0c9 \uae00\uc790<br>The default setting for VGA Text Mode is white text on a black background.<\/p>\n\n\n\n<p>\ud83d\udcc1 \ud14c\uc2a4\ud2b8 \/ Test<\/p>\n\n\n\n<p>\u2714\ufe0f \ucef4\ud30c\uc77c<\/p>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:14px\"><code>% rm -f *.bin *.o *.img temp.bin sector2.bin\nnasm -f bin boot.asm -o boot.bin\nnasm -f elf32 sector2.asm -o sector2.o\ni686-elf-gcc -m32 -c kernel.c -o kernel.o -nostdlib -fno-builtin -fno-stack-protector -fno-pic -fno-PIE\ni686-elf-ld -m elf_i386 -Ttext 0x8000 -e start -o sector2.bin sector2.o kernel.o --oformat binary\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<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \uc2a4\ud06c\ub9b0 \uc0f7 \/ ScreenShot<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"456\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/10\/miniOS-Text-1-jpg.jpg\" alt=\"\" class=\"wp-image-12590\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/10\/miniOS-Text-1-jpg.jpg 700w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/10\/miniOS-Text-1-jpg-300x195.jpg 300w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/10\/miniOS-Text-1-jpg-400x261.jpg 400w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><figcaption class=\"wp-element-caption\">\uc2a4\ud06c\ub9b0\uc0f7\/Screenshot<\/figcaption><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\ub9c8\ud0dc\ubcf5\uc74c 21\uc7a5 22\uc808 \/ Matthew 21: 22<\/p>\n\n\n\n<p>&#8220;\ub108\ud76c\uac00 \uae30\ub3c4\ud560 \ub54c\uc5d0 \ubb34\uc5c7\uc774\ub4e0\uc9c0 \ubbff\uace0 \uad6c\ud558\ub294 \uac83\uc740 \ub2e4 \ubc1b\uc73c\ub9ac\ub77c \ud558\uc2dc\ub2c8\ub77c&#8221;<\/p>\n\n\n\n<p>&#8220;And everything you ask in prayer, believing, you will receive.&#8221;<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\ud83d\udc49\ud83c\udffb \uc774 \ubd80\ubd84\uc740 \ubbf8\ub2c8OS \ud14d\uc2a4\ud2b8 \ubaa8\ub4dc \uc2dc\uc791 \ubd80\ubd84\uc785\ub2c8\ub2e4.This section marks the beginning of the MiniOS text mode. \ud83d\udc49\ud83c\udffb 32\ube44\ud2b8 \ubcf4\ud638 \ubaa8\ub4dc \uc9c4\uc785 \ubc0f C\uc5b8\uc5b4 kernel_maiin()\ud568\uc218\ub85c\ub4dc \uae4c\uc9c0 \uc785\ub2c8\ub2e4.This covers the transition into 32-bit protected mode and the loading of the C-language kernel_main() function. \ud83d\udc49\ud83c\udffb32\ube44\ud2b8 \ubcf4\ud638 \ubaa8\ub4dc\uc5d0\uc11c\ub294 \ub7a8\uc744 4\uae30\uac00\uae4c\uc9c0 \uc0ac\uc6a9\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.In 32-bit protected mode, up to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":12590,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28,27,26,1],"tags":[],"class_list":["post-12576","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-news","category-nextjs","category-os","category-uncategorized","has-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/12576","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=12576"}],"version-history":[{"count":11,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/12576\/revisions"}],"predecessor-version":[{"id":12593,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/12576\/revisions\/12593"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media\/12590"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=12576"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=12576"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=12576"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}