-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.asm
More file actions
50 lines (45 loc) · 2.18 KB
/
Copy pathstart.asm
File metadata and controls
50 lines (45 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
; Declare constants used for creating a multiboot header.
MBALIGN equ 1<<0 ;align loaded modules on page boundaries
MEMINFO equ 1<<1 ; provide memory map
FLAGS equ MBALIGN | MEMINFO ;this is the Multiboot 'flag' field
MAGIC equ 0x1BADB002 ; 'magicnumber' lets bootloader find header
CHECKSUM equ -(MAGIC + FLAGS) ; checksum of above, to prove we are multiboot
; Declare a header as in the Multiboot Standard. We put this into a special
; section so we can force the header to be in start of the final program
; You don't need to understand all these details as it is just magic values that
; is documented in the multiboot standard. The bootloader will search for this
; magic sequence and recognize us as a multiboot kernel.
section multiboot
align 4
dd MAGIC ;align constants in memory
dd FLAGS ;define double word(4bytes)
dd CHECKSUM
; Currently the stack pointer register (esp) points at anything and using it may; cause massive harm. Instead we'll provide our own stack. We will allocate
; room for a small temporary stack by creating a symbol at the bottom of it,
; then allocating 16384 bytes for it. and finally creating a symbol at the top.
section .bootstrap_stack, nobits
align 4
stack_bottom:
resb 16384
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:
;Welcome to kernel Mode!
; To setup stack, we simply set the esp register to point to the top of
; our stack (as it grows downwards).
mov esp, stack_top
; We are now ready to actually execute C code.
; We'll create a kernel.c file. In that file,
;we'll create a C entry point called kernel_main and call it here.
extern kernel_main
call kernel_main
; In case the function returns, we'll have 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