QEMUでRISC-Vベアメタルプログラミング(シリアル通信編)
#QEMU #RISC-V #書きかけ
QEMUからシアルポートへ出力する実験
QEMUのシリアルポートから入力データを受け取る実験
各種初期化処理
実機でシリアル通信する場合は、割り込み設定・ボーレート設定・FIFO設定などを正しく行う必要があるが、QEMU上の仮想シリアル通信を行う場合はこの辺の処理は飛ばしても大丈夫そう。必要になったら以下を見てがんばろう。
https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/uart.c#L53
UART用のレジスタのアドレス
info mtree でUARTのレジスタアドレスを確認できる。
https://gyazo.com/2e31e5db210aeadf36a116f4fadf11e7
0x10000000 ベースアドレス
0 RHR
receive holding register (for input bytes)
0 THR
transmit holding register (for output bytes)
1 IER
interrupt enable register(0をセットすれば割り込みは発生しない)
2 FCR
FIFO control register(2をセット→FIFO enable、8をセット→FIFOをクリア)
2 ISR
interrupt status register
3 LCR
line control register
5 LSR
line status register
LSR_RX_READY (1<<0) input is waiting to be read from RHR
LSR_TX_IDLE (1<<5) THR can cccept another character to send
参考
sv6-riscv/kernel/uart.c
https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/uart.c
Techinical data on 16550
http://byterunner.com/16550.html
シリアルチップ(8250,16650A)制御テクニック
http://hp.vector.co.jp/authors/VA000981/dos-tech/8250.html
The 16550 UART
https://www.slideshare.net/gurls_on_mars/uart-16550
作って分かる!x86_64機械語入門 / 第3章 シリアルドライバを作る
http://yuma.ohgami.jp/Introduction-to-x86_64-Machine-Language/03_serial.html
メモ
qemu-kvm -m 1024 -smp 2 -drive file=../vms/fedora20.img,if=virtio -nographic -serial mon:stdio
-machine virt -bios none -kernel $K/kernel -m 128M -smp $(CPUS) -nographic -drive file=fs.img,if=none,format=raw,id=x0 -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0