1 Star 1 Fork 0

Xthoa / uFexos1

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
proc.c 1.69 KB
一键复制 编辑 原始数据 按行查看 历史
Xthoa 提交于 2021-01-26 09:12 . 'v7.a'
#include "types.h"
#include "macro.h"
#include "asm.h"
Hproc current_proc(){
return proclist->procs+proclist->cur;
}
TSS32* current_tss(){
return (TSS32*)(&current_proc()->tss);
}
ProcList* proclist;
void init_proc(){
proclist=mmalloc_page(1);
proclist->cnt=proclist->cur=0;
cputs("init_proc(): Multi process OK\n",GREY);
}
Hproc create_process(char* name){
Hproc p=proclist->procs+proclist->cnt;
p->pid=proclist->cnt++;
p->status=PST_INIT;
strcpy(p->name,name);
int seg=alloc(&segaloc,1);
p->tsss=seg<<3;
set_segmdesc(seg,p,sizeof(*p)-1,GATE_TSS);
return p;
}
Hproc init_sysproc(){
Hproc p=create_process("system");
int seg=p->tsss;
p->tss.eflags=read_eflags();
p->tss.cr3=PDEPHY;
p->tss.cs=8;
p->tss.ds=p->tss.es=p->tss.fs=p->tss.gs=16;
p->tss.ss=p->tss.ss0=16;
p->status=PST_SLEEP;
__asm__("ltr %0"::"m"(seg));
return p;
}
void init_process(Hproc p,int eip,int kslen){
p->tss.eip=eip;
p->tss.eflags=read_eflags();
p->tss.cr3=PDEPHY;
p->tss.cs=8;
p->tss.ds=p->tss.es=p->tss.fs=p->tss.gs=16;
p->tss.ss=p->tss.ss0=16;
p->tss.esp=p->tss.esp0=mmalloc_page(kslen);
p->status=PST_SLEEP;
}
void ready_process(Hproc p){
p->status=PST_READY;
}
void schedule(){
if(proclist->cnt<2)return;
Hproc p;
while(True){
p=proclist->procs+proclist->cur;
p->status=PST_READY;
proclist->cur++;
if(proclist->cur>=proclist->cnt)proclist->cur=0;
p=proclist->procs+proclist->cur;
if(p->status==PST_READY){
sti();
p->status=PST_ACTIVE;
ljmp(0,p->tsss);
break;
}
}
}
void delete_proc(Hproc p){
cli();
memmove(p,p+1,proclist->cnt-proclist->cur+1);
proclist->cnt--;
sti();
}
void exit(){
sti();
write_pipe(&corepipe,CORE_EXIT_PROC);
write_pipe(&corepipe,current_proc());
while(1);
}
C
1
https://gitee.com/xthoa/u-fexos1.git
git@gitee.com:xthoa/u-fexos1.git
xthoa
u-fexos1
uFexos1
master

搜索帮助