Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 GDTBASE 0x800 /* Physical address of GDT */
  20. #define GDTSIZE 0xFF /* Maximum table size (in entries) */
  21. /* Segment descriptor */
  22. struct gdtdesc
  23. {
  24. u16 lim0_15;
  25. u16 base0_15;
  26. u8 base16_23;
  27. u8 acces;
  28. u8 lim16_19:4;
  29. u8 other:4;
  30. u8 base24_31;
  31. } __attribute__ ((packed));
  32. /* GDTR register */
  33. struct gdtr
  34. {
  35. u16 limite;
  36. u32 base;
  37. } __attribute__ ((packed));
  38. struct gdtr kgdtr;
  39. struct gdtdesc kgdt[GDTSIZE] = { {0, 0, 0, 0, 0, 0, 0} };
  40. unsigned int kgdtptr = 1;
  41. void init_code_desc(u32 base, u32 limite, struct gdtdesc *desc);
  42. void init_data_desc(u32 base, u32 limite, struct gdtdesc *desc);
  43. void add_gdt_desc(struct gdtdesc desc);
  44. void init_gdt(void);
  45. void init_gdt_desc(u32 base, u32 limite, u8 acces, u8 other,
  46. struct gdtdesc *desc)
  47. {
  48. desc->lim0_15 = (limite & 0xffff);
  49. desc->base0_15 = (base & 0xffff);
  50. desc->base16_23 = (base & 0xff0000) >> 16;
  51. desc->acces = acces;
  52. desc->lim16_19 = (limite & 0xf0000) >> 16;
  53. desc->other = (other & 0xf);
  54. desc->base24_31 = (base & 0xff000000) >> 24;
  55. return;
  56. }
  57. void init_code_desc(u32 base, u32 limite, struct gdtdesc *desc)
  58. {
  59. init_gdt_desc(base, limite, 0x9B, 0x0D, desc);
  60. }
  61. void init_data_desc(u32 base, u32 limite, struct gdtdesc *desc)
  62. {
  63. init_gdt_desc(base, limite, 0x93, 0x0D, desc);
  64. }
  65. void add_gdt_desc(struct gdtdesc desc)
  66. {
  67. kgdt[kgdtptr] = desc;
  68. kgdtptr++;
  69. }
  70. void init_gdt(void)
  71. {
  72. struct gdtdesc code, data, stack;
  73. /* initialisation des descripteurs de segment */
  74. init_code_desc(0x0, 0xFFFFF, &code);
  75. init_data_desc(0x0, 0xFFFFF, &data);
  76. init_gdt_desc(0, 0x10, 0x97, 0x0D, &stack);
  77. add_gdt_desc(code);
  78. add_gdt_desc(data);
  79. add_gdt_desc(stack);
  80. /* initialisation de la structure pour GDTR */
  81. kgdtr.limite = GDTSIZE * 8;
  82. kgdtr.base = GDTBASE;
  83. /* recopie de la GDT a son adresse */
  84. memcpy((void *)kgdtr.base, kgdt, kgdtr.limite);
  85. /* chargement du registre GDTR */
  86. asm("lgdtl (kgdtr)");
  87. /* initialisation des segments */
  88. asm(" movw $0x10,%ax \n \
  89. movw %ax, %ds \n \
  90. movw %ax, %es \n \
  91. movw %ax, %fs \n \
  92. movw %ax, %gs \n \
  93. movw $0x18,%ax \n \
  94. movw %ax, %ss \n \
  95. movl $0x1FFFF,%esp \n \
  96. nop \n \
  97. nop \n \
  98. ljmp $0x08,$next \n \
  99. next: \n");
  100. }