diff --git a/Makefile b/Makefile index 8e0085de..707d069f 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,7 @@ endif all: mkdir -p bin/kernel/ mkdir -p bin/user/ + mkdir -p bin/tmp/ @list='$(SUBDIRS)'; for subdir in $$list; do \ echo "make all in $$subdir";\ cd $$subdir;\ diff --git a/kernel/process/process.c b/kernel/process/process.c index 1030025e..e174aef1 100644 --- a/kernel/process/process.c +++ b/kernel/process/process.c @@ -573,13 +573,13 @@ ul initial_kernel_thread(ul arg) // kdebug("current_pcb->thread->rsp=%#018lx", current_pcb->thread->rsp); current_pcb->flags = 0; // 将返回用户层的代码压入堆栈,向rdx传入regs的地址,然后jmp到do_execve这个系统调用api的处理函数 这里的设计思路和switch_proc类似 - // 加载用户态程序:init.bin - char init_path[] = "/init.bin"; + // 加载用户态程序:shell.elf + char init_path[] = "/shell.elf"; uint64_t addr = (uint64_t)&init_path; __asm__ __volatile__("movq %1, %%rsp \n\t" "pushq %2 \n\t" "jmp do_execve \n\t" ::"D"(current_pcb->thread->rsp), - "m"(current_pcb->thread->rsp), "m"(current_pcb->thread->rip), "S"("/init.bin") + "m"(current_pcb->thread->rsp), "m"(current_pcb->thread->rip), "S"("/shell.elf") : "memory"); return 1; diff --git a/run.sh b/run.sh index afe14c21..527f114d 100644 --- a/run.sh +++ b/run.sh @@ -88,10 +88,10 @@ else flag_can_run=1 fi -# 拷贝init文件到硬盘 +# 拷贝shell到硬盘 cd tools bash m* -sudo cp ${root_folder}/bin/user/init.bin ${root_folder}/bin/disk_mount +sudo cp ${root_folder}/bin/user/shell.elf ${root_folder}/bin/disk_mount sync bash u* cd .. diff --git a/user/Makefile b/user/Makefile index ccfa3966..36faedf4 100644 --- a/user/Makefile +++ b/user/Makefile @@ -1,4 +1,4 @@ -user_sub_dirs = libs +user_sub_dirs = libs apps SUBDIR_ROOTS := . DIRS := . $(shell find $(SUBDIR_ROOTS) -type d) @@ -6,9 +6,11 @@ GARBAGE_PATTERNS := *.o *.s~ *.s *.S~ *.c~ *.h~ sys_api_lib GARBAGE := $(foreach DIR,$(DIRS),$(addprefix $(DIR)/,$(GARBAGE_PATTERNS))) -objs := -CFLAGS := $(GLOBAL_CFLAGS) -current_CFLAGS := $(CFLAGS) -I $(shell pwd)/libs +tmp_output_dir=$(ROOT_PATH)/bin/tmp/user +output_dir=$(ROOT_PATH)/bin/user + +CFLAGS := $(GLOBAL_CFLAGS) -I $(shell pwd)/libs +current_CFLAGS := $(CFLAGS) all: @list='$(user_sub_dirs)'; for subdir in $$list; do \ @@ -17,18 +19,25 @@ all: $(MAKE) all CFLAGS="$(CFLAGS)";\ cd ..;\ done - $(MAKE) init.o - $(MAKE) sys_api_lib + + $(shell if [ ! -e $(tmp_output_dir) ];then mkdir -p $(tmp_output_dir); fi) + $(shell if [ ! -e $(output_dir) ];then mkdir -p $(output_dir); fi) + + $(MAKE) sys_api_lib + $(MAKE) shell # objcopy -I elf64-x86-64 -S -R ".eh_frame" -R ".comment" -O binary sys_api_lib $(ROOT_PATH)/bin/user/init.bin - objcopy -I elf64-x86-64 -S -R ".eh_frame" -R ".comment" -O elf64-x86-64 sys_api_lib $(ROOT_PATH)/bin/user/init.bin +#objcopy -I elf64-x86-64 -S -R ".eh_frame" -R ".comment" -O elf64-x86-64 sys_api_lib $(ROOT_PATH)/bin/user/init.bin -sys_api_lib: init.o +sys_api_lib: - ld -b elf64-x86-64 -z muldefs -o sys_api_lib $(shell find . -name "*.o") + ld -b elf64-x86-64 -z muldefs -o $(tmp_output_dir)/sys_api_lib $(shell find ./libs -name "*.o") #ld -b elf64-x86-64 -z muldefs -o sys_api_lib init.o $(shell find . -name "*.o") -T init.lds -init.o: init.c - gcc $(current_CFLAGS) -c init.c -o init.o +shell: + ld -b elf64-x86-64 -z muldefs -o $(tmp_output_dir)/shell $(shell find ./apps/shell -name "*.o") $(shell find ./libs -name "*.o") + + objcopy -I elf64-x86-64 -S -R ".eh_frame" -R ".comment" -O elf64-x86-64 $(tmp_output_dir)/shell $(output_dir)/shell.elf clean: - rm -rf $(GARBAGE) \ No newline at end of file + rm -rf $(GARBAGE) + \ No newline at end of file diff --git a/user/apps/Makefile b/user/apps/Makefile new file mode 100644 index 00000000..c4a4a1e2 --- /dev/null +++ b/user/apps/Makefile @@ -0,0 +1,10 @@ + +user_apps_sub_dirs=shell + +all: + @list='$(user_apps_sub_dirs)'; for subdir in $$list; do \ + echo "make all in $$subdir";\ + cd $$subdir;\ + $(MAKE) all CFLAGS="$(CFLAGS) -I $(shell pwd)";\ + cd ..;\ + done \ No newline at end of file diff --git a/user/apps/shell/Makefile b/user/apps/shell/Makefile new file mode 100644 index 00000000..9c0ffa49 --- /dev/null +++ b/user/apps/shell/Makefile @@ -0,0 +1,4 @@ +all: shell.o + +shell.o: shell.c + gcc $(CFLAGS) -c shell.c -o shell.o \ No newline at end of file diff --git a/user/init.c b/user/apps/shell/shell.c similarity index 99% rename from user/init.c rename to user/apps/shell/shell.c index 5e7a86b7..2fb665dc 100644 --- a/user/init.c +++ b/user/apps/shell/shell.c @@ -5,7 +5,6 @@ #include int main() { - char string[] = "/333.txt"; uint8_t buf[128] = {0}; char tips_str[] = "The first application 'init.bin' started successfully!\n"; diff --git a/user/init.lds b/user/apps/shell/shell.lds similarity index 100% rename from user/init.lds rename to user/apps/shell/shell.lds