Guest User

Untitled

a guest
May 26th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.85 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. .global _ZN16InterruptManager22IgnoreInterruptRequestEv:
  188.  
  189. interruptstubs.s:8: Error: junk at end of line, first unrecognized character is `:'
Add Comment
Please, Sign In to add comment