Add: nonworking serial port driver implementation

This commit is contained in:
xamidev
2024-05-20 21:48:48 +02:00
parent 841dee9e18
commit aca525d3ce
11 changed files with 145 additions and 45 deletions

View File

@@ -44,45 +44,45 @@
00000000000i[USBCTL] Pluggable USB devices 00000000000i[USBCTL] Pluggable USB devices
00000000000i[USBCTL] mouse tablet keypad keyboard floppy disk cdrom printer 00000000000i[USBCTL] mouse tablet keypad keyboard floppy disk cdrom printer
00000000000i[USBCTL] hub 00000000000i[USBCTL] hub
00000000000i[MEM0 ] allocated memory at 0x7f59fd3dc010. after alignment, vector=0x7f59fd3dd000 00000000000i[MEM0 ] allocated memory at 0x7fb8f1ddd010. after alignment, vector=0x7fb8f1dde000
00000000000i[MEM0 ] 32.00MB 00000000000i[MEM0 ] 32.00MB
00000000000i[MEM0 ] mem block size = 0x00020000, blocks=256 00000000000i[MEM0 ] mem block size = 0x00020000, blocks=256
00000000000i[MEM0 ] rom at 0xffff0000/65536 ('/usr/share/bochs/BIOS-bochs-legacy') 00000000000i[MEM0 ] rom at 0xffff0000/65536 ('/usr/share/bochs/BIOS-bochs-legacy')
00000000000i[CPU0 ] WARNING: 3DNow! is not implemented yet ! 00000000000i[CPU0 ] WARNING: 3DNow! is not implemented yet !
00000000000i[DEV ] will paste characters every 100 iodev timer ticks 00000000000i[DEV ] will paste characters every 100 iodev timer ticks
00000000000i[ ] lt_dlhandle is 0x555b0a2aef10 00000000000i[ ] lt_dlhandle is 0x5638a94a38b0
00000000000i[PLUGIN] loaded plugin libbx_soundalsa.so 00000000000i[PLUGIN] loaded plugin libbx_soundalsa.so
00000000000i[WAVOUT] ALSA: opened default PCM output device 00000000000i[WAVOUT] ALSA: opened default PCM output device
00000000000i[WAVOUT] changed sample rate to 44101 00000000000i[WAVOUT] changed sample rate to 44101
00000000000i[ ] lt_dlhandle is 0x555b0aa651a0 00000000000i[ ] lt_dlhandle is 0x5638a9c59430
00000000000i[PLUGIN] loaded plugin libbx_pci.so 00000000000i[PLUGIN] loaded plugin libbx_pci.so
00000000000i[ ] lt_dlhandle is 0x555b0a2aeff0 00000000000i[ ] lt_dlhandle is 0x5638a94a3990
00000000000i[PLUGIN] loaded plugin libbx_pci2isa.so 00000000000i[PLUGIN] loaded plugin libbx_pci2isa.so
00000000000i[ ] lt_dlhandle is 0x555b0a22cea0 00000000000i[ ] lt_dlhandle is 0x5638a9421ac0
00000000000i[PLUGIN] loaded plugin libbx_usb_uhci.so 00000000000i[PLUGIN] loaded plugin libbx_usb_uhci.so
00000000000i[ ] lt_dlhandle is 0x555b0a2c91b0 00000000000i[ ] lt_dlhandle is 0x5638a94bdfc0
00000000000i[PLUGIN] loaded plugin libbx_acpi.so 00000000000i[PLUGIN] loaded plugin libbx_acpi.so
00000000000i[ ] lt_dlhandle is 0x555b0a22c2a0 00000000000i[ ] lt_dlhandle is 0x5638a9420ec0
00000000000i[PLUGIN] loaded plugin libbx_hpet.so 00000000000i[PLUGIN] loaded plugin libbx_hpet.so
00000000000i[ ] lt_dlhandle is 0x555b0aa6f950 00000000000i[ ] lt_dlhandle is 0x5638a9c63be0
00000000000i[PLUGIN] loaded plugin libbx_cmos.so 00000000000i[PLUGIN] loaded plugin libbx_cmos.so
00000000000i[ ] lt_dlhandle is 0x555b0aa70160 00000000000i[ ] lt_dlhandle is 0x5638a9c643f0
00000000000i[PLUGIN] loaded plugin libbx_dma.so 00000000000i[PLUGIN] loaded plugin libbx_dma.so
00000000000i[ ] lt_dlhandle is 0x555b0aa70970 00000000000i[ ] lt_dlhandle is 0x5638a9c64d60
00000000000i[PLUGIN] loaded plugin libbx_pic.so 00000000000i[PLUGIN] loaded plugin libbx_pic.so
00000000000i[ ] lt_dlhandle is 0x555b0aa71130 00000000000i[ ] lt_dlhandle is 0x5638a9c65520
00000000000i[PLUGIN] loaded plugin libbx_pit.so 00000000000i[PLUGIN] loaded plugin libbx_pit.so
00000000000i[ ] lt_dlhandle is 0x555b0aa71b50 00000000000i[ ] lt_dlhandle is 0x5638a9c65f40
00000000000i[PLUGIN] loaded plugin libbx_vga.so 00000000000i[PLUGIN] loaded plugin libbx_vga.so
00000000000i[ ] lt_dlhandle is 0x555b0aa93190 00000000000i[ ] lt_dlhandle is 0x5638a9c87580
00000000000i[PLUGIN] loaded plugin libbx_floppy.so 00000000000i[PLUGIN] loaded plugin libbx_floppy.so
00000000000i[ ] lt_dlhandle is 0x555b0aa939d0 00000000000i[ ] lt_dlhandle is 0x5638a9c87dc0
00000000000i[PLUGIN] loaded plugin libbx_ioapic.so 00000000000i[PLUGIN] loaded plugin libbx_ioapic.so
00000000000i[ ] lt_dlhandle is 0x555b0aa941e0 00000000000i[ ] lt_dlhandle is 0x5638a9c885d0
00000000000i[PLUGIN] loaded plugin libbx_keyboard.so 00000000000i[PLUGIN] loaded plugin libbx_keyboard.so
00000000000i[ ] lt_dlhandle is 0x555b0aa94ae0 00000000000i[ ] lt_dlhandle is 0x5638a9c88ed0
00000000000i[PLUGIN] loaded plugin libbx_harddrv.so 00000000000i[PLUGIN] loaded plugin libbx_harddrv.so
00000000000i[ ] lt_dlhandle is 0x555b0aa96bb0 00000000000i[ ] lt_dlhandle is 0x5638a9c8afa0
00000000000i[PLUGIN] loaded plugin libbx_pci_ide.so 00000000000i[PLUGIN] loaded plugin libbx_pci_ide.so
00000000000i[PLUGIN] init_dev of 'pci' plugin device by virtual method 00000000000i[PLUGIN] init_dev of 'pci' plugin device by virtual method
00000000000i[DEV ] i440FX PMC present at device 0, function 0 00000000000i[DEV ] i440FX PMC present at device 0, function 0
@@ -90,7 +90,7 @@
00000000000i[DEV ] PIIX3 PCI-to-ISA bridge present at device 1, function 0 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[PLUGIN] init_dev of 'cmos' plugin device by virtual method
00000000000i[CMOS ] Using local time for initial clock 00000000000i[CMOS ] Using local time for initial clock
00000000000i[CMOS ] Setting initial clock to: Sun May 19 15:09:18 2024 (time0=1716124158) 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[PLUGIN] init_dev of 'dma' plugin device by virtual method
00000000000i[DMA ] channel 4 used by cascade 00000000000i[DMA ] channel 4 used by cascade
00000000000i[PLUGIN] init_dev of 'pic' plugin device by virtual method 00000000000i[PLUGIN] init_dev of 'pic' plugin device by virtual method
@@ -133,7 +133,7 @@
00000000000i[PAR ] parallel port 1 at 0x0378 irq 7 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 'biosdev' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'serial' plugin device by virtual method 00000000000i[PLUGIN] init_dev of 'serial' plugin device by virtual method
00000000000i[SER ] com1 at 0x03f8 irq 4 (mode: null) 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 'extfpuirq' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'gameport' 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[PLUGIN] init_dev of 'usb_uhci' plugin device by virtual method
@@ -247,28 +247,29 @@
00000443015i[BXVGA ] VBE known Display Interface b0c0 00000443015i[BXVGA ] VBE known Display Interface b0c0
00000443047i[BXVGA ] VBE known Display Interface b0c5 00000443047i[BXVGA ] VBE known Display Interface b0c5
00000445690i[VBIOS ] VBE Bios $Id: vbe.c 292 2021-06-03 12:24:22Z vruppert $ 00000445690i[VBIOS ] VBE Bios $Id: vbe.c 292 2021-06-03 12:24:22Z vruppert $
00004097883i[BIOS ] IDE time out 00004097906i[BIOS ] IDE time out
00716758940i[BIOS ] Booting from 07c0:0000 00685117203i[BIOS ] Booting from 07c0:0000
00716854324i[BIOS ] int13_harddisk: function 41, unmapped device for ELDL=80 00685212587i[BIOS ] int13_harddisk: function 41, unmapped device for ELDL=80
00716857995i[BIOS ] int13_harddisk: function 08, unmapped device for ELDL=80 00685216258i[BIOS ] int13_harddisk: function 08, unmapped device for ELDL=80
00716861666i[BIOS ] *** int 15h function AX=00c0, BX=0000 not yet supported! 00685219929i[BIOS ] *** int 15h function AX=00c0, BX=0000 not yet supported!
00842722000p[SDL2 ] >>PANIC<< User requested shutdown. 00867137284i[ ] Ctrl-C detected in signal handler.
00842722000i[CPU0 ] CPU is in protected mode (active) 00867137285i[ ] dbg: Quit
00842722000i[CPU0 ] CS.mode = 32 bit 00867137285i[CPU0 ] CPU is in protected mode (active)
00842722000i[CPU0 ] SS.mode = 32 bit 00867137285i[CPU0 ] CS.mode = 32 bit
00842722000i[CPU0 ] EFER = 0x00000000 00867137285i[CPU0 ] SS.mode = 32 bit
00842722000i[CPU0 ] | EAX=0000002a EBX=0002cd80 ECX=000000f0 EDX=000003d5 00867137285i[CPU0 ] EFER = 0x00000000
00842722000i[CPU0 ] | ESP=00067ecc EBP=00067ee0 ESI=0002ced8 EDI=0002ced9 00867137285i[CPU0 ] | EAX=0000002a EBX=0002cd80 ECX=000000f0 EDX=00000006
00842722000i[CPU0 ] | IOPL=0 id vip vif ac vm rf nt of df if tf sf zf af pf cf 00867137285i[CPU0 ] | ESP=00067ecc EBP=00067ee0 ESI=0002ced8 EDI=0002ced9
00842722000i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D 00867137285i[CPU0 ] | IOPL=0 id vip vif ac vm rf nt of df if tf sf zf af pf cf
00842722000i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 ffffffff 1 1 00867137285i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00842722000i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 ffffffff 1 1 00867137285i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 ffffffff 1 1
00842722000i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 ffffffff 1 1 00867137285i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00842722000i[CPU0 ] | ES:0010( 0002| 0| 0) 00000000 ffffffff 1 1 00867137285i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00842722000i[CPU0 ] | FS:0010( 0002| 0| 0) 00000000 ffffffff 1 1 00867137285i[CPU0 ] | ES:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00842722000i[CPU0 ] | GS:0010( 0002| 0| 0) 00000000 ffffffff 1 1 00867137285i[CPU0 ] | FS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00842722000i[CPU0 ] | EIP=001004ab (001004ab) 00867137285i[CPU0 ] | GS:0010( 0002| 0| 0) 00000000 ffffffff 1 1
00842722000i[CPU0 ] | CR0=0x60000011 CR2=0x00000000 00867137285i[CPU0 ] | EIP=001006cb (001006cb)
00842722000i[CPU0 ] | CR3=0x00000000 CR4=0x00000000 00867137285i[CPU0 ] | CR0=0x60000011 CR2=0x00000000
00842722000i[CMOS ] Last time is 1716125000 (Sun May 19 15:23:20 2024) 00867137285i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
00842722000i[SIM ] quit_sim called with exit code 1 00867137285i[CMOS ] Last time is 1716235362 (Mon May 20 22:02:42 2024)
00867137285i[SIM ] quit_sim called with exit code 0

