From: acevest Date: Thu, 12 Oct 2023 08:52:26 +0000 (+0800) Subject: 添加serial_monitor调试程序 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=f6c931b791d04db75c689c436c0dd5b79ac6e8ac;p=kernel.git 添加serial_monitor调试程序 --- diff --git a/qemu.sh b/qemu.sh index 507dba6..1d46b76 100755 --- a/qemu.sh +++ b/qemu.sh @@ -1,14 +1,31 @@ +#!/bin/bash +# +# 检查serial_monitor进程是否在运行 +process_name="serial_monitor" +if ! pgrep -x "$process_name" > /dev/null +then + echo "process $process_name is not running." + exit 1 +fi + +echo "process $process_name is running." + + qemu-system-i386 \ -boot d \ - -serial mon:stdio \ + -serial tcp::6666,server,nowait \ -drive file=HDa.IMG,format=raw,index=0,media=disk \ -drive file=kernel.iso,index=1,media=cdrom \ -drive file=HDb.IMG,format=raw,index=2,media=disk \ -name kernel \ - -s -S \ -device ich9-ahci,id=ahci \ + -vga std \ + -display cocoa \ + -s -S \ & + #-serial mon:stdio \ + #-serial tcp::12345,server,nowait \ # -serial tcp::8888,server,nowait \ # -device ich9-ahci,id=ahci \ # -machine accel=tcg \ diff --git a/scripts/iso.grub.cfg b/scripts/iso.grub.cfg index 8d13887..1950e45 100644 --- a/scripts/iso.grub.cfg +++ b/scripts/iso.grub.cfg @@ -1,8 +1,15 @@ -set default="0" +#serial --unit=0 --speed=115200 +serial --unit=0 +terminal_input serial +terminal_output serial + -set timeout=1 +set default="0" +set timeout=0 menuentry 'Kernel' --class os { #insmod ext2 + #set gfxpayload=1024x768x32 + #insmod all_video multiboot2 /boot/Kernel root=hda0 delay=2 boot } diff --git a/scripts/serial_monitor/go.mod b/scripts/serial_monitor/go.mod new file mode 100644 index 0000000..b6dbab7 --- /dev/null +++ b/scripts/serial_monitor/go.mod @@ -0,0 +1,3 @@ +module serial_monitor + +go 1.18 diff --git a/scripts/serial_monitor/main.go b/scripts/serial_monitor/main.go new file mode 100644 index 0000000..aa762ef --- /dev/null +++ b/scripts/serial_monitor/main.go @@ -0,0 +1,61 @@ +package main + +import ( + "flag" + "fmt" + "io" + "log" + "net" + "os" + "time" +) + +var addr string + +func main() { + flag.StringVar(&addr, "a", ":6666", "") + flag.Parse() + + for { + log.Printf("addr %v", addr) + monitor() + } +} + +func monitor() { + var conn net.Conn + var err error + + start := time.Now() + + // 不断尝试连接串行控制台 + for { + conn, err = net.Dial("tcp", addr) + if err == nil { + log.Printf("\nconnected...\n") + break + } else { + fmt.Printf("\r\033[Kwait %d seconds", int(time.Now().Sub(start).Seconds())) + time.Sleep(500 * time.Millisecond) + } + } + + // // 创建一个 WaitGroup 以便在两个协程完成时结束程序 + // var wg sync.WaitGroup + // wg.Add(2) + + // 将串行控制台的输出发送到屏幕 + go func() { + _, _ = io.Copy(os.Stdout, conn) + // wg.Done() + }() + + // 将用户输入发送到串行控制台 + go func() { + _, _ = io.Copy(conn, os.Stdin) + // wg.Done() + }() + + // // 等待两个协程完成 + // wg.Wait() +} diff --git a/std.qemu.sh b/std.qemu.sh new file mode 100755 index 0000000..7d201e9 --- /dev/null +++ b/std.qemu.sh @@ -0,0 +1,52 @@ +qemu-system-i386 \ + -boot d \ + -serial mon:stdio \ + -drive file=HDa.IMG,format=raw,index=0,media=disk \ + -drive file=kernel.iso,index=1,media=cdrom \ + -drive file=HDb.IMG,format=raw,index=2,media=disk \ + -name kernel \ + -device ich9-ahci,id=ahci \ + -vga std \ + -display cocoa \ + -s -S \ + & + + #-serial mon:stdio \ + #-serial tcp::12345,server,nowait \ +# -serial tcp::8888,server,nowait \ +# -device ich9-ahci,id=ahci \ +# -machine accel=tcg \ +# -serial stdio \ +#qemu-system-x86_64 -boot d -s -S -drive file=HD.IMG,format=raw,index=0,media=disk -drive file=kernel.iso,index=1,media=cdrom & +# + +# i386-elf-gdb KERNEL.ELF -x gdbscript + +pid=$! +echo "pid is ${pid}" + +i386-elf-gdb KERNEL.ELF -x gdbscript; kill -9 $pid + +echo "kill pid ${pid}" + +#x86_64-elf-gdb -x gdbscript; kill -9 $pid + + +# qemu-system-i386 -drive file=HD.IMG,format=raw,index=0,media=disk -cdrom kernel.iso + + +# -cdrom kernel.iso +# -drive file=kernel.iso,index=2,media=cdrom + +# connect a CDROM to the slave of ide0 +# -drive if=ide,index=1,media=cdrom + +# -hda,-hdb,-hdc,-hdd +# -drive file=file,index=0,media=disk +# -drive file=file,index=1,media=disk +# -drive file=file,index=2,media=disk +# -drive file=file,index=3,media=disk + + +# -s shorthand for -gdb tcp::1234 +# -S freeze CPU at startup (use 'c' to start execution)