# Init Page Directory
movl %ebx,%edi
movl $init_pgt-KRNLADDR,%eax
- addl $7,%eax
+ addl $3,%eax
movl $BOOT_INIT_PAGETBL_CNT,%ecx
1:
stosl
movl %eax,%edi
movl $init_pgt-KRNLADDR,%eax
- addl $7,%eax
+ addl $3,%eax
movl $BOOT_INIT_PAGETBL_CNT,%ecx
2:
stosl
movl $init_pgt-KRNLADDR,%ebx
movl %ebx,%edi
movl $(BOOT_INIT_PAGETBL_CNT*1024),%ecx
- movl $0x07,%eax
+ movl $3,%eax
cld
3:
stosl
#define PAGE_WR 0x2
#define PAGE_US 0x4
-#define PAGE_SHIFT (12)
-#define PAGE_SIZE (1UL << PAGE_SHIFT)
-#define PAGE_MASK (~((1UL << PAGE_SHIFT)-1))
-#define PAGE_OFFSET (0xC0000000)
+#define PAGE_SHIFT (12)
+#define PAGE_SIZE (1UL << PAGE_SHIFT)
+#define PAGE_MASK (~((1UL << PAGE_SHIFT)-1))
+#define PAGE_OFFSET (0xC0000000)
#define PAGE_PDE_CNT 1024
#define PAGE_PTE_CNT 1024
jmp ret_from_bad_syscnr
#endif
-#if 0
-syscall_entry:
- /* 此时%esp存的是current的地址(¤t) */
- movl (%esp),%esp /* 获得current的值 */
- addl $TASK_SIZE, %esp /* 指向PCB的顶部 */
-
- pushl %ds /* %ss */
- pushl %ebp /* %esp */
- pushfl /* %eflags */
- pushl $SELECTOR_USER_CS /* %cs */
- pushl %gs:(,%ebp) /* %eip */
- pushl %eax /* sysc_nr */
- SAVE_REGS
-
- pushl %eax
- movw %ss,%ax
- movw %ax, %ds
- movw %ax, %es
- movw %ax, %gs
- movw %ax, %fs
- popl %eax
-
- call *sysc_handler_table(,%eax,4)
-
- movl %eax, 0x18(%esp) /* return value */
-
- RESTORE_REGS
-
- movl 0x04(%esp), %edx /* sysexit 参数 %eip */
- movl 0x10(%esp), %ecx /* sysexit 参数 %esp */
- sti /* sysenter会自动清除IF.貌似sysexit不会自动置位 */
- sysexit
-#endif
-
-#if 0
-.global sysc_handler_table
-.extern sysc_write
-.extern sysc_read_kbd
-.extern sysc_reboot
-.extern sysc_fork
-sysc_handler_table:
-.long sysc_write
-.long sysc_read_kbd
-.long sysc_reboot
-.long sysc_fork
-#endif
+# this routine should be load align by PAGE_SIZE
+# this page is shared by the kernel and userspace
+# the reason why i use this method is because of that the user program
+# no need to pay attention on the return address
+.section .sysexit
+.align 0x1000
+.global sysexit
+sysexit:
+ nop
+ nop
+ ret
pde_t __initdata init_pgd[PDECNT_PER_PAGE] __attribute__((__aligned__(PAGE_SIZE)));
pte_t __initdata init_pgt[PTECNT_PER_PAGE*BOOT_INIT_PAGETBL_CNT] __attribute__((__aligned__(PAGE_SIZE)));
+extern void sysexit();
+
+void set_page_shared(void *x)
+{
+ unsigned long addr = (unsigned long) x;
+ addr = PAGE_ALIGN(addr);
+ unsigned int npd = get_npd(addr);
+ init_pgd[npd] |= PAGE_US;
+
+ pte_t *pte = pa2va(init_pgd[npd] & PAGE_MASK);
+ pte[get_npt(addr)] |= PAGE_US;
+}
+
void init_paging()
{
unsigned int i;
memset((void *)pgtb_addr, 0, PAGE_SIZE);
- init_pgd[get_npd(page_addr)] = (pde_t)(pgtb_addr | PAGE_P | PAGE_WR | PAGE_US);
+ init_pgd[get_npd(page_addr)] = (pde_t)(pgtb_addr | PAGE_P | PAGE_WR);
}
pte = ((pte_t *) pa2va(pgtb_addr)) + ti;
- *pte = (pte_t) (page_addr | PAGE_P | PAGE_WR | PAGE_US);
+ *pte = (pte_t) (page_addr | PAGE_P | PAGE_WR);
}
init_pgd[i] = init_pgd[i-delta];
}
+ // paging for user space
+ set_page_shared(sysexit);
+
LOAD_CR3(init_pgd);
}
phys_addr = . - kernel_virtual_addr_start;
*(.multiboot_header)
*(.text)
+ *(.sysexit)
}
etext = .;
.data : AT(phys_addr) ALIGN(0x1000)
setup_irqs();
-
while(1); // TODO MODIFY CODE BELOW
setup_tasks();