summaryrefslogtreecommitdiff
path: root/src/boot.asm
blob: f8ff1c81234fbb1037454ba9a52acfc83a43c8cf (plain) (blame)
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
60
61
62
63
64
bits 16
org 0x7c3e

kernel_sectors equ 16
kernel_segment equ 0x3000

  in al, 0x92
  or al, 0x02
  out 0x92, al

  xor ax, ax
  mov ss, ax
  mov sp, 0x7ffc

  mov ah, 0x01
  mov ch, 0x3f
  int 0x10

  mov ax, kernel_segment
  mov es, ax
  mov ax, 0x0200 + kernel_sectors
  xor bx, bx
  mov cx, 0x0002
  xor dh, dh
  int 0x13

  cli

  lgdt [gdt]

  mov eax, cr0
  or al, 0x01
  mov cr0, eax

  jmp 0x08:pmode

bits 32

pmode:
  mov ax, 0x10
  mov ds, ax
  mov ax, 0x18
  mov ss, ax
  mov esp, 0x00008000

  xor ebp, ebp
  call kernel_segment * 16

halt:
  hlt
  jmp halt

gdt:
  dw .e - .t
  dd .t
.t:
  dq 0x0000_0000_0000_0000
  dq 0x00c0_9a00_0000_007f
  dq 0x00c0_9200_0000_00ff
  dq 0x0040_9203_8000_7fff
.e:

times $$ + 448 - $ db 0
dw 0xaa55