]> Zhao Yanbai Git Server - kernel.git/commitdiff
添加serial_monitor调试程序
authoracevest <zhaoyanbai@126.com>
Thu, 12 Oct 2023 08:52:26 +0000 (16:52 +0800)
committeracevest <zhaoyanbai@126.com>
Thu, 12 Oct 2023 08:53:00 +0000 (16:53 +0800)
qemu.sh
scripts/iso.grub.cfg
scripts/serial_monitor/go.mod [new file with mode: 0644]
scripts/serial_monitor/main.go [new file with mode: 0644]
std.qemu.sh [new file with mode: 0755]

diff --git a/qemu.sh b/qemu.sh
index 507dba6cfc307cf0201d023ced870f832a4deea2..1d46b7603c15279a1f47e5730e594066fa84c997 100755 (executable)
--- 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 \
index 8d138875fd311f9716beec74163982ca7a671c64..1950e45dc9dd74f8d24309377d958d15a17ad6a4 100644 (file)
@@ -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 (file)
index 0000000..b6dbab7
--- /dev/null
@@ -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 (file)
index 0000000..aa762ef
--- /dev/null
@@ -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 (executable)
index 0000000..7d201e9
--- /dev/null
@@ -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)