aboutsummaryrefslogtreecommitdiff
path: root/mubios/include
diff options
context:
space:
mode:
Diffstat (limited to 'mubios/include')
-rw-r--r--mubios/include/io.h21
-rw-r--r--mubios/include/vbe.h75
-rw-r--r--mubios/include/vga.h60
3 files changed, 156 insertions, 0 deletions
diff --git a/mubios/include/io.h b/mubios/include/io.h
index cedd1c1..a056c13 100644
--- a/mubios/include/io.h
+++ b/mubios/include/io.h
@@ -50,4 +50,25 @@ io_in16 (u16 port)
return value;
}
+static inline void
+io_out16 (u16 port, u16 value)
+{
+ __asm__ volatile ("outw %0, %1" : : "a"(value), "Nd"(port));
+}
+
+static inline u32
+io_in32 (u16 port)
+{
+ u32 value;
+
+ __asm__ volatile ("inl %1, %0" : "=a"(value) : "Nd"(port));
+ return value;
+}
+
+static inline void
+io_out32 (u16 port, u32 value)
+{
+ __asm__ volatile ("outl %0, %1" : : "a"(value), "Nd"(port));
+}
+
#endif // MUBIOS_IO_H
diff --git a/mubios/include/vbe.h b/mubios/include/vbe.h
new file mode 100644
index 0000000..eea2bd2
--- /dev/null
+++ b/mubios/include/vbe.h
@@ -0,0 +1,75 @@
+/*
+ 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/>.
+ */
+
+#ifndef MUBIOS_VBE_H
+#define MUBIOS_VBE_H
+
+#include "bios.h"
+
+#define VBE_MODE_COUNT 15u
+#define VBE_MODE_LINEAR 0x4000u
+#define VBE_MODE_PRESERVE 0x8000u
+#define VBE_OK 0x004Fu
+#define VBE_FAILED 0x014Fu
+#define VBE_UNSUPPORTED 0x024Fu
+
+#define DISPI_XRES 1u
+#define DISPI_YRES 2u
+#define DISPI_BPP 3u
+#define DISPI_ENABLE 4u
+#define DISPI_BANK 5u
+#define DISPI_VIRT_WIDTH 6u
+#define DISPI_VIRT_HEIGHT 7u
+#define DISPI_X_OFFSET 8u
+#define DISPI_Y_OFFSET 9u
+
+struct vbe_mode
+{
+ u16 number;
+ u16 width;
+ u16 height;
+ u16 bpp;
+};
+
+struct vbe_state
+{
+ u32 framebuffer;
+ u32 memory_size;
+ u16 max_width;
+ u16 max_height;
+ u16 max_bpp;
+ u16 current_mode;
+ u16 mode_list[VBE_MODE_COUNT + 1u];
+ u8 present;
+};
+
+extern struct vbe_state vbe;
+
+void vbe_init (void);
+void vbe_leave_graphics (void);
+u16 vbe_read (u16 index);
+void vbe_write (u16 index, u16 value);
+const struct vbe_mode *vbe_find_mode (u16 number);
+u16 vbe_set_mode (u16 request);
+u16 vbe_get_mode (u16 *number);
+void vbe_service (struct bios_regs *regs);
+
+#endif
diff --git a/mubios/include/vga.h b/mubios/include/vga.h
new file mode 100644
index 0000000..5b69671
--- /dev/null
+++ b/mubios/include/vga.h
@@ -0,0 +1,60 @@
+/*
+ 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/>.
+ */
+
+#ifndef MUBIOS_VGA_H
+#define MUBIOS_VGA_H
+
+#include "bios.h"
+
+#define VGA_TEXT_BASE 0x000B8000u
+#define VGA_COLUMNS 80u
+#define VGA_ROWS 25u
+#define VGA_TEXT_CELLS (VGA_COLUMNS * VGA_ROWS)
+#define VGA_PAGE_SIZE 0x1000u
+#define VGA_PAGE_COUNT 8u
+#define VGA_FONT_HEIGHT 16u
+
+/* All BDA constants below are offsets relative to MUBIOS_BDA_BASE. */
+#define BDA_VIDEO_MODE 0x49u
+#define BDA_VIDEO_COLUMNS 0x4Au
+#define BDA_VIDEO_PAGE_SIZE 0x4Cu
+#define BDA_VIDEO_PAGE_START 0x4Eu
+#define BDA_CURSOR_BASE 0x50u
+#define BDA_CURSOR_SHAPE 0x60u
+#define BDA_VIDEO_PAGE 0x62u
+#define BDA_VIDEO_CRTC 0x63u
+#define BDA_VIDEO_MSR 0x65u
+#define BDA_VIDEO_PALETTE 0x66u
+#define BDA_VIDEO_ROWS 0x84u
+#define BDA_VIDEO_HEIGHT 0x85u
+#define BDA_VIDEO_CTL 0x87u
+#define BDA_VIDEO_SWITCHES 0x88u
+#define BDA_VIDEO_MODESET_CTL 0x89u
+#define BDA_VIDEO_DCC 0x8Au
+
+extern const u8 vga_font_8x16[256 * VGA_FONT_HEIGHT];
+
+void vga_text_mode_set (u8 preserve);
+void vga_set_cursor_shape (u16 shape);
+void vga_set_cursor_position (u8 page, u16 position);
+void vga_set_active_page (u8 page);
+
+#endif