Ignore:
Timestamp:
Jun 21, 2017, 8:35:30 AM (5 years ago)
Author:
max@…
Message:

Update. The kernel now enables the GDT/IDT, and has trap entries. A
x86_printf function is added for debugging purposes only. The new Makefile
will come in another commit.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/hal/x86_64/hal_boot.S

    r25 r29  
    22 * hal_boot.S - Kernel boot entry point
    33 *
    4  * Author        Maxime Villard (2017)
    5  *               This code is inspired a lot from the NetBSD boot procedure,
    6  *               written by Maxime Villard too.
    7  *
    8  * Copyright (c) UPMC Sorbonne Universites
    9  *
    10  * This file is part of ALMOS-kernel.
    11  *
    12  * ALMOS-kernel is free software; you can redistribute it and/or modify it
     4 * Copyright (c) 2017 Maxime Villard
     5 * This code is inspired a lot from the NetBSD boot procedure, written by
     6 * Maxime Villard too. XXX copyright
     7 *
     8 * This file is part of ALMOS-MKH.
     9 *
     10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
    1311 * under the terms of the GNU General Public License as published by
    1412 * the Free Software Foundation; version 2.0 of the License.
    1513 *
    16  * ALMOS-kernel is distributed in the hope that it will be useful, but
     14 * ALMOS-MKH is distributed in the hope that it will be useful, but
    1715 * WITHOUT ANY WARRANTY; without even the implied warranty of
    1816 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     
    2018 *
    2119 * You should have received a copy of the GNU General Public License
    22  * along with ALMOS-kernel; if not, write to the Free Software Foundation,
     20 * along with ALMOS-MKH.; if not, write to the Free Software Foundation,
    2321 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
    2422 */
    2523
     24#define x86_ASM
    2625#include <hal_boot.h>
    2726#include <hal_register.h>
     
    99982:                                      ;
    10099
     100/*
     101 * killkpt - Destroy a kernel page table (long mode)
     102 *      rbx = page table address
     103 *      rcx = number of pages to destroy
     104 */
     105#define killkpt \
     1061:      movq    $0,(%rbx)       ; \
     107        addq    $PDE_SIZE,%rbx  ; \
     108        loop    1b              ;
     109
    101110/* 32bit version of PG_NX */
    102111#define PG_NX32 0x80000000
     
    106115        .globl  start_x86_64
    107116        .globl  L4paddr
     117        .globl  iom_base
    108118
    109119/*
     
    125135        .type   L4paddr, @object
    126136        L4paddr:        .quad   0       /* paddr of L4 */
     137
     138        .type   iom_base, @object
     139        iom_base:       .quad   0       /* virt. addr. of ISA I/O MEM */
     140
    127141
    128142#define GDT64_LIMIT gdt64_end-gdt64_start-1
     
    152166farjmp64:
    153167        .long   RELOC(longmode)
    154         .word   GSEL(GCODE_SEL, SEL_KPL)
     168        .word   GDT_FIXED_SEL(GDT_KCODE_SEL, SEL_KPL)
    155169.align 64
    156170
     
    169183
    170184        /* Make sure it is a multiboot-compliant bootloader. */
    171         cmpl    $MULTIBOOT_INFO_MAGIC,%eax
    172         jne     boot_panic
     185//      cmpl    $MULTIBOOT_INFO_MAGIC,%eax
     186//      jne     boot_panic
    173187
    174188        movl    $RELOC(tmpstk),%esp
     
    246260        subl    %eax,%ecx
    247261        shrl    $PGSHIFT,%ecx
    248         orl     $(PG_V|PG_KR),%eax
     262        orl     $(PG_V|PG_KR|PG_G),%eax
    249263        fillkpt
    250264
     
    254268        subl    %eax,%ecx
    255269        shrl    $PGSHIFT,%ecx
    256         orl     $(PG_V|PG_KW),%eax
     270        orl     $(PG_V|PG_KW|PG_G),%eax
    257271        fillkpt_nox
    258272
     
    261275        movl    $TABLESIZE,%ecx         /* length of BOOTSTRAP TABLES */
    262276        shrl    $PGSHIFT,%ecx
    263         orl     $(PG_V|PG_KW),%eax
     277        orl     $(PG_V|PG_KW|PG_G),%eax
    264278        fillkpt_nox
    265279
     
    268282        movl    $IOM_SIZE,%ecx  /* size of ISA I/O MEM */
    269283        shrl    $PGSHIFT,%ecx
    270         orl     $(PG_V|PG_KW/*|PG_N*/),%eax
     284        orl     $(PG_V|PG_KW|PG_G),%eax
    271285        fillkpt_nox
    272286
     
    335349         */
    336350        movl    %cr4,%eax
    337         orl     $(CR4_PAE|CR4_OSFXSR|CR4_OSXMMEXCPT),%eax
     351        orl     $(CR4_PAE|CR4_OSFXSR|CR4_OSXMMEXCPT|CR4_PGE),%eax
    338352        movl    %eax,%cr4
    339353
     
    381395         */
    382396        movabsq $longmode_hi,%rax
    383         jmp     *%rax /* XXX XXX: <------ this instruction faults */
     397        jmp     *%rax
    384398
    385399longmode_hi:
     
    397411        movq    $KERNBASE,%r8
    398412
    399 
    400         /*
    401          * STOP HERE FOR NOW
    402          */
    403 1:      nop
    404         jmp     1b
    405 
    406 
    407 boot_panic:
    408         jmp     boot_panic
    409 
     413#if L2_SLOT_KERNBASE > 0
     414        movq    $(NKL2_KIMG_ENTRIES+1),%rcx
     415        leaq    (PROC0_PTP2_OFF)(%rsi),%rbx     /* old, phys address */
     416        addq    %r8,%rbx                        /* new, virt address */
     417        killkpt
     418#endif
     419
     420#if L3_SLOT_KERNBASE > 0
     421        movq    $NKL3_KIMG_ENTRIES,%rcx
     422        leaq    (PROC0_PTP3_OFF)(%rsi),%rbx     /* old, phys address */
     423        addq    %r8,%rbx                        /* new, virt address */
     424        killkpt
     425#endif
     426
     427        movq    $NKL4_KIMG_ENTRIES,%rcx
     428        leaq    (PROC0_PML4_OFF)(%rsi),%rbx     /* old, phys address of PML4 */
     429        addq    %r8,%rbx                        /* new, virt address of PML4 */
     430        killkpt
     431
     432        /* Relocate atdevbase. */
     433        movq    $(TABLESIZE+KERNBASE),%rdx
     434        addq    %rsi,%rdx
     435        movq    %rdx,iom_base(%rip)
     436
     437        /* Set up bootstrap stack. */
     438        leaq    (PROC0_STK_OFF)(%rsi),%rax
     439        addq    %r8,%rax
     440        leaq    (STKSIZE)(%rax),%rsp
     441        xorq    %rbp,%rbp                       /* mark end of frames */
     442
     443        xorw    %ax,%ax
     444        movw    %ax,%gs
     445        movw    %ax,%fs
     446
     447        /* The first physical page available. */
     448        leaq    (TABLESIZE)(%rsi),%rdi
     449
     450        call    init_x86_64
     451
Note: See TracChangeset for help on using the changeset viewer.