Introduce the "ioport" bus
This commit is contained in:
parent
0daf183bb0
commit
d67fe7e2f0
12
src/drivers/bus.c
Normal file
12
src/drivers/bus.c
Normal 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
25
src/drivers/bus.h
Normal 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
18
src/drivers/bus/ioport.S
Normal 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
50
src/drivers/bus/ioport.c
Normal 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;
|
||||||
|
}
|
1
src/drivers/bus/project.conf
Normal file
1
src/drivers/bus/project.conf
Normal file
|
@ -0,0 +1 @@
|
||||||
|
dist=Makefile,ioport.c
|
|
@ -7,6 +7,7 @@
|
||||||
# define UKERNEL_DRIVERS_CONSOLE_H
|
# define UKERNEL_DRIVERS_CONSOLE_H
|
||||||
|
|
||||||
# include <stdint.h>
|
# include <stdint.h>
|
||||||
|
# include "bus.h"
|
||||||
|
|
||||||
|
|
||||||
/* public */
|
/* public */
|
||||||
|
@ -15,7 +16,7 @@ typedef struct _Console Console;
|
||||||
|
|
||||||
|
|
||||||
/* prototypes */
|
/* prototypes */
|
||||||
Console * console_init(void);
|
Console * console_init(Bus * bus);
|
||||||
|
|
||||||
/* useful */
|
/* useful */
|
||||||
void console_clear(Console * console);
|
void console_clear(Console * console);
|
||||||
|
|
|
@ -36,8 +36,10 @@ static void _vga_scroll(Console * console, size_t rows);
|
||||||
/* public */
|
/* public */
|
||||||
/* functions */
|
/* functions */
|
||||||
/* console_init */
|
/* console_init */
|
||||||
Console * console_init(void)
|
Console * console_init(Bus * bus)
|
||||||
{
|
{
|
||||||
|
(void) bus;
|
||||||
|
|
||||||
_vga_console.buf = (uint16_t *)VGA_ADDRESS_BASE;
|
_vga_console.buf = (uint16_t *)VGA_ADDRESS_BASE;
|
||||||
_vga_console.color_bg = VGA_TEXT_COLOR_BLACK;
|
_vga_console.color_bg = VGA_TEXT_COLOR_BLACK;
|
||||||
_vga_console.color_fg = VGA_TEXT_COLOR_WHITE;
|
_vga_console.color_fg = VGA_TEXT_COLOR_WHITE;
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
subdirs=console
|
subdirs=bus,console
|
||||||
dist=Makefile,console.h
|
dist=Makefile,bus.h,console.h
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "drivers/bus.h"
|
||||||
#include "drivers/console.h"
|
#include "drivers/console.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,10 +13,12 @@
|
||||||
/* main */
|
/* main */
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
Bus * bus;
|
||||||
Console * console;
|
Console * console;
|
||||||
const char msg[] = "Starting DeforaOS...\n";
|
const char msg[] = "Starting DeforaOS...\n";
|
||||||
|
|
||||||
console = console_init();
|
bus = bus_init();
|
||||||
|
console = console_init(bus);
|
||||||
console_print(console, msg, sizeof(msg) - 1);
|
console_print(console, msg, sizeof(msg) - 1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ sources=crtn.S
|
||||||
|
|
||||||
[uKernel.bin]
|
[uKernel.bin]
|
||||||
type=binary
|
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
|
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
|
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]
|
[crtn.S]
|
||||||
depends=arch/amd64/crtn.S,arch/i386/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]
|
[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]
|
[main.c]
|
||||||
depends=drivers/console.h
|
depends=drivers/console.h
|
||||||
|
|
25
tools/bus.c
Normal file
25
tools/bus.c
Normal 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;
|
||||||
|
}
|
|
@ -26,7 +26,7 @@ static Console _console;
|
||||||
|
|
||||||
/* functions */
|
/* functions */
|
||||||
/* console_init */
|
/* console_init */
|
||||||
Console * console_init(void)
|
Console * console_init(Bus * bus)
|
||||||
{
|
{
|
||||||
_console.fd = STDOUT_FILENO;
|
_console.fd = STDOUT_FILENO;
|
||||||
return &_console;
|
return &_console;
|
||||||
|
|
|
@ -13,7 +13,7 @@ sources=start.S
|
||||||
|
|
||||||
[uKernel]
|
[uKernel]
|
||||||
type=binary
|
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`
|
ldflags=$(OBJDIR)start.o $(OBJDIR)../src/lib/libuKernel.a `$(CC) -print-libgcc-file-name`
|
||||||
depends=$(OBJDIR)start.o,$(OBJDIR)../src/lib/libuKernel.a
|
depends=$(OBJDIR)start.o,$(OBJDIR)../src/lib/libuKernel.a
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user