2 ; @file interrupts-asm.c
3 ; @brief Kernel's interruptions
4 ; @details About interrupts:
5 ; @details When interrupt handler is called on stack are: [esp]=old eip [esp+2]=old cs [esp+4] old flags
6 ; @details to use local interrupt's variables DS must be changed to local i.e. KERNEL_ADDRESS
7 ; @details all cs of interrupt handler are KERNEL_ADDRESS - only kernel should handle
8 ; @todo divZero is error handle, not only zero division https://gcc.gnu.org/onlinedocs/gcc/x86-Function-Attributes.html#x86-Function-Attributes see error code
16 ; @brief Set system interruptions
17 ; @details set syscall and errors handles
27 mov WORD[ds:bx+2], KERNEL_ADDRESS
28 mov WORD[ds:bx], divZero
31 mov WORD[ds:bx+2], KERNEL_ADDRESS
32 mov WORD[ds:bx], syscall
40 ; @brief add interruption
41 ; @details set *(number*4)=function
42 ; @details set *(number*4+2)=KERNEL_ADDRESS - only kernel can handle interruptions
43 ; @param number new interruption number [ebp+8]
44 ; @param function interruption handler [ebp+12]
53 mov ax, [ebp+8] ; set ax as parameter then ax*=4
59 mov WORD[ds:bx+2], KERNEL_ADDRESS
67 ; @brief System interruption 0x20
69 ; | AH | Description | AL | BX |
70 ; | :---: | :---------- | :-------- | :------------------------------------------------------------------- |
71 ; | 0 | putc() | character | |
72 ; | 1 | puts() | | address of string |
73 ; | 2 | puti() | | unsigned number |
74 ; | 3 | printf() | | address of first parameter on stack, next is 4B behind on stack etc. |
87 ; if not recognised print message
94 .message db "SYSCALL YAY!",0xa,0
97 ; al is character to put
105 ; bx is address of string to put
112 ; bx is number to print
128 ; zero division handler
136 cmp esi, 0 ; when C divides it uses idiv - 3 byte and divides by esi
138 add WORD[esp], 2 ; if esi register is divider then add 2 and 1 byte
139 .Csrc: ; if it is 'normal' div add 2 bytes
144 .err db "ERROR: Zero division!",0xa,0
146 %include "boot/io.asm"