增加了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_rsdt_t *rsdt; // root system descript table
|
||||||
acpi_facp_t *facp; // fixed ACPI table
|
acpi_facp_t *facp; // fixed ACPI table
|
||||||
|
|
||||||
|
int acpi_enable_flag;
|
||||||
|
uint8_t *rsdp_address;
|
||||||
|
|
||||||
int acpi_enable() {
|
int acpi_enable() {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -167,6 +170,7 @@ uint8_t *AcpiCheckRSDPtr(void *ptr) {
|
||||||
// check signature
|
// check signature
|
||||||
if (!memcmp(sign, bptr, 8)) {
|
if (!memcmp(sign, bptr, 8)) {
|
||||||
printf("[acpi] rsdp found at %0x\n", bptr);
|
printf("[acpi] rsdp found at %0x\n", bptr);
|
||||||
|
rsdp_address = bptr;
|
||||||
for (i = 0; i < sizeof(acpi_rsdptr_t); i++) {
|
for (i = 0; i < sizeof(acpi_rsdptr_t); i++) {
|
||||||
check += *bptr;
|
check += *bptr;
|
||||||
bptr++;
|
bptr++;
|
||||||
|
@ -272,7 +276,7 @@ static int AcpiSysInit() {
|
||||||
|
|
||||||
void acpi_install() {
|
void acpi_install() {
|
||||||
AcpiSysInit();
|
AcpiSysInit();
|
||||||
acpi_enable();
|
acpi_enable_flag = !acpi_enable();
|
||||||
// power init
|
// power init
|
||||||
// AcpiPowerInit();
|
// AcpiPowerInit();
|
||||||
}
|
}
|
|
@ -34,5 +34,6 @@ long int strtol(const char *str,char **endptr,int base);
|
||||||
|
|
||||||
void reset_kernel();
|
void reset_kernel();
|
||||||
void shutdown_kernel();
|
void shutdown_kernel();
|
||||||
|
uint32_t memory_all();
|
||||||
|
|
||||||
#endif //CRASHPOWEROS_COMMON_H
|
#endif //CRASHPOWEROS_COMMON_H
|
||||||
|
|
|
@ -19,5 +19,6 @@ void cmd_read(int argc, char **argv);
|
||||||
void cmd_cat(int argc, char **argv);
|
void cmd_cat(int argc, char **argv);
|
||||||
void cmd_ls();
|
void cmd_ls();
|
||||||
void cmd_shutdown();
|
void cmd_shutdown();
|
||||||
|
void cmd_debug();
|
||||||
|
|
||||||
#endif //CRASHPOWEROS_SHELL_H
|
#endif //CRASHPOWEROS_SHELL_H
|
||||||
|
|
|
@ -32,6 +32,10 @@ struct task_struct {
|
||||||
struct task_struct *next; // 链表指针
|
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);
|
int32_t kernel_thread(int (*fn)(void *), void *arg, char *name);
|
||||||
|
|
||||||
void kthread_exit();
|
void kthread_exit();
|
||||||
|
@ -48,4 +52,10 @@ void task_kill(int pid);
|
||||||
|
|
||||||
void kill_all_task();
|
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
|
#endif //CRASHPOWEROS_TASK_H
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
extern uint32_t end;
|
extern uint32_t end;
|
||||||
extern int status;
|
extern int status;
|
||||||
uint32_t placement_address = (uint32_t) & end;
|
uint32_t placement_address = (uint32_t) & end;
|
||||||
|
multiboot_t *multiboot_all;
|
||||||
|
|
||||||
void reset_kernel(){
|
void reset_kernel(){
|
||||||
printf("Restart %s for x86...\n",OS_NAME);
|
printf("Restart %s for x86...\n",OS_NAME);
|
||||||
|
@ -30,7 +31,12 @@ void shutdown_kernel(){
|
||||||
power_off();
|
power_off();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t memory_all(){
|
||||||
|
return (multiboot_all->mem_upper + multiboot_all->mem_lower);
|
||||||
|
}
|
||||||
|
|
||||||
void kernel_main(multiboot_t *multiboot) {
|
void kernel_main(multiboot_t *multiboot) {
|
||||||
|
multiboot_all = multiboot;
|
||||||
io_cli();
|
io_cli();
|
||||||
vga_install();
|
vga_install();
|
||||||
if ((multiboot->mem_upper + multiboot->mem_lower) / 1024 + 1 < 16) {
|
if ((multiboot->mem_upper + multiboot->mem_lower) / 1024 + 1 < 16) {
|
||||||
|
|
107
kernel/task.c
107
kernel/task.c
|
@ -13,64 +13,72 @@ extern void switch_to(struct context *prev, struct context *next);
|
||||||
|
|
||||||
int now_pid = 0;
|
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(cur->pid == base->pid){
|
||||||
switch (cur->state) {
|
if(is_print){
|
||||||
case TASK_RUNNABLE:
|
switch (cur->state) {
|
||||||
printf("%s %d %s\n",cur->name,cur->pid,"Running");
|
case TASK_RUNNABLE:
|
||||||
break;
|
printf("%s %d %s\n",cur->name,cur->pid,"Running");
|
||||||
case TASK_SLEEPING:
|
break;
|
||||||
printf("%s %d %s\n",cur->name,cur->pid,"Sleeping");
|
case TASK_SLEEPING:
|
||||||
break;
|
printf("%s %d %s\n",cur->name,cur->pid,"Sleeping");
|
||||||
case TASK_UNINIT:
|
break;
|
||||||
printf("%s %d %s\n",cur->name,cur->pid,"Init");
|
case TASK_UNINIT:
|
||||||
break;
|
printf("%s %d %s\n",cur->name,cur->pid,"Init");
|
||||||
case TASK_ZOMBIE:
|
break;
|
||||||
printf("%s %d %s\n",cur->name,cur->pid,"Zombie");
|
case TASK_ZOMBIE:
|
||||||
break;
|
printf("%s %d %s\n",cur->name,cur->pid,"Zombie");
|
||||||
case TASK_DEATH:
|
break;
|
||||||
printf("%s %d %s\n",cur->name,cur->pid,"Death");
|
case TASK_DEATH:
|
||||||
break;
|
printf("%s %d %s\n",cur->name,cur->pid,"Death");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(*i)++;
|
(*i)++;
|
||||||
} else{
|
} else{
|
||||||
switch (cur->state) {
|
if(is_print){
|
||||||
case TASK_RUNNABLE:
|
switch (cur->state) {
|
||||||
printf("%s %d %s\n",cur->name,cur->pid,"Running");
|
case TASK_RUNNABLE:
|
||||||
break;
|
printf("%s %d %s\n",cur->name,cur->pid,"Running");
|
||||||
case TASK_SLEEPING:
|
break;
|
||||||
printf("%s %d %s\n",cur->name,cur->pid,"Sleeping");
|
case TASK_SLEEPING:
|
||||||
break;
|
printf("%s %d %s\n",cur->name,cur->pid,"Sleeping");
|
||||||
case TASK_UNINIT:
|
break;
|
||||||
printf("%s %d %s\n",cur->name,cur->pid,"Init");
|
case TASK_UNINIT:
|
||||||
break;
|
printf("%s %d %s\n",cur->name,cur->pid,"Init");
|
||||||
case TASK_ZOMBIE:
|
break;
|
||||||
printf("%s %d %s\n",cur->name,cur->pid,"Zombie");
|
case TASK_ZOMBIE:
|
||||||
break;
|
printf("%s %d %s\n",cur->name,cur->pid,"Zombie");
|
||||||
case TASK_DEATH:
|
break;
|
||||||
printf("%s %d %s\n",cur->name,cur->pid,"Death");
|
case TASK_DEATH:
|
||||||
break;
|
printf("%s %d %s\n",cur->name,cur->pid,"Death");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(*i)++;
|
(*i)++;
|
||||||
print_proc_t(i,base,cur->next);
|
print_proc_t(i,base,cur->next,is_print);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_proc(){
|
void print_proc(){
|
||||||
printf("====--------[Processes]---------===\n");
|
printf("====--------[Processes]---------===\n");
|
||||||
int index = 0;
|
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);
|
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;
|
struct task_struct *t = base;
|
||||||
if(t == NULL){
|
if(t == NULL){
|
||||||
argv = NULL;
|
argv = NULL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(t->pid == pid){
|
if(t->pid == pid){
|
||||||
*argv = *t;
|
*argv = t;
|
||||||
return;
|
return;
|
||||||
} else{
|
} else{
|
||||||
if(!first)
|
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){
|
void task_kill(int pid){
|
||||||
struct task_struct *argv;
|
struct task_struct *argv = found_task_pid(pid);
|
||||||
found_task(pid,running_proc_head,running_proc_head,argv,1);
|
|
||||||
if(argv == NULL){
|
if(argv == NULL){
|
||||||
printf("Cannot found task Pid:[%d].\n",pid);
|
printf("Cannot found task Pid:[%d].\n",pid);
|
||||||
return;
|
return;
|
||||||
|
@ -129,6 +154,10 @@ void task_kill(int pid){
|
||||||
|
|
||||||
void schedule() {
|
void schedule() {
|
||||||
if (current) {
|
if (current) {
|
||||||
|
if(current->next->state == TASK_SLEEPING){
|
||||||
|
change_task_to(current->next->next);
|
||||||
|
return;
|
||||||
|
}
|
||||||
change_task_to(current->next);
|
change_task_to(current->next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@ void cmd_proc(int argc, char **argv){
|
||||||
|
|
||||||
void cmd_date(){
|
void cmd_date(){
|
||||||
printf("System Time: %s\n",get_date_time());
|
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();
|
print_cpu_id();
|
||||||
vga_writestring("\n");
|
vga_writestring("\n");
|
||||||
}
|
}
|
||||||
|
@ -188,6 +188,29 @@ void cmd_shutdown(){
|
||||||
shutdown_kernel();
|
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(){
|
void setup_shell(){
|
||||||
vga_clear();
|
vga_clear();
|
||||||
printf("%s for x86 [Version %s] \n",OS_NAME, OS_VERSION);
|
printf("%s for x86 [Version %s] \n",OS_NAME, OS_VERSION);
|
||||||
|
@ -231,6 +254,8 @@ void setup_shell(){
|
||||||
cmd_reset();
|
cmd_reset();
|
||||||
else if (!strcmp("shutdown", argv[0])||!strcmp("exit", argv[0]))
|
else if (!strcmp("shutdown", argv[0])||!strcmp("exit", argv[0]))
|
||||||
cmd_shutdown();
|
cmd_shutdown();
|
||||||
|
else if (!strcmp("debug", argv[0]))
|
||||||
|
cmd_debug();
|
||||||
else if (!strcmp("help", argv[0]) || !strcmp("?", argv[0]) || !strcmp("h", argv[0])) {
|
else if (!strcmp("help", argv[0]) || !strcmp("?", argv[0]) || !strcmp("h", argv[0])) {
|
||||||
vga_writestring("-=[\037CrashPowerShell Helper\036]=-\n");
|
vga_writestring("-=[\037CrashPowerShell Helper\036]=-\n");
|
||||||
vga_writestring("help ? h \032Print shell help info.\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("proc [kill<pid>|list] \032Lists all running processes.\036\n");
|
||||||
vga_writestring("reset \032Reset OS.\036\n");
|
vga_writestring("reset \032Reset OS.\036\n");
|
||||||
vga_writestring("shutdown exit \032Shutdown 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]);
|
} else printf("\033[Shell]: Unknown command '%s'.\036\n", argv[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue