arch.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) 2009 Corey Tabaka
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining
  5. * a copy of this software and associated documentation files
  6. * (the "Software"), to deal in the Software without restriction,
  7. * including without limitation the rights to use, copy, modify, merge,
  8. * publish, distribute, sublicense, and/or sell copies of the Software,
  9. * and to permit persons to whom the Software is furnished to do so,
  10. * subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  19. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  20. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  21. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #include <debug.h>
  24. #include <arch.h>
  25. #include <arch/ops.h>
  26. #include <arch/x86.h>
  27. #include <arch/x86/mmu.h>
  28. #include <arch/x86/descriptor.h>
  29. #include <platform.h>
  30. #include <sys/types.h>
  31. #include <string.h>
  32. static tss_t system_tss;
  33. void arch_early_init(void)
  34. {
  35. x86_mmu_init();
  36. platform_init_mmu_mappings();
  37. /* enable caches here for now */
  38. clear_in_cr0(X86_CR0_NW | X86_CR0_CD);
  39. memset(&system_tss, 0, sizeof(tss_t));
  40. system_tss.esp0 = 0;
  41. system_tss.ss0 = DATA_SELECTOR;
  42. system_tss.ss1 = 0;
  43. system_tss.ss2 = 0;
  44. system_tss.eflags = 0x00003002;
  45. system_tss.bitmap = offsetof(tss_t, tss_bitmap);
  46. system_tss.trace = 1; // trap on hardware task switch
  47. set_global_desc(TSS_SELECTOR, &system_tss, sizeof(tss_t), 1, 0, 0, SEG_TYPE_TSS, 0, 0);
  48. x86_ltr(TSS_SELECTOR);
  49. }
  50. void arch_init(void)
  51. {
  52. }
  53. uint32_t arch_cycle_count(void)
  54. {
  55. uint32_t timestamp;
  56. rdtscl(timestamp);
  57. return timestamp;
  58. }