提交 cec4e12d 编写于 作者: Y Yanyan Jiang

pte api finalize

上级 fd8024aa
......@@ -59,7 +59,8 @@ typedef struct _RegSet _RegSet;
// A protected address space with user memory @area
// and arch-dependent @ptr
typedef struct _Protect {
_Area area;
size_t pgsize;
_Area area;
void *ptr;
} _Protect;
......@@ -72,7 +73,7 @@ void _halt(int code);
// ======================= I/O Extension (IOE) =======================
int _ioe_init();
_Device *_device(int n);
_Device *_device(int n); // get the device #n
// ================== Asynchronous Extension (ASYE) ==================
......@@ -84,12 +85,11 @@ void _intr_write(int enable);
// =================== Protection Extension (PTE) ====================
int _pte_init(void *(*pgalloc)(size_t npages), void (*pgfree)(void *));
int _prot_create(_Protect *p);
void _prot_destroy(_Protect *p);
void _prot_switch(_Protect *p);
int _pte_init(void *(*pgalloc)(size_t size), void (*pgfree)(void *));
int _protect(_Protect *p);
void _unprotect(_Protect *p);
void _switch(_Protect *p);
int _map(_Protect *p, void *va, void *pa, int prot);
int _unmap(_Protect *p, void *va);
_RegSet *_umake(_Protect *p, _Area ustack, _Area kstack,
void (*entry)(void *), void *args);
......
......@@ -8,5 +8,4 @@ void lapic_bootap(int cpu, uint32_t address);
void ioapic_enable(int irq, int cpu);
void smp_init();
#endif
#endif
\ No newline at end of file
......@@ -212,16 +212,20 @@ int _asye_init(_RegSet*(*handler)(_Event, _RegSet*)) {
}
_RegSet *_make(_Area stack, void (*entry)(void *), void *arg) {
_RegSet *regs = (_RegSet*)stack.start;
_RegSet *regs = (_RegSet *)stack.start;
regs->eax = regs->ebx = regs->ecx = regs->edx = 0;
regs->esi = regs->edi = regs->ebp = regs->esp3 = 0;
regs->ss0 = 0; // only used for ring3 procs
regs->esp0 = (uint32_t)stack.end;
regs->cs = KSEL(SEG_KCODE);
regs->ds = regs->es = regs->ss = KSEL(SEG_KDATA);
regs->eip = (uint32_t)entry;
regs->eflags = 0;
regs->esp0 -= 4;
*((void**)(regs->esp0)) = arg; // argument
regs->esp0 -= 4;
*((void**)(regs->esp0)) = NULL; // return address
uint32_t **esp = (uint32_t **)&regs->esp0;
*(*esp -= 4) = (uint32_t)arg; // argument
*(*esp -= 4) = 0; // return address
return regs;
}
......
......@@ -47,8 +47,9 @@ int _pte_init(void* (*palloc)(size_t), void (*pfree)(void*)) {
return 0;
}
int _prot_create(_Protect *p) {
PDE *updir = (PDE*)(palloc_f(1));
int _protect(_Protect *p) {
PDE *updir = (PDE*)(palloc_f(PGSIZE));
p->pgsize = PGSIZE;
p->ptr = updir;
// map kernel space
for (int i = 0; i < 1024; i ++)
......@@ -62,8 +63,8 @@ int _prot_create(_Protect *p) {
return 0;
}
void _release(_Protect *p) {
// free all spaces
void _unprotect(_Protect *p) {
// DFS pages and call release
}
void _switch(_Protect *p) {
......@@ -76,7 +77,7 @@ int _map(_Protect *p, void *va, void *pa, int prot) {
uint32_t wflag = 0; // TODO: this should be not accessible
if (prot & _PROT_WRITE) wflag = PTE_W;
if (!(*pde & PTE_P)) {
*pde = PTE_P | wflag | PTE_U | (uint32_t)(palloc_f(1));
*pde = PTE_P | wflag | PTE_U | (uint32_t)(palloc_f(PGSIZE));
}
PTE *pte = &((PTE*)PTE_ADDR(*pde))[PTX(va)];
if (!(*pte & PTE_P)) {
......@@ -85,9 +86,6 @@ int _map(_Protect *p, void *va, void *pa, int prot) {
return 0;
}
void _unmap(_Protect *p, void *va) {
}
_RegSet *_umake(_Protect *p, _Area ustack, _Area kstack, void (*entry)(void *), void *args) {
_RegSet *regs = (_RegSet*)kstack.start;
regs->cs = USEL(SEG_UCODE);
......
#include <x86.h>
#include <am-x86.h>
#include <am.h>
#include <am-x86.h>
int main();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册