Skip to content

Commit

Permalink
hal/ia32: change I/O input parameter to u16
Browse files Browse the repository at this point in the history
JIRA: RTOS-912
  • Loading branch information
badochov committed Sep 23, 2024
1 parent aab2598 commit ba7788b
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 40 deletions.
16 changes: 8 additions & 8 deletions hal/ia32/arch/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,16 @@

/* IO Ports */
/* Ports of (8259A) PIC (Programmable Interrupt Controller) */
#define PORT_PIC_MASTER_COMMAND ((void *)0x20)
#define PORT_PIC_MASTER_DATA ((void *)0x21)
#define PORT_PIC_SLAVE_COMMAND ((void *)0xa0)
#define PORT_PIC_SLAVE_DATA ((void *)0xa1)
#define PORT_PIC_MASTER_COMMAND ((u16)0x20)
#define PORT_PIC_MASTER_DATA ((u16)0x21)
#define PORT_PIC_SLAVE_COMMAND ((u16)0xa0)
#define PORT_PIC_SLAVE_DATA ((u16)0xa1)
/* Ports of PIT (Programmable Interval Timer) */
#define PORT_PIT_DATA_CHANNEL0 ((void *)0x40)
#define PORT_PIT_COMMAND ((void *)0x43)
#define PORT_PIT_DATA_CHANNEL0 ((u16)0x40)
#define PORT_PIT_COMMAND ((u16)0x43)
/* Ports of 8042 PS/2 Controller */
#define PORT_PS2_DATA ((void *)0x60)
#define PORT_PS2_COMMAND ((void *)0x64)
#define PORT_PS2_DATA ((u16)0x60)
#define PORT_PS2_COMMAND ((u16)0x64)

