diff --git a/kernel/fork.c b/kernel/fork.c index e9a285a..0b213f0 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -74,11 +74,19 @@ static int fork_mem_cpy(u32 ppid, u32 pid) // 复制代码,代码是共享的,直接将物理地址挂载在子进程的页表上 for (addr_lin = p_proc_current->task.memmap.text_lin_base; addr_lin < p_proc_current->task.memmap.text_lin_limit; addr_lin += num_4K) { - lin_mapping_phy(addr_lin, // 线性地址 - get_page_phy_addr(ppid, addr_lin), // 物理地址,为MAX_UNSIGNED_INT时,由该函数自动分配物理内存 - pid, // 要挂载的进程的pid,子进程的pid - PG_P | PG_USU | PG_RWW, // 页目录属性,一般都为可读写 - PG_P | PG_USU | PG_RWR); // 页表属性,代码是只读的 + // lin_mapping_phy(addr_lin, // 线性地址 + // get_page_phy_addr(ppid, addr_lin), // 物理地址,为MAX_UNSIGNED_INT时,由该函数自动分配物理内存 + // pid, // 要挂载的进程的pid,子进程的pid + // PG_P | PG_USU | PG_RWW, // 页目录属性,一般都为可读写 + // PG_P | PG_USU | PG_RWR); // 页表属性,代码是只读的 + lin_mapping_phy(SharePageBase, 0, ppid, PG_P | PG_USU | PG_RWW, 0); // 使用前必须清除这个物理页映射 + lin_mapping_phy(SharePageBase, MAX_UNSIGNED_INT, ppid, PG_P | PG_USU | PG_RWW, PG_P | PG_USU | PG_RWW); // 利用父进程的共享页申请物理页 + memcpy((void *)SharePageBase, (void *)(addr_lin & 0xFFFFF000), num_4K); // 将数据复制到物理页上,注意这个地方是强制一页一页复制的 + lin_mapping_phy(addr_lin, // 线性地址 + get_page_phy_addr(ppid, SharePageBase), // 物理地址,获取共享页的物理地址,填进子进程页表 + pid, // 要挂载的进程的pid,子进程的pid + PG_P | PG_USU | PG_RWW, // 页目录属性,一般都为可读写 + PG_P | PG_USU | PG_RWW); // 页表属性,数据是可读写的 } // 复制数据,数据不共享,子进程需要申请物理地址,并复制过来 for (addr_lin = p_proc_current->task.memmap.data_lin_base; addr_lin < p_proc_current->task.memmap.data_lin_limit; addr_lin += num_4K) diff --git a/kernel/serialport.c b/kernel/serialport.c index 6773d36..5a3d39f 100644 --- a/kernel/serialport.c +++ b/kernel/serialport.c @@ -21,7 +21,6 @@ void serial_handler(int irq) { void serial_tty_init_i(NTTY* tty) { serial_buf* sp = (serial_buf*)tty->input_buf; sp->buf = (void*)K_PHY2LIN(do_kmalloc(SERIAL_BUF_SIZE)); - kprintf("%p", sp->buf); sp->head = sp->tail = sp->readable = sp->len = 0; outb(PORT + 1, 0x01); put_irq_handler(RS232_IRQ, serial_handler); diff --git a/kernel/tty.c b/kernel/tty.c index 05ab75d..2708e07 100644 --- a/kernel/tty.c +++ b/kernel/tty.c @@ -52,13 +52,14 @@ void init_tty_main() tty = (NTTY*)K_PHY2LIN(do_kmalloc(sizeof(NTTY))); tty->driver_type = 2; tty->input_buf = (serial_buf*)K_PHY2LIN(do_kmalloc(sizeof(serial_buf))); - kprintf("tty: %p, outbuf: %p\n", tty, tty->input_buf); + // kprintf("tty: %p, outbuf: %p\n", tty, tty->input_buf); tty->output_buf = NULL; serial_tty_init_i(tty); serial_tty_init_o(tty); ntty_table[2] = tty; cur_ntty = ntty_table[0]; tty_ok = 1; + kprintf("TTY initialized\n"); } @@ -96,11 +97,18 @@ void tty_write(NTTY *tty, char *buf, int len) } return; } - while (--len >= 0) - { - vga_tty_write(tty, *buf++); + else if (tty->driver_type == 1) { + while (--len >= 0) + { + vga_tty_write(tty, *buf++); + } + if (cur_ntty == tty) vga_tty_flush(tty); + } + else if (tty->driver_type == 2) { + while(--len >= 0) { + serial_tty_write(tty, *buf++); + } } - if (cur_ntty == tty) vga_tty_flush(tty); } /***************************************************************************** diff --git a/kernel/vga.c b/kernel/vga.c index 9d17493..fe8452b 100644 --- a/kernel/vga.c +++ b/kernel/vga.c @@ -119,7 +119,6 @@ static inline void vga_flush_blankline(int line_no) /***************************************************************************** * tty - vga driver *****************************************************************************/ -static u16 pagebuf[3][SCR_BUFSIZE]; void vga_tty_init(NTTY *tty) { diff --git a/user/shell_0.c b/user/shell_0.c index 5691b43..2f66383 100644 --- a/user/shell_0.c +++ b/user/shell_0.c @@ -9,9 +9,9 @@ int main(int arg, char *argv[]) { - int stdin = open("dev_tty0", O_RDWR); - int stdout = open("dev_tty0", O_RDWR); - int stderr = open("dev_tty0", O_RDWR); + int stdin = open("dev_tty2", O_RDWR); + int stdout = open("dev_tty2", O_RDWR); + int stderr = open("dev_tty2", O_RDWR); char buf[1024]; int pid;