Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2013
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Declare constants used for creating a multiboot header.
  2. HEADER_MAGIC    equ  0x1BADB002         ; 'magic number' lets bootloader find the header
  3. HEADER_FLAGS    equ  0x00010003         ; this is the Multiboot 'flag' field
  4. STACK_SIZE  equ  0x4000     ; the size of the stack is 16KB
  5. CHECKSUM        equ  -(HEADER_MAGIC + HEADER_FLAGS) ; to prove we are multiboot
  6.  
  7. ; Declare a header as in the Multiboot Standard.
  8. section .multiboot
  9. align 4
  10.     dd HEADER_MAGIC
  11.     dd HEADER_FLAGS
  12.     dd CHECKSUM
  13.  
  14.  
  15. ; The stack is defined here
  16. [section .init_stack nobits alloc noexec write align=4]
  17. stack_bottom:
  18.     resb STACK_SIZE
  19. stack_top:
  20.    
  21.  
  22. ; The linker script specifies _start as the entry point to the kernel and the
  23. ; bootloader will jump to this position once the kernel has been loaded. It
  24. ; doesn't make sense to return from this function as the bootloader is gone.
  25. section .text
  26. global _start
  27. _start:
  28.     ; Set up a stack
  29.     mov ebp, stack_top
  30.     mov esp, ebp
  31.    
  32.     ; Set EFLAGS to 0
  33.     push 0
  34.     ; pop stack into the EFLAGS register
  35.     popf
  36.  
  37.     ; Push the magic and the address on the stack, so that they
  38.     ; will be the parameters of the C main function
  39.     push ebx
  40.     push eax
  41.  
  42.     ; Calling kernel's entry point.
  43.     extern versatile_main
  44.     call versatile_main
  45.  
  46.     ; In case the function returns, we'll want to put the computer into an
  47.     ; infinite loop. To do that, we use the clear interrupt ('cli') instruction
  48.     ; to disable interrupts, the halt instruction ('hlt') to stop the CPU until
  49.     ; the next interrupt arrives, and jumping to the halt instruction if it ever
  50.     ; continues execution, just to be safe.
  51.     cli
  52.    
  53. .hang:
  54.     hlt
  55.     jmp .hang
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement