Changeset 46c20c8 in mainline for kernel/arch/ppc32/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/ppc32/src
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/ppc32/src/asm.S

    rfb150d78 r46c20c8  
    1 #
    2 # Copyright (c) 2005 Martin Decky
    3 # All rights reserved.
    4 #
    5 # Redistribution and use in source and binary forms, with or without
    6 # modification, are permitted provided that the following conditions
    7 # are met:
    8 #
    9 # - Redistributions of source code must retain the above copyright
    10 #   notice, this list of conditions and the following disclaimer.
    11 # - Redistributions in binary form must reproduce the above copyright
    12 #   notice, this list of conditions and the following disclaimer in the
    13 #   documentation and/or other materials provided with the distribution.
    14 # - The name of the author may not be used to endorse or promote products
    15 #   derived from this software without specific prior written permission.
    16 #
    17 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    18 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    19 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    20 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
    21 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
    22 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    26 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    27 #
     1/*
     2 * Copyright (c) 2005 Martin Decky
     3 * All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
    2828
    2929#include <arch/asm/regname.h>
     30#include <arch/cpu.h>
    3031
    3132.text
     
    4142.global memcpy_from_uspace_failover_address
    4243.global memcpy_to_uspace_failover_address
     44.global early_putchar
    4345
    4446userspace_asm:
    45 
    46         # r3 = uspace_uarg
    47         # r4 = stack
    48         # r5 = entry
    49        
    50         # disable interrupts
    51 
     47       
     48        /*
     49         * r3 = uspace_uarg
     50         * r4 = stack
     51         * r5 = entry
     52         */
     53       
     54        /* Disable interrupts */
     55       
    5256        mfmsr r31
    5357        rlwinm r31, r31, 0, 17, 15
    5458        mtmsr r31
    5559       
    56         # set entry point
     60        /* Set entry point */
    5761       
    5862        mtsrr0 r5
    5963       
    60         # set problem state, enable interrupts
    61        
    62         ori r31, r31, msr_pr
    63         ori r31, r31, msr_ee
     64        /* Set problem state, enable interrupts */
     65       
     66        ori r31, r31, MSR_PR
     67        ori r31, r31, MSR_EE
    6468        mtsrr1 r31
    6569       
    66         # set stack
     70        /* Set stack */
    6771       
    6872        mr sp, r4
    69 
    70         # %r6 is defined to hold pcb_ptr - set it to 0
    71 
     73       
     74        /* %r6 is defined to hold pcb_ptr - set it to 0 */
     75       
    7276        xor r6, r6, r6
    7377       
    74         # jump to userspace
     78        /* Jump to userspace */
    7579       
    7680        rfi
     
    7882iret:
    7983       
    80         # disable interrupts
     84        /* Disable interrupts */
    8185       
    8286        mfmsr r31
     
    140144iret_syscall:
    141145       
    142         # reset decrementer
    143 
     146        /* Reset decrementer */
     147       
    144148        li r31, 1000
    145149        mtdec r31
    146150       
    147         # disable interrupts
     151        /* Disable interrupts */
    148152       
    149153        mfmsr r31
     
    201205        lwz r12, 156(sp)
    202206        lwz sp, 160(sp)
    203 
     207       
    204208        rfi
    205209
     
    213217memcpy_from_uspace:
    214218memcpy_to_uspace:
    215 
     219       
    216220        srwi. r7, r5, 3
    217221        addi r6, r3, -4
    218222        addi r4, r4, -4
    219         beq     2f
     223        beq 2f
    220224       
    221225        andi. r0, r6, 3
     
    225229        1:
    226230       
    227         lwz r7, 4(r4)
    228         lwzu r8, 8(r4)
    229         stw r7, 4(r6)
    230         stwu r8, 8(r6)
    231         bdnz 1b
    232        
    233         andi. r5, r5, 7
     231                lwz r7, 4(r4)
     232                lwzu r8, 8(r4)
     233                stw r7, 4(r6)
     234                stwu r8, 8(r6)
     235                bdnz 1b
     236               
     237                andi. r5, r5, 7
    234238       
    235239        2:
    236240       
    237         cmplwi 0, r5, 4
    238         blt 3f
    239        
    240         lwzu r0, 4(r4)
    241         addi r5, r5, -4
    242         stwu r0, 4(r6)
     241                cmplwi 0, r5, 4
     242                blt 3f
     243               
     244                lwzu r0, 4(r4)
     245                addi r5, r5, -4
     246                stwu r0, 4(r6)
    243247       
    244248        3:
    245249       
    246         cmpwi 0, r5, 0
    247         beqlr
    248         mtctr r5
    249         addi r4, r4, 3
    250         addi r6, r6, 3
     250                cmpwi 0, r5, 0
     251                beqlr
     252                mtctr r5
     253                addi r4, r4, 3
     254                addi r6, r6, 3
    251255       
    252256        4:
    253257       
    254         lbzu r0, 1(r4)
    255         stbu r0, 1(r6)
    256         bdnz 4b
    257         blr
     258                lbzu r0, 1(r4)
     259                stbu r0, 1(r6)
     260                bdnz 4b
     261                blr
    258262       
    259263        5:
    260264       
    261         subfic r0, r0, 4
    262         mtctr r0
     265                subfic r0, r0, 4
     266                mtctr r0
    263267       
    264268        6:
    265269       
    266         lbz r7, 4(r4)
    267         addi r4, r4, 1
    268         stb r7, 4(r6)
    269         addi r6, r6, 1
    270         bdnz 6b
    271         subf r5, r0, r5
    272         rlwinm. r7, r5, 32-3, 3, 31
    273         beq 2b
    274         mtctr r7
    275         b 1b
     270                lbz r7, 4(r4)
     271                addi r4, r4, 1
     272                stb r7, 4(r6)
     273                addi r6, r6, 1
     274                bdnz 6b
     275                subf r5, r0, r5
     276                rlwinm. r7, r5, 32-3, 3, 31
     277                beq 2b
     278                mtctr r7
     279                b 1b
    276280
    277281memcpy_from_uspace_failover_address:
    278282memcpy_to_uspace_failover_address:
    279         # return zero, failure
     283        /* Return zero, failure */
    280284        xor r3, r3, r3
    281285        blr
     286
     287early_putchar:
     288        blr
  • kernel/arch/ppc32/src/boot/boot.S

    rfb150d78 r46c20c8  
    4747       
    4848        # r3 contains physical address of bootinfo_t
    49         # r4 contains size of bootinfo_t
    50        
    51         cmpwi r4, 0
    52         beq bootinfo_end
    5349       
    5450        addis r3, r3, 0x8000
    55        
    56         lis r31, bootinfo@ha
    57         addi r31, r31, bootinfo@l  # r31 = bootinfo
    58        
    59         bootinfo_loop:
    60                
    61                 lwz r30, 0(r3)
    62                 stw r30, 0(r31)
    63                
    64                 addi r3, r3, 4
    65                 addi r31, r31, 4
    66                 subi r4, r4, 4
    67                
    68                 cmpwi r4, 0
    69                 bgt bootinfo_loop
    70                
    71         bootinfo_end:
    72        
    7351        bl arch_pre_main
    7452        b main_bsp
  • kernel/arch/ppc32/src/context.S

    rfb150d78 r46c20c8  
    2929#include <arch/context_offset.h>
    3030
    31 .text   
     31.text
    3232
    3333.global context_save_arch
     
    4646        li r3, 1
    4747        blr
    48        
     48
    4949context_restore_arch:
    5050        CONTEXT_RESTORE_ARCH_CORE r3
  • kernel/arch/ppc32/src/cpu/cpu.c

    rfb150d78 r46c20c8  
    3434
    3535#include <arch/cpu.h>
    36 #include <arch/cpuid.h>
    3736#include <cpu.h>
    3837#include <arch.h>
     
    4544void cpu_identify(void)
    4645{
    47         cpu_info_t info;
    48        
    49         cpu_version(&info);
    50         CPU->arch.version = info.version;
    51         CPU->arch.revision = info.revision;
     46        cpu_version(&CPU->arch);
    5247}
    5348
    54 void cpu_print_report(cpu_t *m)
     49void cpu_print_report(cpu_t *cpu)
    5550{
    56         char *name;
     51        const char *name;
    5752       
    58         switch (m->arch.version) {
     53        switch (cpu->arch.version) {
    5954                case 8:
    60                         name = " (PowerPC 750)";
     55                        name = "PowerPC 750";
    6156                        break;
    6257                case 9:
    63                         name = " (PowerPC 604e)";
     58                        name = "PowerPC 604e";
    6459                        break;
    6560                case 0x81:
    66                         name = " (PowerPC 8260)";
     61                        name = "PowerPC 8260";
    6762                        break;
    6863                case 0x8081:
    69                         name = " (PowerPC 826xA)";
     64                        name = "PowerPC 826xA";
    7065                        break;
    7166                default:
    72                         name = "";
     67                        name = "unknown";
    7368        }
    7469       
    75         printf("cpu%d: version=%d%s, revision=%d\n", m->id, m->arch.version, name, m->arch.revision);
     70        printf("cpu%u: version=%" PRIu16" (%s), revision=%" PRIu16 "\n", cpu->id,
     71            cpu->arch.version, name, cpu->arch.revision);
    7672}
    7773
  • kernel/arch/ppc32/src/ddi/ddi.c

    rfb150d78 r46c20c8  
    3535#include <ddi/ddi.h>
    3636#include <proc/task.h>
    37 #include <arch/types.h>
     37#include <typedefs.h>
    3838
    3939/** Enable I/O space range for task.
     
    4646 *
    4747 * @return 0 on success or an error code from errno.h.
     48 *
    4849 */
    4950int ddi_iospace_enable_arch(task_t *task, uintptr_t ioaddr, size_t size)
  • kernel/arch/ppc32/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 bool kernel_frame_pointer_validate(uintptr_t fp)
     39#define FRAME_OFFSET_FP_PREV  0
     40#define FRAME_OFFSET_RA       1
     41
     42bool kernel_stack_trace_context_validate(stack_trace_context_t *ctx)
    4143{
    42         return false;
     44        return ctx->fp != 0;
    4345}
    4446
    45 bool kernel_frame_pointer_prev(uintptr_t fp, uintptr_t *prev)
     47bool kernel_frame_pointer_prev(stack_trace_context_t *ctx, uintptr_t *prev)
    4648{
    47         return false;
     49        uint32_t *stack = (void *) ctx->fp;
     50        *prev = stack[FRAME_OFFSET_FP_PREV];
     51        return true;
    4852}
    4953
    50 bool kernel_return_address_get(uintptr_t fp, uintptr_t *ra)
     54bool kernel_return_address_get(stack_trace_context_t *ctx, uintptr_t *ra)
    5155{
    52         return false;
     56        uint32_t *stack = (void *) ctx->fp;
     57        *ra = stack[FRAME_OFFSET_RA];
     58        return true;
    5359}
    5460
    55 bool uspace_frame_pointer_validate(uintptr_t fp)
     61bool uspace_stack_trace_context_validate(stack_trace_context_t *ctx)
    5662{
    57         return false;
     63        return ctx->fp != 0;
    5864}
    5965
    60 bool uspace_frame_pointer_prev(uintptr_t fp, uintptr_t *prev)
     66bool uspace_frame_pointer_prev(stack_trace_context_t *ctx, uintptr_t *prev)
    6167{
    62         return false;
     68        return !copy_from_uspace((void *) prev,
     69            (uint32_t *) ctx->fp + FRAME_OFFSET_FP_PREV, sizeof(*prev));
    6370}
    6471
    65 bool uspace_return_address_get(uintptr_t fp, uintptr_t *ra)
     72bool uspace_return_address_get(stack_trace_context_t *ctx, uintptr_t *ra)
    6673{
    67         return false;
     74        return !copy_from_uspace((void *) ra,
     75            (uint32_t *) ctx->fp + FRAME_OFFSET_RA, sizeof(*ra));
    6876}
    6977
  • kernel/arch/ppc32/src/debug/stacktrace_asm.S

    rfb150d78 r46c20c8  
    2727#
    2828
     29#include <arch/asm/regname.h>
     30
    2931.text
    3032
     
    3335
    3436frame_pointer_get:
     37        mr r3, sp
    3538        blr
    3639
    3740program_counter_get:
     41        mflr r3
    3842        blr
  • kernel/arch/ppc32/src/drivers/pic.c

    rfb150d78 r46c20c8  
    3232/** @file
    3333 */
    34 
    3534
    3635#include <arch/drivers/pic.h>
     
    7978}
    8079
    81 /** Return number of pending interrupt */
    82 int pic_get_pending(void)
     80/** Return number of pending interrupts
     81 *
     82 */
     83uint8_t pic_get_pending(void)
    8384{
    8485        if (pic) {
    85                 int pending;
     86                uint32_t pending;
    8687               
    8788                pending = pic[PIC_PENDING_LOW];
    88                 if (pending)
     89                if (pending != 0)
    8990                        return fnzb32(pending);
    9091               
    9192                pending = pic[PIC_PENDING_HIGH];
    92                 if (pending)
     93                if (pending != 0)
    9394                        return fnzb32(pending) + 32;
    9495        }
    9596       
    96         return -1;
     97        return 255;
    9798}
    9899
  • kernel/arch/ppc32/src/exception.S

    rfb150d78 r46c20c8  
    2828
    2929#include <arch/asm/regname.h>
     30#include <arch/cpu.h>
    3031#include <arch/mm/page.h>
    3132
     
    3435.macro CONTEXT_STORE
    3536       
    36         # save R12 in SPRG1, backup CR in R12
     37        # save r12 in SPRG1, backup CR in r12
    3738        # save SP in SPRG2
    38 
     39       
    3940        mtsprg1 r12
    4041        mfcr r12
     
    288289       
    289290        mfmsr r12
    290         ori r12, r12, (msr_ir | msr_dr)@l
     291        ori r12, r12, (MSR_IR | MSR_DR)@l
    291292        mtsrr1 r12
    292293       
     
    307308       
    308309        mfmsr r12
    309         ori r12, r12, (msr_ir | msr_dr)@l
     310        ori r12, r12, (MSR_IR | MSR_DR)@l
    310311        mtsrr1 r12
    311312       
  • kernel/arch/ppc32/src/fpu_context.S

    rfb150d78 r46c20c8  
    3030#include <arch/context_offset.h>
    3131
    32 .text   
     32.text
    3333
    3434.global fpu_context_save
     
    8787       
    8888        blr
    89        
     89
    9090fpu_context_restore:
    9191//      FPU_CONTEXT_LOAD r3
  • kernel/arch/ppc32/src/interrupt.c

    rfb150d78 r46c20c8  
    3636#include <interrupt.h>
    3737#include <arch/interrupt.h>
    38 #include <arch/types.h>
     38#include <typedefs.h>
    3939#include <arch.h>
    4040#include <time/clock.h>
     
    4444#include <print.h>
    4545
    46 
    4746void start_decrementer(void)
    4847{
    4948        asm volatile (
    50                 "mtdec %0\n"
    51                 :
    52                 : "r" (1000)
     49                "mtdec %[dec]\n"
     50                :: [dec] "r" (1000)
    5351        );
    5452}
    5553
     54void istate_decode(istate_t *istate)
     55{
     56        printf("r0 =%#0" PRIx32 "\tr1 =%p\tr2 =%#0" PRIx32 "\n",
     57            istate->r0, (void *) istate->sp, istate->r2);
     58       
     59        printf("r3 =%#0" PRIx32 "\tr4 =%#0" PRIx32 "\tr5 =%#0" PRIx32 "\n",
     60            istate->r3, istate->r4, istate->r5);
     61       
     62        printf("r6 =%#0" PRIx32 "\tr7 =%#0" PRIx32 "\tr8 =%#0" PRIx32 "\n",
     63            istate->r6, istate->r7, istate->r8);
     64       
     65        printf("r9 =%#0" PRIx32 "\tr10=%#0" PRIx32 "\tr11=%#0" PRIx32 "\n",
     66            istate->r9, istate->r10, istate->r11);
     67       
     68        printf("r12=%#0" PRIx32 "\tr13=%#0" PRIx32 "\tr14=%#0" PRIx32 "\n",
     69            istate->r12, istate->r13, istate->r14);
     70       
     71        printf("r15=%#0" PRIx32 "\tr16=%#0" PRIx32 "\tr17=%#0" PRIx32 "\n",
     72            istate->r15, istate->r16, istate->r17);
     73       
     74        printf("r18=%#0" PRIx32 "\tr19=%#0" PRIx32 "\tr20=%#0" PRIx32 "\n",
     75            istate->r18, istate->r19, istate->r20);
     76       
     77        printf("r21=%#0" PRIx32 "\tr22=%#0" PRIx32 "\tr23=%#0" PRIx32 "\n",
     78            istate->r21, istate->r22, istate->r23);
     79       
     80        printf("r24=%#0" PRIx32 "\tr25=%#0" PRIx32 "\tr26=%#0" PRIx32 "\n",
     81            istate->r24, istate->r25, istate->r26);
     82       
     83        printf("r27=%#0" PRIx32 "\tr28=%#0" PRIx32 "\tr29=%#0" PRIx32 "\n",
     84            istate->r27, istate->r28, istate->r29);
     85       
     86        printf("r30=%#0" PRIx32 "\tr31=%#0" PRIx32 "\n",
     87            istate->r30, istate->r31);
     88       
     89        printf("cr =%#0" PRIx32 "\tpc =%p\tlr =%p\n",
     90            istate->cr, (void *) istate->pc, (void *) istate->lr);
     91       
     92        printf("ctr=%#0" PRIx32 "\txer=%#0" PRIx32 "\tdar=%#0" PRIx32 "\n",
     93            istate->ctr, istate->xer, istate->dar);
     94       
     95        printf("srr1=%p\n", (void *) istate->srr1);
     96}
    5697
    57 /** Handler of external interrupts */
    58 static void exception_external(int n, istate_t *istate)
     98/** External interrupts handler
     99 *
     100 */
     101static void exception_external(unsigned int n, istate_t *istate)
    59102{
    60         int inum;
     103        uint8_t inum;
    61104       
    62         while ((inum = pic_get_pending()) != -1) {
     105        while ((inum = pic_get_pending()) != 255) {
    63106                irq_t *irq = irq_dispatch_and_lock(inum);
    64107                if (irq) {
     
    80123                        }
    81124                       
    82                         spinlock_unlock(&irq->lock);
     125                        irq_spinlock_unlock(&irq->lock, false);
    83126                } else {
    84127                        /*
     
    86129                         */
    87130#ifdef CONFIG_DEBUG
    88                         printf("cpu%u: spurious interrupt (inum=%d)\n", CPU->id, inum);
     131                        printf("cpu%u: spurious interrupt (inum=%" PRIu8 ")\n",
     132                            CPU->id, inum);
    89133#endif
    90134                }
     
    92136}
    93137
    94 
    95 static void exception_decrementer(int n, istate_t *istate)
     138static void exception_decrementer(unsigned int n, istate_t *istate)
    96139{
    97140        start_decrementer();
     
    99142}
    100143
    101 
    102144/* Initialize basic tables for exception dispatching */
    103145void interrupt_init(void)
    104146{
    105         exc_register(VECTOR_DATA_STORAGE, "data_storage", pht_refill);
    106         exc_register(VECTOR_INSTRUCTION_STORAGE, "instruction_storage", pht_refill);
    107         exc_register(VECTOR_EXTERNAL, "external", exception_external);
    108         exc_register(VECTOR_DECREMENTER, "timer", exception_decrementer);
     147        exc_register(VECTOR_DATA_STORAGE, "data_storage", true,
     148            pht_refill);
     149        exc_register(VECTOR_INSTRUCTION_STORAGE, "instruction_storage", true,
     150            pht_refill);
     151        exc_register(VECTOR_EXTERNAL, "external", true,
     152            exception_external);
     153        exc_register(VECTOR_DECREMENTER, "timer", true,
     154            exception_decrementer);
    109155}
    110156
  • kernel/arch/ppc32/src/mm/as.c

    rfb150d78 r46c20c8  
    5555void as_install_arch(as_t *as)
    5656{
    57         asid_t asid;
    5857        uint32_t sr;
    59 
    60         asid = as->asid;
    6158       
    6259        /* Lower 2 GB, user and supervisor access */
    63         for (sr = 0; sr < 8; sr++) {
    64                 asm volatile (
    65                         "mtsrin %0, %1\n"
    66                         :
    67                         : "r" ((0x6000 << 16) + (asid << 4) + sr), "r" (sr << 28)
    68                 );
    69         }
     60        for (sr = 0; sr < 8; sr++)
     61                sr_set(0x6000, as->asid, sr);
    7062       
    7163        /* Upper 2 GB, only supervisor access */
    72         for (sr = 8; sr < 16; sr++) {
    73                 asm volatile (
    74                         "mtsrin %0, %1\n"
    75                         :
    76                         : "r" ((0x4000 << 16) + (asid << 4) + sr), "r" (sr << 28)
    77                 );
    78         }
     64        for (sr = 8; sr < 16; sr++)
     65                sr_set(0x4000, as->asid, sr);
    7966}
    8067
  • kernel/arch/ppc32/src/mm/frame.c

    rfb150d78 r46c20c8  
    2727 */
    2828
    29 /** @addtogroup ppc32mm 
     29/** @addtogroup ppc32mm
    3030 * @{
    3131 */
     
    4141
    4242uintptr_t last_frame = 0;
     43memmap_t memmap;
    4344
    4445void physmem_print(void)
    4546{
    46         unsigned int i;
     47        printf("[base    ] [size    ]\n");
    4748       
    48         printf("Base       Size\n");
    49         printf("---------- ----------\n");
    50                
    51         for (i = 0; i < bootinfo.memmap.count; i++) {
    52                 printf("%#10x %#10x\n", bootinfo.memmap.zones[i].start,
    53                         bootinfo.memmap.zones[i].size);
     49        size_t i;
     50        for (i = 0; i < memmap.cnt; i++) {
     51                printf("%p %#0zx\n", memmap.zones[i].start,
     52                    memmap.zones[i].size);
    5453        }
    5554}
     
    5958        pfn_t minconf = 2;
    6059        size_t i;
    61         pfn_t start, conf;
    62         size_t size;
    6360       
    64         for (i = 0; i < bootinfo.memmap.count; i++) {
    65                 start = ADDR2PFN(ALIGN_UP(bootinfo.memmap.zones[i].start, FRAME_SIZE));
    66                 size = SIZE2FRAMES(ALIGN_DOWN(bootinfo.memmap.zones[i].size, FRAME_SIZE));
     61        for (i = 0; i < memmap.cnt; i++) {
     62                /* To be safe, make the available zone possibly smaller */
     63                uintptr_t new_start = ALIGN_UP((uintptr_t) memmap.zones[i].start,
     64                    FRAME_SIZE);
     65                size_t new_size = ALIGN_DOWN(memmap.zones[i].size -
     66                    (new_start - ((uintptr_t) memmap.zones[i].start)), FRAME_SIZE);
    6767               
    68                 if ((minconf < start) || (minconf >= start + size))
    69                         conf = start;
     68                pfn_t pfn = ADDR2PFN(new_start);
     69                size_t count = SIZE2FRAMES(new_size);
     70               
     71                pfn_t conf;
     72                if ((minconf < pfn) || (minconf >= pfn + count))
     73                        conf = pfn;
    7074                else
    7175                        conf = minconf;
    7276               
    73                 zone_create(start, size, conf, 0);
    74                 if (last_frame < ALIGN_UP(bootinfo.memmap.zones[i].start + bootinfo.memmap.zones[i].size, FRAME_SIZE))
    75                         last_frame = ALIGN_UP(bootinfo.memmap.zones[i].start + bootinfo.memmap.zones[i].size, FRAME_SIZE);
     77                zone_create(pfn, count, conf, 0);
     78               
     79                if (last_frame < ALIGN_UP(new_start + new_size, FRAME_SIZE))
     80                        last_frame = ALIGN_UP(new_start + new_size, FRAME_SIZE);
    7681        }
    7782       
     
    8186       
    8287        /* Mark the Page Hash Table frames as unavailable */
    83         uint32_t sdr1;
    84         asm volatile (
    85                 "mfsdr1 %0\n"
    86                 : "=r" (sdr1)
    87         );
    88         frame_mark_unavailable(ADDR2PFN(sdr1 & 0xffff000), 16); // FIXME
     88        uint32_t sdr1 = sdr1_get();
     89       
     90        // FIXME: compute size of PHT exactly
     91        frame_mark_unavailable(ADDR2PFN(sdr1 & 0xffff000), 16);
    8992}
    9093
  • kernel/arch/ppc32/src/mm/page.c

    rfb150d78 r46c20c8  
    4545}
    4646
    47 
    4847uintptr_t hw_map(uintptr_t physaddr, size_t size)
    4948{
    5049        if (last_frame + ALIGN_UP(size, PAGE_SIZE) >
    5150            KA2PA(KERNEL_ADDRESS_SPACE_END_ARCH))
    52                 panic("Unable to map physical memory %p (%" PRIs " bytes).",
    53                     physaddr, size);
     51                panic("Unable to map physical memory %p (%zu bytes).",
     52                    (void *) physaddr, size);
    5453       
    5554        uintptr_t virtaddr = PA2KA(last_frame);
    5655        pfn_t i;
     56        page_table_lock(AS_KERNEL, true);
    5757        for (i = 0; i < ADDR2PFN(ALIGN_UP(size, PAGE_SIZE)); i++)
    5858                page_mapping_insert(AS_KERNEL, virtaddr + PFN2ADDR(i),
    5959                    physaddr + PFN2ADDR(i), PAGE_NOT_CACHEABLE | PAGE_WRITE);
     60        page_table_unlock(AS_KERNEL, true);
    6061       
    6162        last_frame = ALIGN_UP(last_frame + size, FRAME_SIZE);
  • kernel/arch/ppc32/src/mm/tlb.c

    rfb150d78 r46c20c8  
    4545
    4646static unsigned int seed = 10;
    47 static unsigned int seed_real __attribute__ ((section("K_UNMAPPED_DATA_START"))) = 42;
    48 
     47static unsigned int seed_real
     48    __attribute__ ((section("K_UNMAPPED_DATA_START"))) = 42;
    4949
    5050/** Try to find PTE for faulting address
    5151 *
    52  * Try to find PTE for faulting address.
    53  * The as->lock must be held on entry to this function
    54  * if lock is true.
    55  *
    56  * @param as            Address space.
    57  * @param lock          Lock/unlock the address space.
    58  * @param badvaddr      Faulting virtual address.
    59  * @param access        Access mode that caused the fault.
    60  * @param istate        Pointer to interrupted state.
    61  * @param pfrc          Pointer to variable where as_page_fault() return code
    62  *                      will be stored.
    63  * @return              PTE on success, NULL otherwise.
    64  *
    65  */
    66 static pte_t *
    67 find_mapping_and_check(as_t *as, bool lock, uintptr_t badvaddr, int access,
     52 * @param as       Address space.
     53 * @param lock     Lock/unlock the address space.
     54 * @param badvaddr Faulting virtual address.
     55 * @param access   Access mode that caused the fault.
     56 * @param istate   Pointer to interrupted state.
     57 * @param pfrc     Pointer to variable where as_page_fault() return code
     58 *                 will be stored.
     59 *
     60 * @return PTE on success, NULL otherwise.
     61 *
     62 */
     63static pte_t *find_mapping_and_check(as_t *as, uintptr_t badvaddr, int access,
    6864    istate_t *istate, int *pfrc)
    6965{
     66        ASSERT(mutex_locked(&as->lock));
     67
    7068        /*
    7169         * Check if the mapping exists in page tables.
    72          */     
     70         */
    7371        pte_t *pte = page_mapping_find(as, badvaddr);
    7472        if ((pte) && (pte->present)) {
     
    7977                return pte;
    8078        } else {
    81                 int rc;
    82        
    8379                /*
    8480                 * Mapping not found in page tables.
    8581                 * Resort to higher-level page fault handler.
    8682                 */
    87                 page_table_unlock(as, lock);
    88                 switch (rc = as_page_fault(badvaddr, access, istate)) {
     83                page_table_unlock(as, true);
     84               
     85                int rc = as_page_fault(badvaddr, access, istate);
     86                switch (rc) {
    8987                case AS_PF_OK:
    9088                        /*
     
    9290                         * The mapping ought to be in place.
    9391                         */
    94                         page_table_lock(as, lock);
     92                        page_table_lock(as, true);
    9593                        pte = page_mapping_find(as, badvaddr);
    9694                        ASSERT((pte) && (pte->present));
     
    9896                        return pte;
    9997                case AS_PF_DEFER:
    100                         page_table_lock(as, lock);
     98                        page_table_lock(as, true);
    10199                        *pfrc = rc;
    102100                        return NULL;
    103101                case AS_PF_FAULT:
    104                         page_table_lock(as, lock);
     102                        page_table_lock(as, true);
    105103                        *pfrc = rc;
    106104                        return NULL;
    107105                default:
    108106                        panic("Unexpected rc (%d).", rc);
    109                 }       
    110         }
    111 }
    112 
     107                }
     108        }
     109}
    113110
    114111static void pht_refill_fail(uintptr_t badvaddr, istate_t *istate)
    115112{
    116         char *symbol;
    117         char *sym2;
    118 
    119         symbol = symtab_fmt_name_lookup(istate->pc);
    120         sym2 = symtab_fmt_name_lookup(istate->lr);
    121 
    122         fault_if_from_uspace(istate,
    123             "PHT Refill Exception on %p.", badvaddr);
    124         panic("%p: PHT Refill Exception at %p (%s<-%s).", badvaddr,
    125             istate->pc, symbol, sym2);
    126 }
    127 
     113        fault_if_from_uspace(istate, "PHT Refill Exception on %p.",
     114            (void *) badvaddr);
     115        panic_memtrap(istate, PF_ACCESS_UNKNOWN, badvaddr,
     116            "PHT Refill Exception.");
     117}
    128118
    129119static void pht_insert(const uintptr_t vaddr, const pte_t *pte)
     
    132122        uint32_t api = (vaddr >> 22) & 0x3f;
    133123       
    134         uint32_t vsid;
    135         asm volatile (
    136                 "mfsrin %0, %1\n"
    137                 : "=r" (vsid)
    138                 : "r" (vaddr)
    139         );
    140        
    141         uint32_t sdr1;
    142         asm volatile (
    143                 "mfsdr1 %0\n"
    144                 : "=r" (sdr1)
    145         );
     124        uint32_t vsid = sr_get(vaddr);
     125        uint32_t sdr1 = sdr1_get();
     126       
     127        // FIXME: compute size of PHT exactly
    146128        phte_t *phte = (phte_t *) PA2KA(sdr1 & 0xffff0000);
    147129       
     
    218200}
    219201
    220 
    221202/** Process Instruction/Data Storage Exception
    222203 *
     
    225206 *
    226207 */
    227 void pht_refill(int n, istate_t *istate)
    228 {
     208void pht_refill(unsigned int n, istate_t *istate)
     209{
     210        as_t *as = (AS == NULL) ? AS_KERNEL : AS;
    229211        uintptr_t badvaddr;
    230         pte_t *pte;
    231         int pfrc;
    232         as_t *as;
    233         bool lock;
    234        
    235         if (AS == NULL) {
    236                 as = AS_KERNEL;
    237                 lock = false;
    238         } else {
    239                 as = AS;
    240                 lock = true;
    241         }
    242212       
    243213        if (n == VECTOR_DATA_STORAGE)
     
    245215        else
    246216                badvaddr = istate->pc;
    247                
    248         page_table_lock(as, lock);
    249        
    250         pte = find_mapping_and_check(as, lock, badvaddr,
     217       
     218        page_table_lock(as, true);
     219       
     220        int pfrc;
     221        pte_t *pte = find_mapping_and_check(as, badvaddr,
    251222            PF_ACCESS_READ /* FIXME */, istate, &pfrc);
     223       
    252224        if (!pte) {
    253225                switch (pfrc) {
     
    260232                         * or copy_to_uspace().
    261233                         */
    262                         page_table_unlock(as, lock);
     234                        page_table_unlock(as, true);
    263235                        return;
    264236                default:
     
    267239        }
    268240       
    269         pte->accessed = 1; /* Record access to PTE */
     241        /* Record access to PTE */
     242        pte->accessed = 1;
    270243        pht_insert(badvaddr, pte);
    271244       
    272         page_table_unlock(as, lock);
     245        page_table_unlock(as, true);
    273246        return;
    274247       
    275248fail:
    276         page_table_unlock(as, lock);
     249        page_table_unlock(as, true);
    277250        pht_refill_fail(badvaddr, istate);
    278251}
    279 
    280252
    281253/** Process Instruction/Data Storage Exception in Real Mode
     
    285257 *
    286258 */
    287 bool pht_refill_real(int n, istate_t *istate)
     259bool pht_refill_real(unsigned int n, istate_t *istate)
    288260{
    289261        uintptr_t badvaddr;
     
    294266                badvaddr = istate->pc;
    295267       
    296         uint32_t physmem;
    297         asm volatile (
    298                 "mfsprg3 %0\n"
    299                 : "=r" (physmem)
    300         );
     268        uint32_t physmem = physmem_top();
    301269       
    302270        if ((badvaddr < PA2KA(0)) || (badvaddr >= PA2KA(physmem)))
     
    306274        uint32_t api = (badvaddr >> 22) & 0x3f;
    307275       
    308         uint32_t vsid;
    309         asm volatile (
    310                 "mfsrin %0, %1\n"
    311                 : "=r" (vsid)
    312                 : "r" (badvaddr)
    313         );
    314        
    315         uint32_t sdr1;
    316         asm volatile (
    317                 "mfsdr1 %0\n"
    318                 : "=r" (sdr1)
    319         );
     276        uint32_t vsid = sr_get(badvaddr);
     277        uint32_t sdr1 = sdr1_get();
     278       
     279        // FIXME: compute size of PHT exactly
    320280        phte_t *phte_real = (phte_t *) (sdr1 & 0xffff0000);
    321281       
     
    399359}
    400360
    401 
    402361/** Process ITLB/DTLB Miss Exception in Real Mode
    403362 *
    404363 *
    405364 */
    406 void tlb_refill_real(int n, uint32_t tlbmiss, ptehi_t ptehi, ptelo_t ptelo, istate_t *istate)
     365void tlb_refill_real(unsigned int n, uint32_t tlbmiss, ptehi_t ptehi,
     366    ptelo_t ptelo, istate_t *istate)
    407367{
    408368        uint32_t badvaddr = tlbmiss & 0xfffffffc;
    409        
    410         uint32_t physmem;
    411         asm volatile (
    412                 "mfsprg3 %0\n"
    413                 : "=r" (physmem)
    414         );
     369        uint32_t physmem = physmem_top();
    415370       
    416371        if ((badvaddr < PA2KA(0)) || (badvaddr >= PA2KA(physmem)))
     
    423378        uint32_t index = 0;
    424379        asm volatile (
    425                 "mtspr 981, %0\n"
    426                 "mtspr 982, %1\n"
    427                 "tlbld %2\n"
    428                 "tlbli %2\n"
    429                 : "=r" (index)
    430                 : "r" (ptehi),
    431                   "r" (ptelo)
     380                "mtspr 981, %[ptehi]\n"
     381                "mtspr 982, %[ptelo]\n"
     382                "tlbld %[index]\n"
     383                "tlbli %[index]\n"
     384                : [index] "=r" (index)
     385                : [ptehi] "r" (ptehi),
     386                  [ptelo] "r" (ptelo)
    432387        );
    433388}
    434389
    435 
    436390void tlb_arch_init(void)
    437391{
     
    439393}
    440394
    441 
    442395void tlb_invalidate_all(void)
    443396{
    444397        uint32_t index;
     398       
    445399        asm volatile (
    446                 "li %0, 0\n"
     400                "li %[index], 0\n"
    447401                "sync\n"
    448402               
    449403                ".rept 64\n"
    450                 "tlbie %0\n"
    451                 "addi %0, %0, 0x1000\n"
     404                "       tlbie %[index]\n"
     405                "       addi %[index], %[index], 0x1000\n"
    452406                ".endr\n"
    453407               
     
    455409                "tlbsync\n"
    456410                "sync\n"
    457                 : "=r" (index)
     411                : [index] "=r" (index)
    458412        );
    459413}
    460414
    461 
    462415void tlb_invalidate_asid(asid_t asid)
    463416{
    464         uint32_t sdr1;
    465         asm volatile (
    466                 "mfsdr1 %0\n"
    467                 : "=r" (sdr1)
    468         );
     417        uint32_t sdr1 = sdr1_get();
     418       
     419        // FIXME: compute size of PHT exactly
    469420        phte_t *phte = (phte_t *) PA2KA(sdr1 & 0xffff0000);
    470421       
    471         uint32_t i;
     422        size_t i;
    472423        for (i = 0; i < 8192; i++) {
    473424                if ((phte[i].v) && (phte[i].vsid >= (asid << 4)) &&
     
    475426                        phte[i].v = 0;
    476427        }
     428       
    477429        tlb_invalidate_all();
    478430}
    479 
    480431
    481432void tlb_invalidate_pages(asid_t asid, uintptr_t page, size_t cnt)
     
    485436}
    486437
    487 
    488438#define PRINT_BAT(name, ureg, lreg) \
    489439        asm volatile ( \
    490                 "mfspr %0," #ureg "\n" \
    491                 "mfspr %1," #lreg "\n" \
    492                 : "=r" (upper), "=r" (lower) \
     440                "mfspr %[upper], " #ureg "\n" \
     441                "mfspr %[lower], " #lreg "\n" \
     442                : [upper] "=r" (upper), \
     443                  [lower] "=r" (lower) \
    493444        ); \
     445        \
    494446        mask = (upper & 0x1ffc) >> 2; \
    495447        if (upper & 3) { \
    496448                uint32_t tmp = mask; \
    497449                length = 128; \
     450                \
    498451                while (tmp) { \
    499452                        if ((tmp & 1) == 0) { \
     
    506459        } else \
    507460                length = 0; \
    508         printf(name ": page=%.*p frame=%.*p length=%d KB (mask=%#x)%s%s\n", \
    509             sizeof(upper) * 2, upper & 0xffff0000, sizeof(lower) * 2, \
    510             lower & 0xffff0000, length, mask, \
     461        \
     462        printf(name ": page=%#0" PRIx32 " frame=%#0" PRIx32 \
     463            " length=%#0" PRIx32 " KB (mask=%#0" PRIx32 ")%s%s\n", \
     464            upper & UINT32_C(0xffff0000), lower & UINT32_C(0xffff0000), \
     465            length, mask, \
    511466            ((upper >> 1) & 1) ? " supervisor" : "", \
    512467            (upper & 1) ? " user" : "");
    513468
    514 
    515469void tlb_print(void)
    516470{
     
    518472       
    519473        for (sr = 0; sr < 16; sr++) {
    520                 uint32_t vsid;
    521                 asm volatile (
    522                         "mfsrin %0, %1\n"
    523                         : "=r" (vsid)
    524                         : "r" (sr << 28)
    525                 );
    526                 printf("sr[%02u]: vsid=%.*p (asid=%u)%s%s\n", sr,
    527                     sizeof(vsid) * 2, vsid & 0xffffff, (vsid & 0xffffff) >> 4,
     474                uint32_t vsid = sr_get(sr << 28);
     475               
     476                printf("sr[%02" PRIu32 "]: vsid=%#0" PRIx32 " (asid=%" PRIu32 ")"
     477                    "%s%s\n", sr, vsid & UINT32_C(0x00ffffff),
     478                    (vsid & UINT32_C(0x00ffffff)) >> 4,
    528479                    ((vsid >> 30) & 1) ? " supervisor" : "",
    529480                    ((vsid >> 29) & 1) ? " user" : "");
  • kernel/arch/ppc32/src/ppc32.c

    rfb150d78 r46c20c8  
    5353#include <align.h>
    5454#include <macros.h>
    55 #include <string.h>
     55#include <str.h>
    5656#include <print.h>
    5757
     
    6565
    6666/** Performs ppc32-specific initialization before main_bsp() is called. */
    67 void arch_pre_main(void)
    68 {
    69         init.cnt = bootinfo.taskmap.count;
    70        
    71         uint32_t i;
    72        
    73         for (i = 0; i < min3(bootinfo.taskmap.count, TASKMAP_MAX_RECORDS, CONFIG_INIT_TASKS); i++) {
    74                 init.tasks[i].addr = bootinfo.taskmap.tasks[i].addr;
    75                 init.tasks[i].size = bootinfo.taskmap.tasks[i].size;
     67void arch_pre_main(bootinfo_t *bootinfo)
     68{
     69        /* Copy tasks map. */
     70        init.cnt = min3(bootinfo->taskmap.cnt, TASKMAP_MAX_RECORDS, CONFIG_INIT_TASKS);
     71        size_t i;
     72        for (i = 0; i < init.cnt; i++) {
     73                init.tasks[i].addr = (uintptr_t) bootinfo->taskmap.tasks[i].addr;
     74                init.tasks[i].size = bootinfo->taskmap.tasks[i].size;
    7675                str_cpy(init.tasks[i].name, CONFIG_TASK_NAME_BUFLEN,
    77                     bootinfo.taskmap.tasks[i].name);
     76                    bootinfo->taskmap.tasks[i].name);
     77        }
     78       
     79        /* Copy physical memory map. */
     80        memmap.total = bootinfo->memmap.total;
     81        memmap.cnt = min(bootinfo->memmap.cnt, MEMMAP_MAX_RECORDS);
     82        for (i = 0; i < memmap.cnt; i++) {
     83                memmap.zones[i].start = bootinfo->memmap.zones[i].start;
     84                memmap.zones[i].size = bootinfo->memmap.zones[i].size;
    7885        }
    7986       
    8087        /* Copy boot allocations info. */
    81         ballocs.base = bootinfo.ballocs.base;
    82         ballocs.size = bootinfo.ballocs.size;
    83        
    84         ofw_tree_init(bootinfo.ofw_root);
     88        ballocs.base = bootinfo->ballocs.base;
     89        ballocs.size = bootinfo->ballocs.size;
     90       
     91        /* Copy OFW tree. */
     92        ofw_tree_init(bootinfo->ofw_root);
    8593}
    8694
     
    193201                pic_init(assigned_address[0].addr, PAGE_SIZE, &pic_cir,
    194202                    &pic_cir_arg);
    195 
     203               
    196204#ifdef CONFIG_MAC_KBD
    197205                uintptr_t pa = assigned_address[0].addr + 0x16000;
     
    215223                        }
    216224                }
    217 
     225               
    218226                /*
    219227                 * This is the necessary evil until the userspace driver is entirely
     
    276284{
    277285        // TODO
    278         while (1);
     286        while (true);
    279287}
    280288
  • kernel/arch/ppc32/src/proc/scheduler.c

    rfb150d78 r46c20c8  
    3939#include <arch.h>
    4040
    41 /** Perform ppc32 specific tasks needed before the new task is run. */
     41/** Perform ppc32 specific tasks needed before the new task is run.
     42 *
     43 */
    4244void before_task_runs_arch(void)
    4345{
    4446}
    4547
    46 /** Perform ppc32 specific tasks needed before the new thread is scheduled. */
     48/** Perform ppc32 specific tasks needed before the new thread is scheduled.
     49 *
     50 */
    4751void before_thread_runs_arch(void)
    4852{
    4953        tlb_invalidate_all();
     54       
    5055        asm volatile (
    51                 "mtsprg0 %0\n"
    52                 :
    53                 : "r" (KA2PA(&THREAD->kstack[THREAD_STACK_SIZE - SP_DELTA]))
     56                "mtsprg0 %[ksp]\n"
     57                :: [ksp] "r" (KA2PA(&THREAD->kstack[THREAD_STACK_SIZE - SP_DELTA]))
    5458        );
    5559}
Note: See TracChangeset for help on using the changeset viewer.