[OS]miniOS(1~11)-맥에서 컴파일과 실행/Compiling and running for macOS

👉🏻 miniOS 프로젝트를 맥OS에서 컴파일 하고 실행하는 방법입니다.
This is how to compile and run the miniOS project on macOS.

👉🏻 먼저 QEMU에뮬레이터,어셈블러,C언어 컴파일러를 설치합니다.(64비트,32비트)
First, install the QEMU emulator, an assembler, and a C compiler (for both 64-bit and 32-bit architectures).

brew install nasm qemu i686-elf-gcc x86_64-elf-gcc

또는 / Or

brew install nasm 
brew install qemu 
brew install i686-elf-gcc 
brew install x86_64-elf-gcc
  1. qemu-system-i386 :
    32비트 전용 에뮬레이터 / 32-bit-only emulator
  2. qemu-system-x86_64 :
    64비트 전용 에뮬레이터 / 64-bit-only emulator
  3. nasm :
    소스 코드를 바이트 코드나 오브젝트 파일로 변환해 주는 어셈블러
    An assembler that converts source code into bytecode or object files
  4. i686-elf-gcc :
    32비트 베어메탈 및 독립형(ELF) 환경을 타겟으로 하는 C언어 크로스 컴파일러
    A C cross-compiler targeting 32-bit bare-metal and standalone (ELF) environments
  5. x86_64-elf-gcc :
    64비트 베어메탈 및 독립형(ELF) 환경을 타겟으로 하는 C언어 크로스 컴파일러
    A C cross-compiler targeting 64-bit bare-metal and standalone (ELF) environments

👉🏻 설치확인 / Installation Confirmation

% nasm -v
NASM version 3.02 compiled on Jun 29 2026

% qemu-system-x86_64 --version 
QEMU emulator version 11.1.2
Copyright (c) 2003-2026 Fabrice Bellard and the QEMU Project developers

% i686-elf-gcc --version

i686-elf-gcc (GCC) 16.2.0
Copyright (C) 2026 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

% x86_64-elf-gcc --version
x86_64-elf-gcc (GCC) 16.2.0
Copyright (C) 2026 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

📁 miniOS-11 컴파일 및 실행
Compiling and Running miniOS-11

1)NASM을 이용해 1번, 2번 섹터 코드를 각각 올바른 형식으로 컴파일합니다
Use NASM to compile the code for sectors 1 and 2 into their respective correct formats.

nasm -f bin boot.asm -o boot.bin
nasm -f elf32 sector2.asm -o sector2.o

2)C언어 커널 컴파일 (M3 크로스 컴파일러 활용)
Compiling a C-language kernel (using the M3 cross-compiler)

x86_64-elf-gcc -m32 -c kernel.c -o kernel.o -nostdlib -fno-builtin -fno-stack-protector -fno-pic -fno-PIE

3)링킹 및 이미지 결합 / Linking and Image Combining

x86_64-elf-ld -m elf_i386 -Ttext 0x8000 -e start -o sector2.bin sector2.o kernel.o --oformat binary

cat boot.bin sector2.bin > temp.bin
dd if=temp.bin of=os.img bs=512 count=2880 conv=sync

4)QEMU로 가상머신 실행 / Running a virtual machine with QEMU

qemu-system-x86_64 -drive file=os.img,format=raw,if=floppy -boot a

5)QEMU빠져나오기 / Exiting QEMU

control + option + G

📁miniOS-1,miniOS-2 컴파일 및 실행
Compiling and running miniOS-1 and miniOS-2

nasm -f bin boot.asm -o boot.bin
qemu-system-x86_64 -drive format=raw,file=boot.bin

📁miniOS-3,miniOS-4,miniOS-5,miniOS-6,miniOS-7 컴파일 및 실행
Compile and run miniOS-3, miniOS-4, miniOS-5, miniOS-6, miniOS-7

nasm -f bin boot.asm -o boot.bin
nasm -f bin sector2.asm -o sector2.bin
cat boot.bin sector2.bin > temp.bin
dd if=temp.bin of=os.img bs=512 count=2880 conv=sync
qemu-system-x86_64 -drive file=os.img,format=raw,if=floppy -boot a

📁 miniOS-8,miniOS-9,miniOS-10,miniOS-11 컴파일 및 실행
Compile and run miniOS-8,miniOS-9,miniOS-10,miniOS-11

nasm -f bin boot.asm -o boot.bin

nasm -f elf32 sector2.asm -o sector2.o

i686-elf-gcc -m32 -c kernel.c -o kernel.o -nostdlib -fno-builtin -fno-stack-protector -fno-pic -fno-PIE

i686-elf-ld -m elf_i386 -Ttext 0x8000 -e start -o sector2.bin sector2.o kernel.o --oformat binary

cat boot.bin sector2.bin > temp.bin

dd if=temp.bin of=os.img bs=512 count=2880 conv=sync

qemu-system-x86_64 -drive file=os.img,format=raw,if=floppy -boot a

Leave a Reply