多进程
修改后的如下chapter6E的Makefile如下所示如下
#########################
# Makefile for Orange'S #
#########################
# Entry point of Orange'S
# It must have the same value with 'KernelEntryPointPhyAddr' in load.inc!
ENTRYPOINT = 0x30400
# Offset of entry point in kernel file
# It depends on ENTRYPOINT
ENTRYOFFSET = 0x400
# Programs, flags, etc.
ASM = nasm
DASM = ndisasm
CC = gcc
LD = ld
ASMBFLAGS = -I boot/include/
ASMKFLAGS = -I include/ -f elf
CFLAGS = -I include/ -c -fno-builtin -m32 -fno-stack-protector
LDFLAGS = -s -Ttext $(ENTRYPOINT) -m elf_i386
DASMFLAGS = -u -o $(ENTRYPOINT) -e $(ENTRYOFFSET)
# This Program
ORANGESBOOT = boot/boot.bin boot/loader.bin
ORANGESKERNEL = kernel.bin
OBJS = kernel/kernel.o kernel/start.o kernel/main.o kernel/clock.o\
kernel/i8259.o kernel/global.o kernel/protect.o\
lib/kliba.o lib/klib.o lib/string.o
DASMOUTPUT = kernel.bin.asm
IMG:=a.img
# All Phony Targets
.PHONY : everything final image clean realclean disasm all buildimg
# Default starting position
everything : $(ORANGESBOOT) $(ORANGESKERNEL)
all : realclean everything
image : realclean everything clean buildimg
clean :
rm -f $(OBJS)
realclean :
rm -f $(OBJS) $(ORANGESBOOT) $(ORANGESKERNEL)
disasm :
$(DASM) $(DASMFLAGS) $(ORANGESKERNEL) > $(DASMOUTPUT)
# We assume that "a.img" exists in current folder
buildimg :
dd if=boot/boot.bin of=a.img bs=512 count=1 conv=notrunc
sudo mount -o loop a.img /mnt/floppy/
sudo cp -fv boot/loader.bin /mnt/floppy/
sudo cp -fv kernel.bin /mnt/floppy
sudo umount /mnt/floppy
createFp :
bximage -mode=create -fd=1.44M -q $(IMG)
qemu :
qemu-system-i386 -fda $(IMG)
boot/boot.bin : boot/boot.asm boot/include/load.inc boot/include/fat12hdr.inc
$(ASM) $(ASMBFLAGS) -o $@ $<
boot/loader.bin : boot/loader.asm boot/include/load.inc boot/include/fat12hdr.inc boot/include/pm.inc
$(ASM) $(ASMBFLAGS) -o $@ $<
$(ORANGESKERNEL) : $(OBJS)
$(LD) $(LDFLAGS) -o $(ORANGESKERNEL) $(OBJS)
kernel/kernel.o : kernel/kernel.asm include/sconst.inc
$(ASM) $(ASMKFLAGS) -o $@ $<
kernel/start.o: kernel/start.c include/type.h include/const.h include/protect.h include/string.h include/proc.h include/proto.h \
include/global.h
$(CC) $(CFLAGS) -o $@ $<
kernel/main.o: kernel/main.c include/type.h include/const.h include/protect.h include/string.h include/proc.h include/proto.h \
include/global.h
$(CC) $(CFLAGS) -o $@ $<
kernel/clock.o: kernel/clock.c
$(CC) $(CFLAGS) -o $@ $<
kernel/i8259.o: kernel/i8259.c include/type.h include/const.h include/protect.h include/proto.h
$(CC) $(CFLAGS) -o $@ $<
kernel/global.o: kernel/global.c include/type.h include/const.h include/protect.h include/proc.h \
include/global.h include/proto.h
$(CC) $(CFLAGS) -o $@ $<
kernel/protect.o: kernel/protect.c include/type.h include/const.h include/protect.h include/proc.h include/proto.h \
include/global.h
$(CC) $(CFLAGS) -o $@ $<
lib/klib.o: lib/klib.c include/type.h include/const.h include/protect.h include/string.h include/proc.h include/proto.h \
include/global.h
$(CC) $(CFLAGS) -o $@ $<
lib/kliba.o : lib/kliba.asm
$(ASM) $(ASMKFLAGS) -o $@ $<
lib/string.o : lib/string.asm
$(ASM) $(ASMKFLAGS) -o $@ $<
运行过程如下所示:
as@as-virtual-machine:~/osdir/chapter6E$ make clean
rm -f kernel/kernel.o kernel/start.o kernel/main.o kernel/clock.o kernel/i8259.o kernel/global.o kernel/protect.o lib/kliba.o lib/klib.o lib/string.o
as@as-virtual-machine:~/osdir/chapter6E$ make createFP
make: *** No rule to make target 'createFP'. Stop.
as@as-virtual-machine:~/osdir/chapter6E$ make createFp
bximage -mode=create -fd=1.44M -q a.img
========================================================================
bximage
Disk Image Creation / Conversion / Resize and Commit Tool for Bochs
$Id: bximage.cc 13481 2018-03-30 21:04:04Z vruppert $
========================================================================
Creating floppy image 'a.img' with 2880 sectors
The following line should appear in your bochsrc:
floppya: image="a.img", status=inserted
as@as-virtual-machine:~/osdir/chapter6E$ make everything
nasm -I boot/include/ -o boot/boot.bin boot/boot.asm
nasm -I boot/include/ -o boot/loader.bin boot/loader.asm
nasm -I include/ -f elf -o kernel/kernel.o kernel/kernel.asm
gcc -I include/ -c -fno-builtin -m32 -fno-stack-protector -o kernel/start.o kernel/start.c
gcc -I include/ -c -fno-builtin -m32 -fno-stack-protector -o kernel/main.o kernel/main.c
kernel/main.c: In function ‘kernel_main’:
kernel/main.c:30:3: warning: implicit declaration of function ‘strcpy’ [-Wimplicit-function-declaration]
30 | strcpy(p_proc->p_name, p_task->name); // name of the process
| ^~~~~~
kernel/main.c:15:1: note: ‘strcpy’ is defined in header ‘<string.h>’; did you forget to ‘#include <string.h>’?
14 | #include "global.h"
+++ |+#include <string.h>
15 |
kernel/main.c: In function ‘TestA’:
kernel/main.c:80:3: warning: implicit declaration of function ‘disp_int’ [-Wimplicit-function-declaration]
80 | disp_int(i++);
| ^~~~~~~~
gcc -I include/ -c -fno-builtin -m32 -fno-stack-protector -o kernel/clock.o kernel/clock.c
gcc -I include/ -c -fno-builtin -m32 -fno-stack-protector -o kernel/i8259.o kernel/i8259.c
kernel/i8259.c: In function ‘spurious_irq’:
kernel/i8259.c:39:2: warning: implicit declaration of function ‘disp_int’ [-Wimplicit-function-declaration]
39 | disp_int(irq);
| ^~~~~~~~
gcc -I include/ -c -fno-builtin -m32 -fno-stack-protector -o kernel/global.o kernel/global.c
gcc -I include/ -c -fno-builtin -m32 -fno-stack-protector -o kernel/protect.o kernel/protect.c
kernel/protect.c: In function ‘init_prot’:
kernel/protect.c:63:2: warning: implicit declaration of function ‘init_8259A’ [-Wimplicit-function-declaration]
63 | init_8259A();
| ^~~~~~~~~~
kernel/protect.c:100:2: warning: implicit declaration of function ‘memset’ [-Wimplicit-function-declaration]
100 | memset(&tss, 0, sizeof(tss));
| ^~~~~~
kernel/protect.c:14:1: note: ‘memset’ is defined in header ‘<string.h>’; did you forget to ‘#include <string.h>’?
13 | #include "global.h"
+++ |+#include <string.h>
14 |
kernel/protect.c: In function ‘exception_handler’:
kernel/protect.c:211:2: warning: implicit declaration of function ‘disp_int’ [-Wimplicit-function-declaration]
211 | disp_int(eflags);
| ^~~~~~~~
nasm -I include/ -f elf -o lib/kliba.o lib/kliba.asm
gcc -I include/ -c -fno-builtin -m32 -fno-stack-protector -o lib/klib.o lib/klib.c
nasm -I include/ -f elf -o lib/string.o lib/string.asm
ld -s -Ttext 0x30400 -m elf_i386 -o kernel.bin kernel/kernel.o kernel/start.o kernel/main.o kernel/clock.o kernel/i8259.o kernel/global.o kernel/protect.o lib/kliba.o lib/klib.o lib/string.o
as@as-virtual-machine:~/osdir/chapter6E$ make buildimg
dd if=boot/boot.bin of=a.img bs=512 count=1 conv=notrunc
1+0 records in
1+0 records out
512 bytes copied, 0.00043859 s, 1.2 MB/s
sudo mount -o loop a.img /mnt/floppy/
[sudo] password for as:
sudo cp -fv boot/loader.bin /mnt/floppy/
'boot/loader.bin' -> '/mnt/floppy/loader.bin'
sudo cp -fv kernel.bin /mnt/floppy
'kernel.bin' -> '/mnt/floppy/kernel.bin'
sudo umount /mnt/floppy
as@as-virtual-machine:~/osdir/chapter6E$ make qemu
qemu-system-i386 -fda a.img
WARNING: Image format was not specified for 'a.img' and probing guessed raw.
Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
Specify the 'raw' format explicitly to remove the restrictions.
运行结果如下所示
与原书中图6.18基本一致。