Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Declare constants used for creating a multiboot header.
- HEADER_MAGIC equ 0x1BADB002 ; 'magic number' lets bootloader find the header
- HEADER_FLAGS equ 0x00010003 ; this is the Multiboot 'flag' field
- STACK_SIZE equ 0x4000 ; the size of the stack is 16KB
- CHECKSUM equ -(HEADER_MAGIC + HEADER_FLAGS) ; to prove we are multiboot
- ; Declare a header as in the Multiboot Standard.
- section .multiboot
- align 4
- dd HEADER_MAGIC
- dd HEADER_FLAGS
- dd CHECKSUM
- ; The stack is defined here
- [section .init_stack nobits alloc noexec write align=4]
- stack_bottom:
- resb STACK_SIZE
- stack_top:
- ; The linker script specifies _start as the entry point to the kernel and the
- ; bootloader will jump to this position once the kernel has been loaded. It
- ; doesn't make sense to return from this function as the bootloader is gone.
- section .text
- global _start
- _start:
- ; Set up a stack
- mov ebp, stack_top
- mov esp, ebp
- ; Set EFLAGS to 0
- push 0
- ; pop stack into the EFLAGS register
- popf
- ; Push the magic and the address on the stack, so that they
- ; will be the parameters of the C main function
- push ebx
- push eax
- ; Calling kernel's entry point.
- extern versatile_main
- call versatile_main
- ; In case the function returns, we'll want to put the computer into an
- ; infinite loop. To do that, we use the clear interrupt ('cli') instruction
- ; to disable interrupts, the halt instruction ('hlt') to stop the CPU until
- ; the next interrupt arrives, and jumping to the halt instruction if it ever
- ; continues execution, just to be safe.
- cli
- .hang:
- hlt
- jmp .hang
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement