Add: working serial port output driver

This commit is contained in:
xamidev
2024-05-22 10:33:48 +02:00
parent aca525d3ce
commit 87c1a97d47
9 changed files with 46 additions and 350 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
*.o *.o
bochslog.txt

View File

@@ -1,275 +0,0 @@
00000000000i[ ] Bochs x86 Emulator 2.7
00000000000i[ ] Built from SVN snapshot on August 1, 2021
00000000000i[ ] Timestamp: Sun Aug 1 10:07:00 CEST 2021
00000000000i[ ] System configuration
00000000000i[ ] processors: 1 (cores=1, HT threads=1)
00000000000i[ ] A20 line support: yes
00000000000i[ ] IPS is set to 1000000
00000000000i[ ] CPU configuration
00000000000i[ ] SMP support: yes, quantum=16
00000000000i[ ] level: 6
00000000000i[ ] APIC support: xapic
00000000000i[ ] FPU support: yes
00000000000i[ ] MMX support: yes
00000000000i[ ] 3dnow! support: yes
00000000000i[ ] SEP support: yes
00000000000i[ ] SIMD support: sse2
00000000000i[ ] XSAVE support: no
00000000000i[ ] AES support: no
00000000000i[ ] SHA support: no
00000000000i[ ] MOVBE support: no
00000000000i[ ] ADX support: no
00000000000i[ ] x86-64 support: yes
00000000000i[ ] 1G paging support: no
00000000000i[ ] MWAIT support: yes
00000000000i[ ] VMX support: 1
00000000000i[ ] SVM support: no
00000000000i[ ] Optimization configuration
00000000000i[ ] RepeatSpeedups support: yes
00000000000i[ ] Fast function calls: yes
00000000000i[ ] Handlers Chaining speedups: no
00000000000i[ ] Devices configuration
00000000000i[ ] PCI support: i440FX i430FX i440BX
00000000000i[ ] Network devices support: NE2000 E1000
00000000000i[ ] Sound support: SB16 ES1370
00000000000i[ ] USB support: UHCI OHCI EHCI xHCI
00000000000i[ ] VGA extension support: vbe cirrus voodoo
00000000000i[IMG ] Disk image modules
00000000000i[IMG ] flat concat sparse dll growing undoable volatile vpc
00000000000i[IMG ] vmware3 vmware4 vbox vvfat
00000000000i[NETCTL] Networking modules
00000000000i[NETCTL] null vde vnet linux socket tuntap slirp
00000000000i[SNDCTL] Sound drivers
00000000000i[SNDCTL] dummy oss file alsa sdl
00000000000i[USBCTL] Pluggable USB devices
00000000000i[USBCTL] mouse tablet keypad keyboard floppy disk cdrom printer
00000000000i[USBCTL] hub
00000000000i[MEM0 ] allocated memory at 0x7fb8f1ddd010. after alignment, vector=0x7fb8f1dde000
00000000000i[MEM0 ] 32.00MB
00000000000i[MEM0 ] mem block size = 0x00020000, blocks=256
00000000000i[MEM0 ] rom at 0xffff0000/65536 ('/usr/share/bochs/BIOS-bochs-legacy')
00000000000i[CPU0 ] WARNING: 3DNow! is not implemented yet !
00000000000i[DEV ] will paste characters every 100 iodev timer ticks
00000000000i[ ] lt_dlhandle is 0x5638a94a38b0
00000000000i[PLUGIN] loaded plugin libbx_soundalsa.so
00000000000i[WAVOUT] ALSA: opened default PCM output device
00000000000i[WAVOUT] changed sample rate to 44101
00000000000i[ ] lt_dlhandle is 0x5638a9c59430
00000000000i[PLUGIN] loaded plugin libbx_pci.so
00000000000i[ ] lt_dlhandle is 0x5638a94a3990
00000000000i[PLUGIN] loaded plugin libbx_pci2isa.so
00000000000i[ ] lt_dlhandle is 0x5638a9421ac0
00000000000i[PLUGIN] loaded plugin libbx_usb_uhci.so
00000000000i[ ] lt_dlhandle is 0x5638a94bdfc0
00000000000i[PLUGIN] loaded plugin libbx_acpi.so
00000000000i[ ] lt_dlhandle is 0x5638a9420ec0
00000000000i[PLUGIN] loaded plugin libbx_hpet.so
00000000000i[ ] lt_dlhandle is 0x5638a9c63be0
00000000000i[PLUGIN] loaded plugin libbx_cmos.so
00000000000i[ ] lt_dlhandle is 0x5638a9c643f0
00000000000i[PLUGIN] loaded plugin libbx_dma.so
00000000000i[ ] lt_dlhandle is 0x5638a9c64d60
00000000000i[PLUGIN] loaded plugin libbx_pic.so
00000000000i[ ] lt_dlhandle is 0x5638a9c65520
00000000000i[PLUGIN] loaded plugin libbx_pit.so
00000000000i[ ] lt_dlhandle is 0x5638a9c65f40
00000000000i[PLUGIN] loaded plugin libbx_vga.so
00000000000i[ ] lt_dlhandle is 0x5638a9c87580
00000000000i[PLUGIN] loaded plugin libbx_floppy.so
00000000000i[ ] lt_dlhandle is 0x5638a9c87dc0
00000000000i[PLUGIN] loaded plugin libbx_ioapic.so
00000000000i[ ] lt_dlhandle is 0x5638a9c885d0
00000000000i[PLUGIN] loaded plugin libbx_keyboard.so
00000000000i[ ] lt_dlhandle is 0x5638a9c88ed0
00000000000i[PLUGIN] loaded plugin libbx_harddrv.so
00000000000i[ ] lt_dlhandle is 0x5638a9c8afa0
00000000000i[PLUGIN] loaded plugin libbx_pci_ide.so
00000000000i[PLUGIN] init_dev of 'pci' plugin device by virtual method
00000000000i[DEV ] i440FX PMC present at device 0, function 0
00000000000i[PLUGIN] init_dev of 'pci2isa' plugin device by virtual method
00000000000i[DEV ] PIIX3 PCI-to-ISA bridge present at device 1, function 0
00000000000i[PLUGIN] init_dev of 'cmos' plugin device by virtual method
00000000000i[CMOS ] Using local time for initial clock
00000000000i[CMOS ] Setting initial clock to: Mon May 20 21:48:15 2024 (time0=1716234495)
00000000000i[PLUGIN] init_dev of 'dma' plugin device by virtual method
00000000000i[DMA ] channel 4 used by cascade
00000000000i[PLUGIN] init_dev of 'pic' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'pit' plugin device by virtual method
00000000000i[PIT ] PIT using realtime synchronisation method
00000000000i[PLUGIN] init_dev of 'vga' plugin device by virtual method
00000000000i[MEM0 ] Register memory access handlers: 0x0000000a0000 - 0x0000000bffff
00000000000i[VGA ] interval=200000, mode=realtime
00000000000i[VGA ] VSYNC using realtime mode
00000000000i[MEM0 ] Register memory access handlers: 0x0000e0000000 - 0x0000e0ffffff
00000000000i[BXVGA ] VBE Bochs Display Extension Enabled
00000000000i[MEM0 ] rom at 0xc0000/38400 ('/usr/share/bochs/VGABIOS-lgpl-latest')
00000000000i[PLUGIN] init_dev of 'floppy' plugin device by virtual method
00000000000i[DMA ] channel 2 used by Floppy Drive
00000000000i[FLOPPY] Using boot sequence cdrom, none, none
00000000000i[FLOPPY] Floppy boot signature check is enabled
00000000000i[PLUGIN] init_dev of 'acpi' plugin device by virtual method
00000000000i[DEV ] ACPI Controller present at device 1, function 3
00000000000i[PLUGIN] init_dev of 'hpet' plugin device by virtual method
00000000000i[HPET ] initializing HPET
00000000000i[MEM0 ] Register memory access handlers: 0x0000fed00000 - 0x0000fed003ff
00000000000i[PLUGIN] init_dev of 'ioapic' plugin device by virtual method
00000000000i[IOAPIC] initializing I/O APIC
00000000000i[MEM0 ] Register memory access handlers: 0x0000fec00000 - 0x0000fec00fff
00000000000i[IOAPIC] IOAPIC enabled (base address = 0xfec00000)
00000000000i[PLUGIN] init_dev of 'keyboard' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'harddrv' plugin device by virtual method
00000000000i[HD ] CD on ata0-0: 'os.iso'
00000000000i[CD1 ] load cdrom with path='os.iso'
00000000000i[CD1 ] Opening image file as a cd.
00000000000i[HD ] Media present in CD-ROM drive
00000000000i[HD ] Capacity is 237 sectors (0.46 MB)
00000000000i[PLUGIN] init_dev of 'pci_ide' plugin device by virtual method
00000000000i[DEV ] PIIX3 PCI IDE controller present at device 1, function 1
00000000000i[PLUGIN] init_dev of 'unmapped' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'speaker' plugin device by virtual method
00000000000i[PCSPK ] Using lowlevel sound support for output
00000000000i[PLUGIN] init_dev of 'iodebug' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'parallel' plugin device by virtual method
00000000000i[PAR ] parallel port 1 at 0x0378 irq 7
00000000000i[PLUGIN] init_dev of 'biosdev' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'serial' plugin device by virtual method
00000000000i[SER ] com1 at 0x03f8 irq 4 (mode: file)
00000000000i[PLUGIN] init_dev of 'extfpuirq' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'gameport' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'usb_uhci' plugin device by virtual method
00000000000i[DEV ] USB UHCI present at device 1, function 2
00000000000i[UHCI ] USB UHCI initialized
00000000000i[PLUGIN] register state of 'pci' plugin device by virtual method
00000000000i[PLUGIN] register state of 'pci2isa' plugin device by virtual method
00000000000i[PLUGIN] register state of 'cmos' plugin device by virtual method
00000000000i[PLUGIN] register state of 'dma' plugin device by virtual method
00000000000i[PLUGIN] register state of 'pic' plugin device by virtual method
00000000000i[PLUGIN] register state of 'pit' plugin device by virtual method
00000000000i[PLUGIN] register state of 'vga' plugin device by virtual method
00000000000i[PLUGIN] register state of 'floppy' plugin device by virtual method
00000000000i[PLUGIN] register state of 'unmapped' plugin device by virtual method
00000000000i[PLUGIN] register state of 'speaker' plugin device by virtual method
00000000000i[PLUGIN] register state of 'iodebug' plugin device by virtual method
00000000000i[PLUGIN] register state of 'parallel' plugin device by virtual method
00000000000i[PLUGIN] register state of 'biosdev' plugin device by virtual method
00000000000i[PLUGIN] register state of 'serial' plugin device by virtual method
00000000000i[PLUGIN] register state of 'extfpuirq' plugin device by virtual method
00000000000i[PLUGIN] register state of 'gameport' plugin device by virtual method
00000000000i[PLUGIN] register state of 'usb_uhci' plugin device by virtual method
00000000000i[PLUGIN] register state of 'acpi' plugin device by virtual method
00000000000i[PLUGIN] register state of 'hpet' plugin device by virtual method
00000000000i[PLUGIN] register state of 'ioapic' plugin device by virtual method
00000000000i[PLUGIN] register state of 'keyboard' plugin device by virtual method
00000000000i[PLUGIN] register state of 'harddrv' plugin device by virtual method
00000000000i[PLUGIN] register state of 'pci_ide' plugin device by virtual method
00000000000i[SYS ] bx_pc_system_c::Reset(HARDWARE) called
00000000000i[CPU0 ] cpu hardware reset
00000000000i[APIC0 ] allocate APIC id=0 (MMIO enabled) to 0x0000fee00000
00000000000i[CPU0 ] CPU[0] is the bootstrap processor
00000000000i[CPU0 ] CPUID[0x00000000]: 00000005 68747541 444d4163 69746e65
00000000000i[CPU0 ] CPUID[0x00000001]: 00000633 00010800 00002028 17cbfbff
00000000000i[CPU0 ] CPUID[0x00000002]: 00000000 00000000 00000000 00000000
00000000000i[CPU0 ] CPUID[0x00000003]: 00000000 00000000 00000000 00000000
00000000000i[CPU0 ] CPUID[0x00000004]: 00000000 00000000 00000000 00000000
00000000000i[CPU0 ] CPUID[0x00000005]: 00000040 00000040 00000003 00000020
00000000000i[CPU0 ] CPUID[0x80000000]: 80000008 68747541 444d4163 69746e65
00000000000i[CPU0 ] CPUID[0x80000001]: 00000633 00000000 00000101 ebd3f3ff
00000000000i[CPU0 ] CPUID[0x80000002]: 20444d41 6c687441 74286e6f 7020296d
00000000000i[CPU0 ] CPUID[0x80000003]: 65636f72 726f7373 00000000 00000000
00000000000i[CPU0 ] CPUID[0x80000004]: 00000000 00000000 00000000 00000000
00000000000i[CPU0 ] CPUID[0x80000005]: 01ff01ff 01ff01ff 40020140 40020140
00000000000i[CPU0 ] CPUID[0x80000006]: 00000000 42004200 02008140 00000000
00000000000i[CPU0 ] CPUID[0x80000007]: 00000000 00000000 00000000 00000000
00000000000i[CPU0 ] CPUID[0x80000008]: 00003028 00000000 00000000 00000000
00000000000i[CPU0 ] CPU Features supported:
00000000000i[CPU0 ] x87
00000000000i[CPU0 ] 486ni
00000000000i[CPU0 ] pentium_ni
00000000000i[CPU0 ] p6ni
00000000000i[CPU0 ] mmx
00000000000i[CPU0 ] 3dnow!
00000000000i[CPU0 ] debugext
00000000000i[CPU0 ] vme
00000000000i[CPU0 ] pse
00000000000i[CPU0 ] pae
00000000000i[CPU0 ] pge
00000000000i[CPU0 ] pse36
00000000000i[CPU0 ] mtrr
00000000000i[CPU0 ] pat
00000000000i[CPU0 ] sysenter_sysexit
00000000000i[CPU0 ] clflush
00000000000i[CPU0 ] sse
00000000000i[CPU0 ] sse2
00000000000i[CPU0 ] mwait
00000000000i[CPU0 ] vmx
00000000000i[CPU0 ] longmode
00000000000i[CPU0 ] lm_lahf_sahf
00000000000i[CPU0 ] nx
00000000000i[CPU0 ] cmpxhg16b
00000000000i[CPU0 ] rdtscp
00000000000i[CPU0 ] ffxsr
00000000000i[CPU0 ] xapic
00000000000i[PLUGIN] reset of 'pci' plugin device by virtual method
00000000000i[PLUGIN] reset of 'pci2isa' plugin device by virtual method
00000000000i[PLUGIN] reset of 'cmos' plugin device by virtual method
00000000000i[PLUGIN] reset of 'dma' plugin device by virtual method
00000000000i[PLUGIN] reset of 'pic' plugin device by virtual method
00000000000i[PLUGIN] reset of 'pit' plugin device by virtual method
00000000000i[PLUGIN] reset of 'vga' plugin device by virtual method
00000000000i[PLUGIN] reset of 'floppy' plugin device by virtual method
00000000000i[PLUGIN] reset of 'acpi' plugin device by virtual method
00000000000i[PLUGIN] reset of 'hpet' plugin device by virtual method
00000000000i[PLUGIN] reset of 'ioapic' plugin device by virtual method
00000000000i[PLUGIN] reset of 'keyboard' plugin device by virtual method
00000000000i[PLUGIN] reset of 'harddrv' plugin device by virtual method
00000000000i[PLUGIN] reset of 'pci_ide' plugin device by virtual method
00000000000i[PLUGIN] reset of 'unmapped' plugin device by virtual method
00000000000i[PLUGIN] reset of 'speaker' plugin device by virtual method
00000000000i[PLUGIN] reset of 'iodebug' plugin device by virtual method
00000000000i[PLUGIN] reset of 'parallel' plugin device by virtual method
00000000000i[PLUGIN] reset of 'biosdev' plugin device by virtual method
00000000000i[PLUGIN] reset of 'serial' plugin device by virtual method
00000000000i[PLUGIN] reset of 'extfpuirq' plugin device by virtual method
00000000000i[PLUGIN] reset of 'gameport' plugin device by virtual method
00000000000i[PLUGIN] reset of 'usb_uhci' plugin device by virtual method
00000000000i[ ] set SIGINT handler to bx_debug_ctrlc_handler
00000004662i[BIOS ] $Revision: 14314 $ $Date: 2021-07-14 18:10:19 +0200 (Mi, 14. Jul 2021) $
00000317288i[KBD ] reset-disable command received
00000318445i[PIDE ] BAR #4: i/o base address = 0xc000
00000318672i[UHCI ] BAR #4: i/o base address = 0xc100
00000324507i[P2ISA ] PCI IRQ routing: PIRQD# set to 0x0b
00000324523i[P2ISA ] write: ELCR2 = 0x08
00000324543i[UHCI ] new IRQ line = 11
00000324608i[P2ISA ] PCI IRQ routing: PIRQA# set to 0x0a
00000324624i[P2ISA ] write: ELCR2 = 0x0c
00000324644i[ACPI ] new IRQ line = 10
00000442944i[VBIOS ] VGABios $Id: vgabios.c 288 2021-05-28 19:05:28Z vruppert $
00000443015i[BXVGA ] VBE known Display Interface b0c0
00000443047i[BXVGA ] VBE known Display Interface b0c5
00000445690i[VBIOS ] VBE Bios $Id: vbe.c 292 2021-06-03 12:24:22Z vruppert $
00004097906i[BIOS ] IDE time out
00685117203i[BIOS ] Booting from 07c0:0000
00685212587i[BIOS ] int13_harddisk: function 41, unmapped device for ELDL=80
00685216258i[BIOS ] int13_harddisk: function 08, unmapped device for ELDL=80
00685219929i[BIOS ] *** int 15h function AX=00c0, BX=0000 not yet supported!
00867137284i[ ] Ctrl-C detected in signal handler.
00867137285i[ ] dbg: Quit
00867137285i[CPU0 ] CPU is in protected mode (active)
00867137285i[CPU0 ] CS.mode = 32 bit
00867137285i[CPU0 ] SS.mode = 32 bit
00867137285i[CPU0 ] EFER = 0x00000000
00867137285i[CPU0 ] | EAX=0000002a EBX=0002cd80 ECX=000000f0 EDX=00000006
00867137285i[CPU0 ] | ESP=00067ecc EBP=00067ee0 ESI=0002ced8 EDI=0002ced9
00867137285i[CPU0 ] | IOPL=0 id vip vif ac vm rf nt of df if tf sf zf af pf cf
00867137285i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00867137285i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 ffffffff 1 1
00867137285i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00867137285i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00867137285i[CPU0 ] | ES:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00867137285i[CPU0 ] | FS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00867137285i[CPU0 ] | GS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00867137285i[CPU0 ] | EIP=001006cb (001006cb)
00867137285i[CPU0 ] | CR0=0x60000011 CR2=0x00000000
00867137285i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00867137285i[CMOS ] Last time is 1716235362 (Mon May 20 22:02:42 2024)
00867137285i[SIM ] quit_sim called with exit code 0

