1 Star 1 Fork 0

Xthoa / uFexos1

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
entry.c 2.43 KB
一键复制 编辑 原始数据 按行查看 历史
Xthoa 提交于 2021-01-26 09:12 . 'v7.a'
#include "macro.h"
#include "asm.h"
#include "types.h"
#include "bios.h"
Allocator* allocr;
int keystat;
//0 0 0 !nums alt ctrl caps shift
void appfn();
Pipe corepipe;
int corebuf[12];
void init_global(){
clock=0;
keystat=0;
pipe_init(&corepipe,corebuf,12);
}
__attribute__((section(".entry")))
void entry(){
init_global();
init_stdout();
init_screen();
init_mem();
init_vmem();
init_kbd();
init_idt();
init_apic();
init_gdt();
init_proc();
init_fs();
init_ring3env();
Hproc sys=init_sysproc();
sys->msg=&corepipe;
Hproc app=create_process("app");
init_process(app,(int)appfn,1);
ready_process(app);
cputs("Welcome to uFexos1 v6\n",GREY);
init_pit();
enable_pic(0xfff8);
Hproc focus=app;
while(1){
int c;
if(pipe_size(&stdout)){
c=read_pipe(&stdout);
kputcharc(c);
}
if(pipe_size(&kbdp)){
c=seekbd();
if(c==k_caps)keystat^=2;
elif(c==k_shift_l or c==k_shift_r)keystat|=1;
elif(c==k_shift_ld or c==k_shift_rd)keystat&=-2;
elif(c==k_ctrl_l or c==k_ctrl_r)keystat|=4;
elif(c==k_ctrl_ld or c==k_ctrl_rd)keystat&=-5;
elif(c==k_alt_l or c==k_alt_r)keystat|=8;
elif(c==k_alt_ld or c==k_alt_rd)keystat&=-9;
if(keystat&4)c+=0x100;//ctrl
if(keystat&8)c+=0x200;//alt
write_pipe(focus->msg,c);
}
if(pipe_size(&corepipe)){
c=read_pipe(&corepipe);
if(c==CORE_EXIT_PROC){
Hproc p=read_pipe_wait(&corepipe);
//cprintf(GREY,"Core: %x %x\n",c,p);
delete_proc(p);
}
}
}
}
void init_ring3env(){
set_pt_attr(PDE,512,PAGE_USER);
set_page_attr(PDE,lin2pten(enter_ring),PAGE_USER);
//unset_page_attr(PDE,lin2pten(enter_ring),PAGE_RW);
}
void appfn(){
exec3(1);
}
void exec3(int i){
Hproc self=current_proc();
int esp0=self->tss.esp;
set_page_attr(PDE,lin2pten(esp0-4),PAGE_USER);
BlockDesc* b=get_block_desc(i);
int fdpgs=(b->filelen+0xfff)>>12;
int* pos=malloc_load_file(i);
set_pages_attr(PDE,lin2pten(pos),fdpgs,PAGE_USER);
int* esp=mmalloc_page(pos[1])+PAGE_SIZE-4;
set_pages_attr(PDE,lin2pten(esp),pos[1],PAGE_USER);
int pde=mmalloc_page(3);
int pte1=pde+PAGE_SIZE*2;
memcpy(pde,PDE,PAGE_SIZE*2);
memset(pte1,0,1024);
int phy=get_page(PDE,lin2pten(pde));
((int*)pde)[1]=phy+PAGE_SIZE*2+PDE_TAB+PAGE_USER;
int p=((int*)pde)[512];
p=(p&0xfff)+phy+PAGE_SIZE;
((int*)pde)[512]=((int*)pde)[0]=p;
copy_page(pde,1,1,PDE,lin2pten(pos));
esp[0]=0x00401010;
self->tss.cr3=phy;
self->tss.esp=esp;
enter_ring(3);
}
void init_pit(){
out8(0x43,0x34);
out8(0x40,0xa9);
out8(0x40,0x04);
}
C
1
https://gitee.com/xthoa/u-fexos1.git
git@gitee.com:xthoa/u-fexos1.git
xthoa
u-fexos1
uFexos1
master

搜索帮助