-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`了
-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)
p->task->state = TASK_READY;
p->task->reason = "wake_up";
- list_del(&p->entry);
+ list_del_init(&p->entry);
--nr;
if (nr == 0) {
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
-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 \