Linux0.11使用串口进行输入输出
在使用qemu时我们将Linux0.11修改为使用串口作为标准输入输出,从而在文本模式下进行学习调试,补丁如下
diff --git a/Makefile b/Makefile index 3ca10f3..d418782 100644 --- a/Makefile +++ b/Makefile @@ -80,8 +80,10 @@ clean: $(Q)rm -f kernel.elf boot/*.o typescript* info bochsout.txt $(Q)for i in init mm fs kernel lib boot; do (cd $$i; make $(S) clean); done -#QEMU_OPS:= -nographic -serial mon:stdio -m 64M -boot a -QEMU_OPS:= -m 64M -boot a +run: qemu + +QEMU_OPS:= -nographic -serial mon:stdio -m 64M -boot a +#QEMU_OPS:= -m 64M -boot a qemu: qemu-system-i386 ${QEMU_OPS} -fda Image -hda ./rootfs/hdc-0.11.img diff --git a/init/main.c b/init/main.c index cd0b564..ce6b355 100644 --- a/init/main.c +++ b/init/main.c @@ -264,7 +264,7 @@ void init(void) int pid,i; setup((void *) &drive_info); - (void) open("/dev/tty0",O_RDWR,0); + (void) open("/dev/tty1",O_RDWR,0); (void) dup(0); (void) dup(0); printf("init current pid is %d\n", getpid()); @@ -295,7 +295,7 @@ void init(void) printf("while1 fork current pid is %d\n", getpid()); close(0);close(1);close(2); setsid(); - (void) open("/dev/tty0",O_RDWR,0); + (void) open("/dev/tty1",O_RDWR,0); (void) dup(0); (void) dup(0); _exit(execve("/bin/sh",argv,envp)); diff --git a/kernel/chr_drv/kb.S b/kernel/chr_drv/kb.S index ffd28cf..ec476b3 100644 --- a/kernel/chr_drv/kb.S +++ b/kernel/chr_drv/kb.S @@ -65,7 +65,7 @@ e0_e1: inb $0x61,%al outb %al,$0x61 movb $0x20,%al outb %al,$0x20 - pushl $0 + pushl $1 call do_tty_interrupt addl $4,%esp pop %es diff --git a/kernel/chr_drv/tty_io.c b/kernel/chr_drv/tty_io.c index ed14fa8..6d3a927 100644 --- a/kernel/chr_drv/tty_io.c +++ b/kernel/chr_drv/tty_io.c @@ -66,7 +66,7 @@ struct tty_struct tty_table[] = { {0, /* no translation */ 0, /* no translation */ B2400 | CS8, - 0, + ECHO, 0, INIT_C_CC}, 0, @@ -79,7 +79,7 @@ struct tty_struct tty_table[] = { {0, /* no translation */ 0, /* no translation */ B2400 | CS8, - 0, + ECHO, 0, INIT_C_CC}, 0, diff --git a/kernel/printk.c b/kernel/printk.c index fe84b2b..6e3e65b 100644 --- a/kernel/printk.c +++ b/kernel/printk.c @@ -45,7 +45,7 @@ int printk(const char *fmt, ...) "pop %%fs\n\t" "pushl %0\n\t" "pushl $buf\n\t" - "pushl $0\n\t" + "pushl $1\n\t" "call tty_write\n\t" "addl $8,%%esp\n\t" "popl %0\n\t"
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律