aboutsummaryrefslogtreecommitdiff
path: root/src/boot/boot.s
blob: aba32ff824abadae60cbf54ab6b6dd98589c0f53 (plain)
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
51
52
53
54
55
56
57
58
59
MBALIGN   equ 1<<0  ; Align loaded modules on page boundries */
MBMEMINFO equ 1<<1  ; Provide memory map*/
MBFLAGS equ MBALIGN | MBMEMINFO ; Multiboot flag field*/
MAGIC equ 0x1BADB002 ;Lets bootloader find header*/
CHECKSUM equ -(MAGIC + MBFLAGS) ; Proves we are multiboot via checksum*/
CODESEG equ 0x08
DATASEG equ 0x10

section .multiboot
align 4
  dd MAGIC
  dd MBFLAGS
  dd CHECKSUM

section .bss
align 16
stack_bottom:
resb 16384
stack_top:

section .text
global gdtr
gdtr:
  dw 0
  dd 0
global _start:function (_start.end - _start)
_start:
  mov esp, stack_top

  extern get_gdtr
  call get_gdtr
  cli
  lgdt	[gdtr]
  mov eax, cr0
  or al, 1
  mov cr0, eax

  call reloadSegments

  [bits 32]
  extern kernel_main
  call kernel_main


	cli
.hang:	hlt
	jmp .hang
.end:

reloadSegments:
  JMP   CODESEG:.reload_CS ; should def define a CODESEG
.reload_CS:
   MOV   AX, DATASEG
   MOV   DS, AX
   MOV   ES, AX ; TODO: Setup proper extra segment
   MOV   FS, AX ; TODO: Setup proper General purpose segments
   MOV   GS, AX ; ...
   MOV   SS, AX ; TODO: Setup proper stack segment
   RET