Guest User

Untitled

a guest
Feb 24th, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. ; ### Multiboot header section ###
  3. section .multiboot
  4.     MODULEALIGN     equ     1 << 0
  5.     MEMINFO         equ     1 << 1
  6.     FLAGS           equ     MODULEALIGN | MEMINFO
  7.     MAGIC           equ     0x1BADB002
  8.     CHECKSUM        equ     -(MAGIC + FLAGS)
  9.  
  10.     ; Fill constants into memory (dwords)
  11.     align 4
  12.     dd MAGIC
  13.     dd FLAGS
  14.     dd CHECKSUM
  15.  
  16.  
  17. ; ### Code section ###
  18. section .text
  19.  
  20.     global loader
  21.     ; Linker script variables:
  22.         ; Represents first free address after kernel memory
  23.         extern endKernel
  24.         ; Start/end of the constructors in memory
  25.         extern startConstructors
  26.         extern endConstructors
  27.  
  28.     ; Startup method in Kernel.cpp
  29.     extern createKernel
  30.  
  31.     ; Defines the kernels stack size
  32.     STACKSIZE equ 0x4000
  33.  
  34. ; Calls all constructors and then starts the kernel
  35. loader:
  36.     ; Store the given values for later usage in createKernel
  37.     mov esp, stack + STACKSIZE
  38.     push eax        ; Magic number
  39.     push ebx        ; Additional information
  40.     push esp        ; Push stack
  41.     push endKernel  ; Push stack head
  42.  
  43.     ; Execute the constructor calling loop
  44.     mov ebx, startConstructors
  45.     jmp loopConstructors
  46.  
  47. ; Calls the next constructor
  48. callConstructor:
  49.     call [ebx]
  50.     add ebx, 4
  51.  
  52. ; Loops through the constructors
  53. loopConstructors:
  54.     cmp ebx, endConstructors
  55.     jb callConstructor
  56.  
  57. ; Starts the kernel
  58. callKernel:
  59.     call createKernel
  60.  
  61. ; Hang the system after kernel execution
  62. hang:
  63.     hlt
  64.     jmp hang
  65.  
  66.  
  67.  
  68. ; ### Empty data segment ###
  69. section .bss
  70.  
  71.     ; Align the location of the following res-commands
  72. align 4
  73.  
  74. ; Reserves space for the initial kernel stack
  75. stack:
  76.     resb STACKSIZE
Advertisement
Add Comment
Please, Sign In to add comment