From 9dbe6fb9393e145d18187446d60992f452d3d593 Mon Sep 17 00:00:00 2001 From: kunalgulati29 Date: Sat, 24 Aug 2019 00:00:00 +0000 Subject: [PATCH] Serial hello world on COM1 --- Makefile | 16 +++++++++++++++- bios_hello_world_serial.S | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 bios_hello_world_serial.S diff --git a/Makefile b/Makefile index 7107ab6..69ae0d0 100644 --- a/Makefile +++ b/Makefile @@ -13,11 +13,12 @@ OUT_EXT ?= .img QEMU ?= qemu-system-i386 RUN ?= bios_hello_world RUN_ARGS ?= -soundhw pcspk +RUN_SERIAL ?= bios_hello_world_serial TMP_EXT ?= .tmp OUTS := $(sort $(foreach IN_EXT,$(NASM_EXT) $(GAS_EXT),$(patsubst %$(IN_EXT),%$(OUT_EXT),$(wildcard *$(IN_EXT))))) RUN_FILE := $(RUN)$(OUT_EXT) - +RUN_FILE_SERIAL := $(RUN_SERIAL)$(OUT_EXT) .PRECIOUS: %$(OBJ_EXT) .PHONY: all clean doc run @@ -58,6 +59,19 @@ bochs: $(RUN_FILE) 'display_library: sdl2' \ 'megs: 128' +bochs_serial: $(RUN_FILE_SERIAL) + # Supposes size is already multiples of 512. + # We force that with our linker script, + # and `grub-mkrescue` also seems to respect it as well. + CYLINDERS="$$(($$(stat -c '%s' '$(RUN_FILE_SERIAL)') / 512))" && \ + bochs -qf /dev/null \ + 'ata0-master: type=disk, path="$(RUN_FILE_SERIAL)", mode=flat, cylinders='"$$CYLINDERS"', heads=1, spt=1' \ + 'boot: disk' \ + 'display_library: x' \ + 'megs: 128'\ + 'com1: enabled=1, mode=file, dev=serial.out' + + BIG_IMG_DIR := big_img$(TMP_EXT) BOOT_DIR := $(BIG_IMG_DIR)/boot GRUB_DIR := $(BOOT_DIR)/grub diff --git a/bios_hello_world_serial.S b/bios_hello_world_serial.S new file mode 100644 index 0000000..514f206 --- /dev/null +++ b/bios_hello_world_serial.S @@ -0,0 +1,19 @@ +#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 +loop: + lodsb + mov $0x01, %ah//Send value + or %al, %al + jz halt + int $0x14 + jmp loop +halt: + hlt +msg: +.asciz "hello World!\n"