Guest User

Untitled

a guest
May 26th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.67 KB | None | 0 0
  1. sergey@COMPUTER:~/Рабочий стол/myOS_8.0T$ make mykernel.bin
  2. as --32 -o interruptstubs.o interruptstubs.s
  3. interruptstubs.s: Assembler messages:
  4. interruptstubs.s: Warning: конец файла не в конце строки; вставлен символ новой строки
  5. interruptstubs.s:8: Error: junk at end of line, first unrecognized character is `:'
  6. interruptstubs.s:27: Error: bad register name `%0x00+IRQ_BASE'
  7. interruptstubs.s:28: Error: bad register name `%0x01+IRQ_BASE'
  8. Makefile:12: ошибка выполнения рецепта для цели «interruptstubs.o»
  9. make: *** [interruptstubs.o] Ошибка 1
  10. sergey@COMPUTER:~/Рабочий стол/myOS_8.0T$
  11.  
  12. .set IRQ_BASE, 0x20
  13.  
  14. .section .text
  15.  
  16. .extern _ZN16InterruptManager15handleInterruptEhj
  17.  
  18. .global _ZN16InterruptManager22IgnoreInterruptRequestEv:
  19.  
  20.  
  21.  
  22. .macro HandleException num
  23.  
  24. .global _ZN16InterruptManager16HandleExceptionnum()Ev
  25. _ZN16InterruptManager15HandleExceptionnum()Ev:
  26. movb %num, (interruptnumber)
  27. jmp int_bottom
  28. .endm
  29.  
  30. .macro HandleInterruptRequest num
  31. .global _ZN16InterruptManager26HandleInterruptRequestnum()Ev
  32. _ZN16InterruptManager26HandleInterruptRequestnum()Ev:
  33. movb %num + IRQ_BASE, (interruptnumber)
  34. jmp int_bottom
  35. .endm
  36.  
  37. HandleInterruptRequest 0x00
  38. HandleInterruptRequest 0x01
  39.  
  40.  
  41.  
  42. int_bottom:
  43.  
  44. pusha
  45. pushl %ds
  46. pushl %es
  47. pushl %fs
  48. pushl %gs
  49.  
  50. pushl %esp
  51. push (interruptnumber)
  52. call _Z15handleInterrupthj
  53. # addl $5, %esp
  54. movl %eax, %esp
  55.  
  56. popl %gs
  57. popl %fs
  58. popl %es
  59. popl %ds
  60. popa
  61.  
  62. _ZN16InterruptManager22IgnoreInterruptRequestEv:
  63.  
  64. iret
  65.  
  66. .data
  67. interruptnumber: .byte 0
  68.  
  69. #include "interrupts.h"
  70.  
  71.  
  72. void printf(char* str);
  73.  
  74.  
  75. InterruptManager::GateDescriptor InterruptManager::InterruptDescriptorTable[256];
  76.  
  77. void InterruptManager::SetInterruptDescriptorTableEntry(
  78. uint8_t interruptNumber,
  79. uint16_t codeSegmentSelectorOffset,
  80. void (*handler)(),
  81. uint8_t DescriptorPrivilegeLevel,
  82. uint8_t DescriptorType)
  83. {
  84.  
  85. const uint8_t IDT_DESC_PRESENT = 0x80;
  86.  
  87. InterruptDescriptorTable[interruptNumber].handlerAddressLowBits = ((uint32_t)handler) & 0xFFFF;
  88. InterruptDescriptorTable[interruptNumber].handlerAddressHighBits = (((uint32_t)handler) >> 16) & 0xFFFF;
  89. InterruptDescriptorTable[interruptNumber].gdt_codeSegmentSelector = codeSegmentSelectorOffset;
  90. InterruptDescriptorTable[interruptNumber].access = IDT_DESC_PRESENT | DescriptorType | ((DescriptorPrivilegeLevel&3) << 5);
  91. InterruptDescriptorTable[interruptNumber].reserved = 0;
  92.  
  93. }
  94.  
  95. InterruptManager::InterruptManager(GlobalDescriptorTable* gdt)
  96. {
  97. uint16_t CodeSegment = gdt->CodeSegmentSelector();
  98. const uint8_t IDT_INTERRUPT_GATE = 0xE;
  99.  
  100. for(uint16_t i = 0; i < 256; i++)
  101. SetInterruptDescriptorTableEntry(i, CodeSegment, &IgnoreInterruptRequest, 0, IDT_INTERRUPT_GATE);
  102.  
  103. SetInterruptDescriptorTableEntry(0x20, CodeSegment, &HandleInterruptRequest0x00, 0, IDT_INTERRUPT_GATE);
  104. SetInterruptDescriptorTableEntry(0x21, CodeSegment, &HandleInterruptRequest0x01, 0, IDT_INTERRUPT_GATE);
  105.  
  106. InterruptDescriptorTablePointer idt;
  107. idt.size = 256 * sizeof(GateDescriptor) - 1;
  108. idt.base = (uint32_t)InterruptDescriptorTable;
  109. asm volatile("lidt %0" : : "m" (idt));
  110.  
  111. }
  112.  
  113. InterruptManager::~InterruptManager()
  114. {
  115. }
  116.  
  117. void InterruptManager::Activate()
  118. {
  119. asm("sti");
  120. }
  121.  
  122.  
  123.  
  124. uint32_t InterruptManager::handleInterrupt(uint8_t interruptNumber, uint32_t esp)
  125. {
  126.  
  127. printf(" INTERRUPT");
  128.  
  129. return esp;
  130. }
  131.  
  132. #ifndef __INTERRUPTS_H
  133. #define __INTERRUPTS_H
  134.  
  135. #include "types.h"
  136. #include "port.h"
  137. #include "gdt.h"
  138.  
  139.  
  140. class InterruptManager
  141. {
  142.  
  143. protected:
  144.  
  145. struct GateDescriptor
  146. {
  147. uint16_t handlerAddressLowBits;
  148. uint16_t gdt_codeSegmentSelector;
  149. uint8_t reserved;
  150. uint8_t access;
  151. uint16_t handlerAddressHighBits;
  152.  
  153.  
  154. } __attribute__((packed));
  155.  
  156. static GateDescriptor InterruptDescriptorTable[256];
  157.  
  158. struct InterruptDescriptorTablePointer
  159. {
  160. uint16_t size;
  161. uint32_t base;
  162. } __attribute__((packed));
  163.  
  164. static void SetInterruptDescriptorTableEntry(
  165. uint8_t interruptNumber,
  166. uint16_t codeSegmentSelectorOffset,
  167. void (*handler)(),
  168. uint8_t DescriptorPrivilegeLevel,
  169. uint8_t DescriptorType
  170. );
  171.  
  172. public:
  173.  
  174. InterruptManager(GlobalDescriptorTable* gdt);
  175. ~InterruptManager();
  176.  
  177. void Activate();
  178.  
  179. static uint32_t handleInterrupt(uint8_t interruptNumber, uint32_t esp);
  180.  
  181. static void IgnoreInterruptRequest();
  182. static void HandleInterruptRequest0x00();
  183. static void HandleInterruptRequest0x01();
  184. };
  185. #endif
  186.  
  187. sergey@COMPUTER:~/Рабочий стол/myOS_8.0T$ make mykernel.bin
  188. as --32 -o interruptstubs.o interruptstubs.s
  189. interruptstubs.s: Assembler messages:
  190. interruptstubs.s: Warning: конец файла не в конце строки; вставлен символ новой строки
  191. interruptstubs.s:22: Error: bad register name `%0x20+IRQ_BASE'
  192. interruptstubs.s:23: Error: bad register name `%0x21+IRQ_BASE'
  193. Makefile:12: ошибка выполнения рецепта для цели «interruptstubs.o»
  194. make: *** [interruptstubs.o] Ошибка 1
  195. sergey@COMPUTER:~/Рабочий стол/myOS_8.0T$
  196.  
  197. .global _ZN16InterruptManager22IgnoreInterruptRequestEv:
  198.  
  199. interruptstubs.s:8: Error: junk at end of line, first unrecognized character is `:'
  200.  
  201. .set IRQ_BASE, 0x20
  202.  
  203. .section .text
  204.  
  205. .extern _ZN16InterruptManager15handleInterruptEhj
  206.  
  207.  
  208. .macro HandleException num
  209. .global _ZN16InterruptManager19HandleExceptionnum()Ev
  210. _ZN16InterruptManager19HandleExceptionnum()Ev:
  211. movb $num, (interruptnumber)
  212. jmp int_bottom
  213. .endm
  214.  
  215. .macro HandleInterruptRequest num
  216. .global _ZN16InterruptManager26HandleInterruptRequestnum()Ev
  217. _ZN16InterruptManager26HandleInterruptRequestnum()Ev:
  218. movb $num + IRQ_BASE, (interruptnumber)
  219. pushl $0
  220. jmp int_bottom
  221. .endm
  222.  
  223. HandleException 0x00
  224. HandleException 0x01
  225. HandleException 0x02
  226. HandleException 0x03
  227. HandleException 0x04
  228. HandleException 0x05
  229. HandleException 0x06
  230. HandleException 0x07
  231. HandleException 0x08
  232. HandleException 0x09
  233. HandleException 0x0A
  234. HandleException 0x0B
  235. HandleException 0x0C
  236. HandleException 0x0D
  237. HandleException 0x0E
  238. HandleException 0x0F
  239. HandleException 0x10
  240. HandleException 0x11
  241. HandleException 0x12
  242. HandleException 0x13
  243.  
  244. HandleInterruptRequest 0x00
  245. HandleInterruptRequest 0x01
  246. HandleInterruptRequest 0x02
  247. HandleInterruptRequest 0x03
  248. HandleInterruptRequest 0x04
  249. HandleInterruptRequest 0x05
  250. HandleInterruptRequest 0x06
  251. HandleInterruptRequest 0x07
  252. HandleInterruptRequest 0x08
  253. HandleInterruptRequest 0x09
  254. HandleInterruptRequest 0x0A
  255. HandleInterruptRequest 0x0B
  256. HandleInterruptRequest 0x0C
  257. HandleInterruptRequest 0x0D
  258. HandleInterruptRequest 0x0E
  259. HandleInterruptRequest 0x0F
  260. HandleInterruptRequest 0x31
  261.  
  262. HandleInterruptRequest 0x80
  263.  
  264.  
  265.  
  266. int_bottom:
  267.  
  268. # save registers
  269. #pusha
  270. #pushl %ds
  271. #pushl %es
  272. #pushl %fs
  273. #pushl %gs
  274.  
  275. pushl %ebp
  276. pushl %edi
  277. pushl %esi
  278.  
  279. pushl %edx
  280. pushl %ecx
  281. pushl %ebx
  282. pushl %eax
  283.  
  284. # load ring 0 segment register
  285. #cld
  286. #mov $0x10, %eax
  287. #mov %eax, %eds
  288. #mov %eax, %ees
  289.  
  290. # call C++ Handler
  291. pushl %esp
  292. push (interruptnumber)
  293. call _ZN16InterruptManager15handleInterruptEhj
  294. # add $5, %esp
  295. mov %eax, %esp # switch the stack
  296.  
  297. # restore registers
  298. popl %eax
  299. popl %ebx
  300. popl %ecx
  301. popl %edx
  302.  
  303. popl %esi
  304. popl %edi
  305. popl %ebp
  306. #pop %gs
  307. #pop %fs
  308. #pop %es
  309. #pop %ds
  310. #popa
  311.  
  312. add $4, %esp
  313.  
  314. .global _ZN16InterruptManager15InterruptIgnoreEv
  315. _ZN16InterruptManager15InterruptIgnoreEv:
  316.  
  317. iret
  318.  
  319. .data
  320. interruptnumber: .byte 0
Add Comment
Please, Sign In to add comment