mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-08 14:16:47 +00:00
🎨 将shell独立成单独的app
This commit is contained in:
parent
1eb9a299b6
commit
afeca18206
1
Makefile
1
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;\
|
||||
|
@ -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;
|
||||
|
4
run.sh
4
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 ..
|
||||
|
@ -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)
|
||||
rm -rf $(GARBAGE)
|
||||
|
10
user/apps/Makefile
Normal file
10
user/apps/Makefile
Normal file
@ -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
|
4
user/apps/shell/Makefile
Normal file
4
user/apps/shell/Makefile
Normal file
@ -0,0 +1,4 @@
|
||||
all: shell.o
|
||||
|
||||
shell.o: shell.c
|
||||
gcc $(CFLAGS) -c shell.c -o shell.o
|
@ -5,7 +5,6 @@
|
||||
#include <libKeyboard/keyboard.h>
|
||||
int main()
|
||||
{
|
||||
|
||||
char string[] = "/333.txt";
|
||||
uint8_t buf[128] = {0};
|
||||
char tips_str[] = "The first application 'init.bin' started successfully!\n";
|
Loading…
x
Reference in New Issue
Block a user