View File

@@ -7,3 +7,4 @@ boot: cdrom
log: bochslog.txt log: bochslog.txt
clock: sync=realtime, time0=local clock: sync=realtime, time0=local
cpu: count=1, ips=1000000 cpu: count=1, ips=1000000
com1: enabled=1, mode=file, dev=com1.out

1
io.h
View File

@@ -2,5 +2,6 @@
#define INCLUDE_IO_H #define INCLUDE_IO_H
void outb(unsigned short port, unsigned char data); void outb(unsigned short port, unsigned char data);
unsigned char inb(unsigned short port);
#endif #endif

7
io.s
View File

@@ -5,3 +5,10 @@ outb:
mov dx, [esp + 4] mov dx, [esp + 4]
out dx, al out dx, al
ret ret
global inb
inb:
mov dx, [esp + 4]
in al, dx
ret

Binary file not shown.

Binary file not shown.

View File

@@ -1,8 +1,10 @@
#include "stdio.h" #include "stdio.h"
#include "serial.h"
int kmain(int retvalue) int kmain(int retvalue)
{ {
clear(); clear();
puts("hello\nbrave\nnew\nworld"); puts("hello\nbrave\nnew\nworld");
serial_write("hello", 1);
return retvalue; return retvalue;
} }

View File

@@ -1,4 +1,4 @@
OBJECTS = loader.o kmain.o stdio.o io.o string.o OBJECTS = loader.o kmain.o stdio.o io.o string.o serial.o
CC = gcc CC = gcc
CFLAGS = -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles -nodefaultlibs -Wall -Wextra -c CFLAGS = -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles -nodefaultlibs -Wall -Wextra -c
LDFLAGS = -T link.ld -melf_i386 LDFLAGS = -T link.ld -melf_i386

BIN
os.iso

Binary file not shown.

68
serial.c Normal file
View File

@@ -0,0 +1,68 @@
#include "io.h"
#include "serial.h"
void serial_configure_baud_rate(unsigned short com, unsigned short divisor)
{
outb(SERIAL_LINE_CMD_PORT(com), SERIAL_LINE_ENABLE_DLAB);
outb(SERIAL_DATA_PORT(com), (divisor >> 8) & 0x00FF);
outb(SERIAL_DATA_PORT(com), divisor & 0x00FF);
}
void serial_configure_line(unsigned short com)
{
/*
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)
{
/*
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)
{
/*
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)
{
return (inb(SERIAL_LINE_STATUS_PORT(com)) & 0x20);
}
void serial_write(const char* buf, unsigned short com)
{
serial_configure_baud_rate(com, 2);
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;
}

20
serial.h Normal file
View File

@@ -0,0 +1,20 @@
#ifndef INCLUDE_SERIAL_H
#define INCLUDE_SERIAL_H
#define SERIAL_COM1_BASE 0x3F8
#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
void serial_configure_baud_rate(unsigned short com, unsigned short divisor);
void serial_configure_line(unsigned short com);
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