aboutsummaryrefslogtreecommitdiff
path: root/i686/init.s
blob: ad329bb33a3ab07b1721ce53395fc32a562c7e77 (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
.section .stack, "aw", @nobits
.global k_stack
.align 16       /* Stack on x86 must be 16-byte aligned according to System V ABI */
k_stack_bottom:
    .skip 16 * 1024     /* 16 kByte */
k_stack:

.section .pages, "aw", @nobits
.align 4096
.global k_pagedir
k_pagedir:      .skip 1024 * 4
.global k_ptable0x300
k_ptable0x300: .skip 1024 * 4

.section .text
.global k_init
.extern kmain
.extern gdt_install
.extern idt_install
k_init:
    # kernel entry point, higher half

    # unmap the identity mapping as its no longer necessary
    movl $0, k_pagedir + 0 * 4
    mov %cr3, %ecx              # reload cr3 to force a TLB flush
    mov %ecx, %cr3

    # zero out the stack
    mov  $4096, %ecx # loop counter
    mov  $k_stack_bottom, %edi  # start from the bottom
    xor  %edx, %edx             # clear %edx
1:  movl %edx, (%edi)           # store %edx into address in %edi
    addl $4, %edi               # point to next address
    loop 1b                     # loop according to %ecx

    mov   $k_stack, %esp        # point stack pointer to the stack

    # hardware init
    call gdt_install    # Global Descriptor Table
    call idt_install    # Interrupt Descriptor Table

    # jump into kernel
    call kmain

    /* If the system has nothing more to do, put it in an infinite loop */
    cli         # disable interrupts
h:  hlt         # wait for interrupt
    jmp h       # continue waiting for interrupt