aboutsummaryrefslogtreecommitdiff
path: root/devices
diff options
context:
space:
mode:
Diffstat (limited to 'devices')
-rw-r--r--devices/i8042.c25
-rw-r--r--devices/mouse.c26
-rw-r--r--devices/pckbd.c16
-rw-r--r--devices/pic_8259.c24
-rw-r--r--devices/uart/uart_16550.c29
-rw-r--r--devices/uart/uart_16550.h56
-rw-r--r--devices/vga.c30
-rw-r--r--devices/vga.h8
8 files changed, 113 insertions, 101 deletions
diff --git a/devices/i8042.c b/devices/i8042.c
index c612e6d..4805529 100644
--- a/devices/i8042.c
+++ b/devices/i8042.c
@@ -8,8 +8,8 @@
#include <stdio.h>
#include <sys/io.h>
-// r status register
-// w command register
+/* r status register */
+/* w command register */
#define comm_port 0x64
#define comm_enable_first_ps2 0xae
#define comm_enable_second_ps2 0xa8
@@ -19,13 +19,15 @@
#define data_port 0x60
#define data_enable_scanning 0xf4
-// TODO: All output to port 0x60 or 0x64 must be preceded by waiting for bit 1 (value=2) of port 0x64 to become clear.
-// TODO: Similarly, bytes cannot be read from port 0x60 until bit 0 (value=1) of port 0x64 is set.
+/* TODO: All output to port 0x60 or 0x64 must be preceded by waiting for bit 1 (value=2) of port 0x64 to become clear.
+ * TODO: Similarly, bytes cannot be read from port 0x60 until bit 0 (value=1) of port 0x64 is set. */
void
ps2_ctrl_init()
{
- // eat all previous keystrikes
+ int i;
+
+ /* eat all previous keystrikes */
while (inb(comm_port) & 0x1) inb(data_port);
uint8_t test;
@@ -39,30 +41,30 @@ ps2_ctrl_init()
test = inb(data_port);
printf("i8042: port2 test 0xa9:%x %s\n", test, test == 0x00 ? "ok" : "failed");
- // printf("8042: init keyboard\n");
+ /* printf("8042: init keyboard\n"); */
outb(comm_enable_first_ps2, comm_port);
outb(comm_enable_second_ps2, comm_port);
- // resets the cpu
- // outb(0xfe, 0x64);
+ /* resets the cpu */
+ /* outb(0xfe, 0x64); */
outb(0xf2, 0x60);
printf("i8042: id port1: ");
while ((inb(0x64) & 0x01) == 0) {}
- for (int i = 0; i < 3; ++i) printf("%x ", inb(0x60));
+ for (i = 0; i < 3; ++i) printf("%x ", inb(0x60));
printf("\n");
outb(0xd4, 0x64);
outb(0xf2, 0x60);
printf("i8042: id port2: ");
while ((inb(0x64) & 0x01) == 0) {}
- for (int i = 0; i < 3; ++i) printf("%x ", inb(0x60));
+ for (i = 0; i < 3; ++i) printf("%x ", inb(0x60));
printf("\n");
outb(comm_read_ctrl_config, comm_port);
uint8_t conf = (inb(data_port) | 1) & ~0x10;
- conf |= 0x22; // mouse
+ conf |= 0x22; /* mouse */
outb(comm_write_ctrl_config, comm_port);
outb(conf, data_port);
@@ -81,7 +83,6 @@ ps2_read_port1()
unsigned char
ps2_read_port2()
{
-
outb(0xd4, 0x64);
return inb(0x60);
}
diff --git a/devices/mouse.c b/devices/mouse.c
index a950e8c..a03388a 100644
--- a/devices/mouse.c
+++ b/devices/mouse.c
@@ -7,29 +7,33 @@
void
mouse_init()
{
- // Sending a command or data byte to the mouse (to port 0x60) must be preceded by sending a 0xD4 byte to port 0x64
- // (with appropriate waits on port 0x64, bit 1, before sending each output byte). Note: this 0xD4 byte does not
- // generate any ACK, from either the keyboard or mouse.
+ int i;
- // enable second ps/2
- // outb(0xa8, 0x64);
+ /* Sending a command or data byte to the mouse (to port 0x60) must be preceded by sending a 0xD4 byte to port 0x64
+ * (with appropriate waits on port 0x64, bit 1, before sending each output byte). Note: this 0xD4 byte does not
+ * generate any ACK, from either the keyboard or mouse. */
- // outb(0x64, 0xd4);
- // outb(0x60, 0xf4);
- // printf("mouse_init: enable streaming(0xf4): %x\n", inb(0x60));
+ /* enable second ps/2 */
+ /* outb(0xa8, 0x64); */
+
+ /* outb(0x64, 0xd4); */
+ /* outb(0x60, 0xf4); */
+ /* printf("mouse_init: enable streaming(0xf4): %x\n", inb(0x60)); */
outb(0xd4, 0x64);
- outb(0xeb, 0x60); // single packet
+ outb(0xeb, 0x60); /* single packet */
printf("mouse_init: single packet 0xeb\n");
while ((inb(0x64) & 0x01) == 0) {}
- for (int i = 0; i < 10; ++i) printf("%x ", inb(0x60));
+ for (i = 0; i < 10; ++i) printf("%x ", inb(0x60));
printf("\n");
}
void
mouse_packet()
{
+ int i;
+
printf("mouse packet: ");
- for (int i = 0; i < 4; ++i) printf("%x ", ps2_read_port2());
+ for (i = 0; i < 4; ++i) printf("%x ", ps2_read_port2());
printf("\n");
}
diff --git a/devices/pckbd.c b/devices/pckbd.c
index d550f91..0e99fe6 100644
--- a/devices/pckbd.c
+++ b/devices/pckbd.c
@@ -26,22 +26,22 @@ ps2_keyboard_irq_handler()
const uint8_t key = ps2_read_port1();
switch (key) {
- case 0x2a: // left shift down
- case 0x36: // right shift down
+ case 0x2a: /* left shift down */
+ case 0x36: /* right shift down */
shift_case = 1;
return;
- case 0xaa: // left shift up
- case 0xb6: // right shift up
+ case 0xaa: /* left shift up */
+ case 0xb6: /* right shift up */
shift_case = 0;
return;
- case 0x5b: // left meta
- case 0x5c: // right meta
+ case 0x5b: /* left meta */
+ case 0x5c: /* right meta */
return;
- case 0x58: // F12
- // vga_clear(VGA_COLOR_LIGHT_BLUE, VGA_COLOR_LIGHT_GREY);
+ case 0x58: /* F12 */
+ /* vga_clear(VGA_COLOR_LIGHT_BLUE, VGA_COLOR_LIGHT_GREY); */
return;
}
diff --git a/devices/pic_8259.c b/devices/pic_8259.c
index 75a2d0e..7b4807c 100644
--- a/devices/pic_8259.c
+++ b/devices/pic_8259.c
@@ -6,11 +6,11 @@
#define PIC2 0xa0
#define DATA 1
-// initialization
+/* initialization */
#define ICW1_INIT 0x10
-// TODO
+/* TODO */
#define ICW1_ICW4 0x01
-// 8086/88 mode
+/* 8086/88 mode */
#define ICW4_8086 0x01
void
@@ -19,16 +19,16 @@ pic_init()
outb(ICW1_INIT | ICW1_ICW4, PIC1);
outb(ICW1_INIT | ICW1_ICW4, PIC2);
- outb(0x20, PIC1 + DATA); // offset 0x20
- outb(0x28, PIC2 + DATA); // offset 0x28
+ outb(0x20, PIC1 + DATA); /* offset 0x20 */
+ outb(0x28, PIC2 + DATA); /* offset 0x28 */
- outb(0x04, PIC1 + DATA); // tell master pic there is a slave pic
- outb(0x02, PIC2 + DATA); // tell slave pic its cascade identity
+ outb(0x04, PIC1 + DATA); /* tell master pic there is a slave pic */
+ outb(0x02, PIC2 + DATA); /* tell slave pic its cascade identity */
outb(ICW4_8086, PIC1 + DATA);
outb(ICW4_8086, PIC2 + DATA);
- // PIC masks
+ /* PIC masks */
outb(0xff, PIC1 + DATA);
outb(0xff, PIC2 + DATA);
}
@@ -37,13 +37,13 @@ void
pic_enable()
{
unsigned char mask1 = 0xff;
- mask1 &= ~(1 << 0); // irq0 timer
- mask1 &= ~(1 << 1); // irq1 keyboard
- mask1 &= ~(1 << 2); // irq1 cascade
+ mask1 &= ~(1 << 0); /* irq0 timer */
+ mask1 &= ~(1 << 1); /* irq1 keyboard */
+ mask1 &= ~(1 << 2); /* irq1 cascade */
outb(mask1, PIC1 + DATA);
unsigned char mask2 = 0xff;
- mask2 &= ~(1 << 4); // irq12 mouse
+ mask2 &= ~(1 << 4); /* irq12 mouse */
outb(mask2, PIC2 + DATA);
enable_interrupts();
diff --git a/devices/uart/uart_16550.c b/devices/uart/uart_16550.c
index 47a7fd3..0e19842 100644
--- a/devices/uart/uart_16550.c
+++ b/devices/uart/uart_16550.c
@@ -22,6 +22,7 @@ uart_putc(const FILE *self, char a)
int
uart_puts(const FILE *self, const char *string, int length)
{
+ int i;
int written = 0;
if (length == -1)
@@ -32,7 +33,7 @@ uart_puts(const FILE *self, const char *string, int length)
}
else
- for (int i = 0; i < length; ++i) {
+ for (i = 0; i < length; ++i) {
uart_putc(self, string[i]);
++written;
}
@@ -50,22 +51,22 @@ FILE uart_stream;
FILE *
uart_init(enum UART port)
{
- outb(0x00, port + 1); // Disable all interrupts
- outb(0x80, port + 3); // Enable DLAB (set baud rate divisor)
- outb(0x03, port + 0); // Set divisor to 3 (lo byte) 38400 baud
- outb(0x00, port + 1); // (hi byte)
- outb(0x03, port + 3); // 8 bits, no parity, one stop bit
- outb(0xc7, port + 2); // Enable FIFO, clear them, with 14-byte threshold
- outb(0x0b, port + 4); // IRQs enabled, RTS/DSR set
- outb(0x1e, port + 4); // Set in loopback mode, test the serial chip
- outb(0xae, port + 0); // Test serial chip (send byte 0xAE and check if serial
- // returns same byte)
+ outb(0x00, port + 1); /* Disable all interrupts */
+ outb(0x80, port + 3); /* Enable DLAB (set baud rate divisor) */
+ outb(0x03, port + 0); /* Set divisor to 3 (lo byte) 38400 baud */
+ outb(0x00, port + 1); /* (hi byte) */
+ outb(0x03, port + 3); /* 8 bits, no parity, one stop bit */
+ outb(0xc7, port + 2); /* Enable FIFO, clear them, with 14-byte threshold */
+ outb(0x0b, port + 4); /* IRQs enabled, RTS/DSR set */
+ outb(0x1e, port + 4); /* Set in loopback mode, test the serial chip */
+ outb(0xae, port + 0); /* Test serial chip (send byte 0xAE and check if serial */
+ /* returns same byte) */
- // Check if serial is faulty (i.e: not same byte as sent)
+ /* Check if serial is faulty (i.e: not same byte as sent) */
if (inb(port + 0) != 0xae) { return NULL; }
- // If serial is not faulty set it in normal operation mode
- // (not-loopback with IRQs enabled and OUT#1 and OUT#2 bits enabled)
+ /* If serial is not faulty set it in normal operation mode */
+ /* (not-loopback with IRQs enabled and OUT#1 and OUT#2 bits enabled) */
outb(0x0f, port + 4);
uart_stream.id = port;
uart_stream.putc = &uart_putc;
diff --git a/devices/uart/uart_16550.h b/devices/uart/uart_16550.h
index f8e1931..176dea2 100644
--- a/devices/uart/uart_16550.h
+++ b/devices/uart/uart_16550.h
@@ -8,42 +8,42 @@ int uart_puts(const FILE *self, const char *string, int length);
void uart_flush(__attribute__((unused)) const FILE *self);
enum uart_16550_offset {
- Data = 0, // read from receive buffer / write to transmit buffer | BaudDiv_l
- InterruptControl = 1, // interrupt enable | BaudDiv_h
- FifoControl = 2, // interrupt ID and FIFO control
- LineControl = 3, // most significant bit is the DLAB
+ Data = 0, /* read from receive buffer / write to transmit buffer | BaudDiv_l */
+ InterruptControl = 1, /* interrupt enable | BaudDiv_h */
+ FifoControl = 2, /* interrupt ID and FIFO control */
+ LineControl = 3, /* most significant bit is the DLAB */
ModemControl = 4,
LineStatus = 5,
ModemStatus = 6,
Scratch = 7,
};
-// Line Control
-// | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
-// |dla| | parity | s | data |
+/* Line Control
+ * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
+ * |dla| | parity | s | data | */
enum LineControl {
- d5bit = 0x00, // 0000 0000 data bits
- d6bit = 0x01, // 0000 0001
- d7bit = 0x02, // 0000 0010
- d8bit = 0x03, // 0000 0011
- // none = 0b00000000, // parity bits
- odd = 0x08, // 0000 1000
- even = 0x18, // 0001 1000
- mark = 0x28, // 0010 1000
- space = 0x38, // 0011 1000
- // s1bit = 0b00000000, // stop bits
- s2bit = 0x04, // 0000 0100 1.5 for 5bit data; 2 otherwise
- dlab = 0x80 // 1000 0000 divisor latch access bit
+ d5bit = 0x00, /* 0000 0000 data bits */
+ d6bit = 0x01, /* 0000 0001 */
+ d7bit = 0x02, /* 0000 0010 */
+ d8bit = 0x03, /* 0000 0011 */
+ /* none = 0b00000000, // parity bits */
+ odd = 0x08, /* 0000 1000 */
+ even = 0x18, /* 0001 1000 */
+ mark = 0x28, /* 0010 1000 */
+ space = 0x38, /* 0011 1000 */
+ /* s1bit = 0b00000000, // stop bits */
+ s2bit = 0x04, /* 0000 0100 1.5 for 5bit data; 2 otherwise */
+ dlab = 0x80 /* 1000 0000 divisor latch access bit */
};
-// Line Status Register
+/* Line Status Register */
enum LineStatus {
- DR = (1 << 0), // data ready: see if there is data to read
- OE = (1 << 1), // overrun error: see if there has been data lost
- PE = (1 << 2), // parity error: see if there was error in transmission
- FE = (1 << 3), // framing error: see if a stop bit was missing
- BI = (1 << 4), // break indicator: see if there is a break in data input
- THRE = (1 << 5), // transmitter holding register empty: see if transmission buffer is empty
- TEMT = (1 << 6), // transmitter empty: see if transmitter is not doing anything
- ERRO = (1 << 7), // impending error: see if there is an error with a word in the input buffer
+ DR = (1 << 0), /* data ready: see if there is data to read */
+ OE = (1 << 1), /* overrun error: see if there has been data lost */
+ PE = (1 << 2), /* parity error: see if there was error in transmission */
+ FE = (1 << 3), /* framing error: see if a stop bit was missing */
+ BI = (1 << 4), /* break indicator: see if there is a break in data input */
+ THRE = (1 << 5), /* transmitter holding register empty: see if transmission buffer is empty */
+ TEMT = (1 << 6), /* transmitter empty: see if transmitter is not doing anything */
+ ERRO = (1 << 7), /* impending error: see if there is an error with a word in the input buffer */
};
diff --git a/devices/vga.c b/devices/vga.c
index e4831b8..b2a6da4 100644
--- a/devices/vga.c
+++ b/devices/vga.c
@@ -16,7 +16,7 @@ struct __attribute__((packed)) VGAEntry {
uint8_t foreground : 4;
uint8_t background : 4;
};
-_Static_assert(sizeof(struct VGAEntry) == 2, "sizeof VGAEntry");
+/* TODO _Static_assert(sizeof(struct VGAEntry) == 2, "sizeof VGAEntry"); */
const int width = 80;
const int height = 25;
@@ -25,7 +25,7 @@ struct VGAEntry *buffer;
int col = 0;
int row = 0;
-// *** Cursor ***
+/* *** Cursor *** */
void
vga_enable_cursor(unsigned char start, unsigned char end)
{
@@ -55,10 +55,12 @@ vga_update_cursor(void)
outb((pos >> 8) & 0xff, cga_dat_port);
}
-// *** Text Mode Output ***
+/* *** Text Mode Output *** */
void
vga_putc(__attribute__((unused)) const FILE *self, char a)
{
+ int i, x, y;
+
switch (a) {
case '\n':
col = 0;
@@ -82,15 +84,15 @@ vga_putc(__attribute__((unused)) const FILE *self, char a)
}
if (row == height) {
- // scroll up
- for (int y = 1; y < height; ++y)
- for (int x = 0; x < width; ++x) {
+ /* scroll up */
+ for (y = 1; y < height; ++y)
+ for (x = 0; x < width; ++x) {
const int prev = (y - 1) * width + x;
const int curr = y * width + x;
buffer[prev] = buffer[curr];
}
- // blank out last row
- for (int i = (height - 1) * width; i < height * width; ++i) buffer[i].text = ' ';
+ /* blank out last row */
+ for (i = (height - 1) * width; i < height * width; ++i) buffer[i].text = ' ';
--row;
}
}
@@ -98,6 +100,8 @@ vga_putc(__attribute__((unused)) const FILE *self, char a)
int
vga_puts(const FILE *self, const char *string, int len)
{
+ int i;
+
int written = 0;
if (len == -1)
while (*string != '\0') {
@@ -107,7 +111,7 @@ vga_puts(const FILE *self, const char *string, int len)
}
else
- for (int i = 0; i < len; ++i) {
+ for (i = 0; i < len; ++i) {
vga_putc(self, string[i]);
++written;
}
@@ -120,7 +124,7 @@ vga_flush(__attribute__((unused)) const FILE *self)
vga_update_cursor();
}
-// *** Text Mode ***
+/* *** Text Mode *** */
FILE vga_stream;
FILE *
@@ -140,8 +144,10 @@ vga_init(void *addr)
void
vga_clear(enum vga_color foreground, enum vga_color background)
{
- for (int y = 0; y < height; ++y)
- for (int x = 0; x < width; ++x) {
+ int x, y;
+
+ for (y = 0; y < height; ++y)
+ for (x = 0; x < width; ++x) {
const int index = y * width + x;
buffer[index].text = ' ';
buffer[index].foreground = foreground;
diff --git a/devices/vga.h b/devices/vga.h
index bd77e2a..cd3a272 100644
--- a/devices/vga.h
+++ b/devices/vga.h
@@ -25,9 +25,9 @@ enum vga_color {
FILE *vga_init(void *addr);
void vga_clear(enum vga_color foreground, enum vga_color background);
-// void vga_putc(char a);
-// void vga_puts(const char *string, int len);
+/* void vga_putc(char a); */
+/* void vga_puts(const char *string, int len); */
-// void vga_enable_cursor(unsigned char start, unsigned char end);
-// void vga_disable_cursor();
+/* void vga_enable_cursor(unsigned char start, unsigned char end); */
+/* void vga_disable_cursor(); */
void vga_update_cursor(void);