From 75f21a5124cc4ed542c8faff64a36c68bb7fbe57 Mon Sep 17 00:00:00 2001 From: Richard Qin Date: Sun, 8 Nov 2026 04:34:02 +0800 Subject: [mubios] Create 16-bit entry points for IRQ0/IRQ1 and install the IVT vectors. Signed-off-by: Richard Qin --- mubios/arch/irq.S | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ mubios/core/bda.c | 32 ++++++++++++++++++++++++++++++++ mubios/core/post.c | 4 +++- mubios/include/bios.h | 2 ++ mubios/linker.ld | 4 ++++ 5 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 mubios/arch/irq.S diff --git a/mubios/arch/irq.S b/mubios/arch/irq.S new file mode 100644 index 0000000..6eea350 --- /dev/null +++ b/mubios/arch/irq.S @@ -0,0 +1,51 @@ +# 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 +# . + + .intel_syntax noprefix + .code16 + + .section .text16.irq, "ax" + + .global irq0_entry + .type irq0_entry, @function + +irq0_entry: + push ax + + # Acknowledge IRQ0 on the master PIC. + mov al, 0x20 + out 0x20, al + + pop ax + iret + + .global irq1_entry + .type irq1_entry, @function + +irq1_entry: + push ax + + # Read the PS/2 scan code before sending EOI. + in al, 0x60 + + mov al, 0x20 + out 0x20, al + + pop ax + iret diff --git a/mubios/core/bda.c b/mubios/core/bda.c index d626963..c2ecfb1 100644 --- a/mubios/core/bda.c +++ b/mubios/core/bda.c @@ -45,3 +45,35 @@ bda_init (void) store_u16 (bda + BDA_CONVENTIONAL_MEMORY_OFFSET, (u16)(ebda_base >> 10)); } + +struct ivt_entry +{ + u16 offset; + u16 segment; +}; + +extern u8 __rom_start[]; +extern void irq0_entry (void); +extern void irq1_entry (void); + +static void +install_ivt_entry (u8 vector, void (*handler) (void)) +{ + volatile struct ivt_entry *ivt; + u32 rom_base; + u32 handler_address; + + ivt = (volatile struct ivt_entry *)MUBIOS_IVT_BASE; + rom_base = (u32)__rom_start; + handler_address = (u32)handler; + + ivt[vector].offset = (u16)(handler_address - rom_base); + ivt[vector].segment = (u16)(rom_base >> 4); +} + +void +ivt_init (void) +{ + install_ivt_entry (0x08u, irq0_entry); + install_ivt_entry (0x09u, irq1_entry); +} diff --git a/mubios/core/post.c b/mubios/core/post.c index afad12b..34ee715 100644 --- a/mubios/core/post.c +++ b/mubios/core/post.c @@ -30,8 +30,10 @@ post_main (void) memory_init (); bda_init (); + ivt_init(); + pic_init (); pit_init (); - serial_write ("mubios: PIC/PIT initialized\r\n"); + serial_write ("mubios: IVT/PIC/PIT initialized\r\n"); } diff --git a/mubios/include/bios.h b/mubios/include/bios.h index 3df9846..e524682 100644 --- a/mubios/include/bios.h +++ b/mubios/include/bios.h @@ -47,4 +47,6 @@ void serial_write (const char *text); void pic_init (void); void pit_init (void); +void ivt_init (void); + #endif // MUBIOS_BIOS_H diff --git a/mubios/linker.ld b/mubios/linker.ld index 004c1bc..5dee699 100644 --- a/mubios/linker.ld +++ b/mubios/linker.ld @@ -43,6 +43,10 @@ SECTIONS { KEEP(*(.text16.mode)) } > ROM + .text16.irq : + { + KEEP(*(.text16.irq)) + } > ROM .text16 : { KEEP(*(.text16.mode)) -- cgit v1.2.3