Migrate the bus driver to a class

This commit is contained in:
Pierre Pronchery 2018-04-04 02:04:09 +02:00
parent e938588d31
commit 0ef750cd7e
4 changed files with 37 additions and 24 deletions

View File

@ -12,14 +12,20 @@
/* public */
/* types */
typedef struct _Bus Bus;
typedef void * BusAddress;
typedef struct _BusData BusData;
struct _Bus
{
int (*write8)(Bus * bus, BusAddress * address, uint8_t value);
int (*write16)(Bus * bus, BusAddress * address, uint16_t value);
int (*write32)(Bus * bus, BusAddress * address, uint32_t value);
BusData * data;
};
/* 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 */

View File

@ -7,10 +7,10 @@
#if defined(__amd64__) || defined(__i386__)
/* functions */
.section .text
/* bus_write8 */
.global bus_write8
.type bus_write8, @function
bus_write8:
/* ioport_write8 */
.global ioport_write8
.type ioport_write8, @function
ioport_write8:
mov 0x8(%esp), %dx
mov 0xc(%esp), %al
out %al, %dx

View File

@ -4,18 +4,25 @@
#include <stddef.h>
#include <errno.h>
/* private */
/* types */
struct _Bus
{
};
/* prototypes */
extern int ioport_write8(Bus * bus, BusAddress * address, uint8_t value);
static int _ioport_write16(Bus * bus, BusAddress * address, uint16_t value);
static int _ioport_write32(Bus * bus, BusAddress * address, uint32_t value);
/* variables */
static Bus _ioport_bus;
static Bus _ioport_bus =
{
ioport_write8,
_ioport_write16,
_ioport_write32,
NULL
};
/* public */
@ -28,22 +35,22 @@ Bus * bus_init(void)
/* useful */
/* bus_write16 */
int bus_write16(Bus * bus, void * addr, uint16_t value)
/* ioport_write16 */
static int _ioport_write16(Bus * bus, BusAddress * address, uint16_t value)
{
(void) bus;
(void) addr;
(void) address;
(void) value;
return -ENOTSUP;
}
/* bus_write32 */
int bus_write32(Bus * bus, void * addr, uint32_t value)
/* ioport_write32 */
static int _ioport_write32(Bus * bus, BusAddress * address, uint32_t value)
{
(void) bus;
(void) addr;
(void) address;
(void) value;
return -ENOTSUP;

View File

@ -111,10 +111,10 @@ static void _vga_cursor_set(Console * console, bool enabled,
if(row >= VGA_TEXT_ROWS || column >= VGA_TEXT_COLUMNS)
return;
bus_write8(&console->bus, 0x3d4, 0x0f);
bus_write8(&console->bus, 0x3d5, pos & 0xff);
bus_write8(&console->bus, 0x3d4, 0x0e);
bus_write8(&console->bus, 0x3d5, pos >> 8);
console->bus->write8(console->bus, (BusAddress *)0x3d4, 0x0f);
console->bus->write8(console->bus, (BusAddress *)0x3d5, pos & 0xff);
console->bus->write8(console->bus, (BusAddress *)0x3d4, 0x0e);
console->bus->write8(console->bus, (BusAddress *)0x3d5, pos >> 8);
}