Introduce the "ioport" bus

This commit is contained in:
Pierre Pronchery 2018-04-04 01:46:35 +02:00
parent 0daf183bb0
commit d67fe7e2f0
13 changed files with 149 additions and 9 deletions

12
src/drivers/bus.c Normal file
View File

@ -0,0 +1,12 @@
/* $Id$ */
/* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
#include "bus.h"
#if defined(__amd64__) || defined(__i386__)
# include "bus/ioport.c"
#endif

25
src/drivers/bus.h Normal file
View File

@ -0,0 +1,25 @@
/* $Id$ */
/* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
#ifndef UKERNEL_DRIVERS_BUS_H
# define UKERNEL_DRIVERS_BUS_H
# include <stdint.h>
/* public */
/* types */
typedef struct _Bus Bus;
/* prototypes */
Bus * bus_init(void);
/* useful */
int bus_write8(Bus * bus, void * addr, uint8_t value);
int bus_write16(Bus * bus, void * addr, uint16_t value);
int bus_write32(Bus * bus, void * addr, uint32_t value);
#endif /* !UKERNEL_DRIVERS_BUS_H */

18
src/drivers/bus/ioport.S Normal file
View File

@ -0,0 +1,18 @@
/* $Id$ */
/* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
#if defined(__amd64__) || defined(__i386__)
/* functions */
.section .text
/* bus_write8 */
.global bus_write8
.type bus_write8, @function
bus_write8:
mov 0x8(%esp), %dx
mov 0xc(%esp), %al
out %al, %dx
ret
#endif

50
src/drivers/bus/ioport.c Normal file
View File

@ -0,0 +1,50 @@
/* $Id$ */
/* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
#include <errno.h>
/* private */
/* types */
struct _Bus
{
};
/* variables */
static Bus _ioport_bus;
/* public */
/* functions */
/* bus_init */
Bus * bus_init(void)
{
return &_ioport_bus;
}
/* useful */
/* bus_write16 */
int bus_write16(Bus * bus, void * addr, uint16_t value)
{
(void) bus;
(void) addr;
(void) value;
return -ENOTSUP;
}
/* bus_write32 */
int bus_write32(Bus * bus, void * addr, uint32_t value)
{
(void) bus;
(void) addr;
(void) value;
return -ENOTSUP;
}

View File

@ -0,0 +1 @@
dist=Makefile,ioport.c

View File

@ -7,6 +7,7 @@
# define UKERNEL_DRIVERS_CONSOLE_H
# include <stdint.h>
# include "bus.h"
/* public */
@ -15,7 +16,7 @@ typedef struct _Console Console;
/* prototypes */
Console * console_init(void);
Console * console_init(Bus * bus);
/* useful */
void console_clear(Console * console);

View File

@ -36,8 +36,10 @@ static void _vga_scroll(Console * console, size_t rows);
/* public */
/* functions */
/* console_init */
Console * console_init(void)
Console * console_init(Bus * bus)
{
(void) bus;
_vga_console.buf = (uint16_t *)VGA_ADDRESS_BASE;
_vga_console.color_bg = VGA_TEXT_COLOR_BLACK;
_vga_console.color_fg = VGA_TEXT_COLOR_WHITE;

View File

@ -1,2 +1,2 @@
subdirs=console
dist=Makefile,console.h
subdirs=bus,console
dist=Makefile,bus.h,console.h

View File

@ -4,6 +4,7 @@
#include "drivers/bus.h"
#include "drivers/console.h"
@ -12,10 +13,12 @@
/* main */
int main(void)
{
Bus * bus;
Console * console;
const char msg[] = "Starting DeforaOS...\n";
console = console_init();
bus = bus_init();
console = console_init(bus);
console_print(console, msg, sizeof(msg) - 1);
return 0;
}

View File

@ -26,7 +26,7 @@ sources=crtn.S
[uKernel.bin]
type=binary
sources=boot.S,drivers/console.c,main.c
sources=boot.S,drivers/bus.c,drivers/bus/ioport.S,drivers/console.c,main.c
ldflags=$(OBJDIR)crti.o $(OBJDIR)crtbegin.o $(OBJDIR)lib/libuKernel.a $(OBJDIR)crtend.o $(OBJDIR)crtn.o
depends=$(OBJDIR)crtbegin.o,$(OBJDIR)crtend.o,$(OBJDIR)crti.o,$(OBJDIR)crtn.o,$(OBJDIR)lib/libuKernel.a,arch/amd64/uKernel.ld,arch/i386/uKernel.ld
@ -39,8 +39,11 @@ depends=arch/amd64/crti.S,arch/i386/crti.S
[crtn.S]
depends=arch/amd64/crtn.S,arch/i386/crtn.S
[drivers/bus.c]
depends=drivers/bus.h,drivers/bus/ioport.c
[drivers/console.c]
depends=drivers/console/vga.h,drivers/console/vga.c
depends=drivers/bus.h,drivers/console/vga.h,drivers/console/vga.c
[main.c]
depends=drivers/console.h

25
tools/bus.c Normal file
View File

@ -0,0 +1,25 @@
/* $Id$ */
/* Copyright (c) 2018 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS uKernel */
#include "drivers/bus.h"
/* types */
struct _Bus
{
};
/* variables */
static Bus _bus;
/* functions */
/* bus_init */
Bus * bus_init(void)
{
return &_bus;
}

View File

@ -26,7 +26,7 @@ static Console _console;
/* functions */
/* console_init */
Console * console_init(void)
Console * console_init(Bus * bus)
{
_console.fd = STDOUT_FILENO;
return &_console;

View File

@ -13,7 +13,7 @@ sources=start.S
[uKernel]
type=binary
sources=console.c,main.c
sources=bus.c,console.c,main.c
ldflags=$(OBJDIR)start.o $(OBJDIR)../src/lib/libuKernel.a `$(CC) -print-libgcc-file-name`
depends=$(OBJDIR)start.o,$(OBJDIR)../src/lib/libuKernel.a