aboutsummaryrefslogtreecommitdiffstats
path: root/src/boot/boot.stage2.asm
blob: 968bedcdc17fe912470953b11da66f2cb4eeb934 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
    ;; boot.stage2.asm

    [bits 16]
    [org 0x7e00]
    
    %include "common.asm"

    jmp 0x0000:_s2_entry

_s2_entry:  
    cli
    xor ax, ax
    mov ds, ax

    mov si, DAP_kernel
    mov ah, 0x42
    int 0x13
    jc _kernel_load_err
    jmp _kernel_loaded

_kernel_load_err:   
    mov si, boot_kernel_err
    call _print_string

    jmp $

_kernel_loaded: 
    mov si, boot_s2_msg
    call _print_string

    call _enable_a20            ; Enable A20 line 
    lgdt [GDT32_ptr]            ; Load GDT

    ;; Setup Protected Mode
    mov eax, cr0
    or eax, 1
    mov cr0, eax

    jmp CODE_SEG32:_protected_mode

    [bits 32]
_protected_mode:    
    mov ax, DATA_SEG32
    mov ds, ax
    mov ss, ax
    mov esp, 0x90000
    and esp, 0xFFFFFFF0         ; Align to 16-byte boundary

    mov esi, boot_protmode_msg
    call _print_string_pm_vga 

    call 0x10000
    
boot_s2_msg:    
    db "Entering Stage 2", 13, 10, 0
boot_protmode_msg:  
    db "Enabling Protected Mode", 13, 10, 0
boot_kernel_err:    
    db "Error loading kernel from disk", 13, 10, 0


    align 16
DAP_kernel: 
    db 0x10
    db 0
    dw 1                         ; Number of sectors
    dw 0x0000   
    dw 0x1000                    ; Offset
    dq 66                        ; Starting sector

    %include "boot.stage1.print.asm"
    %include "boot.stage2.a20.asm"
    %include "boot.stage2.gdt32.asm"
    %include "boot.stage2.print.asm"