/* There are objects in memory that require O(MAX_CPU_COUNT^2) memory. */
#define MAX_CPU_COUNT 64
Expand Down
14 changes: 8 additions & 6 deletions hal/ia32/console-serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,21 @@ enum {

static inline void _console_uartWrite(unsigned int reg, u8 val)
{
if (!console_common.type)
hal_outb(console_common.base + reg, val);
else
if (console_common.type == 0) {
hal_outb((u16)((addr_t)console_common.base + reg), val);
}
else {
*(u8 *)(console_common.base + reg) = val;
}
return;
}


static inline u8 _console_uartRead(unsigned int reg)
{
if (!console_common.type)
return hal_inb(console_common.base + reg);

if (console_common.type == 0) {
return hal_inb((u16)((addr_t)console_common.base + reg));
}
return *(u8 *)(console_common.base + reg);
}

Expand Down
18 changes: 9 additions & 9 deletions hal/ia32/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static const unsigned char ansi2bg[] = {

struct {
volatile u16 *vram; /* Video memory */
void *crtc; /* CRT controller register */
u16 crtc; /* CRT controller register */
unsigned int rows; /* Console height */
unsigned int cols; /* Console width */
unsigned char attr; /* Character attribute */
Expand Down Expand Up @@ -92,9 +92,9 @@ static void _hal_consolePrint(const char *s)

/* Print from current cursor position */
hal_outb(halconsole_common.crtc, 0x0f);
pos = hal_inb((void *)((addr_t)halconsole_common.crtc + 1));
pos = hal_inb(halconsole_common.crtc + 1);
hal_outb(halconsole_common.crtc, 0x0e);
pos |= (u16)hal_inb((void *)((addr_t)halconsole_common.crtc + 1)) << 8;
pos |= (u16)hal_inb(halconsole_common.crtc + 1) << 8;
row = pos / halconsole_common.cols;
col = pos % halconsole_common.cols;

Expand Down Expand Up @@ -273,7 +273,7 @@ static void _hal_consolePrint(const char *s)
switch (halconsole_common.parms[0]) {
case 25:
hal_outb(halconsole_common.crtc, 0x0a);
hal_outb((void *)((addr_t)halconsole_common.crtc + 1), hal_inb((void *)((addr_t)halconsole_common.crtc + 1)) & ~0x20);
hal_outb(halconsole_common.crtc + 1, hal_inb(halconsole_common.crtc + 1) & ~0x20);
break;
}
halconsole_common.esc = esc_init;
Expand All @@ -283,7 +283,7 @@ static void _hal_consolePrint(const char *s)
switch (halconsole_common.parms[0]) {
case 25:
hal_outb(halconsole_common.crtc, 0x0a);
hal_outb((void *)((addr_t)halconsole_common.crtc + 1), hal_inb((void *)((addr_t)halconsole_common.crtc + 1)) | 0x20);
hal_outb(halconsole_common.crtc + 1, hal_inb(halconsole_common.crtc + 1) | 0x20);
break;
}
halconsole_common.esc = esc_init;
Expand Down Expand Up @@ -315,9 +315,9 @@ static void _hal_consolePrint(const char *s)
/* Update cursor */
i = row * halconsole_common.cols + col;
hal_outb(halconsole_common.crtc, 0x0e);
hal_outb((void *)((addr_t)halconsole_common.crtc + 1), i >> 8);
hal_outb(halconsole_common.crtc + 1, i >> 8);
hal_outb(halconsole_common.crtc, 0x0f);
hal_outb((void *)((addr_t)halconsole_common.crtc + 1), i);
hal_outb(halconsole_common.crtc + 1, i);
*((u8 *)(halconsole_common.vram + i) + 1) = halconsole_common.attr;
}

Expand Down Expand Up @@ -349,11 +349,11 @@ __attribute__ ((section (".init"))) void _hal_consoleInit(void)
unsigned char color;

/* Check color support */
color = hal_inb((void *)0x3cc) & 0x01;
color = hal_inb((u16)0x3cc) & 0x01;

/* Initialize VGA */
halconsole_common.vram = (u16 *)(VADDR_KERNEL + (color ? 0xb8000 : 0xb0000));
halconsole_common.crtc = (void *)(color ? 0x3d4 : 0x3b4);
halconsole_common.crtc = (u16)(color ? 0x3d4 : 0x3b4);

/* Default 80x25 text mode with cyan color attribute */
halconsole_common.rows = 25;
Expand Down
2 changes: 1 addition & 1 deletion hal/ia32/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ void hal_cpuReboot(void)
hal_outb(PORT_PS2_COMMAND, 0xfe);

/* 2. Try to reboot by PCI reset */
hal_outb((void *)0xcf9, 0xe);
hal_outb((u16)0xcf9, 0xe);

/* 3. Triple fault (interrupt with null idt) */
/* clang-format off */
Expand Down
20 changes: 10 additions & 10 deletions hal/ia32/ia32.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,66 +21,66 @@
/* io access */


static inline u8 hal_inb(void *addr)
static inline u8 hal_inb(u16 addr)
{
u8 b;

/* clang-format off */
__asm__ volatile (
"inb %1, %0\n\t"
: "=a" (b)
: "d" ((u16)(addr_t)addr)
: "d" (addr)
: );
/* clang-format on */
return b;
}


static inline void hal_outb(void *addr, u8 b)
static inline void hal_outb(u16 addr, u8 b)
{
/* clang-format off */
__asm__ volatile (
"outb %1, %0"
:
: "d" ((u16)(addr_t)addr), "a" (b)
: "d" (addr), "a" (b)
: );
/* clang-format on */

return;
}


static inline u16 hal_inw(void *addr)
static inline u16 hal_inw(u16 addr)
{
u16 w;

/* clang-format off */
__asm__ volatile (
"inw %1, %0\n\t"
: "=a" (w)
: "d" ((u16)(addr_t)addr)
: "d" (addr)
: );
/* clang-format on */

return w;
}


static inline void hal_outw(void *addr, u16 w)
static inline void hal_outw(u16 addr, u16 w)
{
/* clang-format off */
__asm__ volatile (
"outw %1, %0"
:
: "d" ((u16)(addr_t)addr), "a" (w)
: "d" (addr), "a" (w)
: );
/* clang-format on */

return;
}


static inline u32 hal_inl(void *addr)
static inline u32 hal_inl(u16 addr)
{
u32 l;

Expand All @@ -96,7 +96,7 @@ static inline u32 hal_inl(void *addr)
}


static inline void hal_outl(void *addr, u32 l)
static inline void hal_outl(u16 addr, u32 l)
{
/* clang-format off */
__asm__ volatile (
Expand Down
4 changes: 2 additions & 2 deletions hal/ia32/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ int _hal_gasWrite32(hal_gasMapped_t *gas, u32 offset, u32 val)
ret = 0;
break;
case GAS_ADDRESS_SPACE_ID_IOPORT:
hal_outl(gas->address + offset, val);
hal_outl((u16)(addr_t)(gas->address + offset), val);
ret = 0;
break;
case GAS_ADDRESS_SPACE_ID_PCI:
Expand Down Expand Up @@ -261,7 +261,7 @@ int _hal_gasRead32(hal_gasMapped_t *gas, u32 offset, u32 *val)
ret = 0;
break;
case GAS_ADDRESS_SPACE_ID_IOPORT:
*val = hal_inl(gas->address + offset);
*val = hal_inl((u16)(addr_t)(gas->address + offset));
ret = 0;
break;
case GAS_ADDRESS_SPACE_ID_PCI:
Expand Down
8 changes: 4 additions & 4 deletions hal/ia32/pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ struct {
/* Reads word from PCI configuration space */
static u32 _hal_pciGet(u8 bus, u8 dev, u8 func, u8 reg)
{
hal_outl((void *)0xcf8, 0x80000000 | ((u32)bus << 16 ) | ((u32)dev << 11) | ((u32)func << 8) | (reg << 2));
return hal_inl((void *)0xcfc);
hal_outl((u16)0xcf8, 0x80000000 | ((u32)bus << 16) | ((u32)dev << 11) | ((u32)func << 8) | (reg << 2));
return hal_inl((u16)0xcfc);
}


/* Writes word to PCI configuration space */
static void _hal_pciSet(u8 bus, u8 dev, u8 func, u8 reg, u32 val)
{
hal_outl((void *)0xcf8, 0x80000000 | ((u32)bus << 16 ) | ((u32)dev << 11) | ((u32)func << 8) | (reg << 2));
hal_outl((void *)0xcfc, val);
hal_outl((u16)0xcf8, 0x80000000 | ((u32)bus << 16) | ((u32)dev << 11) | ((u32)func << 8) | (reg << 2));
hal_outl((u16)0xcfc, val);
}


Expand Down

0 comments on commit ba7788b

Please sign in to comment.