Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

155 righe
4.4 KiB

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