增加了task操作接口
This commit is contained in:
parent
b684034c10
commit
66e698432e
|
@ -19,6 +19,9 @@ uint16_t SCI_EN;
|
|||
acpi_rsdt_t *rsdt; // root system descript table
|
||||
acpi_facp_t *facp; // fixed ACPI table
|
||||
|
||||
int acpi_enable_flag;
|
||||
uint8_t *rsdp_address;
|
||||
|
||||
int acpi_enable() {
|
||||
int i;
|
||||
|
||||
|
@ -167,6 +170,7 @@ uint8_t *AcpiCheckRSDPtr(void *ptr) {
|
|||
// check signature
|
||||
if (!memcmp(sign, bptr, 8)) {
|
||||
printf("[acpi] rsdp found at %0x\n", bptr);
|
||||
rsdp_address = bptr;
|
||||
for (i = 0; i < sizeof(acpi_rsdptr_t); i++) {
|
||||
check += *bptr;
|
||||
bptr++;
|
||||
|
@ -272,7 +276,7 @@ static int AcpiSysInit() {
|
|||
|
||||
void acpi_install() {
|
||||
AcpiSysInit();
|
||||
acpi_enable();
|
||||
acpi_enable_flag = !acpi_enable();
|
||||
// power init
|
||||
// AcpiPowerInit();
|
||||
}
|
|
@ -34,5 +34,6 @@ long int strtol(const char *str,char **endptr,int base);
|
|||
|
||||
void reset_kernel();
|
||||
void shutdown_kernel();
|
||||
uint32_t memory_all();
|
||||
|
||||
#endif //CRASHPOWEROS_COMMON_H
|
||||
|
|
|
@ -19,5 +19,6 @@ void cmd_read(int argc, char **argv);
|
|||
void cmd_cat(int argc, char **argv);
|
||||
void cmd_ls();
|
||||
void cmd_shutdown();
|
||||
void cmd_debug();
|
||||
|
||||
#endif //CRASHPOWEROS_SHELL_H
|
||||
|
|
|
@ -32,6 +32,10 @@ struct task_struct {
|
|||
struct task_struct *next; // 链表指针
|
||||
};
|
||||
|
||||
void print_proc_t(int *i,struct task_struct *base,struct task_struct *cur,int is_print);
|
||||
|
||||
struct task_struct* get_current();
|
||||
|
||||
int32_t kernel_thread(int (*fn)(void *), void *arg, char *name);
|
||||
|
||||
void kthread_exit();
|
||||
|
@ -48,4 +52,10 @@ void task_kill(int pid);
|
|||
|
||||
void kill_all_task();
|
||||
|
||||
struct task_struct* found_task_pid(int pid);
|
||||
|
||||
void wait_task(struct task_struct *task);
|
||||
|
||||
void start_task(struct task_struct *task);
|
||||
|
||||
#endif //CRASHPOWEROS_TASK_H
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
extern uint32_t end;
|
||||
extern int status;
|
||||
uint32_t placement_address = (uint32_t) & end;
|
||||
multiboot_t *multiboot_all;
|
||||
|
||||
void reset_kernel(){
|
||||
printf("Restart %s for x86...\n",OS_NAME);
|
||||
|
@ -30,7 +31,12 @@ void shutdown_kernel(){
|
|||
power_off();
|
||||
}
|
||||
|
||||
uint32_t memory_all(){
|
||||
return (multiboot_all->mem_upper + multiboot_all->mem_lower);
|
||||
}
|
||||
|
||||
void kernel_main(multiboot_t *multiboot) {
|
||||
multiboot_all = multiboot;
|
||||
io_cli();
|
||||
vga_install();
|
||||
if ((multiboot->mem_upper + multiboot->mem_lower) / 1024 + 1 < 16) {
|
||||
|
|
|
@ -13,8 +13,13 @@ extern void switch_to(struct context *prev, struct context *next);
|
|||
|
||||
int now_pid = 0;
|
||||
|
||||
void print_proc_t(int *i,struct task_struct *base,struct task_struct *cur){
|
||||
struct task_struct* get_current(){
|
||||
return current;
|
||||
}
|
||||
|
||||
void print_proc_t(int *i,struct task_struct *base,struct task_struct *cur,int is_print){
|
||||
if(cur->pid == base->pid){
|
||||
if(is_print){
|
||||
switch (cur->state) {
|
||||
case TASK_RUNNABLE:
|
||||
printf("%s %d %s\n",cur->name,cur->pid,"Running");
|
||||
|
@ -32,8 +37,10 @@ void print_proc_t(int *i,struct task_struct *base,struct task_struct *cur){
|
|||
printf("%s %d %s\n",cur->name,cur->pid,"Death");
|
||||
break;
|
||||
}
|
||||
}
|
||||
(*i)++;
|
||||
} else{
|
||||
if(is_print){
|
||||
switch (cur->state) {
|
||||
case TASK_RUNNABLE:
|
||||
printf("%s %d %s\n",cur->name,cur->pid,"Running");
|
||||
|
@ -51,26 +58,27 @@ void print_proc_t(int *i,struct task_struct *base,struct task_struct *cur){
|
|||
printf("%s %d %s\n",cur->name,cur->pid,"Death");
|
||||
break;
|
||||
}
|
||||
}
|
||||
(*i)++;
|
||||
print_proc_t(i,base,cur->next);
|
||||
print_proc_t(i,base,cur->next,is_print);
|
||||
}
|
||||
}
|
||||
|
||||
void print_proc(){
|
||||
printf("====--------[Processes]---------===\n");
|
||||
int index = 0;
|
||||
print_proc_t(&index,current,current->next);
|
||||
print_proc_t(&index,current,current->next,1);
|
||||
printf("Name Pid Status [All Proc: %d]\n\n",index);
|
||||
}
|
||||
|
||||
static void found_task(int pid,struct task_struct *head,struct task_struct *base,struct task_struct *argv,int first){
|
||||
static void found_task(int pid,struct task_struct *head,struct task_struct *base,struct task_struct **argv,int first){
|
||||
struct task_struct *t = base;
|
||||
if(t == NULL){
|
||||
argv = NULL;
|
||||
return;
|
||||
}
|
||||
if(t->pid == pid){
|
||||
*argv = *t;
|
||||
*argv = t;
|
||||
return;
|
||||
} else{
|
||||
if(!first)
|
||||
|
@ -82,9 +90,26 @@ static void found_task(int pid,struct task_struct *head,struct task_struct *base
|
|||
}
|
||||
}
|
||||
|
||||
struct task_struct* found_task_pid(int pid){
|
||||
struct task_struct *argv = NULL;
|
||||
found_task(pid,running_proc_head,running_proc_head,&argv,1);
|
||||
if(argv == NULL){
|
||||
printf("Cannot found task Pid:[%d].\n",pid);
|
||||
return;
|
||||
}
|
||||
return argv;
|
||||
}
|
||||
|
||||
void wait_task(struct task_struct *task){
|
||||
task->state = TASK_SLEEPING;
|
||||
}
|
||||
|
||||
void start_task(struct task_struct *task){
|
||||
task->state = TASK_RUNNABLE;
|
||||
}
|
||||
|
||||
void task_kill(int pid){
|
||||
struct task_struct *argv;
|
||||
found_task(pid,running_proc_head,running_proc_head,argv,1);
|
||||
struct task_struct *argv = found_task_pid(pid);
|
||||
if(argv == NULL){
|
||||
printf("Cannot found task Pid:[%d].\n",pid);
|
||||
return;
|
||||
|
@ -129,6 +154,10 @@ void task_kill(int pid){
|
|||
|
||||
void schedule() {
|
||||
if (current) {
|
||||
if(current->next->state == TASK_SLEEPING){
|
||||
change_task_to(current->next->next);
|
||||
return;
|
||||
}
|
||||
change_task_to(current->next);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ void cmd_proc(int argc, char **argv){
|
|||
|
||||
void cmd_date(){
|
||||
printf("System Time: %s\n",get_date_time());
|
||||
printf("Memory Usage: %dKB | All Size: %dMB\n",memory_usage()/1024,(KHEAP_START+KHEAP_INITIAL_SIZE)/1024/1024);
|
||||
printf("Memory Usage: [%dKB] | All Size: [%dMB]\n",memory_usage()/1024,(KHEAP_START+KHEAP_INITIAL_SIZE)/1024/1024);
|
||||
print_cpu_id();
|
||||
vga_writestring("\n");
|
||||
}
|
||||
|
@ -188,6 +188,29 @@ void cmd_shutdown(){
|
|||
shutdown_kernel();
|
||||
}
|
||||
|
||||
void cmd_debug(){
|
||||
vga_clear();
|
||||
printf("%s for x86 [Version %s] \n",OS_NAME, OS_VERSION);
|
||||
printf("\032Copyright 2024 XIAOYI12 (Build by GCC i686-elf-tools)\036\n");
|
||||
extern int acpi_enable_flag;
|
||||
extern uint8_t *rsdp_address;
|
||||
printf("ACPI: Enable: %s | RSDP Address: 0x%08x\n",acpi_enable_flag?"\035ENABLE\036":"\033DISABLE\036",rsdp_address);
|
||||
int index = 0;
|
||||
print_proc_t(&index,get_current(),get_current()->next,0);
|
||||
printf("Process Runnable: %d\n",index);
|
||||
cmd_date();
|
||||
printf(" > > > > ====[Registers Info]==== < < < <\n");
|
||||
register uint32_t eax asm("eax"),
|
||||
ecx asm("ecx"),
|
||||
esp asm("esp"),
|
||||
ebp asm("ebp"),
|
||||
ebx asm("ebx"),
|
||||
esi asm("esi"),
|
||||
edi asm("edi");
|
||||
printf("EAX: 0x%08x | EBX 0x%08x | ECX 0x%08x | ESP 0x%08x \n",eax,ebx,ecx,esp);
|
||||
printf("ESI: 0x%08x | EDI 0x%08x | EBP 0x%08x | EFLAGS 0x%08x\n",esi,edi,ebp,get_current()->context.eflags);
|
||||
}
|
||||
|
||||
void setup_shell(){
|
||||
vga_clear();
|
||||
printf("%s for x86 [Version %s] \n",OS_NAME, OS_VERSION);
|
||||
|
@ -231,6 +254,8 @@ void setup_shell(){
|
|||
cmd_reset();
|
||||
else if (!strcmp("shutdown", argv[0])||!strcmp("exit", argv[0]))
|
||||
cmd_shutdown();
|
||||
else if (!strcmp("debug", argv[0]))
|
||||
cmd_debug();
|
||||
else if (!strcmp("help", argv[0]) || !strcmp("?", argv[0]) || !strcmp("h", argv[0])) {
|
||||
vga_writestring("-=[\037CrashPowerShell Helper\036]=-\n");
|
||||
vga_writestring("help ? h \032Print shell help info.\036\n");
|
||||
|
@ -245,6 +270,7 @@ void setup_shell(){
|
|||
vga_writestring("proc [kill<pid>|list] \032Lists all running processes.\036\n");
|
||||
vga_writestring("reset \032Reset OS.\036\n");
|
||||
vga_writestring("shutdown exit \032Shutdown OS.\036\n");
|
||||
vga_writestring("debug \032Print os debug info.\036\n");
|
||||
} else printf("\033[Shell]: Unknown command '%s'.\036\n", argv[0]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue