From 3f8443a485300fca62678a0b164c334eb2359da5 Mon Sep 17 00:00:00 2001 From: acevest Date: Sat, 27 Dec 2025 10:51:54 +0800 Subject: [PATCH] =?utf8?q?=E8=A7=A3=E5=86=B3=E6=96=B0=E9=81=87=E5=88=B0?= =?utf8?q?=E7=9A=84=E7=8E=AF=E5=A2=83=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- README.md | 51 +++++++++++++++++++++++++++++++++++++++++++-------- bin/Makefile | 7 ++++--- kernel/wait.c | 2 +- mkiso.sh | 6 ++++++ qemu.sh | 2 +- 5 files changed, 55 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 40ee1b6..e17342f 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,45 @@ -kernel -====== +# KERNEL -I can't find a satisfactory name for my kernel. +## Mac环境准备 -### HOW TO GET THE LATEST SOURCECODE? - git clone https://github.com/acevest/kernel.git -### WHEN DID YOU START TO DO THIS WORK? - Maybe 2006.12 -### HOW TO COMPILE THIS KERNEL? + +### mac + +```bash +brew install i686-elf-binutils +brew install i686-elf-gcc +brew install i386-elf-gdb +brew install qemu +``` + +### docker + +安装 fedora docker, 注意如果是arm Mac是要指定`--platform=linux/amd64` +这个docker 主要是用来打包kernel.iso的。 + +```bash +docker pull --platform=linux/amd64 fedora:latest +dnf install grub2-mkrescue +# 不安装grub2-pc-modules就没有/usr/lib/grub/i386-pc/就无法正确生成iso +dnf install grub2-pc-modules +dnf install xorriso + +# mke2fs +dnf install e2fsprogs.x86_64 + +# 以下选装 +# 如果要安装 chsh +dnf install util-linux-user + +dnf install gcc-x86_64-linux-gnu.x86_64 +dnf install binutils-x86_64-linux-gnu.x86_64 +dnf install vim +dnf install git +``` + +运行 +``` +docker run -h kernel -itv kernel:/root/kernel --privileged=true --name kernel fedora +``` + +然后就可以在本地用`mkiso.sh`通过指定docker container的id来生成`kernel.iso`了 diff --git a/bin/Makefile b/bin/Makefile index 9fce26c..3fd0cbe 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -24,13 +24,14 @@ endif -CFLAGS = -g -c -fno-builtin -m32 -DBUILDER='"$(shell whoami)"' +CFLAGS := -g -c -fno-builtin -m32 -DBUILDER='"$(shell whoami)"' +CFLAGS += -m32 -c -I../include -fno-builtin +CFLAGS += -std=gnu11 LDFLAG = -e _start -CFLAGS = -m32 -c -I../include -fno-builtin LIBC_DIRS = ../lib LIBC_SRCS := $(foreach DIR, $(LIBC_DIRS), $(wildcard $(DIR)/*.[cS])) LIBC_OBJS := $(patsubst %,%.o,$(LIBC_SRCS)) -BINS := shell hello +BINS := init all:$(BINS) diff --git a/kernel/wait.c b/kernel/wait.c index d987955..9536f1f 100644 --- a/kernel/wait.c +++ b/kernel/wait.c @@ -62,7 +62,7 @@ volatile void __wake_up(wait_queue_head_t *head, int nr) { p->task->state = TASK_READY; p->task->reason = "wake_up"; - list_del(&p->entry); + list_del_init(&p->entry); --nr; if (nr == 0) { diff --git a/mkiso.sh b/mkiso.sh index 9026e71..3b3645f 100755 --- a/mkiso.sh +++ b/mkiso.sh @@ -54,6 +54,12 @@ for i in "${!files[@]}"; do IFS=':' read -ra parts <<< "${file_line}" src_file="${parts[0]}" dst_file="${parts[1]}" + + if [ ! -f "$src_file" ]; then + echo -e "\033[31merror: file $src_file not found\033[0m" + exit 1 + fi + src_file_md5=$($MD5 "$src_file" | awk '{ print $1 }') docker cp $src_file $CONTAINER_ID:$dst_file diff --git a/qemu.sh b/qemu.sh index e620846..f1b5adf 100755 --- a/qemu.sh +++ b/qemu.sh @@ -21,7 +21,7 @@ qemu-system-i386 \ -boot d \ -m 128 \ -serial tcp::6666,server,nowait \ - -drive file=HD.IMG,format=raw,index=0,media=disk \ + -drive file=hd.img,format=raw,index=0,media=disk \ -drive file=kernel.iso,index=1,media=cdrom \ -name kernel \ -device ich9-ahci,id=ahci \ -- 2.47.0