aboutsummaryrefslogtreecommitdiff
path: root/mubios
diff options
context:
space:
mode:
Diffstat (limited to 'mubios')
-rw-r--r--mubios/core/post.c5
-rw-r--r--mubios/drivers/pic.c65
-rw-r--r--mubios/drivers/pit.c45
-rw-r--r--mubios/include/bios.h3
4 files changed, 117 insertions, 1 deletions
diff --git a/mubios/core/post.c b/mubios/core/post.c
index 69ad7e7..afad12b 100644
--- a/mubios/core/post.c
+++ b/mubios/core/post.c
@@ -30,5 +30,8 @@ post_main (void)
memory_init ();
bda_init ();
- serial_write ("mubios: memory initialized\r\n");
+ pic_init ();
+ pit_init ();
+
+ serial_write ("mubios: PIC/PIT initialized\r\n");
}
diff --git a/mubios/drivers/pic.c b/mubios/drivers/pic.c
new file mode 100644
index 0000000..099cee8
--- /dev/null
+++ b/mubios/drivers/pic.c
@@ -0,0 +1,65 @@
+/*
+ RCC-Project
+
+ Copyright (C) 2026 Richard Qin
+
+ This file is part of RCC-Project.
+
+ RCC-Project is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 3 of the License, or (at your option) any
+ later version.
+
+ RCC-Project is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ RCC-Project; see the file COPYING. If not see
+ <http://www.gnu.org/licenses/>.
+ */
+
+#include "bios.h"
+#include "io.h"
+
+#define PIC1_COMMAND 0x0020u
+#define PIC1_DATA 0x0021u
+#define PIC2_COMMAND 0x00A0u
+#define PIC2_DATA 0x00A1u
+
+#define PIC_ICW1_INIT 0x11u
+#define PIC_ICW4_8086 0x01u
+
+#define PIC1_VECTOR_BASE 0x08u
+#define PIC2_VECTOR_BASE 0x70u
+
+#define PIC1_CASCADE_ID 0x04u
+#define PIC2_CASCADE_ID 0x02u
+
+#define PIC1_MASK_DEFAULT 0xFBu
+#define PIC2_MASK_DEFAULT 0xFFu
+
+void
+pic_init (void)
+{
+ io_out8 (PIC1_COMMAND, PIC_ICW1_INIT);
+ io_out8(PIC2_COMMAND, PIC_ICW1_INIT);
+
+ io_out8(PIC1_DATA, PIC1_VECTOR_BASE);
+ io_out8 (PIC2_DATA, PIC2_VECTOR_BASE);
+
+ io_out8(PIC1_DATA, PIC1_CASCADE_ID);
+ io_out8 (PIC2_DATA, PIC2_CASCADE_ID);
+
+ io_out8(PIC1_DATA, PIC_ICW4_8086);
+ io_out8 (PIC2_DATA, PIC_ICW4_8086);
+
+ /*
+ * Keep the cascade line enabled.
+ * All actual hardware IRQ lines remain masked.
+ */
+ io_out8(PIC1_DATA, PIC1_MASK_DEFAULT);
+ io_out8 (PIC2_DATA, PIC2_MASK_DEFAULT);
+
+}
+
diff --git a/mubios/drivers/pit.c b/mubios/drivers/pit.c
new file mode 100644
index 0000000..4213940
--- /dev/null
+++ b/mubios/drivers/pit.c
@@ -0,0 +1,45 @@
+/*
+ RCC-Project
+
+ Copyright (C) 2026 Richard Qin
+
+ This file is part of RCC-Project.
+
+ RCC-Project is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 3 of the License, or (at your option) any
+ later version.
+
+ RCC-Project is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ RCC-Project; see the file COPYING. If not see
+ <http://www.gnu.org/licenses/>.
+ */
+
+#include "bios.h"
+#include "io.h"
+
+#define PIT_COUNTER0 0x0040u
+#define PIT_COMMAND 0x0043u
+
+#define PIT_SELECT_CHANNEL0 0x00u
+#define PIT_ACCESS_WORD 0x30u
+#define PIT_MODE_2 0x04u
+#define PIT_BINARY 0x00u
+
+#define PIT_COMMAND_CHANNEL0_MODE2 \
+ (PIT_SELECT_CHANNEL0 | PIT_ACCESS_WORD | PIT_MODE_2 | PIT_BINARY)
+
+void pit_init(void)
+{
+ io_out8 (PIT_COMMAND, PIT_COMMAND_CHANNEL0_MODE2);
+
+ /*
+ * A divisor of zero represents 65536.
+ */
+ io_out8 (PIT_COUNTER0, 0x00u);
+ io_out8 (PIT_COUNTER0, 0x00u);
+}
diff --git a/mubios/include/bios.h b/mubios/include/bios.h
index c3b5026..3df9846 100644
--- a/mubios/include/bios.h
+++ b/mubios/include/bios.h
@@ -44,4 +44,7 @@ void serial_init (void);
void serial_putc (u8 value);
void serial_write (const char *text);
+void pic_init (void);
+void pit_init (void);
+
#endif // MUBIOS_BIOS_H