Changeset 46c20c8 in mainline for kernel/arch/amd64/src


Ignore:
Timestamp:
2010-11-26T20:08:10Z (15 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
45df59a
Parents:
fb150d78 (diff), ffdd2b9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

Location:
kernel/arch/amd64/src
Files:
1 added
1 deleted
20 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/amd64/src/amd64.c

    rfb150d78 r46c20c8  
    3535#include <arch.h>
    3636
    37 #include <arch/types.h>
     37#include <typedefs.h>
    3838
    3939#include <config.h>
     
    122122        /* Enable FPU */
    123123        cpu_setup_fpu();
    124 
     124       
    125125        /* Initialize segmentation */
    126126        pm_init();
     
    132132        /* Disable alignment check */
    133133        clean_AM_flag();
    134 
     134       
    135135        if (config.cpu_active == 1) {
    136136                interrupt_init();
     
    228228            (uintptr_t) I8042_BASE);
    229229#endif
     230       
     231        /*
     232         * This nasty hack should also go away ASAP.
     233         */
     234        trap_virtual_enable_irqs(1 << IRQ_DP8390);
     235        sysinfo_set_item_val("netif.dp8390.inr", NULL, IRQ_DP8390);
    230236}
    231237
     
    254260        THREAD->arch.tls = addr;
    255261        write_msr(AMD_MSR_FS, addr);
     262       
    256263        return 0;
    257264}
  • kernel/arch/amd64/src/boot/boot.S

    rfb150d78 r46c20c8  
    1 #
    2 # Copyright (c) 2005 Ondrej Palkovsky
    3 # Copyright (c) 2006 Martin Decky
    4 # Copyright (c) 2008 Jakub Jermar
    5 # All rights reserved.
    6 #
    7 # Redistribution and use in source and binary forms, with or without
    8 # modification, are permitted provided that the following conditions
    9 # are met:
    10 #
    11 # - Redistributions of source code must retain the above copyright
    12 #   notice, this list of conditions and the following disclaimer.
    13 # - Redistributions in binary form must reproduce the above copyright
    14 #   notice, this list of conditions and the following disclaimer in the
    15 #   documentation and/or other materials provided with the distribution.
    16 # - The name of the author may not be used to endorse or promote products
    17 #   derived from this software without specific prior written permission.
    18 #
    19 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    20 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    21 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    22 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
    23 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
    24 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    28 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    29 #
     1/*
     2 * Copyright (c) 2005 Ondrej Palkovsky
     3 * Copyright (c) 2006 Martin Decky
     4 * Copyright (c) 2008 Jakub Jermar
     5 * All rights reserved.
     6 *
     7 * Redistribution and use in source and binary forms, with or without
     8 * modification, are permitted provided that the following conditions
     9 * are met:
     10 *
     11 * - Redistributions of source code must retain the above copyright
     12 *   notice, this list of conditions and the following disclaimer.
     13 * - Redistributions in binary form must reproduce the above copyright
     14 *   notice, this list of conditions and the following disclaimer in the
     15 *   documentation and/or other materials provided with the distribution.
     16 * - The name of the author may not be used to endorse or promote products
     17 *   derived from this software without specific prior written permission.
     18 *
     19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29 */
    3030
    3131#include <arch/boot/boot.h>
    3232#include <arch/boot/memmap.h>
    33 #include <arch/mm/page.h>       
     33#include <arch/mm/page.h>
    3434#include <arch/mm/ptl.h>
    3535#include <arch/pm.h>
     
    3737#include <arch/cpuid.h>
    3838
    39 #define START_STACK     (BOOT_OFFSET - BOOT_STACK_SIZE)
     39#define START_STACK  (BOOT_OFFSET - BOOT_STACK_SIZE)
    4040
    4141.section K_TEXT_START, "ax"
    4242
    4343.code32
     44
     45.macro pm_error msg
     46        movl \msg, %esi
     47        jmp pm_error_halt
     48.endm
     49
     50.macro pm_status msg
     51#ifdef CONFIG_EGA
     52        pushl %esi
     53        movl \msg, %esi
     54        call pm_early_puts
     55        popl %esi
     56#endif
     57.endm
     58
     59.macro pm2_status msg
     60#ifndef CONFIG_FB
     61        pm_status \msg
     62#endif
     63.endm
     64
    4465.align 4
    4566.global multiboot_image_start
     
    4768        .long MULTIBOOT_HEADER_MAGIC
    4869        .long MULTIBOOT_HEADER_FLAGS
    49         .long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)  # checksum
     70        .long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)  /* checksum */
    5071        .long multiboot_header
    5172        .long unmapped_ktext_start
     
    5677multiboot_image_start:
    5778        cld
    58         movl $START_STACK, %esp             # initialize stack pointer
    59         lgdtl bootstrap_gdtr                # initialize Global Descriptor Table register
    60        
    61         movw $gdtselector(KDATA_DES), %cx
     79       
     80        /* Initialize stack pointer */
     81        movl $START_STACK, %esp
     82       
     83        /* Initialize Global Descriptor Table register */
     84        lgdtl bootstrap_gdtr
     85       
     86        /* Kernel data + stack */
     87        movw $GDT_SELECTOR(KDATA_DES), %cx
    6288        movw %cx, %es
    63         movw %cx, %ds                       # kernel data + stack
     89        movw %cx, %ds
    6490        movw %cx, %ss
    6591       
    66         #
    67         # Simics seems to remove hidden part of GS on entering user mode
    68         # when _visible_ part of GS does not point to user-mode segment.
    69         #
    70        
    71         movw $gdtselector(UDATA_DES), %cx
     92        /*
     93         * Simics seems to remove hidden part of GS on entering user mode
     94         * when _visible_ part of GS does not point to user-mode segment.
     95         */
     96        movw $GDT_SELECTOR(UDATA_DES), %cx
    7297        movw %cx, %fs
    7398        movw %cx, %gs
    7499       
    75         jmpl $gdtselector(KTEXT32_DES), $multiboot_meeting_point
     100        jmpl $GDT_SELECTOR(KTEXT32_DES), $multiboot_meeting_point
    76101        multiboot_meeting_point:
    77102       
    78         movl %eax, grub_eax                 # save parameters from GRUB
     103        /* Save GRUB arguments */
     104        movl %eax, grub_eax
    79105        movl %ebx, grub_ebx
    80106       
    81         #
    82         # Protected 32-bit. We want to reuse the code-seg descriptor,
    83         # the Default operand size must not be 1 when entering long mode.
    84         #
     107        pm_status $status_prot
    85108       
    86109        movl $(INTEL_CPUID_EXTENDED), %eax
     
    89112        ja extended_cpuid_supported
    90113       
    91                 movl $extended_cpuid_msg, %esi
    92                 jmp error_halt
     114                pm_error $err_extended_cpuid
    93115       
    94116        extended_cpuid_supported:
     
    99121        jc long_mode_supported
    100122       
    101                 movl $long_mode_msg, %esi
    102                 jmp error_halt
     123                pm_error $err_long_mode
    103124       
    104125        long_mode_supported:
     
    107128        jc noexecute_supported
    108129       
    109                 movl $noexecute_msg, %esi
    110                 jmp error_halt
     130                pm_error $err_noexecute
    111131       
    112132        noexecute_supported:
     
    117137        jc fx_supported
    118138       
    119                 movl $fx_msg, %esi
    120                 jmp error_halt
     139                pm_error $err_fx
    121140       
    122141        fx_supported:
     
    125144        jc sse2_supported
    126145       
    127                 movl $sse2_msg, %esi
    128                 jmp error_halt
     146                pm_error $err_sse2
    129147       
    130148        sse2_supported:
    131 
     149       
    132150#include "vesa_prot.inc"
    133 
    134         #
    135         # Enable 64-bit page translation entries - CR4.PAE = 1.
    136         # Paging is not enabled until after long mode is enabled.
    137         #
     151       
     152        /*
     153         * Protected 32-bit. We want to reuse the code-seg descriptor,
     154         * the Default operand size must not be 1 when entering long mode.
     155         */
     156       
     157        pm2_status $status_prot2
     158       
     159        /*
     160         * Enable 64-bit page translation entries - CR4.PAE = 1.
     161         * Paging is not enabled until after long mode is enabled.
     162         */
    138163       
    139164        movl %cr4, %eax
     
    141166        movl %eax, %cr4
    142167       
    143         # set up paging tables
    144        
     168        /* Set up paging tables */
    145169        leal ptl_0, %eax
    146170        movl %eax, %cr3
    147171       
    148         # enable long mode
    149        
    150         movl $EFER_MSR_NUM, %ecx            # EFER MSR number
    151         rdmsr                               # read EFER
    152         btsl $AMD_LME_FLAG, %eax            # set LME = 1
    153         wrmsr                               # write EFER
    154        
    155         # enable paging to activate long mode (set CR0.PG = 1)
    156        
     172        /* Enable long mode */
     173        movl $EFER_MSR_NUM, %ecx
     174        rdmsr                     /* read EFER */
     175        btsl $AMD_LME_FLAG, %eax  /* set LME = 1 */
     176        wrmsr
     177       
     178        /* Enable paging to activate long mode (set CR0.PG = 1) */
    157179        movl %cr0, %eax
    158180        btsl $31, %eax
    159181        movl %eax, %cr0
    160182       
    161         # at this point we are in compatibility mode
    162        
    163         jmpl $gdtselector(KTEXT_DES), $start64
     183        /* At this point we are in compatibility mode */
     184        jmpl $GDT_SELECTOR(KTEXT_DES), $start64
     185
     186/** Print string to EGA display (in light red) and halt.
     187 *
     188 * Should be executed from 32 bit protected mode with paging
     189 * turned off. Stack is not required. This routine is used even
     190 * if CONFIG_EGA is not enabled. Since we are going to halt the
     191 * CPU anyway, it is always better to at least try to print
     192 * some hints.
     193 *
     194 * @param %esi Pointer to the NULL-terminated string
     195 *             to be print.
     196 *
     197 */
     198pm_error_halt:
     199        movl $0xb8000, %edi  /* base of EGA text mode memory */
     200        xorl %eax, %eax
     201       
     202        /* Read bits 8 - 15 of the cursor address */
     203        movw $0x3d4, %dx
     204        movb $0xe, %al
     205        outb %al, %dx
     206       
     207        movw $0x3d5, %dx
     208        inb %dx, %al
     209        shl $8, %ax
     210       
     211        /* Read bits 0 - 7 of the cursor address */
     212        movw $0x3d4, %dx
     213        movb $0xf, %al
     214        outb %al, %dx
     215       
     216        movw $0x3d5, %dx
     217        inb %dx, %al
     218       
     219        /* Sanity check for the cursor on screen */
     220        cmp $2000, %ax
     221        jb err_cursor_ok
     222       
     223                movw $1998, %ax
     224       
     225        err_cursor_ok:
     226       
     227        movw %ax, %bx
     228        shl $1, %eax
     229        addl %eax, %edi
     230       
     231        err_ploop:
     232                lodsb
     233               
     234                cmp $0, %al
     235                je err_ploop_end
     236               
     237                movb $0x0c, %ah  /* black background, light red foreground */
     238                stosw
     239               
     240                /* Sanity check for the cursor on the last line */
     241                inc %bx
     242                cmp $2000, %bx
     243                jb err_ploop
     244               
     245                /* Scroll the screen (24 rows) */
     246                movl %esi, %edx
     247                movl $0xb80a0, %esi
     248                movl $0xb8000, %edi
     249                movl $960, %ecx
     250                rep movsl
     251               
     252                /* Clear the 24th row */
     253                xorl %eax, %eax
     254                movl $40, %ecx
     255                rep stosl
     256               
     257                /* Go to row 24 */
     258                movl %edx, %esi
     259                movl $0xb8f00, %edi
     260                movw $1920, %bx
     261               
     262                jmp err_ploop
     263        err_ploop_end:
     264       
     265        /* Write bits 8 - 15 of the cursor address */
     266        movw $0x3d4, %dx
     267        movb $0xe, %al
     268        outb %al, %dx
     269       
     270        movw $0x3d5, %dx
     271        movb %bh, %al
     272        outb %al, %dx
     273       
     274        /* Write bits 0 - 7 of the cursor address */
     275        movw $0x3d4, %dx
     276        movb $0xf, %al
     277        outb %al, %dx
     278       
     279        movw $0x3d5, %dx
     280        movb %bl, %al
     281        outb %al, %dx
     282       
     283        cli
     284        hlt1:
     285                hlt
     286                jmp hlt1
     287
     288/** Print string to EGA display (in light green).
     289 *
     290 * Should be called from 32 bit protected mode with paging
     291 * turned off. A stack space of at least 24 bytes is required,
     292 * but the function does not establish a stack frame.
     293 *
     294 * Macros such as pm_status and pm2_status take care that
     295 * this function is used only when CONFIG_EGA is enabled
     296 * and CONFIG_FB is disabled.
     297 *
     298 * @param %esi Pointer to the NULL-terminated string
     299 *             to be print.
     300 *
     301 */
     302pm_early_puts:
     303        pushl %eax
     304        pushl %ebx
     305        pushl %ecx
     306        pushl %edx
     307        pushl %edi
     308       
     309        movl $0xb8000, %edi  /* base of EGA text mode memory */
     310        xorl %eax, %eax
     311       
     312        /* Read bits 8 - 15 of the cursor address */
     313        movw $0x3d4, %dx
     314        movb $0xe, %al
     315        outb %al, %dx
     316       
     317        movw $0x3d5, %dx
     318        inb %dx, %al
     319        shl $8, %ax
     320       
     321        /* Read bits 0 - 7 of the cursor address */
     322        movw $0x3d4, %dx
     323        movb $0xf, %al
     324        outb %al, %dx
     325       
     326        movw $0x3d5, %dx
     327        inb %dx, %al
     328       
     329        /* Sanity check for the cursor on screen */
     330        cmp $2000, %ax
     331        jb pm_puts_cursor_ok
     332       
     333                movw $1998, %ax
     334       
     335        pm_puts_cursor_ok:
     336       
     337        movw %ax, %bx
     338        shl $1, %eax
     339        addl %eax, %edi
     340       
     341        pm_puts_ploop:
     342                lodsb
     343               
     344                cmp $0, %al
     345                je pm_puts_ploop_end
     346               
     347                movb $0x0a, %ah  /* black background, light green foreground */
     348                stosw
     349               
     350                /* Sanity check for the cursor on the last line */
     351                inc %bx
     352                cmp $2000, %bx
     353                jb pm_puts_ploop
     354               
     355                /* Scroll the screen (24 rows) */
     356                movl %esi, %edx
     357                movl $0xb80a0, %esi
     358                movl $0xb8000, %edi
     359                movl $960, %ecx
     360                rep movsl
     361               
     362                /* Clear the 24th row */
     363                xorl %eax, %eax
     364                movl $40, %ecx
     365                rep stosl
     366               
     367                /* Go to row 24 */
     368                movl %edx, %esi
     369                movl $0xb8f00, %edi
     370                movw $1920, %bx
     371               
     372                jmp pm_puts_ploop
     373        pm_puts_ploop_end:
     374       
     375        /* Write bits 8 - 15 of the cursor address */
     376        movw $0x3d4, %dx
     377        movb $0xe, %al
     378        outb %al, %dx
     379       
     380        movw $0x3d5, %dx
     381        movb %bh, %al
     382        outb %al, %dx
     383       
     384        /* Write bits 0 - 7 of the cursor address */
     385        movw $0x3d4, %dx
     386        movb $0xf, %al
     387        outb %al, %dx
     388       
     389        movw $0x3d5, %dx
     390        movb %bl, %al
     391        outb %al, %dx
     392       
     393        popl %edi
     394        popl %edx
     395        popl %ecx
     396        popl %ebx
     397        popl %eax
     398       
     399        ret
    164400
    165401.code64
     402
     403.macro long_status msg
     404        pushq %rdi
     405        movq \msg, %rdi
     406        call early_puts
     407        popq %rdi
     408.endm
     409
    166410start64:
     411       
     412        /*
     413         * Long mode.
     414         */
     415       
    167416        movq $(PA2KA(START_STACK)), %rsp
    168417       
    169         # call arch_pre_main(grub_eax, grub_ebx)
     418        /* Create the first stack frame */
     419        pushq $0
     420        movq %rsp, %rbp
     421       
     422        long_status $status_long
     423       
     424        /* Call arch_pre_main(grub_eax, grub_ebx) */
    170425        xorq %rdi, %rdi
    171426        movl grub_eax, %edi
    172427        xorq %rsi, %rsi
    173428        movl grub_ebx, %esi
    174         call arch_pre_main
    175        
    176         # create the first stack frame
    177         pushq $0
    178         movq %rsp, %rbp
    179 
    180         call main_bsp
    181        
    182         # not reached
    183        
     429       
     430        movabsq $arch_pre_main, %rax
     431        callq *%rax
     432       
     433        long_status $status_main
     434       
     435        /* Call main_bsp() */
     436        movabsq $main_bsp, %rax
     437        call *%rax
     438       
     439        /* Not reached */
    184440        cli
    185441        hlt0:
     
    187443                jmp hlt0
    188444
    189 # Print string from %esi to EGA display (in red) and halt
    190 error_halt:
    191         movl $0xb8000, %edi       # base of EGA text mode memory
    192         xorl %eax, %eax
    193        
    194         movw $0x3d4, %dx          # read bits 8 - 15 of the cursor address
     445/** Print string to EGA display.
     446 *
     447 * Should be called from long mode (with paging enabled
     448 * and stack established). This function is ABI compliant
     449 * (without red-zone).
     450 *
     451 * If CONFIG_EGA is undefined or CONFIG_FB is defined
     452 * then this function does nothing.
     453 *
     454 * @param %rdi Pointer to the NULL-terminated string
     455 *             to be printed.
     456 *
     457 */
     458early_puts:
     459       
     460#if ((defined(CONFIG_EGA)) && (!defined(CONFIG_FB)))
     461       
     462        /* Prologue, save preserved registers */
     463        pushq %rbp
     464        movq %rsp, %rbp
     465        pushq %rbx
     466       
     467        movq %rdi, %rsi
     468        movq $(PA2KA(0xb8000)), %rdi  /* base of EGA text mode memory */
     469        xorq %rax, %rax
     470       
     471        /* Read bits 8 - 15 of the cursor address */
     472        movw $0x3d4, %dx
    195473        movb $0xe, %al
    196474        outb %al, %dx
     
    200478        shl $8, %ax
    201479       
    202         movw $0x3d4, %dx          # read bits 0 - 7 of the cursor address
     480        /* Read bits 0 - 7 of the cursor address */
     481        movw $0x3d4, %dx
    203482        movb $0xf, %al
    204483        outb %al, %dx
     
    207486        inb %dx, %al
    208487       
    209         cmp $1920, %ax
    210         jbe cursor_ok
    211        
    212                 movw $1920, %ax       # sanity check for the cursor on the last line
    213        
    214         cursor_ok:
     488        /* Sanity check for the cursor on screen */
     489        cmp $2000, %ax
     490        jb early_puts_cursor_ok
     491       
     492                movw $1998, %ax
     493       
     494        early_puts_cursor_ok:
    215495       
    216496        movw %ax, %bx
    217         shl $1, %eax
    218         addl %eax, %edi
    219        
    220         movw $0x0c00, %ax         # black background, light red foreground
    221        
    222         ploop:
     497        shl $1, %rax
     498        addq %rax, %rdi
     499       
     500        early_puts_ploop:
    223501                lodsb
     502               
    224503                cmp $0, %al
    225                 je ploop_end
     504                je early_puts_ploop_end
     505               
     506                movb $0x0e, %ah  /* black background, yellow foreground */
    226507                stosw
     508               
     509                /* Sanity check for the cursor on the last line */
    227510                inc %bx
    228                 jmp ploop
    229         ploop_end:
    230        
    231         movw $0x3d4, %dx          # write bits 8 - 15 of the cursor address
     511                cmp $2000, %bx
     512                jb early_puts_ploop
     513               
     514                /* Scroll the screen (24 rows) */
     515                movq %rsi, %rdx
     516                movq $(PA2KA(0xb80a0)), %rsi
     517                movq $(PA2KA(0xb8000)), %rdi
     518                movl $480, %ecx
     519                rep movsq
     520               
     521                /* Clear the 24th row */
     522                xorl %eax, %eax
     523                movl $20, %ecx
     524                rep stosq
     525               
     526                /* Go to row 24 */
     527                movq %rdx, %rsi
     528                movq $(PA2KA(0xb8f00)), %rdi
     529                movw $1920, %bx
     530               
     531                jmp early_puts_ploop
     532        early_puts_ploop_end:
     533       
     534        /* Write bits 8 - 15 of the cursor address */
     535        movw $0x3d4, %dx
    232536        movb $0xe, %al
    233537        outb %al, %dx
     
    237541        outb %al, %dx
    238542       
    239         movw $0x3d4, %dx          # write bits 0 - 7 of the cursor address
     543        /* Write bits 0 - 7 of the cursor address */
     544        movw $0x3d4, %dx
    240545        movb $0xf, %al
    241546        outb %al, %dx
     
    245550        outb %al, %dx
    246551       
    247         cli
    248         hlt1:
    249                 hlt
    250                 jmp hlt1
     552        /* Epilogue, restore preserved registers */
     553        popq %rbx
     554        leave
     555       
     556#endif
     557       
     558        ret
    251559
    252560#include "vesa_real.inc"
     
    254562.section K_INI_PTLS, "aw", @progbits
    255563
    256 #
    257 # Macro for generating initial page table contents.
    258 # @param cnt Number of entries to generat. Must be multiple of 8.
    259 # @param g   Number of GB that will be added to the mapping.
    260 #
    261 .macro ptl2gen cnt g
    262 .if \cnt
    263         ptl2gen "\cnt - 8" \g
    264         .quad ((\cnt - 8) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
    265         .quad ((\cnt - 7) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
    266         .quad ((\cnt - 6) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
    267         .quad ((\cnt - 5) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
    268         .quad ((\cnt - 4) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
    269         .quad ((\cnt - 3) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
    270         .quad ((\cnt - 2) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
    271         .quad ((\cnt - 1) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
    272 .endif
     564/** Generate initial page table contents.
     565 *
     566 * @param cnt Number of entries to generate. Must be multiple of 8.
     567 * @param g   Number of GB that will be added to the mapping.
     568 *
     569 */
     570.macro ptl2gen cnt g
     571        .if \cnt
     572                ptl2gen "\cnt - 8" \g
     573                .quad ((\cnt - 8) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
     574                .quad ((\cnt - 7) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
     575                .quad ((\cnt - 6) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
     576                .quad ((\cnt - 5) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
     577                .quad ((\cnt - 4) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
     578                .quad ((\cnt - 3) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
     579                .quad ((\cnt - 2) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
     580                .quad ((\cnt - 1) * 0x200000) + (\g * 1024 * 1024 * 1024) | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
     581        .endif
    273582.endm
    274583
    275 # Page table for pages in the first gigabyte.
    276 .align 4096
    277 .global ptl_2_0g
    278 ptl_2_0g:       
     584/* Page table for pages in the 1st gigabyte. */
     585.align 4096
     586ptl_2_0g:
    279587        ptl2gen 512 0
    280588
    281 # Page table for pages in the second gigabyte.
    282 .align 4096
    283 .global ptl_2_1g
     589/* Page table for pages in the 2nd gigabyte. */
     590.align 4096
    284591ptl_2_1g:
    285592        ptl2gen 512 1
    286593
    287 # Page table for pages in the third gigabyte.
    288 .align 4096
    289 .global ptl_2_2g
     594/* Page table for pages in the 3rd gigabyte. */
     595.align 4096
    290596ptl_2_2g:
    291597        ptl2gen 512 2
    292598
    293 # Page table for pages in the fourth gigabyte.
    294 .align 4096
    295 .global ptl_2_3g
     599/* Page table for pages in the 4th gigabyte. */
     600.align 4096
    296601ptl_2_3g:
    297602        ptl2gen 512 3
    298603
    299 .align 4096
    300 .global ptl_1
     604/* Page table for pages in the 5th gigabyte. */
     605.align 4096
     606ptl_2_4g:
     607        ptl2gen 512 4
     608
     609/* Page table for pages in the 6th gigabyte. */
     610.align 4096
     611ptl_2_5g:
     612        ptl2gen 512 5
     613
     614/* Page table for pages in the 7th gigabyte. */
     615.align 4096
     616ptl_2_6g:
     617        ptl2gen 512 6
     618
     619/* Page table for pages in the 8th gigabyte. */
     620.align 4096
     621ptl_2_7g:
     622        ptl2gen 512 7
     623
     624.align 4096
    301625ptl_1:
    302         # Identity mapping for [0; 4G)
     626        /* Identity mapping for [0; 8G) */
    303627        .quad ptl_2_0g + (PTL_WRITABLE | PTL_PRESENT)
    304         .quad ptl_2_1g + (PTL_WRITABLE | PTL_PRESENT) 
     628        .quad ptl_2_1g + (PTL_WRITABLE | PTL_PRESENT)
    305629        .quad ptl_2_2g + (PTL_WRITABLE | PTL_PRESENT)
    306630        .quad ptl_2_3g + (PTL_WRITABLE | PTL_PRESENT)
    307         .fill 506, 8, 0
    308         # Mapping of [0; 1G) at -2G
    309         .quad ptl_2_0g + (PTL_WRITABLE | PTL_PRESENT)
    310         .fill 1, 8, 0
     631        .quad ptl_2_4g + (PTL_WRITABLE | PTL_PRESENT)
     632        .quad ptl_2_5g + (PTL_WRITABLE | PTL_PRESENT)
     633        .quad ptl_2_6g + (PTL_WRITABLE | PTL_PRESENT)
     634        .quad ptl_2_7g + (PTL_WRITABLE | PTL_PRESENT)
     635        .fill 504, 8, 0
    311636
    312637.align 4096
     
    314639ptl_0:
    315640        .quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT)
    316         .fill 255,8,0
     641        .fill 255, 8, 0
    317642        .quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT)
    318         .fill 254,8,0
    319         .quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT)
     643        .fill 255, 8, 0
    320644
    321645.section K_DATA_START, "aw", @progbits
    322646
    323 .global bootstrap_gdtr
    324647bootstrap_gdtr:
    325         .word gdtselector(GDT_ITEMS)
     648        .word GDT_SELECTOR(GDT_ITEMS)
    326649        .long KA2PA(gdt)
    327650
     
    332655        .long 0
    333656
    334 extended_cpuid_msg:
     657err_extended_cpuid:
    335658        .asciz "Error: Extended CPUID not supported -- CPU is not 64-bit. System halted."
    336 long_mode_msg:
     659err_long_mode:
    337660        .asciz "Error: 64-bit long mode not supported. System halted."
    338 noexecute_msg:
     661err_noexecute:
    339662        .asciz "Error: No-execute pages not supported. System halted."
    340 fx_msg:
     663err_fx:
    341664        .asciz "Error: FXSAVE/FXRESTORE instructions not supported. System halted."
    342 sse2_msg:
     665err_sse2:
    343666        .asciz "Error: SSE2 instructions not supported. System halted."
     667
     668status_prot:
     669        .asciz "[prot] "
     670status_vesa_copy:
     671        .asciz "[vesa_copy] "
     672status_grub_cmdline:
     673        .asciz "[grub_cmdline] "
     674status_vesa_real:
     675        .asciz "[vesa_real] "
     676status_prot2:
     677        .asciz "[prot2] "
     678status_long:
     679        .asciz "[long] "
     680status_main:
     681        .asciz "[main] "
  • kernel/arch/amd64/src/boot/memmap.c

    rfb150d78 r46c20c8  
    3535#include <arch/boot/memmap.h>
    3636
    37 uint8_t e820counter = 0xff;
     37uint8_t e820counter = 0xffU;
    3838e820memmap_t e820table[MEMMAP_E820_MAX_RECORDS];
    3939
  • kernel/arch/amd64/src/boot/vesa_ret.inc

    rfb150d78 r46c20c8  
    11.code32
    22vesa_init_protected:
    3         movw $gdtselector(KDATA_DES), %cx
     3        cld
     4       
     5        /* Initialize stack pointer */
     6        movl $START_STACK, %esp
     7       
     8        /* Kernel data + stack */
     9        movw $GDT_SELECTOR(KDATA_DES), %cx
    410        movw %cx, %es
    5         movw %cx, %ds                       # kernel data + stack
     11        movw %cx, %ds
    612        movw %cx, %ss
    713       
    8         #
    9         # Simics seems to remove hidden part of GS on entering user mode
    10         # when _visible_ part of GS does not point to user-mode segment.
    11         #
     14        /*
     15         * Simics seems to remove hidden part of GS on entering user mode
     16         * when _visible_ part of GS does not point to user-mode segment.
     17         */
    1218       
    13         movw $gdtselector(UDATA_DES), %cx
     19        movw $GDT_SELECTOR(UDATA_DES), %cx
    1420        movw %cx, %fs
    1521        movw %cx, %gs
    1622       
    17         movl $START_STACK, %esp             # initialize stack pointer
    18        
    19         jmpl $gdtselector(KTEXT32_DES), $vesa_meeting_point
     23        jmpl $GDT_SELECTOR(KTEXT32_DES), $vesa_meeting_point
  • kernel/arch/amd64/src/context.S

    rfb150d78 r46c20c8  
    4141context_save_arch:
    4242        movq (%rsp), %rdx     # the caller's return %eip
    43 
    44         # In %edi is passed 1st argument
    45         CONTEXT_SAVE_ARCH_CORE %rdi %rdx
    4643       
    47         xorq %rax,%rax          # context_save returns 1
    48         incq %rax
     44        # 1st argument passed in %edi
     45        CONTEXT_SAVE_ARCH_CORE %rdi %rdx
     46       
     47        xorl %eax, %eax       # context_save returns 1
     48        incl %eax
    4949        ret
    5050
     
    5555# pointed by the 1st argument. Returns 0 in EAX.
    5656#
    57 context_restore_arch:   
    58 
     57context_restore_arch:
    5958        CONTEXT_RESTORE_ARCH_CORE %rdi %rdx
    60 
    61         movq %rdx,(%rsp)
    62 
    63         xorq %rax,%rax          # context_restore returns 0
     59       
     60        movq %rdx, (%rsp)
     61       
     62        xorl %eax, %eax       # context_restore returns 0
    6463        ret
  • kernel/arch/amd64/src/cpu/cpu.c

    rfb150d78 r46c20c8  
    3939
    4040#include <arch.h>
    41 #include <arch/types.h>
     41#include <typedefs.h>
    4242#include <print.h>
    4343#include <fpu_context.h>
     
    4747 * Contains only non-MP-Specification specific SMP code.
    4848 */
    49 #define AMD_CPUID_EBX   0x68747541
    50 #define AMD_CPUID_ECX   0x444d4163
    51 #define AMD_CPUID_EDX   0x69746e65
     49#define AMD_CPUID_EBX  UINT32_C(0x68747541)
     50#define AMD_CPUID_ECX  UINT32_C(0x444d4163)
     51#define AMD_CPUID_EDX  UINT32_C(0x69746e65)
    5252
    53 #define INTEL_CPUID_EBX 0x756e6547
    54 #define INTEL_CPUID_ECX 0x6c65746e
    55 #define INTEL_CPUID_EDX 0x49656e69
    56 
     53#define INTEL_CPUID_EBX  UINT32_C(0x756e6547)
     54#define INTEL_CPUID_ECX  UINT32_C(0x6c65746e)
     55#define INTEL_CPUID_EDX  UINT32_C(0x49656e69)
    5756
    5857enum vendor {
     
    6261};
    6362
    64 static char *vendor_str[] = {
     63static const char *vendor_str[] = {
    6564        "Unknown Vendor",
    6665        "AuthenticAMD",
     
    127126{
    128127        cpu_info_t info;
    129 
     128       
    130129        CPU->arch.vendor = VendorUnknown;
    131130        if (has_cpuid()) {
    132131                cpuid(INTEL_CPUID_LEVEL, &info);
    133 
     132               
    134133                /*
    135134                 * Check for AMD processor.
    136135                 */
    137                 if (info.cpuid_ebx == AMD_CPUID_EBX &&
    138                     info.cpuid_ecx == AMD_CPUID_ECX &&
    139                     info.cpuid_edx == AMD_CPUID_EDX) {
     136                if ((info.cpuid_ebx == AMD_CPUID_EBX) &&
     137                    (info.cpuid_ecx == AMD_CPUID_ECX) &&
     138                    (info.cpuid_edx == AMD_CPUID_EDX)) {
    140139                        CPU->arch.vendor = VendorAMD;
    141140                }
    142 
     141               
    143142                /*
    144143                 * Check for Intel processor.
    145                  */             
    146                 if (info.cpuid_ebx == INTEL_CPUID_EBX &&
    147                     info.cpuid_ecx == INTEL_CPUID_ECX &&
    148                     info.cpuid_edx == INTEL_CPUID_EDX) {
     144                 */
     145                if ((info.cpuid_ebx == INTEL_CPUID_EBX) &&
     146                    (info.cpuid_ecx == INTEL_CPUID_ECX) &&
     147                    (info.cpuid_edx == INTEL_CPUID_EDX)) {
    149148                        CPU->arch.vendor = VendorIntel;
    150149                }
    151                                
     150               
    152151                cpuid(INTEL_CPUID_STANDARD, &info);
    153152                CPU->arch.family = (info.cpuid_eax >> 8) & 0xf;
    154153                CPU->arch.model = (info.cpuid_eax >> 4) & 0xf;
    155                 CPU->arch.stepping = (info.cpuid_eax >> 0) & 0xf;                                               
     154                CPU->arch.stepping = (info.cpuid_eax >> 0) & 0xf;
    156155        }
    157156}
  • kernel/arch/amd64/src/ddi/ddi.c

    rfb150d78 r46c20c8  
    3636#include <arch/ddi/ddi.h>
    3737#include <proc/task.h>
    38 #include <arch/types.h>
     38#include <typedefs.h>
    3939#include <adt/bitmap.h>
    4040#include <mm/slab.h>
     
    4949 * Interrupts are disabled and task is locked.
    5050 *
    51  * @param task Task.
     51 * @param task   Task.
    5252 * @param ioaddr Startign I/O space address.
    53  * @param size Size of the enabled I/O range.
     53 * @param size   Size of the enabled I/O range.
    5454 *
    5555 * @return 0 on success or an error code from errno.h.
     56 *
    5657 */
    5758int ddi_iospace_enable_arch(task_t *task, uintptr_t ioaddr, size_t size)
    5859{
    59         size_t bits;
    60        
    61         bits = ioaddr + size;
     60        size_t bits = ioaddr + size;
    6261        if (bits > IO_PORTS)
    6362                return ENOENT;
    6463       
    6564        if (task->arch.iomap.bits < bits) {
    66                 bitmap_t oldiomap;
    67                 uint8_t *newmap;
    68                
    6965                /*
    7066                 * The I/O permission bitmap is too small and needs to be grown.
    7167                 */
    7268               
    73                 newmap = (uint8_t *) malloc(BITS2BYTES(bits), FRAME_ATOMIC);
     69                uint8_t *newmap = (uint8_t *) malloc(BITS2BYTES(bits), FRAME_ATOMIC);
    7470                if (!newmap)
    7571                        return ENOMEM;
    7672               
     73                bitmap_t oldiomap;
    7774                bitmap_initialize(&oldiomap, task->arch.iomap.map,
    7875                    task->arch.iomap.bits);
     
    115112 *
    116113 * Interrupts must be disabled prior this call.
     114 *
    117115 */
    118116void io_perm_bitmap_install(void)
    119117{
    120         size_t bits;
    121         ptr_16_64_t cpugdtr;
    122         descriptor_t *gdt_p;
    123         tss_descriptor_t *tss_desc;
    124         size_t ver;
    125        
    126118        /* First, copy the I/O Permission Bitmap. */
    127         spinlock_lock(&TASK->lock);
    128         ver = TASK->arch.iomapver;
    129         if ((bits = TASK->arch.iomap.bits)) {
     119        irq_spinlock_lock(&TASK->lock, false);
     120        size_t ver = TASK->arch.iomapver;
     121        size_t bits = TASK->arch.iomap.bits;
     122        if (bits) {
     123                ASSERT(TASK->arch.iomap.map);
     124               
    130125                bitmap_t iomap;
    131        
    132                 ASSERT(TASK->arch.iomap.map);
    133126                bitmap_initialize(&iomap, CPU->arch.tss->iomap,
    134127                    TSS_IOMAP_SIZE * 8);
    135                 bitmap_copy(&iomap, &TASK->arch.iomap, TASK->arch.iomap.bits);
     128                bitmap_copy(&iomap, &TASK->arch.iomap, bits);
     129               
     130                /*
     131                 * Set the trailing bits in the last byte of the map to disable
     132                 * I/O access.
     133                 */
     134                bitmap_set_range(&iomap, bits, ALIGN_UP(bits, 8) - bits);
    136135                /*
    137136                 * It is safe to set the trailing eight bits because of the
    138137                 * extra convenience byte in TSS_IOMAP_SIZE.
    139138                 */
    140                 bitmap_set_range(&iomap, ALIGN_UP(TASK->arch.iomap.bits, 8), 8);
     139                bitmap_set_range(&iomap, ALIGN_UP(bits, 8), 8);
    141140        }
    142         spinlock_unlock(&TASK->lock);
     141        irq_spinlock_unlock(&TASK->lock, false);
    143142       
    144143        /*
     
    146145         * Take the extra ending byte will all bits set into account.
    147146         */
     147        ptr_16_64_t cpugdtr;
    148148        gdtr_store(&cpugdtr);
    149         gdt_p = (descriptor_t *) cpugdtr.base;
     149       
     150        descriptor_t *gdt_p = (descriptor_t *) cpugdtr.base;
    150151        gdt_tss_setlimit(&gdt_p[TSS_DES], TSS_BASIC_SIZE + BITS2BYTES(bits));
    151152        gdtr_load(&cpugdtr);
     
    155156         * type must be changed to describe inactive TSS.
    156157         */
    157         tss_desc = (tss_descriptor_t *) &gdt_p[TSS_DES];
     158        tss_descriptor_t *tss_desc = (tss_descriptor_t *) &gdt_p[TSS_DES];
    158159        tss_desc->type = AR_TSS;
    159         tr_load(gdtselector(TSS_DES));
     160        tr_load(GDT_SELECTOR(TSS_DES));
    160161       
    161162        /*
  • kernel/arch/amd64/src/debug/stacktrace.c

    rfb150d78 r46c20c8  
    3535#include <stacktrace.h>
    3636#include <syscall/copy.h>
    37 #include <arch/types.h>
    3837#include <typedefs.h>
    3938
    40 #define FRAME_OFFSET_FP_PREV    0
    41 #define FRAME_OFFSET_RA         1
     39#define FRAME_OFFSET_FP_PREV  0
     40#define FRAME_OFFSET_RA       1
    4241
    43 bool kernel_frame_pointer_validate(uintptr_t fp)
     42bool kernel_stack_trace_context_validate(stack_trace_context_t *ctx)
    4443{
    45         return fp != 0;
     44        return ctx->fp != 0;
    4645}
    4746
    48 bool kernel_frame_pointer_prev(uintptr_t fp, uintptr_t *prev)
     47bool kernel_frame_pointer_prev(stack_trace_context_t *ctx, uintptr_t *prev)
    4948{
    50         uint64_t *stack = (void *) fp;
     49        uint64_t *stack = (void *) ctx->fp;
    5150        *prev = stack[FRAME_OFFSET_FP_PREV];
     51       
    5252        return true;
    5353}
    5454
    55 bool kernel_return_address_get(uintptr_t fp, uintptr_t *ra)
     55bool kernel_return_address_get(stack_trace_context_t *ctx, uintptr_t *ra)
    5656{
    57         uint64_t *stack = (void *) fp;
     57        uint64_t *stack = (void *) ctx->fp;
    5858        *ra = stack[FRAME_OFFSET_RA];
     59       
    5960        return true;
    6061}
    6162
    62 bool uspace_frame_pointer_validate(uintptr_t fp)
     63bool uspace_stack_trace_context_validate(stack_trace_context_t *ctx)
    6364{
    64         return fp != 0;
     65        return ctx->fp != 0;
    6566}
    6667
    67 bool uspace_frame_pointer_prev(uintptr_t fp, uintptr_t *prev)
     68bool uspace_frame_pointer_prev(stack_trace_context_t *ctx, uintptr_t *prev)
    6869{
    6970        return !copy_from_uspace((void *) prev,
    70             (uint64_t *) fp + FRAME_OFFSET_FP_PREV, sizeof(*prev));
     71            (uint64_t *) ctx->fp + FRAME_OFFSET_FP_PREV, sizeof(*prev));
    7172}
    7273
    73 bool uspace_return_address_get(uintptr_t fp, uintptr_t *ra)
     74bool uspace_return_address_get(stack_trace_context_t *ctx, uintptr_t *ra)
    7475{
    75         return !copy_from_uspace((void *) ra, (uint64_t *) fp + FRAME_OFFSET_RA,
    76             sizeof(*ra));
     76        return !copy_from_uspace((void *) ra,
     77            (uint64_t *) ctx->fp + FRAME_OFFSET_RA, sizeof(*ra));
    7778}
    7879
  • kernel/arch/amd64/src/debugger.c

    rfb150d78 r46c20c8  
    4646#include <symtab.h>
    4747
     48#ifdef __64_BITS__
     49        #define getip(x)  ((x)->rip)
     50#endif
     51
     52#ifdef __32_BITS__
     53        #define getip(x)  ((x)->eip)
     54#endif
     55
    4856typedef struct  {
    49         uintptr_t address;      /**< Breakpoint address */
    50         int flags;              /**< Flags regarding breakpoint */
    51         int counter;            /**< How many times the exception occured */
     57        uintptr_t address;   /**< Breakpoint address */
     58        unsigned int flags;  /**< Flags regarding breakpoint */
     59        size_t counter;      /**< How many times the exception occured */
    5260} bpinfo_t;
    5361
    5462static bpinfo_t breakpoints[BKPOINTS_MAX];
    55 SPINLOCK_INITIALIZE(bkpoint_lock);
     63IRQ_SPINLOCK_STATIC_INITIALIZE(bkpoint_lock);
    5664
    5765#ifdef CONFIG_KCONSOLE
    5866
    59 static int cmd_print_breakpoints(cmd_arg_t *argv);
     67static int cmd_print_breakpoints(cmd_arg_t *);
     68static int cmd_del_breakpoint(cmd_arg_t *);
     69static int cmd_add_breakpoint(cmd_arg_t *);
     70
    6071static cmd_info_t bkpts_info = {
    6172        .name = "bkpts",
     
    6576};
    6677
    67 static int cmd_del_breakpoint(cmd_arg_t *argv);
    6878static cmd_arg_t del_argv = {
    6979        .type = ARG_TYPE_INT
    7080};
     81
    7182static cmd_info_t delbkpt_info = {
    7283        .name = "delbkpt",
    73         .description = "delbkpt <number> - Delete breakpoint.",
     84        .description = "Delete breakpoint.",
    7485        .func = cmd_del_breakpoint,
    7586        .argc = 1,
     
    7788};
    7889
    79 static int cmd_add_breakpoint(cmd_arg_t *argv);
    8090static cmd_arg_t add_argv = {
    8191        .type = ARG_TYPE_INT
    8292};
     93
    8394static cmd_info_t addbkpt_info = {
    8495        .name = "addbkpt",
    85         .description = "addbkpt <&symbol> - new breakpoint.",
     96        .description = "Add breakpoint.",
    8697        .func = cmd_add_breakpoint,
    8798        .argc = 1,
     
    92103        .type = ARG_TYPE_INT
    93104};
     105
    94106static cmd_info_t addwatchp_info = {
    95107        .name = "addwatchp",
    96         .description = "addbwatchp <&symbol> - new write watchpoint.",
     108        .description = "Add write watchpoint.",
    97109        .func = cmd_add_breakpoint,
    98110        .argc = 1,
     
    102114#endif /* CONFIG_KCONSOLE */
    103115
    104 /* Setup DR register according to table */
     116/** Setup DR register according to table
     117 *
     118 */
    105119static void setup_dr(int curidx)
    106120{
    107         unative_t dr7;
     121        ASSERT(curidx >= 0);
     122       
    108123        bpinfo_t *cur = &breakpoints[curidx];
    109         int flags = breakpoints[curidx].flags;
    110 
     124        unsigned int flags = breakpoints[curidx].flags;
     125       
    111126        /* Disable breakpoint in DR7 */
    112         dr7 = read_dr7();
    113         dr7 &= ~(0x2 << (curidx*2));
    114 
    115         if (cur->address) { /* Setup DR register */
     127        unative_t dr7 = read_dr7();
     128        dr7 &= ~(0x02U << (curidx * 2));
     129       
     130        /* Setup DR register */
     131        if (cur->address) {
    116132                /* Set breakpoint to debug registers */
    117133                switch (curidx) {
     
    129145                        break;
    130146                }
     147               
    131148                /* Set type to requested breakpoint & length*/
    132                 dr7 &= ~ (0x3 << (16 + 4*curidx));
    133                 dr7 &= ~ (0x3 << (18 + 4*curidx));
    134                 if ((flags & BKPOINT_INSTR)) {
    135                         ;
    136                 } else {
     149                dr7 &= ~(0x03U << (16 + 4 * curidx));
     150                dr7 &= ~(0x03U << (18 + 4 * curidx));
    137151               
     152                if (!(flags & BKPOINT_INSTR)) {
    138153#ifdef __32_BITS__
    139                         dr7 |= ((unative_t) 0x3) << (18 + 4 * curidx);
    140 #endif
    141 
     154                        dr7 |= ((unative_t) 0x03U) << (18 + 4 * curidx);
     155#endif
     156                       
    142157#ifdef __64_BITS__
    143                         dr7 |= ((unative_t) 0x2) << (18 + 4 * curidx);
     158                        dr7 |= ((unative_t) 0x02U) << (18 + 4 * curidx);
    144159#endif
    145160                       
    146161                        if ((flags & BKPOINT_WRITE))
    147                                 dr7 |= ((unative_t) 0x1) << (16 + 4 * curidx);
     162                                dr7 |= ((unative_t) 0x01U) << (16 + 4 * curidx);
    148163                        else if ((flags & BKPOINT_READ_WRITE))
    149                                 dr7 |= ((unative_t) 0x3) << (16 + 4 * curidx);
    150                 }
    151 
     164                                dr7 |= ((unative_t) 0x03U) << (16 + 4 * curidx);
     165                }
     166               
    152167                /* Enable global breakpoint */
    153                 dr7 |= 0x2 << (curidx * 2);
    154 
     168                dr7 |= 0x02U << (curidx * 2);
     169               
    155170                write_dr7(dr7);
    156                
    157         }
    158 }
    159        
     171        }
     172}
     173
    160174/** Enable hardware breakpoint
    161175 *
    162176 * @param where Address of HW breakpoint
    163177 * @param flags Type of breakpoint (EXECUTE, WRITE)
     178 *
    164179 * @return Debug slot on success, -1 - no available HW breakpoint
    165  */
    166 int breakpoint_add(const void *where, const int flags, int curidx)
    167 {
    168         ipl_t ipl;
    169         int i;
    170         bpinfo_t *cur;
    171 
     180 *
     181 */
     182int breakpoint_add(const void *where, const unsigned int flags, int curidx)
     183{
    172184        ASSERT(flags & (BKPOINT_INSTR | BKPOINT_WRITE | BKPOINT_READ_WRITE));
    173 
    174         ipl = interrupts_disable();
    175         spinlock_lock(&bkpoint_lock);
     185       
     186        irq_spinlock_lock(&bkpoint_lock, true);
    176187       
    177188        if (curidx == -1) {
    178189                /* Find free space in slots */
    179                 for (i = 0; i < BKPOINTS_MAX; i++)
     190                unsigned int i;
     191                for (i = 0; i < BKPOINTS_MAX; i++) {
    180192                        if (!breakpoints[i].address) {
    181193                                curidx = i;
    182194                                break;
    183195                        }
     196                }
     197               
    184198                if (curidx == -1) {
    185199                        /* Too many breakpoints */
    186                         spinlock_unlock(&bkpoint_lock);
    187                         interrupts_restore(ipl);
     200                        irq_spinlock_unlock(&bkpoint_lock, true);
    188201                        return -1;
    189202                }
    190203        }
    191         cur = &breakpoints[curidx];
    192 
     204       
     205        bpinfo_t *cur = &breakpoints[curidx];
     206       
    193207        cur->address = (uintptr_t) where;
    194208        cur->flags = flags;
    195209        cur->counter = 0;
    196 
     210       
    197211        setup_dr(curidx);
    198 
    199         spinlock_unlock(&bkpoint_lock);
    200         interrupts_restore(ipl);
    201 
     212       
     213        irq_spinlock_unlock(&bkpoint_lock, true);
     214       
    202215        /* Send IPI */
    203 #ifdef CONFIG_SMP
    204216//      ipi_broadcast(VECTOR_DEBUG_IPI);
    205 #endif 
    206 
     217       
    207218        return curidx;
    208219}
    209220
    210 #ifdef __64_BITS__
    211         #define getip(x)  ((x)->rip)
    212 #else
    213         #define getip(x)  ((x)->eip)
    214 #endif
    215 
    216221static void handle_exception(int slot, istate_t *istate)
    217222{
     223        ASSERT(slot >= 0);
    218224        ASSERT(breakpoints[slot].address);
    219 
     225       
    220226        /* Handle zero checker */
    221         if (! (breakpoints[slot].flags & BKPOINT_INSTR)) {
     227        if (!(breakpoints[slot].flags & BKPOINT_INSTR)) {
    222228                if ((breakpoints[slot].flags & BKPOINT_CHECK_ZERO)) {
    223229                        if (*((unative_t *) breakpoints[slot].address) != 0)
    224230                                return;
    225                         printf("*** Found ZERO on address %lx (slot %d) ***\n",
    226                             breakpoints[slot].address, slot);
     231                       
     232                        printf("*** Found ZERO on address %p (slot %d) ***\n",
     233                            (void *) breakpoints[slot].address, slot);
    227234                } else {
    228                         printf("Data watchpoint - new data: %lx\n",
     235                        printf("Data watchpoint - new data: %#" PRIxn "\n",
    229236                            *((unative_t *) breakpoints[slot].address));
    230237                }
    231238        }
    232 
    233         printf("Reached breakpoint %d:%lx (%s)\n", slot, getip(istate),
    234             symtab_fmt_name_lookup(getip(istate)));
    235 
     239       
     240        printf("Reached breakpoint %d:%p (%s)\n", slot,
     241            (void *) getip(istate), symtab_fmt_name_lookup(getip(istate)));
     242       
    236243#ifdef CONFIG_KCONSOLE
    237244        atomic_set(&haltstate, 1);
     
    243250void breakpoint_del(int slot)
    244251{
    245         bpinfo_t *cur;
    246         ipl_t ipl;
    247 
    248         ipl = interrupts_disable();
    249         spinlock_lock(&bkpoint_lock);
    250 
    251         cur = &breakpoints[slot];
     252        ASSERT(slot >= 0);
     253       
     254        irq_spinlock_lock(&bkpoint_lock, true);
     255       
     256        bpinfo_t *cur = &breakpoints[slot];
    252257        if (!cur->address) {
    253                 spinlock_unlock(&bkpoint_lock);
    254                 interrupts_restore(ipl);
     258                irq_spinlock_unlock(&bkpoint_lock, true);
    255259                return;
    256260        }
    257 
    258         cur->address = NULL;
    259 
     261       
     262        cur->address = (uintptr_t) NULL;
     263       
    260264        setup_dr(slot);
    261 
    262         spinlock_unlock(&bkpoint_lock);
    263         interrupts_restore(ipl);
    264 #ifdef CONFIG_SMP
    265 //      ipi_broadcast(VECTOR_DEBUG_IPI);       
    266 #endif
    267 }
    268 
    269 
    270 
    271 static void debug_exception(int n __attribute__((unused)), istate_t *istate)
    272 {
    273         unative_t dr6;
    274         int i;
    275        
     265       
     266        irq_spinlock_unlock(&bkpoint_lock, true);
     267//      ipi_broadcast(VECTOR_DEBUG_IPI);
     268}
     269
     270static void debug_exception(unsigned int n __attribute__((unused)), istate_t *istate)
     271{
    276272        /* Set RF to restart the instruction  */
    277273#ifdef __64_BITS__
    278274        istate->rflags |= RFLAGS_RF;
    279 #else
     275#endif
     276       
     277#ifdef __32_BITS__
    280278        istate->eflags |= EFLAGS_RF;
    281279#endif
    282 
    283         dr6 = read_dr6();
    284         for (i=0; i < BKPOINTS_MAX; i++) {
     280       
     281        unative_t dr6 = read_dr6();
     282       
     283        unsigned int i;
     284        for (i = 0; i < BKPOINTS_MAX; i++) {
    285285                if (dr6 & (1 << i)) {
    286286                        dr6 &= ~ (1 << i);
     
    293293
    294294#ifdef CONFIG_SMP
    295 static void
    296 debug_ipi(int n __attribute__((unused)),
     295static void debug_ipi(unsigned int n __attribute__((unused)),
    297296    istate_t *istate __attribute__((unused)))
    298297{
    299         int i;
    300 
    301         spinlock_lock(&bkpoint_lock);
     298        irq_spinlock_lock(&bkpoint_lock, false);
     299       
     300        unsigned int i;
    302301        for (i = 0; i < BKPOINTS_MAX; i++)
    303302                setup_dr(i);
    304         spinlock_unlock(&bkpoint_lock);
    305 }
    306 #endif
    307 
    308 /** Initialize debugger */
     303       
     304        irq_spinlock_unlock(&bkpoint_lock, false);
     305}
     306#endif /* CONFIG_SMP */
     307
     308/** Initialize debugger
     309 *
     310 */
    309311void debugger_init()
    310312{
    311         int i;
    312 
     313        unsigned int i;
    313314        for (i = 0; i < BKPOINTS_MAX; i++)
    314                 breakpoints[i].address = NULL;
    315 
     315                breakpoints[i].address = (uintptr_t) NULL;
     316       
    316317#ifdef CONFIG_KCONSOLE
    317318        cmd_initialize(&bkpts_info);
    318319        if (!cmd_register(&bkpts_info))
    319320                printf("Cannot register command %s\n", bkpts_info.name);
    320 
     321       
    321322        cmd_initialize(&delbkpt_info);
    322323        if (!cmd_register(&delbkpt_info))
    323324                printf("Cannot register command %s\n", delbkpt_info.name);
    324 
     325       
    325326        cmd_initialize(&addbkpt_info);
    326327        if (!cmd_register(&addbkpt_info))
    327328                printf("Cannot register command %s\n", addbkpt_info.name);
    328 
     329       
    329330        cmd_initialize(&addwatchp_info);
    330331        if (!cmd_register(&addwatchp_info))
     
    332333#endif /* CONFIG_KCONSOLE */
    333334       
    334         exc_register(VECTOR_DEBUG, "debugger", debug_exception);
     335        exc_register(VECTOR_DEBUG, "debugger", true,
     336            debug_exception);
     337       
    335338#ifdef CONFIG_SMP
    336         exc_register(VECTOR_DEBUG_IPI, "debugger_smp", debug_ipi);
    337 #endif
     339        exc_register(VECTOR_DEBUG_IPI, "debugger_smp", true,
     340            debug_ipi);
     341#endif /* CONFIG_SMP */
    338342}
    339343
    340344#ifdef CONFIG_KCONSOLE
    341 /** Print table of active breakpoints */
     345/** Print table of active breakpoints
     346 *
     347 */
    342348int cmd_print_breakpoints(cmd_arg_t *argv __attribute__((unused)))
    343349{
     350#ifdef __32_BITS__
     351        printf("[nr] [count] [address ] [in symbol\n");
     352#endif
     353       
     354#ifdef __64_BITS__
     355        printf("[nr] [count] [address         ] [in symbol\n");
     356#endif
     357       
    344358        unsigned int i;
    345         char *symbol;
    346 
     359        for (i = 0; i < BKPOINTS_MAX; i++) {
     360                if (breakpoints[i].address) {
     361                        const char *symbol = symtab_fmt_name_lookup(
     362                            breakpoints[i].address);
     363                       
    347364#ifdef __32_BITS__
    348         printf("#  Count Address    In symbol\n");
    349         printf("-- ----- ---------- ---------\n");
    350 #endif
    351 
     365                        printf("%-4u %7zu %p %s\n", i,
     366                            breakpoints[i].counter, (void *) breakpoints[i].address,
     367                            symbol);
     368#endif
     369                       
    352370#ifdef __64_BITS__
    353         printf("#  Count Address            In symbol\n");
    354         printf("-- ----- ------------------ ---------\n");
    355 #endif
    356        
    357         for (i = 0; i < BKPOINTS_MAX; i++)
    358                 if (breakpoints[i].address) {
    359                         symbol = symtab_fmt_name_lookup(
    360                             breakpoints[i].address);
    361 
    362 #ifdef __32_BITS__
    363                         printf("%-2u %-5d %#10zx %s\n", i,
    364                             breakpoints[i].counter, breakpoints[i].address,
     371                        printf("%-4u %7zu %p %s\n", i,
     372                            breakpoints[i].counter, (void *) breakpoints[i].address,
    365373                            symbol);
    366374#endif
    367 
    368 #ifdef __64_BITS__
    369                         printf("%-2u %-5d %#18zx %s\n", i,
    370                             breakpoints[i].counter, breakpoints[i].address,
    371                             symbol);
    372 #endif
    373 
    374                 }
     375                }
     376        }
     377       
    375378        return 1;
    376379}
    377380
    378 /** Remove breakpoint from table */
     381/** Remove breakpoint from table
     382 *
     383 */
    379384int cmd_del_breakpoint(cmd_arg_t *argv)
    380385{
     
    384389                return 0;
    385390        }
     391       
    386392        breakpoint_del(argv->intval);
    387393        return 1;
    388394}
    389395
    390 /** Add new breakpoint to table */
     396/** Add new breakpoint to table
     397 *
     398 */
    391399static int cmd_add_breakpoint(cmd_arg_t *argv)
    392400{
    393         int flags;
    394         int id;
    395 
    396         if (argv == &add_argv) {
     401        unsigned int flags;
     402        if (argv == &add_argv)
    397403                flags = BKPOINT_INSTR;
    398         } else { /* addwatchp */
     404        else
    399405                flags = BKPOINT_WRITE;
    400         }
    401         printf("Adding breakpoint on address: %p\n", argv->intval);
    402         id = breakpoint_add((void *)argv->intval, flags, -1);
     406       
     407        printf("Adding breakpoint on address: %p\n",
     408            (void *) argv->intval);
     409       
     410        int id = breakpoint_add((void *) argv->intval, flags, -1);
    403411        if (id < 0)
    404412                printf("Add breakpoint failed.\n");
  • kernel/arch/amd64/src/delay.S

    rfb150d78 r46c20c8  
    3737
    3838asm_delay_loop:
    39 0:      dec %rdi
    40         jnz 0b
     39        0:
     40                dec %rdi
     41                jnz 0b
     42       
    4143        ret
    4244
    4345asm_fake_loop:
    44 0:      dec %rdi
    45         jz 0b
     46        0:
     47                dec %rdi
     48                jz 0b
     49       
    4650        ret
  • kernel/arch/amd64/src/fpu_context.c

    rfb150d78 r46c20c8  
    2727 */
    2828
    29 /** @addtogroup amd64   
     29/** @addtogroup amd64
    3030 * @{
    3131 */
  • kernel/arch/amd64/src/interrupt.c

    rfb150d78 r46c20c8  
    6363void (* eoi_function)(void) = NULL;
    6464
    65 void decode_istate(int n, istate_t *istate)
    66 {
    67         char *symbol;
    68 
    69         symbol = symtab_fmt_name_lookup(istate->rip);
    70 
    71         printf("-----EXCEPTION(%d) OCCURED----- ( %s )\n", n, __func__);
    72         printf("%%rip: %#llx (%s)\n", istate->rip, symbol);
    73         printf("ERROR_WORD=%#llx\n", istate->error_word);
    74         printf("%%cs=%#llx, rflags=%#llx, %%cr0=%#llx\n", istate->cs,
    75             istate->rflags, read_cr0());
    76         printf("%%rax=%#llx, %%rcx=%#llx, %%rdx=%#llx\n", istate->rax,
    77             istate->rcx, istate->rdx);
    78         printf("%%rsi=%#llx, %%rdi=%#llx, %%r8=%#llx\n", istate->rsi,
    79             istate->rdi, istate->r8);
    80         printf("%%r9=%#llx, %%r10=%#llx, %%r11=%#llx\n", istate->r9,
    81             istate->r10, istate->r11);
    82         printf("%%rsp=%#llx\n", &istate->stack[0]);
    83        
    84         stack_trace_istate(istate);
     65void istate_decode(istate_t *istate)
     66{
     67        printf("cs =%#0" PRIx64 "\trip=%p\t"
     68            "rfl=%#0" PRIx64 "\terr=%#0" PRIx64 "\n",
     69            istate->cs, (void *) istate->rip,
     70            istate->rflags, istate->error_word);
     71       
     72        if (istate_from_uspace(istate))
     73                printf("ss =%#0" PRIx64 "\n", istate->ss);
     74       
     75        printf("rax=%#0" PRIx64 "\trbx=%#0" PRIx64 "\t"
     76            "rcx=%#0" PRIx64 "\trdx=%#0" PRIx64 "\n",
     77            istate->rax, istate->rbx, istate->rcx, istate->rdx);
     78       
     79        printf("rsi=%p\trdi=%p\trbp=%p\trsp=%p\n",
     80            (void *) istate->rsi, (void *) istate->rdi,
     81            (void *) istate->rbp,
     82            istate_from_uspace(istate) ? ((void *) istate->rsp) :
     83            &istate->rsp);
     84       
     85        printf("r8 =%#0" PRIx64 "\tr9 =%#0" PRIx64 "\t"
     86            "r10=%#0" PRIx64 "\tr11=%#0" PRIx64 "\n",
     87            istate->r8, istate->r9, istate->r10, istate->r11);
     88       
     89        printf("r12=%#0" PRIx64 "\tr13=%#0" PRIx64 "\t"
     90            "r14=%#0" PRIx64 "\tr15=%#0" PRIx64 "\n",
     91            istate->r12, istate->r13, istate->r14, istate->r15);
    8592}
    8693
     
    94101}
    95102
    96 static void null_interrupt(int n, istate_t *istate)
    97 {
    98         fault_if_from_uspace(istate, "Unserviced interrupt: %d.", n);
    99         decode_istate(n, istate);
    100         panic("Unserviced interrupt.");
    101 }
    102 
    103 static void de_fault(int n, istate_t *istate)
     103static void null_interrupt(unsigned int n, istate_t *istate)
     104{
     105        fault_if_from_uspace(istate, "Unserviced interrupt: %u.", n);
     106        panic_badtrap(istate, n, "Unserviced interrupt.");
     107}
     108
     109static void de_fault(unsigned int n, istate_t *istate)
    104110{
    105111        fault_if_from_uspace(istate, "Divide error.");
    106         decode_istate(n, istate);
    107         panic("Divide error.");
    108 }
    109 
    110 /** General Protection Fault. */
    111 static void gp_fault(int n, istate_t *istate)
     112        panic_badtrap(istate, n, "Divide error.");
     113}
     114
     115/** General Protection Fault.
     116 *
     117 */
     118static void gp_fault(unsigned int n, istate_t *istate)
    112119{
    113120        if (TASK) {
    114                 size_t ver;
    115 
    116                 spinlock_lock(&TASK->lock);
    117                 ver = TASK->arch.iomapver;
    118                 spinlock_unlock(&TASK->lock);
    119 
     121                irq_spinlock_lock(&TASK->lock, false);
     122                size_t ver = TASK->arch.iomapver;
     123                irq_spinlock_unlock(&TASK->lock, false);
     124               
    120125                if (CPU->arch.iomapver_copy != ver) {
    121126                        /*
     
    131136                fault_if_from_uspace(istate, "General protection fault.");
    132137        }
    133 
    134         decode_istate(n, istate);
    135         panic("General protection fault.");
    136 }
    137 
    138 static void ss_fault(int n, istate_t *istate)
     138        panic_badtrap(istate, n, "General protection fault.");
     139}
     140
     141static void ss_fault(unsigned int n, istate_t *istate)
    139142{
    140143        fault_if_from_uspace(istate, "Stack fault.");
    141         decode_istate(n, istate);
    142         panic("Stack fault.");
    143 }
    144 
    145 static void nm_fault(int n, istate_t *istate)
     144        panic_badtrap(istate, n, "Stack fault.");
     145}
     146
     147static void nm_fault(unsigned int n, istate_t *istate)
    146148{
    147149#ifdef CONFIG_FPU_LAZY
     
    154156
    155157#ifdef CONFIG_SMP
    156 static void tlb_shootdown_ipi(int n, istate_t *istate)
     158static void tlb_shootdown_ipi(unsigned int n, istate_t *istate)
    157159{
    158160        trap_virtual_eoi();
     
    161163#endif
    162164
    163 /** Handler of IRQ exceptions */
    164 static void irq_interrupt(int n, istate_t *istate)
     165/** Handler of IRQ exceptions.
     166 *
     167 */
     168static void irq_interrupt(unsigned int n, istate_t *istate)
    165169{
    166170        ASSERT(n >= IVT_IRQBASE);
    167171       
    168         int inum = n - IVT_IRQBASE;
     172        unsigned int inum = n - IVT_IRQBASE;
    169173        bool ack = false;
    170174        ASSERT(inum < IRQ_COUNT);
     
    176180                 * The IRQ handler was found.
    177181                 */
    178                  
     182               
    179183                if (irq->preack) {
    180184                        /* Send EOI before processing the interrupt */
     
    183187                }
    184188                irq->handler(irq);
    185                 spinlock_unlock(&irq->lock);
     189                irq_spinlock_unlock(&irq->lock, false);
    186190        } else {
    187191                /*
     
    189193                 */
    190194#ifdef CONFIG_DEBUG
    191                 printf("cpu%d: spurious interrupt (inum=%d)\n", CPU->id, inum);
     195                printf("cpu%u: spurious interrupt (inum=%u)\n", CPU->id, inum);
    192196#endif
    193197        }
     
    199203void interrupt_init(void)
    200204{
    201         int i;
     205        unsigned int i;
    202206       
    203207        for (i = 0; i < IVT_ITEMS; i++)
    204                 exc_register(i, "null", (iroutine) null_interrupt);
     208                exc_register(i, "null", false, (iroutine_t) null_interrupt);
    205209       
    206210        for (i = 0; i < IRQ_COUNT; i++) {
    207211                if ((i != IRQ_PIC_SPUR) && (i != IRQ_PIC1))
    208                         exc_register(IVT_IRQBASE + i, "irq",
    209                             (iroutine) irq_interrupt);
     212                        exc_register(IVT_IRQBASE + i, "irq", true,
     213                            (iroutine_t) irq_interrupt);
    210214        }
    211215       
    212         exc_register(0, "de_fault", (iroutine) de_fault);
    213         exc_register(7, "nm_fault", (iroutine) nm_fault);
    214         exc_register(12, "ss_fault", (iroutine) ss_fault);
    215         exc_register(13, "gp_fault", (iroutine) gp_fault);
    216         exc_register(14, "ident_mapper", (iroutine) ident_page_fault);
     216        exc_register(0, "de_fault", true, (iroutine_t) de_fault);
     217        exc_register(7, "nm_fault", true, (iroutine_t) nm_fault);
     218        exc_register(12, "ss_fault", true, (iroutine_t) ss_fault);
     219        exc_register(13, "gp_fault", true, (iroutine_t) gp_fault);
    217220       
    218221#ifdef CONFIG_SMP
    219         exc_register(VECTOR_TLB_SHOOTDOWN_IPI, "tlb_shootdown",
    220             (iroutine) tlb_shootdown_ipi);
     222        exc_register(VECTOR_TLB_SHOOTDOWN_IPI, "tlb_shootdown", true,
     223            (iroutine_t) tlb_shootdown_ipi);
    221224#endif
    222225}
  • kernel/arch/amd64/src/mm/page.c

    rfb150d78 r46c20c8  
    3939#include <mm/frame.h>
    4040#include <mm/as.h>
    41 #include <arch/interrupt.h>
    4241#include <arch/asm.h>
    4342#include <config.h>
     
    4847#include <align.h>
    4948
    50 /* Definitions for identity page mapper */
    51 pte_t helper_ptl1[512] __attribute__((aligned (PAGE_SIZE)));
    52 pte_t helper_ptl2[512] __attribute__((aligned (PAGE_SIZE)));
    53 pte_t helper_ptl3[512] __attribute__((aligned (PAGE_SIZE)));
    54 extern pte_t ptl_0; /* From boot.S */
    55 
    56 #define PTL1_PRESENT(ptl0, page) (!(GET_PTL1_FLAGS_ARCH(ptl0, PTL0_INDEX_ARCH(page)) & PAGE_NOT_PRESENT))
    57 #define PTL2_PRESENT(ptl1, page) (!(GET_PTL2_FLAGS_ARCH(ptl1, PTL1_INDEX_ARCH(page)) & PAGE_NOT_PRESENT))
    58 #define PTL3_PRESENT(ptl2, page) (!(GET_PTL3_FLAGS_ARCH(ptl2, PTL2_INDEX_ARCH(page)) & PAGE_NOT_PRESENT))
    59 
    60 #define PTL1_ADDR(ptl0, page) ((pte_t *)PA2KA(GET_PTL1_ADDRESS_ARCH(ptl0, PTL0_INDEX_ARCH(page))))
    61 #define PTL2_ADDR(ptl1, page) ((pte_t *)PA2KA(GET_PTL2_ADDRESS_ARCH(ptl1, PTL1_INDEX_ARCH(page))))
    62 #define PTL3_ADDR(ptl2, page) ((pte_t *)PA2KA(GET_PTL3_ADDRESS_ARCH(ptl2, PTL2_INDEX_ARCH(page))))
    63 
    64 #define SETUP_PTL1(ptl0, page, tgt)  {  \
    65         SET_PTL1_ADDRESS_ARCH(ptl0, PTL0_INDEX_ARCH(page), (uintptr_t)KA2PA(tgt)); \
    66         SET_PTL1_FLAGS_ARCH(ptl0, PTL0_INDEX_ARCH(page), PAGE_WRITE | PAGE_EXEC); \
    67     }
    68 #define SETUP_PTL2(ptl1, page, tgt)  {  \
    69         SET_PTL2_ADDRESS_ARCH(ptl1, PTL1_INDEX_ARCH(page), (uintptr_t)KA2PA(tgt)); \
    70         SET_PTL2_FLAGS_ARCH(ptl1, PTL1_INDEX_ARCH(page), PAGE_WRITE | PAGE_EXEC); \
    71     }
    72 #define SETUP_PTL3(ptl2, page, tgt)  {  \
    73         SET_PTL3_ADDRESS_ARCH(ptl2, PTL2_INDEX_ARCH(page), (uintptr_t)KA2PA(tgt)); \
    74         SET_PTL3_FLAGS_ARCH(ptl2, PTL2_INDEX_ARCH(page), PAGE_WRITE | PAGE_EXEC); \
    75     }
    76 #define SETUP_FRAME(ptl3, page, tgt)  { \
    77         SET_FRAME_ADDRESS_ARCH(ptl3, PTL3_INDEX_ARCH(page), (uintptr_t)KA2PA(tgt)); \
    78         SET_FRAME_FLAGS_ARCH(ptl3, PTL3_INDEX_ARCH(page), PAGE_WRITE | PAGE_EXEC); \
    79     }
    80 
    81 
    8249void page_arch_init(void)
    8350{
    84         uintptr_t cur;
    85         unsigned int i;
    86         int identity_flags = PAGE_CACHEABLE | PAGE_EXEC | PAGE_GLOBAL | PAGE_WRITE;
    87 
    8851        if (config.cpu_active == 1) {
     52                uintptr_t cur;
     53                unsigned int identity_flags =
     54                    PAGE_CACHEABLE | PAGE_EXEC | PAGE_GLOBAL | PAGE_WRITE;
     55               
    8956                page_mapping_operations = &pt_mapping_operations;
    90 
     57               
     58                page_table_lock(AS_KERNEL, true);
     59               
    9160                /*
    9261                 * PA2KA(identity) mapping for all frames.
    9362                 */
    94                 for (cur = 0; cur < last_frame; cur += FRAME_SIZE) {
    95                         /* Standard identity mapping */
     63                for (cur = 0; cur < last_frame; cur += FRAME_SIZE)
    9664                        page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, identity_flags);
    97                 }
    9865               
    99                 /* Upper kernel mapping
    100                  * - from zero to top of kernel (include bottom addresses
    101                  *   because some are needed for init)
    102                  */
    103                 for (cur = PA2KA_CODE(0); cur < config.base + config.kernel_size; cur += FRAME_SIZE)
    104                         page_mapping_insert(AS_KERNEL, cur, KA2PA(cur), identity_flags);
     66                page_table_unlock(AS_KERNEL, true);
    10567               
    106                 for (cur = config.stack_base; cur < config.stack_base + config.stack_size; cur += FRAME_SIZE)
    107                         page_mapping_insert(AS_KERNEL, cur, KA2PA(cur), identity_flags);
    108                
    109                 for (i = 0; i < init.cnt; i++) {
    110                         for (cur = init.tasks[i].addr; cur < init.tasks[i].addr + init.tasks[i].size; cur += FRAME_SIZE)
    111                                 page_mapping_insert(AS_KERNEL, PA2KA_CODE(KA2PA(cur)), KA2PA(cur), identity_flags);
    112                 }
    113 
    114                 exc_register(14, "page_fault", (iroutine) page_fault);
     68                exc_register(14, "page_fault", true, (iroutine_t) page_fault);
    11569                write_cr3((uintptr_t) AS_KERNEL->genarch.page_table);
    116         } else 
     70        } else
    11771                write_cr3((uintptr_t) AS_KERNEL->genarch.page_table);
    11872}
    11973
    120 
    121 /** Identity page mapper
    122  *
    123  * We need to map whole physical memory identically before the page subsystem
    124  * is initializaed. This thing clears page table and fills in the specific
    125  * items.
    126  */
    127 void ident_page_fault(int n, istate_t *istate)
     74void page_fault(unsigned int n, istate_t *istate)
    12875{
    129         uintptr_t page;
    130         static uintptr_t oldpage = 0;
    131         pte_t *aptl_1, *aptl_2, *aptl_3;
    132 
    133         page = read_cr2();
    134         if (oldpage) {
    135                 /* Unmap old address */
    136                 aptl_1 = PTL1_ADDR(&ptl_0, oldpage);
    137                 aptl_2 = PTL2_ADDR(aptl_1, oldpage);
    138                 aptl_3 = PTL3_ADDR(aptl_2, oldpage);
    139 
    140                 SET_FRAME_FLAGS_ARCH(aptl_3, PTL3_INDEX_ARCH(oldpage), PAGE_NOT_PRESENT);
    141                 if (KA2PA(aptl_3) == KA2PA(helper_ptl3))
    142                         SET_PTL3_FLAGS_ARCH(aptl_2, PTL2_INDEX_ARCH(oldpage), PAGE_NOT_PRESENT);
    143                 if (KA2PA(aptl_2) == KA2PA(helper_ptl2))
    144                         SET_PTL2_FLAGS_ARCH(aptl_1, PTL1_INDEX_ARCH(oldpage), PAGE_NOT_PRESENT);
    145                 if (KA2PA(aptl_1) == KA2PA(helper_ptl1))
    146                         SET_PTL1_FLAGS_ARCH(&ptl_0, PTL0_INDEX_ARCH(oldpage), PAGE_NOT_PRESENT);
    147         }
    148         if (PTL1_PRESENT(&ptl_0, page))
    149                 aptl_1 = PTL1_ADDR(&ptl_0, page);
    150         else {
    151                 SETUP_PTL1(&ptl_0, page, helper_ptl1);
    152                 aptl_1 = helper_ptl1;
    153         }
    154            
    155         if (PTL2_PRESENT(aptl_1, page))
    156                 aptl_2 = PTL2_ADDR(aptl_1, page);
    157         else {
    158                 SETUP_PTL2(aptl_1, page, helper_ptl2);
    159                 aptl_2 = helper_ptl2;
    160         }
    161 
    162         if (PTL3_PRESENT(aptl_2, page))
    163                 aptl_3 = PTL3_ADDR(aptl_2, page);
    164         else {
    165                 SETUP_PTL3(aptl_2, page, helper_ptl3);
    166                 aptl_3 = helper_ptl3;
    167         }
    168        
    169         SETUP_FRAME(aptl_3, page, page);
    170 
    171         oldpage = page;
    172 }
    173 
    174 
    175 void page_fault(int n, istate_t *istate)
    176 {
    177         uintptr_t page;
    178         pf_access_t access;
    179        
    180         page = read_cr2();
     76        uintptr_t page = read_cr2();
    18177       
    18278        if (istate->error_word & PFERR_CODE_RSVD)
    18379                panic("Reserved bit set in page table entry.");
     80       
     81        pf_access_t access;
    18482       
    18583        if (istate->error_word & PFERR_CODE_RW)
     
    19189       
    19290        if (as_page_fault(page, access, istate) == AS_PF_FAULT) {
    193                 fault_if_from_uspace(istate, "Page fault: %#x.", page);
    194 
    195                 decode_istate(n, istate);
    196                 printf("Page fault address: %llx.\n", page);
    197                 panic("Page fault.");
     91                fault_if_from_uspace(istate, "Page fault: %p.", (void *) page);
     92                panic_memtrap(istate, access, page, NULL);
    19893        }
    19994}
    200 
    20195
    20296uintptr_t hw_map(uintptr_t physaddr, size_t size)
    20397{
    20498        if (last_frame + ALIGN_UP(size, PAGE_SIZE) > KA2PA(KERNEL_ADDRESS_SPACE_END_ARCH))
    205                 panic("Unable to map physical memory %p (%d bytes).", physaddr,
    206                     size);
     99                panic("Unable to map physical memory %p (%zu bytes).",
     100                    (void *) physaddr, size);
    207101       
    208102        uintptr_t virtaddr = PA2KA(last_frame);
    209103        pfn_t i;
     104       
     105        page_table_lock(AS_KERNEL, true);
     106       
    210107        for (i = 0; i < ADDR2PFN(ALIGN_UP(size, PAGE_SIZE)); i++)
    211108                page_mapping_insert(AS_KERNEL, virtaddr + PFN2ADDR(i), physaddr + PFN2ADDR(i), PAGE_NOT_CACHEABLE | PAGE_WRITE);
     109       
     110        page_table_unlock(AS_KERNEL, true);
    212111       
    213112        last_frame = ALIGN_UP(last_frame + size, FRAME_SIZE);
  • kernel/arch/amd64/src/pm.c

    rfb150d78 r46c20c8  
    2828 */
    2929
    30 /** @addtogroup amd64   
     30/** @addtogroup amd64
    3131 * @{
    3232 */
     
    5252        { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    5353        /* KTEXT descriptor */
    54         { .limit_0_15  = 0xffff,
    55           .base_0_15   = 0, 
    56           .base_16_23  = 0, 
    57           .access      = AR_PRESENT | AR_CODE | DPL_KERNEL | AR_READABLE, 
    58           .limit_16_19 = 0xf,
    59           .available   = 0, 
    60           .longmode    = 1, 
     54        { .limit_0_15  = 0xffffU,
     55          .base_0_15   = 0,
     56          .base_16_23  = 0,
     57          .access      = AR_PRESENT | AR_CODE | DPL_KERNEL | AR_READABLE,
     58          .limit_16_19 = 0x0fU,
     59          .available   = 0,
     60          .longmode    = 1,
    6161          .special     = 0,
    62           .granularity = 1, 
     62          .granularity = 1,
    6363          .base_24_31  = 0 },
    6464        /* KDATA descriptor */
    65         { .limit_0_15  = 0xffff,
    66           .base_0_15   = 0, 
    67           .base_16_23  = 0, 
    68           .access      = AR_PRESENT | AR_DATA | AR_WRITABLE | DPL_KERNEL, 
    69           .limit_16_19 = 0xf,
    70           .available   = 0, 
    71           .longmode    = 0, 
    72           .special     = 0, 
    73           .granularity = 1, 
     65        { .limit_0_15  = 0xffffU,
     66          .base_0_15   = 0,
     67          .base_16_23  = 0,
     68          .access      = AR_PRESENT | AR_DATA | AR_WRITABLE | DPL_KERNEL,
     69          .limit_16_19 = 0x0fU,
     70          .available   = 0,
     71          .longmode    = 0,
     72          .special     = 0,
     73          .granularity = 1,
    7474          .base_24_31  = 0 },
    7575        /* UDATA descriptor */
    76         { .limit_0_15  = 0xffff,
    77           .base_0_15   = 0, 
    78           .base_16_23  = 0, 
    79           .access      = AR_PRESENT | AR_DATA | AR_WRITABLE | DPL_USER, 
    80           .limit_16_19 = 0xf,
    81           .available   = 0, 
    82           .longmode    = 0, 
    83           .special     = 1, 
    84           .granularity = 1, 
     76        { .limit_0_15  = 0xffffU,
     77          .base_0_15   = 0,
     78          .base_16_23  = 0,
     79          .access      = AR_PRESENT | AR_DATA | AR_WRITABLE | DPL_USER,
     80          .limit_16_19 = 0x0fU,
     81          .available   = 0,
     82          .longmode    = 0,
     83          .special     = 1,
     84          .granularity = 1,
    8585          .base_24_31  = 0 },
    8686        /* UTEXT descriptor */
    87         { .limit_0_15  = 0xffff,
    88           .base_0_15   = 0, 
    89           .base_16_23  = 0, 
    90           .access      = AR_PRESENT | AR_CODE | DPL_USER, 
    91           .limit_16_19 = 0xf,
    92           .available   = 0, 
    93           .longmode    = 1, 
    94           .special     = 0, 
    95           .granularity = 1, 
     87        { .limit_0_15  = 0xffffU,
     88          .base_0_15   = 0,
     89          .base_16_23  = 0,
     90          .access      = AR_PRESENT | AR_CODE | DPL_USER,
     91          .limit_16_19 = 0x0fU,
     92          .available   = 0,
     93          .longmode    = 1,
     94          .special     = 0,
     95          .granularity = 1,
    9696          .base_24_31  = 0 },
    9797        /* KTEXT 32-bit protected, for protected mode before long mode */
    98         { .limit_0_15  = 0xffff,
    99           .base_0_15   = 0, 
    100           .base_16_23  = 0, 
    101           .access      = AR_PRESENT | AR_CODE | DPL_KERNEL | AR_READABLE, 
    102           .limit_16_19 = 0xf,
    103           .available   = 0, 
    104           .longmode    = 0, 
     98        { .limit_0_15  = 0xffffU,
     99          .base_0_15   = 0,
     100          .base_16_23  = 0,
     101          .access      = AR_PRESENT | AR_CODE | DPL_KERNEL | AR_READABLE,
     102          .limit_16_19 = 0x0fU,
     103          .available   = 0,
     104          .longmode    = 0,
    105105          .special     = 1,
    106           .granularity = 1, 
     106          .granularity = 1,
    107107          .base_24_31  = 0 },
    108108        /* TSS descriptor - set up will be completed later,
     
    111111        { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    112112        /* VESA Init descriptor */
    113 #ifdef CONFIG_FB       
    114         { 0xffff, 0, VESA_INIT_SEGMENT >> 12, AR_PRESENT | AR_CODE | DPL_KERNEL,
    115           0xf, 0, 0, 0, 0, 0
     113#ifdef CONFIG_FB
     114        {
     115                0xffff, 0, VESA_INIT_SEGMENT >> 12, AR_PRESENT | AR_CODE | DPL_KERNEL,
     116                    0xf, 0, 0, 0, 0, 0
    116117        }
    117118#endif
     
    129130{
    130131        tss_descriptor_t *td = (tss_descriptor_t *) d;
    131 
    132         td->base_0_15 = base & 0xffff;
    133         td->base_16_23 = ((base) >> 16) & 0xff;
    134         td->base_24_31 = ((base) >> 24) & 0xff;
     132       
     133        td->base_0_15 = base & 0xffffU;
     134        td->base_16_23 = ((base) >> 16) & 0xffU;
     135        td->base_24_31 = ((base) >> 24) & 0xffU;
    135136        td->base_32_63 = ((base) >> 32);
    136137}
     
    140141        tss_descriptor_t *td = (tss_descriptor_t *) d;
    141142       
    142         td->limit_0_15 = limit & 0xffff;
    143         td->limit_16_19 = (limit >> 16) & 0xf;
     143        td->limit_0_15 = limit & 0xffffU;
     144        td->limit_16_19 = (limit >> 16) & 0x0fU;
    144145}
    145146
     
    149150         * Offset is a linear address.
    150151         */
    151         d->offset_0_15 = offset & 0xffff;
    152         d->offset_16_31 = offset >> 16 & 0xffff;
     152        d->offset_0_15 = offset & 0xffffU;
     153        d->offset_16_31 = (offset >> 16) & 0xffffU;
    153154        d->offset_32_63 = offset >> 32;
    154155}
     
    165166{
    166167        idescriptor_t *d;
    167         int i;
    168 
     168        unsigned int i;
     169       
    169170        for (i = 0; i < IDT_ITEMS; i++) {
    170171                d = &idt[i];
    171 
     172               
    172173                d->unused = 0;
    173                 d->selector = gdtselector(KTEXT_DES);
    174 
     174                d->selector = GDT_SELECTOR(KTEXT_DES);
     175               
    175176                d->present = 1;
    176                 d->type = AR_INTERRUPT; /* masking interrupt */
    177 
    178                 idt_setoffset(d, ((uintptr_t) interrupt_handlers) +
    179                     i * interrupt_handler_size);
     177                d->type = AR_INTERRUPT;  /* masking interrupt */
    180178        }
     179       
     180        d = &idt[0];
     181        idt_setoffset(d++, (uintptr_t) &int_0);
     182        idt_setoffset(d++, (uintptr_t) &int_1);
     183        idt_setoffset(d++, (uintptr_t) &int_2);
     184        idt_setoffset(d++, (uintptr_t) &int_3);
     185        idt_setoffset(d++, (uintptr_t) &int_4);
     186        idt_setoffset(d++, (uintptr_t) &int_5);
     187        idt_setoffset(d++, (uintptr_t) &int_6);
     188        idt_setoffset(d++, (uintptr_t) &int_7);
     189        idt_setoffset(d++, (uintptr_t) &int_8);
     190        idt_setoffset(d++, (uintptr_t) &int_9);
     191        idt_setoffset(d++, (uintptr_t) &int_10);
     192        idt_setoffset(d++, (uintptr_t) &int_11);
     193        idt_setoffset(d++, (uintptr_t) &int_12);
     194        idt_setoffset(d++, (uintptr_t) &int_13);
     195        idt_setoffset(d++, (uintptr_t) &int_14);
     196        idt_setoffset(d++, (uintptr_t) &int_15);
     197        idt_setoffset(d++, (uintptr_t) &int_16);
     198        idt_setoffset(d++, (uintptr_t) &int_17);
     199        idt_setoffset(d++, (uintptr_t) &int_18);
     200        idt_setoffset(d++, (uintptr_t) &int_19);
     201        idt_setoffset(d++, (uintptr_t) &int_20);
     202        idt_setoffset(d++, (uintptr_t) &int_21);
     203        idt_setoffset(d++, (uintptr_t) &int_22);
     204        idt_setoffset(d++, (uintptr_t) &int_23);
     205        idt_setoffset(d++, (uintptr_t) &int_24);
     206        idt_setoffset(d++, (uintptr_t) &int_25);
     207        idt_setoffset(d++, (uintptr_t) &int_26);
     208        idt_setoffset(d++, (uintptr_t) &int_27);
     209        idt_setoffset(d++, (uintptr_t) &int_28);
     210        idt_setoffset(d++, (uintptr_t) &int_29);
     211        idt_setoffset(d++, (uintptr_t) &int_30);
     212        idt_setoffset(d++, (uintptr_t) &int_31);
     213        idt_setoffset(d++, (uintptr_t) &int_32);
     214        idt_setoffset(d++, (uintptr_t) &int_33);
     215        idt_setoffset(d++, (uintptr_t) &int_34);
     216        idt_setoffset(d++, (uintptr_t) &int_35);
     217        idt_setoffset(d++, (uintptr_t) &int_36);
     218        idt_setoffset(d++, (uintptr_t) &int_37);
     219        idt_setoffset(d++, (uintptr_t) &int_38);
     220        idt_setoffset(d++, (uintptr_t) &int_39);
     221        idt_setoffset(d++, (uintptr_t) &int_40);
     222        idt_setoffset(d++, (uintptr_t) &int_41);
     223        idt_setoffset(d++, (uintptr_t) &int_42);
     224        idt_setoffset(d++, (uintptr_t) &int_43);
     225        idt_setoffset(d++, (uintptr_t) &int_44);
     226        idt_setoffset(d++, (uintptr_t) &int_45);
     227        idt_setoffset(d++, (uintptr_t) &int_46);
     228        idt_setoffset(d++, (uintptr_t) &int_47);
     229        idt_setoffset(d++, (uintptr_t) &int_48);
     230        idt_setoffset(d++, (uintptr_t) &int_49);
     231        idt_setoffset(d++, (uintptr_t) &int_50);
     232        idt_setoffset(d++, (uintptr_t) &int_51);
     233        idt_setoffset(d++, (uintptr_t) &int_52);
     234        idt_setoffset(d++, (uintptr_t) &int_53);
     235        idt_setoffset(d++, (uintptr_t) &int_54);
     236        idt_setoffset(d++, (uintptr_t) &int_55);
     237        idt_setoffset(d++, (uintptr_t) &int_56);
     238        idt_setoffset(d++, (uintptr_t) &int_57);
     239        idt_setoffset(d++, (uintptr_t) &int_58);
     240        idt_setoffset(d++, (uintptr_t) &int_59);
     241        idt_setoffset(d++, (uintptr_t) &int_60);
     242        idt_setoffset(d++, (uintptr_t) &int_61);
     243        idt_setoffset(d++, (uintptr_t) &int_62);
     244        idt_setoffset(d++, (uintptr_t) &int_63);
    181245}
    182246
     
    228292         * to its own TSS. We just need to load the TR register.
    229293         */
    230         tr_load(gdtselector(TSS_DES));
     294        tr_load(GDT_SELECTOR(TSS_DES));
    231295}
    232296
  • kernel/arch/amd64/src/proc/scheduler.c

    rfb150d78 r46c20c8  
    3838#include <proc/thread.h>
    3939#include <arch.h>
    40 #include <arch/context.h>       /* SP_DELTA */
    4140#include <arch/asm.h>
    4241#include <print.h>
     
    5756{
    5857        CPU->arch.tss->rsp0 =
    59             (uintptr_t) &THREAD->kstack[THREAD_STACK_SIZE - SP_DELTA];
    60 
     58            (uintptr_t) &THREAD->kstack[THREAD_STACK_SIZE];
     59       
    6160        /*
    6261         * Syscall support.
    6362         */
    6463        swapgs();
    65         write_msr(AMD_MSR_GS, (uintptr_t)THREAD->arch.syscall_rsp);
     64        write_msr(AMD_MSR_GS, (uintptr_t) THREAD->arch.syscall_rsp);
    6665        swapgs();
    67 
     66       
    6867        /* TLS support - set FS to thread local storage */
    6968        write_msr(AMD_MSR_FS, THREAD->arch.tls);
  • kernel/arch/amd64/src/proc/task.c

    rfb150d78 r46c20c8  
    3535#include <proc/task.h>
    3636#include <mm/slab.h>
    37 #include <arch/types.h>
     37#include <typedefs.h>
    3838
    3939/** Perform amd64 specific task initialization.
    4040 *
    41  * @param t Task to be initialized.
     41 * @param task Task to be initialized.
     42 *
    4243 */
    43 void task_create_arch(task_t *t)
     44void task_create_arch(task_t *task)
    4445{
    45         t->arch.iomapver = 0;
    46         bitmap_initialize(&t->arch.iomap, NULL, 0);
     46        task->arch.iomapver = 0;
     47        bitmap_initialize(&task->arch.iomap, NULL, 0);
    4748}
    4849
    4950/** Perform amd64 specific task destruction.
    5051 *
    51  * @param t Task to be initialized.
     52 * @param task Task to be initialized.
     53 *
    5254 */
    53 void task_destroy_arch(task_t *t)
     55void task_destroy_arch(task_t *task)
    5456{
    55         if (t->arch.iomap.map)
    56                 free(t->arch.iomap.map);
     57        if (task->arch.iomap.map)
     58                free(task->arch.iomap.map);
    5759}
    5860
  • kernel/arch/amd64/src/proc/thread.c

    rfb150d78 r46c20c8  
    3434
    3535#include <proc/thread.h>
     36#include <arch/interrupt.h>
    3637
    3738/** Perform amd64 specific thread initialization.
    3839 *
    39  * @param t Thread to be initialized.
     40 * @param thread Thread to be initialized.
     41 *
    4042 */
    41 void thread_create_arch(thread_t *t)
     43void thread_create_arch(thread_t *thread)
    4244{
    43         t->arch.tls = 0;
    44         t->arch.syscall_rsp[SYSCALL_USTACK_RSP] = 0;
     45        thread->arch.tls = 0;
     46        thread->arch.syscall_rsp[SYSCALL_USTACK_RSP] = 0;
     47       
    4548        /*
    4649         * Kernel RSP can be precalculated at thread creation time.
    4750         */
    48         t->arch.syscall_rsp[SYSCALL_KSTACK_RSP] =
    49             (uintptr_t) &t->kstack[PAGE_SIZE - sizeof(uint64_t)];
     51        thread->arch.syscall_rsp[SYSCALL_KSTACK_RSP] =
     52            (uintptr_t) &thread->kstack[PAGE_SIZE - sizeof(istate_t)];
    5053}
    5154
  • kernel/arch/amd64/src/smp/ap.S

    rfb150d78 r46c20c8  
    5555        xorw %ax, %ax
    5656        movw %ax, %ds
    57 
    58         lgdtl ap_gdtr           # initialize Global Descriptor Table register
     57       
     58        lgdtl ap_gdtr       # initialize Global Descriptor Table register
    5959       
    6060        movl %cr0, %eax
    6161        orl $1, %eax
    62         movl %eax, %cr0         # switch to protected mode
    63         jmpl $gdtselector(KTEXT32_DES), $jump_to_kernel - BOOT_OFFSET + AP_BOOT_OFFSET
    64        
     62        movl %eax, %cr0     # switch to protected mode
     63        jmpl $GDT_SELECTOR(KTEXT32_DES), $jump_to_kernel - BOOT_OFFSET + AP_BOOT_OFFSET
     64
    6565jump_to_kernel:
    6666.code32
    67         movw $gdtselector(KDATA_DES), %ax
     67        movw $GDT_SELECTOR(KDATA_DES), %ax
    6868        movw %ax, %ds
    6969        movw %ax, %es
    7070        movw %ax, %ss
    71         movw $gdtselector(UDATA_DES), %ax
     71        movw $GDT_SELECTOR(UDATA_DES), %ax
    7272        movw %ax, %gs
    7373       
    74         # Enable 64-bit page transaltion entries - CR4.PAE = 1.
     74        # Enable 64-bit page transaltion entries (CR4.PAE = 1).
    7575        # Paging is not enabled until after long mode is enabled
    7676       
     
    7878        btsl $5, %eax
    7979        movl %eax, %cr4
    80 
     80       
    8181        leal ptl_0, %eax
    8282        movl %eax, %cr3
    8383       
    8484        # Enable long mode
    85         movl $EFER_MSR_NUM, %ecx        # EFER MSR number
    86         rdmsr                           # Read EFER
    87         btsl $AMD_LME_FLAG, %eax        # Set LME=1
    88         wrmsr                           # Write EFER
     85        movl $EFER_MSR_NUM, %ecx  # EFER MSR number
     86        rdmsr                     # Read EFER
     87        btsl $AMD_LME_FLAG, %eax  # Set LME=1
     88        wrmsr                     # Write EFER
    8989       
    90         # Enable paging to activate long mode (set CR0.PG=1)
     90        # Enable paging to activate long mode (set CR0.PG = 1)
    9191        movl %cr0, %eax
    9292        btsl $31, %eax
     
    9494       
    9595        # At this point we are in compatibility mode
    96         jmpl $gdtselector(KTEXT_DES), $start64 - BOOT_OFFSET + AP_BOOT_OFFSET
     96        jmpl $GDT_SELECTOR(KTEXT_DES), $start64 - BOOT_OFFSET + AP_BOOT_OFFSET
    9797
    9898.code64
    9999start64:
    100         movq (ctx), %rsp
     100        movabsq $ctx, %rsp
     101        movq (%rsp), %rsp
     102       
    101103        pushq $0
    102104        movq %rsp, %rbp
    103         call main_ap - AP_BOOT_OFFSET + BOOT_OFFSET   # never returns
     105       
     106        movabsq $main_ap, %rax
     107        callq *%rax   # never returns
    104108
    105109#endif /* CONFIG_SMP */
  • kernel/arch/amd64/src/syscall.c

    rfb150d78 r46c20c8  
    5858         */
    5959        write_msr(AMD_MSR_STAR,
    60             ((uint64_t)(gdtselector(KDATA_DES) | PL_USER) << 48) |
    61             ((uint64_t)(gdtselector(KTEXT_DES) | PL_KERNEL) << 32));
     60            ((uint64_t) (GDT_SELECTOR(KDATA_DES) | PL_USER) << 48) |
     61            ((uint64_t) (GDT_SELECTOR(KTEXT_DES) | PL_KERNEL) << 32));
    6262        write_msr(AMD_MSR_LSTAR, (uint64_t)syscall_entry);
    6363        /* Mask RFLAGS on syscall
     
    6666         * - clear DF so that the string instructions operate in
    6767         *   the right direction
     68         * - clear NT to prevent a #GP should the flag proliferate to an IRET
    6869         */
    69         write_msr(AMD_MSR_SFMASK, RFLAGS_IF | RFLAGS_DF);
     70        write_msr(AMD_MSR_SFMASK, RFLAGS_IF | RFLAGS_DF | RFLAGS_NT);
    7071}
    7172
  • kernel/arch/amd64/src/userspace.c

    rfb150d78 r46c20c8  
    3636#include <arch/cpu.h>
    3737#include <arch/pm.h>
    38 #include <arch/types.h>
     38#include <typedefs.h>
    3939#include <arch.h>
    4040#include <proc/uarg.h>
     
    6565                "xorq %%rdi, %%rdi\n"
    6666                "iretq\n"
    67                 :: [udata_des] "i" (gdtselector(UDATA_DES) | PL_USER),
     67                :: [udata_des] "i" (GDT_SELECTOR(UDATA_DES) | PL_USER),
    6868                   [stack_size] "r" (kernel_uarg->uspace_stack + THREAD_STACK_SIZE),
    6969                   [ipl] "r" (ipl),
    70                    [utext_des] "i" (gdtselector(UTEXT_DES) | PL_USER),
     70                   [utext_des] "i" (GDT_SELECTOR(UTEXT_DES) | PL_USER),
    7171                   [entry] "r" (kernel_uarg->uspace_entry),
    7272                   [uarg] "r" (kernel_uarg->uspace_uarg)
Note: See TracChangeset for help on using the changeset viewer.