aboutsummaryrefslogtreecommitdiff
path: root/src/boot.asm
blob: 011c00f152890d6524e50af49d15ea81eec2dd22 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
; boot.asm - stage 1

[bits 16]
[org 0x7C00]

start:
    xor ax, ax
    mov ds, ax
    mov es, ax
    mov ss, ax

                                    ; clear screen by big scrollup
    mov ah, 0x06                    ; scrollup function
    mov al, 0                       ; al contains the n of lines to scroll (0 is clearall)
    mov bh, 0x07                    ; 'attribute byte' 0x07 is white on black
    mov cx, 0x0000                  ; upper-left corner
    mov dx, 0x184F                  ; bottom-right corner

    int 0x10                        ; call
                                    ; set cursor position back to default
    mov ah, 0x02                    ; set cur pos function
                                    ; position parameters:
    mov bh, 0x00                    ; page number (0)
    mov dh, 0x00                    ; row
    mov dl, 0x00                    ; col

    int 0x10                        ; call

    mov si, msg1                    ; print msg1
    call print_string

    mov ah, 0x02                    ; set cur pos function
                                    ; position parameters:
    mov bh, 0x00                    ; page number (0)
    mov dh, 0x01                    ; row
    mov dl, 0x00                    ; col

    int 0x10                        ; call

    mov si, msg2                    ; print msg2
    call print_string

    mov ah, 0x02                    ; set cur pos function
                                    ; position parameters:
    mov bh, 0x00                    ; page number (0)
    mov dh, 0x02                    ; row
    mov dl, 0x00                    ; col

    int 0x10                        ; call

    mov si, msg3
    call print_string

    mov ah, 0x02                    ; set cur pos function
                                    ; position parameters:
    mov bh, 0x00                    ; page number (0)
    mov dh, 0x03                    ; row
    mov dl, 0x00                    ; col

    int 0x10                        ; call

load_stage2:
    mov ax, 0x0000
    mov es, ax
    mov bx, 0x1000
                                    ; load stage2 from disk - first sector at 0x1000
    mov bx, 0x1000                  ; load address
    mov dh, 0
    mov ch, 0
    mov cl, 2                        ; sector 2
    mov al, 20                       ; sectors to read
    mov ah, 0x02

    int 0x13
    jc halt

                                    ; GDT for protected mode
gdt_start:
    dq 0
    dq 0x00CF9A000000FFFF           ; code
    dq 0x00CF92000000FFFF           ; data
    gdt_end:

gdt_descriptor:
    dw gdt_end - gdt_start -1
    dd gdt_start

                                    ; enable protected mode cleanly and transfer to 32-bit stub
    cli
    lgdt [gdt_descriptor]

    mov eax, cr0
    or eax, 1
    mov cr0, eax

                                    ; far jump reloads CS with selector 0x08 and enters protected mode
    jmp 0x08:pm_entry

                                    ; 32-bit entry point
    [bits 32]
pm_entry:
                                    ; reload data segment registers with data selector (0x10)
    mov ax, 0x10
    mov ds, ax
    mov es, ax
    mov fs, ax
    mov gs, ax
    mov ss, ax

    mov esp, 0x90000                ; setup stack

    mov eax, 0x1000                 ; jump to linear address 0x1000 (which wloud be where s2.bin was loaded)
    jmp eax

halt:
    hlt
    jmp halt

print_string:
    lodsb
    cmp al, 0
    je .done
    mov ah, 0x0E
    int 0x10
    jmp print_string
.done:
    ret

msg1 db `mull_bootloader hath bespoken unto thee:\n`, 0
msg2 db `\"behold, \'O user! mull_kernel doth now commence its solemn journey!\"\n`, 0
msg3 db `trying to kernel kernel :3`, 0

times 510-($-$$) db 0
dw 0xAA55