From 52a22c4b18195dd777e1f0b9d22e2e6decca0bbe Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Sat, 24 Aug 2019 00:00:01 +0000 Subject: [PATCH] serial: make awesome --- .gitignore | 1 + Makefile | 1 + README.adoc | 22 ++++++++++++++++++++++ bios_hello_world_serial.S | 19 +++++++++++-------- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index e10ebfd..8ec8d44 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,6 @@ *.o *.so *.tmp +*.tmp.* /README.html tmp.S diff --git a/Makefile b/Makefile index 69ae0d0..1ec48c3 100644 --- a/Makefile +++ b/Makefile @@ -55,6 +55,7 @@ bochs: $(RUN_FILE) CYLINDERS="$$(($$(stat -c '%s' '$(RUN_FILE)') / 512))" && \ bochs -qf /dev/null \ 'ata0-master: type=disk, path="$(RUN_FILE)", mode=flat, cylinders='"$$CYLINDERS"', heads=1, spt=1' \ + 'com1: enabled=1, mode=file, dev=$(RUN).tmp.serial' \ 'boot: disk' \ 'display_library: sdl2' \ 'megs: 128' diff --git a/README.adoc b/README.adoc index 7e29ec3..e7a2e90 100644 --- a/README.adoc +++ b/README.adoc @@ -68,6 +68,11 @@ Then on the terminal start the simulation with: c .... +To quit Bochs either: + +* press the poweroff button inside its GUI +* Ctrl + C on terminal and the type `quit` and hit enter + TODO: automate this step. Bibliography: https://stackoverflow.com/questions/6142925/how-can-i-use-bochs-to-run-assembly-code/32871939#32871939 @@ -2164,6 +2169,23 @@ While it is possible to learn those topics as you go along, and it is almost cer === Serial UART +TODO: get working on QEMU, working on Bochs: + +.... +./run bios_hello_world_serial bochs +cat bios_hello_world_serial.tmp.serial +.... + +File content: + +.... +hello world +.... + +Source: link:bios_hello_world_serial.S[] + +Bibliography: + * https://stackoverflow.com/questions/22571379/intel-galileo-bare-metal-uart * https://stackoverflow.com/questions/27594297/how-to-print-a-string-to-the-terminal-in-x86-64-assembly-nasm-without-syscall diff --git a/bios_hello_world_serial.S b/bios_hello_world_serial.S index 514f206..0764851 100644 --- a/bios_hello_world_serial.S +++ b/bios_hello_world_serial.S @@ -1,14 +1,17 @@ #include "common.h" BEGIN - DBG - mov $0x00, %ah// Initialize COM port - mov $0xe3, %al// Initialization value - mov $0x00, %dx// Port number - int $0x14 - mov $msg, %si + /* Initialize COM port. */ + mov $0x00, %ah + /* Initialization value. */ + mov $0xe3, %al + /* Port number. */ + mov $0x00, %dx + int $0x14 + mov $msg, %si loop: lodsb - mov $0x01, %ah//Send value + /* Send value */ + mov $0x01, %ah or %al, %al jz halt int $0x14 @@ -16,4 +19,4 @@ loop: halt: hlt msg: -.asciz "hello World!\n" + .asciz "hello world\n"