I write some code to make my own operating system and study x86 assembly language, too. While studying x86 assembly language, I start wondering about interrupt. Look at below as
The int
instruction raises a software interrupt. This causes the CPU to execute an interrupt handler from the interrupt description table (IDT). On startup, the BIOS sets up an IDT with a number of interrupt handlers that perform some elementary services. DOS adds its own interrupt handlers to this table to provide DOS specific functionality.
Modern operating systems run in protected mode. In this mode, the BIOS services do not function as they are written to be executed in real mode. A modern operating system typically replaces the standard interrupt description table with a custom table. Thus, neither DOS nor BIOS services are available.
The INT instruction triggers an exception almost like a divide by zero causes an exception. The difference is that INT allows you to specify what exception you are triggering.
The operating system must define a table of exception and interrupt handlers. The location and size of the table is defined by hardware register IDTR. The various exceptions (like divide by zero) have an assigned exception number. (INT allows specifying any exception number.)
See https://en.wikipedia.org/wiki/Interrupt_descriptor_table
When an exception (or interrupt) occurs, the CPU uses the exception/interrupt number as an index into the table and calls the specific handler.
The operating system defines the table and the handlers for interrupts and exceptions so they are different amount operating systems.