You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 15 година
пре 15 година
пре 15 година
пре 15 година
пре 15 година
пре 15 година
пре 15 година
пре 15 година
пре 15 година
пре 15 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * libcaca Colour ASCII-Art library
  3. * Copyright (c) 2006 Sam Hocevar <sam@hocevar.net>
  4. * 2009 Jean-Yves Lamoureux <jylam@lnxscene.org>
  5. * All Rights Reserved
  6. *
  7. * This library is free software. It comes without any warranty, to
  8. * the extent permitted by applicable law. You can redistribute it
  9. * and/or modify it under the terms of the Do What the Fuck You Want
  10. * to Public License, Version 2, as published by Sam Hocevar. See
  11. * http://www.wtfpl.net/ for more details.
  12. */
  13. /*
  14. *'freely' inspired by http://jojo.ouvaton.org/dossiers/boot_sector/tutorial02.html
  15. * (actually, that's mostly copied, with minor compilation fixes)
  16. */
  17. #include "kernel.h"
  18. #include "klibc.h"
  19. #define IDTBASE 0 /* GDT Physical address */
  20. #define IDTSIZE 256 /* Max descriptor count */
  21. #define INTGATE 0x8E00 /* Interruptions */
  22. #define TRAPGATE 0x8F00 /* Syscalls */
  23. #define TASKGATE 0x8500 /* Task switching */
  24. /* segment descriptor */
  25. struct idtdesc
  26. {
  27. u16 offset0_15;
  28. u16 select;
  29. u16 type;
  30. u16 offset16_31;
  31. } __attribute__ ((packed));
  32. /* IDTR register */
  33. struct idtr
  34. {
  35. u16 limite;
  36. u32 base;
  37. } __attribute__ ((packed));
  38. struct idtr kidtr;
  39. /* IDT table */
  40. struct idtdesc kidt[IDTSIZE] = { {0, 0, 0, 0} };
  41. /* pointer on a free IDT entry */
  42. unsigned int kidtptr = 0;
  43. void default_int(void);
  44. void k_int0(void);
  45. void k_int1(void);
  46. void k_int2(void);
  47. void k_int3(void);
  48. void k_int4(void);
  49. void k_int5(void);
  50. void k_int6(void);
  51. void k_int7(void);
  52. void k_int8(void);
  53. void k_int9(void);
  54. void k_int10(void);
  55. void k_int11(void);
  56. void k_int12(void);
  57. void k_int13(void);
  58. void k_int14(void);
  59. void k_int15(void);
  60. void k_int16(void);
  61. void k_int17(void);
  62. void k_int18(void);
  63. void k_irq0(void);
  64. void k_irq1(void);
  65. void k_irq2(void);
  66. void k_irq3(void);
  67. void k_irq4(void);
  68. void k_irq5(void);
  69. void k_irq6(void);
  70. void k_irq7(void);
  71. void k_irq8(void);
  72. void init_idt_desc(u32 offset, u16 select, u16 type, struct idtdesc *desc)
  73. {
  74. desc->offset0_15 = (offset & 0xffff);
  75. desc->select = select;
  76. desc->type = type;
  77. desc->offset16_31 = (offset & 0xffff0000) >> 16;
  78. return;
  79. }
  80. void add_idt_desc(struct idtdesc desc)
  81. {
  82. kidt[kidtptr++] = desc;
  83. return;
  84. }
  85. void init_idt(void)
  86. {
  87. struct idtdesc desc;
  88. int i;
  89. for (i = 0; i < IDTSIZE; i++)
  90. {
  91. init_idt_desc((u32) default_int, 0x08, INTGATE, &desc);
  92. add_idt_desc(desc);
  93. }
  94. init_idt_desc((u32) k_int0, 0x08, INTGATE, &kidt[0]);
  95. init_idt_desc((u32) k_int1, 0x08, INTGATE, &kidt[1]);
  96. init_idt_desc((u32) k_int2, 0x08, INTGATE, &kidt[2]);
  97. init_idt_desc((u32) k_int3, 0x08, INTGATE, &kidt[3]);
  98. init_idt_desc((u32) k_int4, 0x08, INTGATE, &kidt[4]);
  99. init_idt_desc((u32) k_int5, 0x08, INTGATE, &kidt[5]);
  100. init_idt_desc((u32) k_int6, 0x08, INTGATE, &kidt[6]);
  101. init_idt_desc((u32) k_int7, 0x08, INTGATE, &kidt[7]);
  102. init_idt_desc((u32) k_int8, 0x08, INTGATE, &kidt[8]);
  103. init_idt_desc((u32) k_int9, 0x08, INTGATE, &kidt[9]);
  104. init_idt_desc((u32) k_int10, 0x08, INTGATE, &kidt[10]);
  105. init_idt_desc((u32) k_int11, 0x08, INTGATE, &kidt[11]);
  106. init_idt_desc((u32) k_int12, 0x08, INTGATE, &kidt[12]);
  107. init_idt_desc((u32) k_int13, 0x08, INTGATE, &kidt[13]);
  108. init_idt_desc((u32) k_int14, 0x08, INTGATE, &kidt[14]);
  109. init_idt_desc((u32) k_int15, 0x08, INTGATE, &kidt[15]);
  110. init_idt_desc((u32) k_int16, 0x08, INTGATE, &kidt[16]);
  111. init_idt_desc((u32) k_int17, 0x08, INTGATE, &kidt[17]);
  112. init_idt_desc((u32) k_int18, 0x08, INTGATE, &kidt[18]);
  113. init_idt_desc((u32) k_irq0, 0x08, INTGATE, &kidt[32]);
  114. init_idt_desc((u32) k_irq1, 0x08, INTGATE, &kidt[33]);
  115. init_idt_desc((u32) k_irq2, 0x08, INTGATE, &kidt[34]);
  116. init_idt_desc((u32) k_irq3, 0x08, INTGATE, &kidt[35]);
  117. init_idt_desc((u32) k_irq4, 0x08, INTGATE, &kidt[36]);
  118. init_idt_desc((u32) k_irq5, 0x08, INTGATE, &kidt[37]);
  119. init_idt_desc((u32) k_irq6, 0x08, INTGATE, &kidt[38]);
  120. init_idt_desc((u32) k_irq7, 0x08, INTGATE, &kidt[39]);
  121. init_idt_desc((u32) k_irq8, 0x08, INTGATE, &kidt[40]);
  122. kidtr.limite = IDTSIZE * 8;
  123. kidtr.base = IDTBASE;
  124. memcpy((void *)kidtr.base, kidt, kidtr.limite);
  125. #define printf(format, ...) { char __str[255]; sprintf (__str, format, __VA_ARGS__); print(__str);}
  126. printf("Loading IDT from 0x%x\n", kidtr);
  127. #undef printf
  128. asm("lidtl (kidtr)");
  129. }