difference of 'INT' instruction between Linux and Windows

一世执手 提交于 2020-11-29 10:13:48

问题


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 assembly code:

mov ah, 2
mov dl, 'A'
int 0x21

This code prints 'A' to the screen. it is for MS-DOS.

mov eax, 1
mov ebx, 0
int 0x80

This code makes program to exit. it is for Linux. The last one:

mov ah, 2
mov al, 1
mov ch, 0
mov cl, 2
mov dh, 0
mov dl, 0
int 0x13

I wrote this code to copy kernel code from disk. This code is included in MBR sector. so there is no operating system when this code is executed. I have one question on here.

Let's assume that someone executes 'int' instruction to invoke interrupt and if that 'int' instruction is executed on MBR sector, it invokes BIOS routine. But I wonder if that 'int' instruction is executed on Linux or Windows, what happens ? does it refer to Linux/Windows interrupt vector or BIOS routine same like the situation on MBR sector ?

Frankly, I tested that trying to execute the first code on Linux, but it didn't work. I think the result of 'int' instruction depends on Operating System. if it isn't truth, Does anyone can tell me truth or any idea ?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/42439538/difference-of-int-instruction-between-linux-and-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!