aboutsummaryrefslogtreecommitdiff
path: root/mubios/arch/interrupt.S
blob: 0822b1aa7b24d5d23a7d57c170ffff9a68fabc6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# 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.

	.intel_syntax noprefix
	.code16

	.section .text16.irq, "ax"

	.extern enter_protected_service

	.global int1a_entry
	.type int1a_entry, @function

int1a_entry:
	cmp ah, 0x00
	jne int1a_return

	push ds
	push bx

	xor bx, bx
	mov ds, bx

	mov bx, 0x046C
	mov cx, word ptr [bx + 2]
	mov dx, word ptr [bx]

	mov al, byte ptr [0x0470]
	mov byte ptr [0x0470], 0
	mov ah, 0x00

	pop bx
	pop ds

int1a_return:
	iret

	.macro BIOS_SERVICE_ENTRY name, vector
	.global \name
	.type \name, @function

\name:
		# Build struct bios_regs on the interrupted real-mode stack.
		push 0
		push es
		push ds
		push bp
		push di
		push si
		push dx
		push cx
		push bx
		push ax

		mov bp, sp
		mov ax, word ptr [bp + 24]
		mov word ptr [bp + 18], ax

		# ESI = linear address of struct bios_regs.
		movzx esi, sp
		xor eax, eax
		mov ax, ss
		shl eax, 4
		add esi, eax

		# EBP = original SS:SP return point, packed as SS:SP.
		movzx ebp, sp
		sub ebp, 2
		xor eax, eax
		mov ax, ss
		shl eax, 16
		or ebp, eax

		mov edi, \vector
		call enter_protected_service

		# Restore the context modified by the C service.
		pop ax
		pop bx
		pop cx
		pop dx
		pop si
		pop di
		pop bp
		pop ds
		pop es
		add sp, 2
		iret
	.endm

	BIOS_SERVICE_ENTRY int10_entry, 0x10
	BIOS_SERVICE_ENTRY int13_entry, 0x13