Advertisement
Guest User

loader.s

a guest
Jul 20th, 2023
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. global loader                   ; the entry symbol for ELF
  2.  
  3. extern main
  4.  
  5. section .__mbHeader
  6. align 0x4
  7. mboot:
  8.     MODULEALIGN  equ  1<<0                   ; align loaded modules on page boundaries
  9.     MEMINFO      equ  1<<1                   ; provide memory map
  10.     MAGIC_NUMBER equ 0x1BADB002              ; define the magic number constant
  11.     FLAGS        equ MODULEALIGN | MEMINFO   ; multiboot flags
  12.     CHECKSUM     equ -(MAGIC_NUMBER + FLAGS) ; calculate the checksum
  13.                                             ; (magic number + checksum + flags should equal 0)
  14.     KERNEL_STACK_SIZE equ 4096               ; size of stack in bytes
  15.                       ; the code must be 4 byte aligned
  16.     dd MAGIC_NUMBER             ; write the magic number to the machine code,
  17.     dd FLAGS                    ; the flags,
  18.     dd CHECKSUM                 ; and the checksum
  19.    
  20.  
  21.  
  22. section .text                   ; start of the text (code) section
  23. loader:                                       ; the loader label (defined as entry point in linker script)
  24.     mov esp, kernel_stack + KERNEL_STACK_SIZE ; point esp to the start of the stack (end of memory area)
  25.     call main
  26.  
  27. .loop:
  28.     jmp .loop                   ; loop forever
  29.  
  30.  
  31. section .bss
  32. align 4                         ; align at 4 bytes
  33. kernel_stack:                   ; label points to beginning of memory
  34.     resb KERNEL_STACK_SIZE      ; reserve stack for the kernel
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement