Guest User

boot.S

a guest
Apr 6th, 2013
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  kernel/boot.S
  3. //
  4. //  (C) Copyright 2012-2013 Michael Sippel
  5. //
  6. //  This program is free software: you can redistribute it and/or modify
  7. //  it under the terms of the GNU General Public License as published by
  8. //  the Free Software Foundation, either version 3 of the License, or
  9. //  (at your option) any later version.
  10. //
  11. //  This program is distributed in the hope that it will be useful,
  12. //  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. //  GNU General Public License for more details.
  15. //
  16. //  You should have received a copy of the GNU General Public License
  17. //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18. #define VADDR_KERNEL_START 0xC0000000
  19. #define KERNEL_PAGES (VADDR_KERNEL_START >> 22)
  20.  
  21. .section multiboot
  22. #define MB_MAGIC 0x1BADB002
  23. #define MB_FLAGS 0x0
  24. #define MB_CHECKSUM -(MB_MAGIC + MB_FLAGS)
  25.  
  26. .align 4
  27. .int     MB_MAGIC
  28. .int     MB_FLAGS
  29. .int     MB_CHECKSUM
  30.  
  31. .section .data
  32. .align 0x1000
  33. _first_pd:
  34.     .long 0x00000083
  35.  
  36.     .rept (KERNEL_PAGES - 1)  
  37.     .long 0
  38.     .endr
  39.  
  40.     .long 0x00000083
  41.  
  42.     .rept (1024 - KERNEL_PAGES - 1)
  43.     .long 0
  44.     .endr
  45.  
  46. .section .text
  47. .global _start
  48. .extern init
  49. _start:
  50.   movl (_first_pd) - VADDR_KERNEL_START, %ecx
  51.   movl %ecx, %cr3
  52.  
  53.   movl %cr4, %ecx
  54.   orl %ecx, (1 << 4)
  55.   movl %ecx, %cr4
  56.  
  57.   movl %cr0, %ecx
  58.   orl %ecx, (1 << 31)
  59.   movl %ecx, %cr0  
  60.  
  61.   mov $kernel_stack, %esp
  62.   add $VADDR_KERNEL_START, %ebx
  63.   push %ebx
  64.   call init
  65.   jmp _stop
  66.  
  67. _stop:
  68.   cli
  69.   hlt
  70.   jmp _stop
  71.  
  72. .section .bss
  73. .space 8192
  74.  
  75. kernel_stack:
Advertisement
Add Comment
Please, Sign In to add comment