-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkernel.asm
More file actions
78 lines (69 loc) · 1.62 KB
/
kernel.asm
File metadata and controls
78 lines (69 loc) · 1.62 KB
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
;kernel.asm
;Michael Black, 2007
;kernel.asm contains assembly functions that you can use in your kernel
.global _putInMemory
.global _interrupt
.global _makeInterrupt21
.extern _handleInterrupt21
;void putInMemory (int segment, int address, char character)
_putInMemory:
push bp
mov bp,sp
push ds
mov ax,[bp+4]
mov si,[bp+6]
mov cl,[bp+8]
mov ds,ax
mov [si],cl
pop ds
pop bp
ret
;int interrupt (int number, int AX, int BX, int CX, int DX)
_interrupt:
push bp
mov bp,sp
push ds ;use self-modifying code to call the right interrupt
mov ax,[bp+4] ;get the interrupt number in AL
mov bx,cs
mov ds,bx
mov si,#intr
mov [si+1],al ;change the 00 below to the contents of AL
pop ds
mov ax,[bp+6] ;get the other parameters AX, BX, CX, and DX
mov bx,[bp+8]
mov cx,[bp+10]
mov dx,[bp+12]
intr: int #0x00 ;call the interrupt (00 will be changed above)
mov ah,#0 ;we only want AL returned
pop bp
ret
;void makeInterrupt21()
;this sets up the interrupt 0x21 vector
;when an interrupt 0x21 is called in the future,
;_interrupt21ServiceRoutine will run
_makeInterrupt21:
;get the address of the service routine
mov dx,#_interrupt21ServiceRoutine
push ds
mov ax, #0 ;interrupts are in lowest memory
mov ds,ax
mov si,#0x84 ;interrupt 0x21 vector (21 * 4 = 84)
mov ax,cs ;have interrupt go to the current segment
mov [si+2],ax
mov [si],dx ;set up our vector
pop ds
ret
;this is called when interrupt 21 happens
;it will call your function:
;void handleInterrupt21 (int AX, int BX, int CX, int DX)
_interrupt21ServiceRoutine:
push dx
push cx
push bx
push ax
call _handleInterrupt21
pop ax
pop bx
pop cx
pop dx
iret