BIN
com1.out Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -5,6 +5,9 @@ int kmain(int retvalue)
{ {
clear(); clear();
puts("hello\nbrave\nnew\nworld"); puts("hello\nbrave\nnew\nworld");
serial_write("hello", 1);
init_serial();
serial_puts("Hello, brave new world. This is a message to let you know that the kernel has started.\n");
serial_puts("This is a second message.\n");
return retvalue; return retvalue;
} }

BIN
os.iso

Binary file not shown.

View File

@@ -1,68 +1,44 @@
#include "io.h" #include "io.h"
#include "serial.h" #include "serial.h"
void serial_configure_baud_rate(unsigned short com, unsigned short divisor) int init_serial()
{ {
outb(SERIAL_LINE_CMD_PORT(com), SERIAL_LINE_ENABLE_DLAB); outb(PORT+1, 0x00);
outb(SERIAL_DATA_PORT(com), (divisor >> 8) & 0x00FF); outb(PORT+3, 0x80);
outb(SERIAL_DATA_PORT(com), divisor & 0x00FF); outb(PORT+0, 0x03);
outb(PORT+1, 0x00);
outb(PORT+3, 0x03);
outb(PORT+2, 0xC7);
outb(PORT+4, 0x0B);
outb(PORT+4, 0x1E);
outb(PORT+0, 0xAE);
if (inb(PORT+0) != 0xAE) {
return 1;
} }
void serial_configure_line(unsigned short com) outb(PORT+4, 0x0F);
{ return 0;
/*
d b p s dl
0 0 000 0 11 = 0x03
Length 8 bits, no parity bit, one stop bit, break control off
*/
outb(SERIAL_LINE_CMD_PORT(com), 0x03);
} }
void serial_configure_buffer(unsigned short com) int is_transmit_empty()
{ {
/* return inb(PORT+5) & 0x20;
lv b r d c c e
11 0 0 0 1 1 1 = 0xC7
Enable FIFO, clear FIFO queues, use 14 bytes as queue size
*/
outb(SERIAL_LINE_CMD_PORT(com), 0xC7);
} }
void serial_configure_modem(unsigned short com) void write_serial(const char a)
{ {
/* while (is_transmit_empty() == 0);
outb(PORT, a);
r r a l a a r d
0 0 0 0 0 0 1 1 = 0x03
Ready to transmit, data terminal ready
*/
outb(SERIAL_LINE_CMD_PORT(com), 0x03);
} }
int serial_is_transmit_fifo_empty(unsigned short com) void serial_puts(const char* str)
{ {
return (inb(SERIAL_LINE_STATUS_PORT(com)) & 0x20); unsigned int i = 0;
} write_serial(str[0]); // Transmit first byte 2 times
while (*str++)
void serial_write(const char* buf, unsigned short com)
{ {
serial_configure_baud_rate(com, 2); write_serial(str[i]);
serial_configure_line(com);
serial_configure_buffer(com);
serial_configure_modem(com);
for (unsigned int i = 0; i<sizeof(buf); i++)
{
while (serial_is_transmit_fifo_empty(com))
{
outb(SERIAL_DATA_PORT(com), buf[i]);
} }
} }
return;
}

View File

@@ -1,20 +1,11 @@
#ifndef INCLUDE_SERIAL_H #ifndef INCLUDE_SERIAL_H
#define INCLUDE_SERIAL_H #define INCLUDE_SERIAL_H
#define SERIAL_COM1_BASE 0x3F8 #define PORT 0x3f8 //COM1
#define SERIAL_DATA_PORT(base) (base)
#define SERIAL_FIFO_CMD_PORT(base) (base + 2)
#define SERIAL_LINE_CMD_PORT(base) (base + 3)
#define SERIAL_MODEM_CMD_PORT(base) (base + 4)
#define SERIAL_LINE_STATUS_PORT(base) (base + 5)
#define SERIAL_LINE_ENABLE_DLAB 0x80 int init_serial();
int is_transmit_empty();
void serial_configure_baud_rate(unsigned short com, unsigned short divisor); void write_serial(const char a);
void serial_configure_line(unsigned short com); void serial_puts(const char* str);
void serial_configure_buffer(unsigned short com);
void serial_configure_modem(unsigned short com);
int serial_is_transmit_fifo_empty(unsigned short com);
void serial_write(const char* buf, unsigned short com);
#endif #endif