新增change_path的syscall

This commit is contained in:
XIAOYI12 2024-09-06 23:11:41 +08:00
parent beee408a87
commit 91c097aad6
8 changed files with 30 additions and 12 deletions

View File

@ -14,6 +14,7 @@
#define SYSCALL_VFS_WRITEFILE 11
#define SYSCALL_SYSINFO 12
#define SYSCALL_EXEC 13
#define SYSCALL_CHANGE_PATH 14
#include "ctype.h"
@ -30,5 +31,6 @@ void syscall_vfs_readfile(char* filename,char* buffer);
void syscall_vfs_writefile(char* filename,char* buffer,unsigned int size);
void* syscall_sysinfo();
int syscall_exec(char *filename);
void syscall_vfs_change_path(const char* path);
#endif

View File

@ -3,8 +3,8 @@
int main(){
printf("Init service launched.\n");
syscall_vfs_change_path("apps");
int pid = exec_elf("shell.bin");
printf("Launching shell pid [%d]\n",pid);
if(pid != -1){
printf("Shell launch win! PID:[%d]\n",pid);
} else printf("Error: Cannot launch shell\n");

View File

@ -94,4 +94,12 @@ int syscall_exec(char *filename){
register uint32_t ebx asm("ebx") = __arg1;
asm volatile("int $31\n\t" : "=a"(rets) : "0"(SYSCALL_EXEC), "r"(ebx) : "memory", "cc");
return rets;
}
void syscall_vfs_change_path(const char *path){
uint32_t rets;
uint32_t __arg1 = (uint32_t)(path);
register uint32_t ebx asm("ebx") = __arg1;
asm volatile("int $31\n\t" : "=a"(rets) : "0"(SYSCALL_CHANGE_PATH), "r"(ebx) : "memory", "cc");
return rets;
}

View File

@ -18,6 +18,7 @@
#define SYSCALL_VFS_WRITEFILE 11
#define SYSCALL_SYSINFO 12
#define SYSCALL_EXEC 13
#define SYSCALL_CHANGE_PATH 14
void syscall_install();

View File

@ -159,13 +159,13 @@ void kernel_main(multiboot_t *multiboot) {
clock_sleep(25);
vfs_change_path("apps");
klogf(user_process("init.bin","InitService") != -1,"Init service process init.\n");
//klogf(user_process("init.bin","InitService") != -1,"Init service process init.\n");
int pid = user_process("shell.bin","UserShell");
kernel_thread(check_task_usershell,&pid,"CTU");
//klogf(user_process("init.bin","Init") != -1,"Init base process init.\n");
//int pid = kernel_thread(setup_shell,NULL,"CPOS-Shell");
//klogf(pid != -1,"Launch kernel shell.\n");
// int pid = kernel_thread(setup_shell,NULL,"CPOS-Shell");
// klogf(pid != -1,"Launch kernel shell.\n");
//kernel_thread(check_task,&pid,"CPOS-CK");
//panic_pane("System out of memory error!",OUT_OF_MEMORY);

View File

@ -230,7 +230,7 @@ void init_page(multiboot_t *mboot) {
current_directory = kernel_directory;
int i = 0;
while (i < placement_address + 0x50000) {
while (i < placement_address + 0xf0000) {
/*
* ring3而言不可读不可写
*
@ -240,6 +240,11 @@ void init_page(multiboot_t *mboot) {
i += 0x1000;
}
for (int i = KHEAP_START; i < KHEAP_START + KHEAP_INITIAL_SIZE; i++) {
alloc_frame(get_page(i, 1, kernel_directory,false), 1, 1);
}
unsigned int j = mboot->framebuffer_addr,size = mboot->framebuffer_height * mboot->framebuffer_width*mboot->framebuffer_bpp;
while (j <= mboot->framebuffer_addr + size){
@ -247,9 +252,7 @@ void init_page(multiboot_t *mboot) {
j += 0x1000;
}
for (int i = KHEAP_START; i < KHEAP_START + KHEAP_INITIAL_SIZE; i++) {
alloc_frame(get_page(i, 1, kernel_directory,false), 1, 1);
}
register_interrupt_handler(14, page_fault);

View File

@ -63,6 +63,10 @@ static void syscall_vfs_writefile(uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_
vfs_writefile(ebx,ecx,edx);
}
static void syscall_vfs_chang_path(uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_t esi,uint32_t edi){
vfs_change_path(ebx);
}
struct sysinfo{
char* osname;
char* kenlname;
@ -133,6 +137,7 @@ void *sycall_handlers[MAX_SYSCALLS] = {
[SYSCALL_VFS_WRITEFILE] = syscall_vfs_writefile,
[SYSCALL_SYSINFO] = syscall_sysinfo,
[SYSCALL_EXEC] = syscall_exec,
[SYSCALL_CHANGE_PATH] = syscall_vfs_chang_path,
};
typedef size_t (*syscall_t)(size_t, size_t, size_t, size_t, size_t);

View File

@ -194,6 +194,7 @@ int32_t user_process(char *path, char *name){ // 用户进程创建
return -1;
}
io_sti();
uint32_t size = vfs_filesize(path);
if(size == -1){
return -1;
@ -221,8 +222,6 @@ int32_t user_process(char *path, char *name){ // 用户进程创建
new_task->tty = kmalloc(sizeof(tty_t));
init_default_tty(new_task);
extern char root_disk;
vfs_change_disk(new_task,root_disk);
vfs_copy(new_task,get_current()->vfs_now);
io_sti();