Changeset a35b458 in mainline for boot


Ignore:
Timestamp:
2018-03-02T20:10:49Z (8 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f1380b7
Parents:
3061bc1
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
Message:

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

Location:
boot
Files:
34 edited

Legend:

Unmodified
Added
Removed
  • boot/arch/arm32/src/asm.S

    r3061bc1 ra35b458  
    6767#ifndef PROCESSOR_ARCH_armv7_a
    6868        mrc     p15, 0, r4, c1, c0, 0
    69        
     69
    7070        # Disable D-cache before the kernel is started.
    7171        bic     r4, r4, #(1 << CP15_C1_DC)
     
    7676        bic     r4, r4, #(1 << CP15_C1_BP)
    7777#endif
    78        
     78
    7979        mcr     p15, 0, r4, c1, c0, 0
    8080#endif
    81        
     81
    8282        # Wait for the operations to complete
    8383#ifdef PROCESSOR_ARCH_armv7_a
     
    8888        mcr p15, 0, r4, c7, c10, 4
    8989#endif
    90        
     90
    9191        # Clean ICache and BPredictors, r4 ignored (SBZ)
    9292        mov r4, #0
  • boot/arch/arm32/src/main.c

    r3061bc1 ra35b458  
    8989        mmu_start();
    9090        version_print();
    91        
     91
    9292        printf("Boot data: %p -> %p\n", &bdata_start, &bdata_end);
    9393        printf("\nMemory statistics\n");
     
    9797        printf(" %p|%p: kernel entry point\n",
    9898            (void *) PA2KA(BOOT_OFFSET), (void *) BOOT_OFFSET);
    99        
     99
    100100        for (size_t i = 0; i < COMPONENTS; i++) {
    101101                printf(" %p|%p: %s image (%u/%u bytes)\n", components[i].addr,
     
    103103                    components[i].size);
    104104        }
    105        
     105
    106106        void *dest[COMPONENTS];
    107107        size_t top = 0;
     
    110110        for (size_t i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) {
    111111                top = ALIGN_UP(top, PAGE_SIZE);
    112                
     112
    113113                if (i > 0) {
    114114                        bootinfo.tasks[bootinfo.cnt].addr = TOP2ADDR(top);
    115115                        bootinfo.tasks[bootinfo.cnt].size = components[i].inflated;
    116                        
     116
    117117                        str_cpy(bootinfo.tasks[bootinfo.cnt].name,
    118118                            BOOTINFO_TASK_NAME_BUFLEN, components[i].name);
    119                        
     119
    120120                        bootinfo.cnt++;
    121121                }
    122                
     122
    123123                dest[i] = TOP2ADDR(top);
    124124                top += components[i].inflated;
    125125                cnt++;
    126126        }
    127        
     127
    128128        printf("\nInflating components ... ");
    129        
     129
    130130        for (size_t i = cnt; i > 0; i--) {
    131131                void *tail = components[i - 1].addr + components[i - 1].size;
     
    135135                        halt();
    136136                }
    137                
     137
    138138                printf("%s ", components[i - 1].name);
    139                
     139
    140140                int err = inflate(components[i - 1].addr, components[i - 1].size,
    141141                    dest[i - 1], components[i - 1].inflated);
     
    147147                clean_dcache_poc(dest[i - 1], components[i - 1].inflated);
    148148        }
    149        
     149
    150150        printf(".\n");
    151151
    152152        /* Flush PT too. We need this if we disable caches later */
    153153        clean_dcache_poc(boot_pt, PTL0_ENTRIES * PTL0_ENTRY_SIZE);
    154        
     154
    155155        printf("Booting the kernel...\n");
    156156        jump_to_kernel((void *) PA2KA(BOOT_OFFSET), &bootinfo);
  • boot/arch/arm32/src/mm.c

    r3061bc1 ra35b458  
    209209                /* Current settings */
    210210                "mrc p15, 0, r0, c1, c0, 0\n"
    211                
     211
    212212                /* Enable ICache, DCache, BPredictors and MMU,
    213213                 * we disable caches before jumping to kernel
     
    221221                "ldr r1, =0x00001805\n"
    222222#endif
    223                
     223
    224224                "orr r0, r0, r1\n"
    225225
     
    228228                 */
    229229                "mcr p15, 0, r0, c8, c7, 0\n"
    230                
     230
    231231                /* Store settings, enable the MMU */
    232232                "mcr p15, 0, r0, c1, c0, 0\n"
  • boot/arch/ia64/src/main.c

    r3061bc1 ra35b458  
    6767        memmap_item_t *memmap = bootinfo.memmap;
    6868        size_t items = 0;
    69        
     69
    7070        if (!bootpar) {
    7171                /* Fake-up a memory map for simulators. */
     
    8383                size_t mm_size = bootpar->efi_memmap_sz;
    8484                size_t md_size = bootpar->efi_memdesc_sz;
    85                
     85
    8686                /*
    8787                 * Walk the EFI memory map using the V1 memory descriptor
     
    109109                                continue;
    110110                        }
    111                        
     111
    112112                        memmap[items].base = md->phys_start;
    113113                        memmap[items].size = md->pages * EFI_PAGE_SIZE;
     
    115115                }
    116116        }
    117        
     117
    118118        bootinfo.memmap_items = items;
    119119}
     
    134134                efi_guid_t sal_guid = SAL_SYSTEM_TABLE_GUID;
    135135                sal_system_table_header_t *sal_st;
    136                
     136
    137137                sal_st = efi_vendor_table_find(
    138138                    (efi_system_table_t *) bootpar->efi_system_table, sal_guid);
    139139
    140140                sal_system_table_parse(sal_st);
    141                
     141
    142142                bootinfo.sys_freq = sal_base_clock_frequency();
    143143        } else {
     
    150150{
    151151        version_print();
    152        
     152
    153153        printf(" %p|%p: boot info structure\n", &bootinfo, &bootinfo);
    154154        printf(" %p|%p: kernel entry point\n",
     
    156156        printf(" %p|%p: loader entry point\n",
    157157            (void *) LOADER_ADDRESS, (void *) LOADER_ADDRESS);
    158        
     158
    159159        size_t i;
    160160        for (i = 0; i < COMPONENTS; i++)
     
    162162                    components[i].addr, components[i].name,
    163163                    components[i].inflated, components[i].size);
    164        
     164
    165165        void *dest[COMPONENTS];
    166166        size_t top = KERNEL_ADDRESS;
     
    169169        for (i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) {
    170170                top = ALIGN_UP(top, PAGE_SIZE);
    171                
     171
    172172                if (i > 0) {
    173173                        bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].addr =
     
    175175                        bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].size =
    176176                            components[i].inflated;
    177                        
     177
    178178                        str_cpy(bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].name,
    179179                            BOOTINFO_TASK_NAME_BUFLEN, components[i].name);
    180                        
     180
    181181                        bootinfo.taskmap.cnt++;
    182182                }
    183                
     183
    184184                dest[i] = (void *) top;
    185185                top += components[i].inflated;
    186186                cnt++;
    187187        }
    188        
     188
    189189        printf("\nInflating components ... ");
    190        
     190
    191191        /*
    192192         * We will use the next available address for a copy of each component to
     
    197197        for (i = cnt; i > 0; i--) {
    198198                printf("%s ", components[i - 1].name);
    199                
     199
    200200                /*
    201201                 * Copy the component to a location which is guaranteed not to
     
    203203                 */
    204204                memmove((void *) top, components[i - 1].addr, components[i - 1].size);
    205                
     205
    206206                int err = inflate((void *) top, components[i - 1].size,
    207207                    dest[i - 1], components[i - 1].inflated);
    208                
     208
    209209                if (err != EOK) {
    210210                        printf("\n%s: Inflating error %d, halting.\n",
     
    213213                }
    214214        }
    215        
     215
    216216        printf(".\n");
    217217
     
    219219        read_sal_configuration();
    220220        read_pal_configuration();
    221        
     221
    222222        printf("Booting the kernel ...\n");
    223223        jump_to_kernel(&bootinfo);
  • boot/arch/ia64/src/pal.c

    r3061bc1 ra35b458  
    3535{
    3636        uint64_t proc_ratio;
    37        
     37
    3838        pal_static_call_0_1(PAL_FREQ_RATIOS, &proc_ratio);
    39        
     39
    4040        return proc_ratio;
    4141}
  • boot/arch/ia64/src/pal_asm.S

    r3061bc1 ra35b458  
    3838        srlz.i
    3939        srlz.d
    40        
     40
    4141        mov loc2 = gp
    4242        mov loc3 = rp
    43        
     43
    4444        addl loc4 = @gprel(pal_proc), gp
    4545
     
    4848        mov r30 = in2
    4949        mov r31 = in3 ;;
    50        
     50
    5151        ld8 loc4 = [loc4]
    5252        movl loc5 = 0f ;;
     
    6464        cmp.ne p8,p0 = 0, in5
    6565        cmp.ne p9,p0 = 0, in6 ;;
    66        
     66
    6767(p7)    st8 [in4] = r9
    6868(p8)    st8 [in5] = r10
    6969(p9)    st8 [in6] = r11
    70        
     70
    7171        mov gp = loc2
    7272        mov rp = loc3 ;;
    73        
     73
    7474        mov ar.pfs = loc0
    7575        br.ret.sptk.many rp
  • boot/arch/ia64/src/sal.c

    r3061bc1 ra35b458  
    7575{
    7676        uint64_t freq;
    77        
     77
    7878        sal_call_1_1(SAL_FREQ_BASE, 0, &freq);
    79        
     79
    8080        return freq;
    8181}
  • boot/arch/ia64/src/sal_asm.S

    r3061bc1 ra35b458  
    4545FUNCTION_BEGIN(sal_call)
    4646        alloc loc0 = ar.pfs, 8, 8, 8, 0
    47        
     47
    4848        adds sp = -STACK_SCRATCH_AREA, sp
    4949
    5050        mov loc1 = gp
    5151        mov loc2 = rp
    52        
     52
    5353        addl loc3 = @gprel(sal_proc), gp
    5454        addl loc4 = @gprel(sal_proc_gp), gp
    55        
     55
    5656        mov out0 = in0
    5757        mov out1 = in1
     
    6262        mov out6 = in6
    6363        mov out7 = in7 ;;
    64        
     64
    6565        ld8 loc3 = [loc3]
    6666        ld8 gp = [loc4]
     
    7373        ld8 loc6 = [r15]
    7474        ld8 loc7 = [r16]
    75        
     75
    7676        mov b6 = loc3 ;;
    7777        br.call.sptk.many rp = b6
    78        
     78
    7979        cmp.ne p7,p0 = 0, loc5
    8080        cmp.ne p8,p0 = 0, loc6
    8181        cmp.ne p9,p0 = 0, loc7 ;;
    82        
     82
    8383(p7)    st8 [loc5] = r9
    8484(p8)    st8 [loc6] = r10
    8585(p9)    st8 [loc7] = r11
    86        
     86
    8787        mov gp = loc1
    8888        mov rp = loc2
    8989
    9090        adds sp = STACK_SCRATCH_AREA, sp ;;
    91        
     91
    9292        mov ar.pfs = loc0
    9393        br.ret.sptk.many rp
  • boot/arch/ia64/src/ski.c

    r3061bc1 ra35b458  
    3737{
    3838        static bool initialized = false;
    39        
     39
    4040        if (initialized)
    4141                return;
     
    4848                : "r15", "r8"
    4949        );
    50        
     50
    5151        initialized = true;
    5252}
  • boot/arch/mips32/src/asm.S

    r3061bc1 ra35b458  
    5555        sw $a3, 0($a0)
    5656#endif
    57        
     57
    5858        /*
    5959         * Setup CPU map (on msim this code
     
    6262         */
    6363        la $a0, PA2KA(CPUMAP_OFFSET)
    64        
     64
    6565        sw $zero, 0($a0)
    6666        sw $zero, 4($a0)
    6767        sw $zero, 8($a0)
    6868        sw $zero, 12($a0)
    69        
     69
    7070        sw $zero, 16($a0)
    7171        sw $zero, 20($a0)
    7272        sw $zero, 24($a0)
    7373        sw $zero, 28($a0)
    74        
     74
    7575        sw $zero, 32($a0)
    7676        sw $zero, 36($a0)
    7777        sw $zero, 40($a0)
    7878        sw $zero, 44($a0)
    79        
     79
    8080        sw $zero, 48($a0)
    8181        sw $zero, 52($a0)
    8282        sw $zero, 56($a0)
    8383        sw $zero, 60($a0)
    84        
     84
    8585        sw $zero, 64($a0)
    8686        sw $zero, 68($a0)
    8787        sw $zero, 72($a0)
    8888        sw $zero, 76($a0)
    89        
     89
    9090        sw $zero, 80($a0)
    9191        sw $zero, 84($a0)
    9292        sw $zero, 88($a0)
    9393        sw $zero, 92($a0)
    94        
     94
    9595        sw $zero, 96($a0)
    9696        sw $zero, 100($a0)
    9797        sw $zero, 104($a0)
    9898        sw $zero, 108($a0)
    99        
     99
    100100        sw $zero, 112($a0)
    101101        sw $zero, 116($a0)
    102102        sw $zero, 120($a0)
    103103        sw $zero, 124($a0)
    104        
     104
    105105        lui $a1, 1
    106        
     106
    107107#ifdef MACHINE_msim
    108        
     108
    109109        /* Read dorder value */
    110110        la $k0, MSIM_DORDER_ADDRESS
    111111        lw $k1, ($k0)
    112        
     112
    113113        /*
    114114         * If we are not running on BSP
     
    117117        beq $k1, $zero, bsp
    118118        nop
    119        
     119
    120120        /* Record CPU presence */
    121121        sll $a2, $k1, 2
    122122        addu $a2, $a2, $a0
    123123        sw $a1, ($a2)
    124        
     124
    125125        loop:
    126126                j loop
    127127                nop
    128        
     128
    129129#endif
    130        
     130
    131131        bsp:
    132132                /* Record CPU presence */
    133133                sw $a1, ($a0)
    134                
     134
    135135                /* Setup initial stack */
    136136                la $sp, PA2KA(STACK_OFFSET)
    137                
     137
    138138                j bootstrap
    139139                nop
  • boot/arch/mips32/src/boot.S

    r3061bc1 ra35b458  
    3838.global start
    3939start:
    40        
     40
    4141        /* Setup CPU map (on msim this code
    4242           is executed in parallel on all CPUs,
    4343           but it not an issue) */
    4444        la $a0, CPUMAP
    45        
     45
    4646        sw $zero, 0($a0)
    4747        sw $zero, 4($a0)
    4848        sw $zero, 8($a0)
    4949        sw $zero, 12($a0)
    50        
     50
    5151        sw $zero, 16($a0)
    5252        sw $zero, 20($a0)
    5353        sw $zero, 24($a0)
    5454        sw $zero, 28($a0)
    55        
     55
    5656        sw $zero, 32($a0)
    5757        sw $zero, 36($a0)
    5858        sw $zero, 40($a0)
    5959        sw $zero, 44($a0)
    60        
     60
    6161        sw $zero, 48($a0)
    6262        sw $zero, 52($a0)
    6363        sw $zero, 56($a0)
    6464        sw $zero, 60($a0)
    65        
     65
    6666        sw $zero, 64($a0)
    6767        sw $zero, 68($a0)
    6868        sw $zero, 72($a0)
    6969        sw $zero, 76($a0)
    70        
     70
    7171        sw $zero, 80($a0)
    7272        sw $zero, 84($a0)
    7373        sw $zero, 88($a0)
    7474        sw $zero, 92($a0)
    75        
     75
    7676        sw $zero, 96($a0)
    7777        sw $zero, 100($a0)
    7878        sw $zero, 104($a0)
    7979        sw $zero, 108($a0)
    80        
     80
    8181        sw $zero, 112($a0)
    8282        sw $zero, 116($a0)
    8383        sw $zero, 120($a0)
    8484        sw $zero, 124($a0)
    85        
     85
    8686        lui $a1, 1
    87        
     87
    8888#ifdef MACHINE_msim
    89        
     89
    9090        /* Read dorder value */
    9191        la $k0, MSIM_DORDER_ADDRESS
    9292        lw $k1, ($k0)
    93        
     93
    9494        /* If we are not running on BSP
    9595           then end in an infinite loop  */
    9696        beq $k1, $zero, bsp
    9797        nop
    98        
     98
    9999        /* Record CPU presence */
    100100        sll $a2, $k1, 2
    101101        addu $a2, $a2, $a0
    102102        sw $a1, ($a2)
    103        
     103
    104104        loop:
    105105                j loop
    106106                nop
    107        
     107
    108108#endif
    109        
     109
    110110        bsp:
    111111                /* Record CPU presence */
    112112                sw $a1, ($a0)
    113                
     113
    114114                /* Setup initial stack */
    115115                la $sp, INITIAL_STACK
    116                
     116
    117117                j bootstrap
    118118                nop
  • boot/arch/mips32/src/main.c

    r3061bc1 ra35b458  
    4949{
    5050        version_print();
    51        
     51
    5252        printf("\nMemory statistics\n");
    5353        printf(" %p|%p: CPU map\n", (void *) PA2KA(CPUMAP_OFFSET),
     
    6161        printf(" %p|%p: bootloader entry point\n",
    6262            (void *) PA2KA(LOADER_OFFSET), (void *) LOADER_OFFSET);
    63        
     63
    6464        size_t i;
    6565        for (i = 0; i < COMPONENTS; i++)
     
    7070                    components[i].name, components[i].inflated,
    7171                    components[i].size);
    72        
     72
    7373        void *dest[COMPONENTS];
    7474        size_t top = 0;
     
    7777        for (i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) {
    7878                top = ALIGN_UP(top, PAGE_SIZE);
    79                
     79
    8080                if (i > 0) {
    8181                        bootinfo->tasks[bootinfo->cnt].addr = TOP2ADDR(top);
    8282                        bootinfo->tasks[bootinfo->cnt].size = components[i].inflated;
    83                        
     83
    8484                        str_cpy(bootinfo->tasks[bootinfo->cnt].name,
    8585                            BOOTINFO_TASK_NAME_BUFLEN, components[i].name);
    86                        
     86
    8787                        bootinfo->cnt++;
    8888                }
    89                
     89
    9090                dest[i] = TOP2ADDR(top);
    9191                top += components[i].inflated;
    9292                cnt++;
    9393        }
    94        
     94
    9595        printf("\nInflating components ... ");
    96        
     96
    9797        for (i = cnt; i > 0; i--) {
    9898#ifdef MACHINE_msim
     
    104104                }
    105105#endif
    106                
     106
    107107                printf("%s ", components[i - 1].name);
    108                
     108
    109109                int err = inflate(components[i - 1].addr, components[i - 1].size,
    110110                    dest[i - 1], components[i - 1].inflated);
    111                
     111
    112112                if (err != EOK) {
    113113                        printf("\n%s: Inflating error %d, halting.\n",
     
    116116                }
    117117        }
    118        
     118
    119119        printf(".\n");
    120        
     120
    121121        printf("Copying CPU map ... \n");
    122        
     122
    123123        bootinfo->cpumap = 0;
    124124        for (i = 0; i < CPUMAP_MAX_RECORDS; i++) {
     
    126126                        bootinfo->cpumap |= (1 << i);
    127127        }
    128        
     128
    129129        printf("Booting the kernel ... \n");
    130130        jump_to_kernel((void *) PA2KA(BOOT_OFFSET), bootinfo);
  • boot/arch/ppc32/src/asm.S

    r3061bc1 ra35b458  
    4848        li \reg, 0
    4949        sync
    50        
     50
    5151        .rept 64
    5252                tlbie \reg
    5353                addi \reg, \reg, 0x1000
    5454        .endr
    55        
     55
    5656        eieio
    5757        tlbsync
     
    6161.macro BAT_COMPUTE base size mask lower upper
    6262        # less than 128 KB -> no BAT
    63        
     63
    6464        lis \upper, 0x0002
    6565        cmpw \size, \upper
    6666        blt no_bat
    67        
     67
    6868        # mask = total >> 18
    69        
     69
    7070        li \upper, 18
    7171        srw \mask, \size, \upper
    72        
     72
    7373        # create Block Length mask by replicating
    7474        # the leading logical one 14 times
    75        
     75
    7676        li \upper, 14
    7777        mtctr \mask
    7878        li \upper, 1
    79        
     79
    8080        0:
    8181                # mask = (mask >> 1) | mask
    82                
     82
    8383                srw \lower, \mask, \upper
    8484                or \mask, \mask, \lower
    85                
     85
    8686                bdnz 0b
    87        
     87
    8888        # mask = mask & 0x07ff
    8989        # (BAT can map up to 256 MB)
    90        
     90
    9191        andi. \mask, \mask, 0x07ff
    92        
     92
    9393        # mask = (mask << 2) | 0x0002
    9494        # (priviledged access only)
    95        
     95
    9696        li \upper, 2
    9797        slw \mask, \mask, \upper
    9898        ori \mask, \mask, 0x0002
    99        
     99
    100100        lis \upper, (0x8000 + \base)
    101101        or \upper, \upper, \mask
    102        
     102
    103103        lis \lower, \base
    104104        ori \lower, \lower, 0x0002
     
    111111        addi r4, r4, ofw_cif@l
    112112        stw r5, 0(r4)
    113        
     113
    114114        bl ofw_init
    115115        b bootstrap
     
    127127        # r5 = pages to translate
    128128        # r6 = real mode meeting point (physical address)
    129        
     129
    130130        # disable interrupts
    131        
     131
    132132        mfmsr r31
    133133        rlwinm r31, r31, 0, 17, 15
    134134        mtmsr r31
    135        
     135
    136136        # set real mode meeting point physical address
    137        
     137
    138138        mtspr srr0, r6
    139        
     139
    140140        # jump to real_mode
    141        
     141
    142142        mfmsr r31
    143143        lis r30, ~0@h
     
    145145        and r31, r31, r30
    146146        mtspr srr1, r31
    147        
     147
    148148        sync
    149149        isync
     
    155155.align PAGE_WIDTH
    156156SYMBOL(real_mode)
    157        
     157
    158158        # arguments:
    159159        # r3 = bootinfo (physical address)
    160160        # r4 = translate table (physical address)
    161161        # r5 = pages to translate
    162        
     162
    163163        # move the images of components to the proper
    164164        # location using the translate table
    165        
     165
    166166        li r31, PAGE_SIZE >> 2
    167167        li r30, 0
    168        
     168
    169169        page_copy:
    170                
     170
    171171                cmpwi r5, 0
    172172                beq copy_end
    173                
     173
    174174                mtctr r31
    175175                lwz r29, 0(r4)
    176                
     176
    177177                copy_loop:
    178                        
     178
    179179                        lwz r28, 0(r29)
    180180                        stw r28, 0(r30)
    181                        
     181
    182182                        SMC_COHERENCY r30
    183                        
     183
    184184                        addi r29, r29, 4
    185185                        addi r30, r30, 4
    186                        
     186
    187187                        bdnz copy_loop
    188                
     188
    189189                addi r4, r4, 4
    190190                subi r5, r5, 1
    191191                b page_copy
    192        
     192
    193193        copy_end:
    194        
     194
    195195        # initially fill segment registers
    196        
     196
    197197        li r31, 0
    198        
     198
    199199        li r29, 8
    200200        mtctr r29
    201201        li r30, 0                     # ASID 0 (VSIDs 0 .. 7)
    202        
     202
    203203        seg_fill_uspace:
    204        
     204
    205205                mtsrin r30, r31
    206206                addi r30, r30, 1
    207207                addis r31, r31, 0x1000    # move to next SR
    208                
     208
    209209                bdnz seg_fill_uspace
    210        
     210
    211211        li r29, 8
    212212        mtctr r29
    213213        lis r30, 0x4000               # priviledged access only
    214214        ori r30, r30, 8               # ASID 0 (VSIDs 8 .. 15)
    215        
     215
    216216        seg_fill_kernel:
    217        
     217
    218218                mtsrin r30, r31
    219219                addi r30, r30, 1
    220220                addis r31, r31, 0x1000    # move to next SR
    221                
     221
    222222                bdnz seg_fill_kernel
    223        
     223
    224224        # invalidate block address translation registers
    225        
     225
    226226        li r30, 0
    227        
     227
    228228        mtspr ibat0u, r30
    229229        mtspr ibat0l, r30
    230        
     230
    231231        mtspr ibat1u, r30
    232232        mtspr ibat1l, r30
    233        
     233
    234234        mtspr ibat2u, r30
    235235        mtspr ibat2l, r30
    236        
     236
    237237        mtspr ibat3u, r30
    238238        mtspr ibat3l, r30
    239        
     239
    240240        mtspr dbat0u, r30
    241241        mtspr dbat0l, r30
    242        
     242
    243243        mtspr dbat1u, r30
    244244        mtspr dbat1l, r30
    245        
     245
    246246        mtspr dbat2u, r30
    247247        mtspr dbat2l, r30
    248        
     248
    249249        mtspr dbat3u, r30
    250250        mtspr dbat3l, r30
    251        
     251
    252252        # create empty Page Hash Table
    253253        # on top of memory, size 64 KB
    254        
     254
    255255        lwz r31, 4(r3)                # r31 = memory size
    256        
     256
    257257        lis r30, 65536@h
    258258        ori r30, r30, 65536@l         # r30 = 65536
    259        
     259
    260260        subi r29, r30, 1              # r29 = 65535
    261        
     261
    262262        sub r31, r31, r30
    263263        andc r31, r31, r29            # pht = ALIGN_DOWN(memory_size - 65536, 65536)
    264        
     264
    265265        mtsdr1 r31
    266        
     266
    267267        li r29, 2
    268268        srw r30, r30, r29             # r30 = 16384
    269269        li r29, 0
    270        
     270
    271271        pht_clear:
    272                
     272
    273273                # write zeroes
    274                
     274
    275275                stw r29, 0(r31)
    276276                FLUSH_DCACHE r31
    277                
     277
    278278                addi r31, r31, 4
    279279                subi r30, r30, 4
    280                
     280
    281281                cmpwi r30, 0
    282282                beq clear_end
    283                
     283
    284284                bdnz pht_clear
    285                
     285
    286286        clear_end:
    287        
     287
    288288        # create BAT identity mapping
    289        
     289
    290290        lwz r31, 4(r3)                # r31 = memory size
    291        
     291
    292292        lis r30, 268435456@h
    293293        ori r30, r30, 268435456@l     # r30 = 256 MB
    294        
     294
    295295        # BAT0
    296        
     296
    297297        # r29 = min(r31, r30)
    298        
     298
    299299        cmpw r31, r30
    300300        blt bat0_r31
    301        
     301
    302302                mr r29, r30
    303303                b bat0_r30
    304        
     304
    305305        bat0_r31:
    306        
     306
    307307                mr r29, r31
    308        
     308
    309309        bat0_r30:
    310        
     310
    311311        BAT_COMPUTE 0x0000 r29 r28 r27 r26
    312312        mtspr ibat0u, r26
    313313        mtspr ibat0l, r27
    314        
     314
    315315        mtspr dbat0u, r26
    316316        mtspr dbat0l, r27
    317        
     317
    318318        # BAT1
    319        
     319
    320320        sub r31, r31, r29             # r31 = r31 - r29
    321        
     321
    322322        # r29 = min(r31, r30)
    323        
     323
    324324        cmpw r31, r30
    325325        blt bat1_r31
    326        
     326
    327327                mr r29, r30
    328328                b bat1_r30
    329        
     329
    330330        bat1_r31:
    331        
     331
    332332                mr r29, r31
    333        
     333
    334334        bat1_r30:
    335        
     335
    336336        BAT_COMPUTE 0x1000 r29 r28 r27 r26
    337337        mtspr ibat1u, r26
    338338        mtspr ibat1l, r27
    339        
     339
    340340        mtspr dbat1u, r26
    341341        mtspr dbat1l, r27
    342        
     342
    343343        # BAT2
    344        
     344
    345345        sub r31, r31, r29             # r31 = r31 - r29
    346        
     346
    347347        # r29 = min(r31, r30)
    348        
     348
    349349        cmpw r31, r30
    350350        blt bat2_r31
    351        
     351
    352352                mr r29, r30
    353353                b bat2_r30
    354        
     354
    355355        bat2_r31:
    356        
     356
    357357                mr r29, r31
    358        
     358
    359359        bat2_r30:
    360        
     360
    361361        BAT_COMPUTE 0x2000 r29 r28 r27 r26
    362362        mtspr ibat2u, r26
    363363        mtspr ibat2l, r27
    364        
     364
    365365        mtspr dbat2u, r26
    366366        mtspr dbat2l, r27
    367        
     367
    368368        # BAT3
    369        
     369
    370370        sub r31, r31, r29             # r31 = r31 - r29
    371        
     371
    372372        # r29 = min(r31, r30)
    373        
     373
    374374        cmpw r31, r30
    375375        blt bat3_r31
    376        
     376
    377377                mr r29, r30
    378378                b bat3_r30
    379        
     379
    380380        bat3_r31:
    381        
     381
    382382                mr r29, r31
    383        
     383
    384384        bat3_r30:
    385        
     385
    386386        BAT_COMPUTE 0x3000 r29 r28 r27 r26
    387387        mtspr ibat3u, r26
    388388        mtspr ibat3l, r27
    389        
     389
    390390        mtspr dbat3u, r26
    391391        mtspr dbat3l, r27
    392        
     392
    393393        no_bat:
    394        
     394
    395395        # flush TLB
    396        
     396
    397397        TLB_FLUSH r31
    398        
     398
    399399        # start the kernel
    400400        #
     
    404404        # sprg3 = physical memory size
    405405        # sp = 0 (enforces the usage of sprg0 as exception stack)
    406        
     406
    407407        lis r31, PA2KA(BOOT_OFFSET)@ha
    408408        addi r31, r31, PA2KA(BOOT_OFFSET)@l
    409409        mtspr srr0, r31
    410        
     410
    411411        lis r31, BOOT_OFFSET@ha
    412412        addi r31, r31, BOOT_OFFSET@l
    413413        mtsprg0 r31
    414        
     414
    415415        # bootinfo starts with a 64 bit integer containing
    416416        # the physical memory size, get the lower 4 bytes
    417        
     417
    418418        lwz r31, 4(r3)
    419419        mtsprg3 r31
    420        
     420
    421421        li sp, 0
    422        
     422
    423423        mfmsr r31
    424424        ori r31, r31, (msr_ir | msr_dr)@l
    425425        mtspr srr1, r31
    426        
     426
    427427        sync
    428428        isync
  • boot/arch/ppc32/src/main.c

    r3061bc1 ra35b458  
    6060        version_print();
    6161        ofw_memmap(&bootinfo.memmap);
    62        
     62
    6363        void *bootinfo_pa = ofw_translate(&bootinfo);
    6464        void *real_mode_pa = ofw_translate(&real_mode);
    6565        void *loader_address_pa = ofw_translate((void *) LOADER_ADDRESS);
    66        
     66
    6767        printf("\nMemory statistics (total %llu MB)\n", bootinfo.memmap.total >> 20);
    6868        printf(" %p|%p: real mode trampoline\n", &real_mode, real_mode_pa);
     
    7272        printf(" %p|%p: loader entry point\n",
    7373            (void *) LOADER_ADDRESS, loader_address_pa);
    74        
     74
    7575        size_t i;
    7676        for (i = 0; i < COMPONENTS; i++)
     
    7878                    ofw_translate(components[i].addr), components[i].name,
    7979                    components[i].inflated, components[i].size);
    80        
     80
    8181        size_t dest[COMPONENTS];
    8282        size_t top = 0;
     
    8585        for (i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) {
    8686                top = ALIGN_UP(top, PAGE_SIZE);
    87                
     87
    8888                if (i > 0) {
    8989                        bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].addr =
     
    9191                        bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].size =
    9292                            components[i].inflated;
    93                        
     93
    9494                        str_cpy(bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].name,
    9595                            BOOTINFO_TASK_NAME_BUFLEN, components[i].name);
    96                        
     96
    9797                        bootinfo.taskmap.cnt++;
    9898                }
    99                
     99
    100100                dest[i] = top;
    101101                top += components[i].inflated;
    102102                cnt++;
    103103        }
    104        
     104
    105105        if (top >= (size_t) loader_address_pa) {
    106106                printf("Inflated components overlap loader area.\n");
     
    108108                halt();
    109109        }
    110        
     110
    111111        void *balloc_base;
    112112        void *balloc_base_pa;
     
    114114            BALLOC_MAX_SIZE, loader_address_pa);
    115115        printf(" %p|%p: boot allocator area\n", balloc_base, balloc_base_pa);
    116        
     116
    117117        void *inflate_base;
    118118        void *inflate_base_pa;
     
    120120            loader_address_pa);
    121121        printf(" %p|%p: inflate area\n", inflate_base, inflate_base_pa);
    122        
     122
    123123        uintptr_t balloc_start = ALIGN_UP(top, PAGE_SIZE);
    124124        size_t pages = (balloc_start + ALIGN_UP(BALLOC_MAX_SIZE, PAGE_SIZE))
     
    129129            pages * sizeof(void *), loader_address_pa);
    130130        printf(" %p|%p: translate table\n", transtable, transtable_pa);
    131        
     131
    132132        check_overlap("boot allocator area", balloc_base_pa, pages);
    133133        check_overlap("inflate area", inflate_base_pa, pages);
    134134        check_overlap("translate table", transtable_pa, pages);
    135        
     135
    136136        printf("\nInflating components ... ");
    137        
     137
    138138        for (i = cnt; i > 0; i--) {
    139139                printf("%s ", components[i - 1].name);
    140                
     140
    141141                int err = inflate(components[i - 1].addr, components[i - 1].size,
    142142                    inflate_base + dest[i - 1], components[i - 1].inflated);
    143                
     143
    144144                if (err != EOK) {
    145145                        printf("\n%s: Inflating error %d, halting.\n",
     
    148148                }
    149149        }
    150        
     150
    151151        printf(".\n");
    152        
     152
    153153        printf("Setting up boot allocator ...\n");
    154154        balloc_init(&bootinfo.ballocs, balloc_base, PA2KA(balloc_start),
    155155            BALLOC_MAX_SIZE);
    156        
     156
    157157        printf("Setting up screens ...\n");
    158158        ofw_setup_screens();
    159        
     159
    160160        printf("Canonizing OpenFirmware device tree ...\n");
    161161        bootinfo.ofw_root = ofw_tree_build();
    162        
     162
    163163        printf("Setting up translate table ...\n");
    164164        for (i = 0; i < pages; i++) {
    165165                uintptr_t off = i << PAGE_WIDTH;
    166166                void *phys;
    167                
     167
    168168                if (off < balloc_start)
    169169                        phys = ofw_translate(inflate_base + off);
    170170                else
    171171                        phys = ofw_translate(balloc_base + off - balloc_start);
    172                
     172
    173173                ((void **) transtable)[i] = phys;
    174174        }
    175        
     175
    176176        printf("Booting the kernel...\n");
    177177        jump_to_kernel(bootinfo_pa, transtable_pa, pages, real_mode_pa);
  • boot/arch/ppc32/src/ofw.c

    r3061bc1 ra35b458  
    4343        if (ch == '\n')
    4444                ofw_putchar('\r');
    45        
     45
    4646        if (ascii_check(ch))
    4747                ofw_putchar(ch);
  • boot/arch/riscv64/src/asm.S

    r3061bc1 ra35b458  
    8585        li x30, 0
    8686        li x31, 0
    87        
     87
    8888        /* Set up stack, create stack frame */
    8989        la sp, boot_stack + BOOT_STACK_SIZE
    9090        addi sp, sp, -16
    91        
     91
    9292        j bootstrap
    9393
     
    9797        /* Enable performance counters access in supervisor mode */
    9898        csrsi mcounteren, MCOUNTEREN_CY_MASK | MCOUNTEREN_TM_MASK | MCOUNTEREN_IR_MASK
    99        
     99
    100100        /* Setup SV48 paging for supervisor mode */
    101101        la t0, ptl_0
    102102        srli t0, t0, 12
    103        
     103
    104104        li t1, SATP_PFN_MASK
    105105        and t0, t0, t1
    106        
     106
    107107        li t1, SATP_MODE_SV48
    108108        or t0, t0, t1
    109        
     109
    110110        csrw sptbr, t0
    111        
     111
    112112        /* Jump to supervisor mode */
    113113        csrr t0, mstatus
    114        
     114
    115115        li t1, ~MSTATUS_MPP_MASK
    116116        and t0, t0, t1
    117        
     117
    118118        /*
    119119         * TODO: Enable running with Supervisor User Mode
     
    122122        li t1, MSTATUS_MPP_SUPERVISOR | MSTATUS_SUM_MASK
    123123        or t0, t0, t1
    124        
     124
    125125        csrw mstatus, t0
    126        
     126
    127127        li ra, PA2KA(BOOT_OFFSET)
    128128        csrw mepc, ra
    129        
     129
    130130        mret
    131131FUNCTION_END(jump_to_kernel)
  • boot/arch/riscv64/src/main.c

    r3061bc1 ra35b458  
    4848{
    4949        version_print();
    50        
     50
    5151        bootinfo.htif_frame = ((uintptr_t) &htif_page) >> PAGE_WIDTH;
    5252        bootinfo.pt_frame = ((uintptr_t) &pt_page) >> PAGE_WIDTH;
    53        
     53
    5454        bootinfo.ucbinfo.tohost =
    5555            (volatile uint64_t *) PA2KA((uintptr_t) &tohost);
    5656        bootinfo.ucbinfo.fromhost =
    5757            (volatile uint64_t *) PA2KA((uintptr_t) &fromhost);
    58        
     58
    5959        // FIXME TODO: read from device tree
    6060        bootinfo.physmem_start = PHYSMEM_START;
     
    6363        bootinfo.memmap.zones[0].start = (void *) PHYSMEM_START;
    6464        bootinfo.memmap.zones[0].size = PHYSMEM_SIZE;
    65        
     65
    6666        printf("\nMemory statistics (total %lu MB, starting at %p)\n\n",
    6767            bootinfo.memmap.total >> 20, (void *) bootinfo.physmem_start);
    6868        printf(" %p: boot info structure\n", &bootinfo);
    69        
     69
    7070        uintptr_t top = BOOT_OFFSET;
    71        
     71
    7272        for (size_t i = 0; i < COMPONENTS; i++) {
    7373                printf(" %p: %s image (%zu/%zu bytes)\n", components[i].addr,
    7474                    components[i].name, components[i].inflated,
    7575                    components[i].size);
    76                
     76
    7777                uintptr_t tail = (uintptr_t) components[i].addr +
    7878                    components[i].size;
     
    8383                }
    8484        }
    85        
     85
    8686        printf(" %p: inflate area\n", (void *) top);
    87        
     87
    8888        void *kernel_entry = NULL;
    8989        void *dest[COMPONENTS];
    9090        size_t cnt = 0;
    9191        bootinfo.taskmap.cnt = 0;
    92        
     92
    9393        for (size_t i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) {
    9494                top = ALIGN_UP(top, PAGE_SIZE);
    95                
     95
    9696                if (i > 0) {
    9797                        bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].addr =
     
    9999                        bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].size =
    100100                            components[i].inflated;
    101                        
     101
    102102                        str_cpy(bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].name,
    103103                            BOOTINFO_TASK_NAME_BUFLEN, components[i].name);
    104                        
     104
    105105                        bootinfo.taskmap.cnt++;
    106106                } else
    107107                        kernel_entry = (void *) PA2KA(top);
    108                
     108
    109109                dest[i] = (void *) top;
    110110                top += components[i].inflated;
    111111                cnt++;
    112112        }
    113        
     113
    114114        printf(" %p: kernel entry point\n", kernel_entry);
    115        
     115
    116116        if (top >= bootinfo.physmem_start + bootinfo.memmap.total) {
    117117                printf("Not enough physical memory available.\n");
     
    119119                halt();
    120120        }
    121        
     121
    122122        printf("\nInflating components ... ");
    123        
     123
    124124        for (size_t i = cnt; i > 0; i--) {
    125125                printf("%s ", components[i - 1].name);
    126                
     126
    127127                int err = inflate(components[i - 1].addr, components[i - 1].size,
    128128                    dest[i - 1], components[i - 1].inflated);
    129                
     129
    130130                if (err != EOK) {
    131131                        printf("\n%s: Inflating error %d, halting.\n",
     
    134134                }
    135135        }
    136        
     136
    137137        printf(".\n");
    138        
     138
    139139        printf("Booting the kernel...\n");
    140140        jump_to_kernel(PA2KA(&bootinfo));
  • boot/arch/riscv64/src/ucb.c

    r3061bc1 ra35b458  
    3939        if (!val)
    4040                return;
    41        
     41
    4242        fromhost = 0;
    4343}
     
    4848            (((uint64_t) cmd) << 48) |
    4949            (payload & UINT64_C(0xffffffffffff));
    50        
     50
    5151        while (tohost)
    5252                poll_fromhost();
    53        
     53
    5454        tohost = val;
    5555}
  • boot/arch/sparc64/src/asm.S

    r3061bc1 ra35b458  
    65651:
    6666        ! Disable interrupts and disable address masking.
    67        
     67
    6868        wrpr %g0, PSTATE_PRIV_BIT, %pstate
    69        
     69
    7070        wrpr %g0, NWINDOWS - 2, %cansave   ! Set maximum saveable windows
    7171        wrpr %g0, 0, %canrestore           ! Get rid of windows we will never need again
    7272        wrpr %g0, 0, %otherwin             ! Make sure the window state is consistent
    7373        wrpr %g0, NWINDOWS - 1, %cleanwin  ! Prevent needless clean_window traps for kernel
    74        
     74
    7575        set initial_stack, %sp
    7676        add %sp, -STACK_BIAS, %sp
    77        
     77
    7878        set ofw_cif, %l0
    79        
     79
    8080        ! Initialize OpenFirmware
    81        
     81
    8282        call ofw_init
    8383        stx %o4, [%l0]
    84        
     84
    8585        ba %xcc, bootstrap
    8686        nop
     
    105105         * 3. Flush instruction pipeline.
    106106         */
    107        
     107
    108108        /*
    109109         * US3 processors have a write-invalidate cache, so explicitly
     
    115115        be %xcc, 1f
    116116        nop
    117        
     117
    118118        0:
    119119                call icache_flush
    120120                nop
    121        
     121
    122122        1:
    123123                membar #StoreStore
    124        
     124
    125125        /*
    126126         * Flush the instruction pipeline.
    127127         */
    128128        flush %i7
    129        
     129
    130130        ! Jump to kernel
    131131        jmp %o3
     
    138138        set ((ICACHE_SIZE - ICACHE_LINE_SIZE) | ICACHE_SET_BIT), %g1
    139139        stxa %g0, [%g1] ASI_ICACHE_TAG
    140        
     140
    141141        0:
    142142                membar #Sync
    143143                subcc %g1, ICACHE_LINE_SIZE, %g1
    144144                bnz,pt %xcc, 0b
    145        
     145
    146146        stxa %g0, [%g1] ASI_ICACHE_TAG
    147147        membar #Sync
    148148        retl
    149        
     149
    150150        ! SF Erratum #51
    151        
     151
    152152        nop
    153153#else
     
    161161        set ofw_cif, %l0
    162162        ldx [%l0], %l0
    163        
     163
    164164        rdpr %pstate, %l1
    165165        and %l1, ~PSTATE_AM_BIT, %l2
    166166        wrpr %l2, 0, %pstate
    167        
     167
    168168        jmpl %l0, %o7
    169169        mov %i0, %o0
    170        
     170
    171171        wrpr %l1, 0, %pstate
    172        
     172
    173173        ret
    174174        restore %o0, 0, %o0
  • boot/arch/sparc64/src/main.c

    r3061bc1 ra35b458  
    8686        phandle root = ofw_find_device("/");
    8787        char compatible[OFW_TREE_PROPERTY_MAX_VALUELEN];
    88        
     88
    8989        if (ofw_get_property(root, "compatible", compatible,
    9090            OFW_TREE_PROPERTY_MAX_VALUELEN) <= 0) {
     
    9393                return;
    9494        }
    95        
     95
    9696        if (str_cmp(compatible, "sun4v") != 0) {
    9797                /*
     
    122122                : [ver] "=r" (ver)
    123123        );
    124        
     124
    125125        ver = (ver << 16) >> 48;
    126        
     126
    127127        if ((ver >= FIRST_US3_CPU) && (ver <= LAST_US3_CPU)) {
    128128                subarch = SUBARCH_US3;
    129                
     129
    130130                if (ver == US_IIIi_CODE)
    131131                        mid_mask = (1 << 5) - 1;
    132132                else
    133133                        mid_mask = (1 << 10) - 1;
    134                
     134
    135135        } else if (ver < FIRST_US3_CPU) {
    136136                subarch = SUBARCH_US;
     
    193193{
    194194        version_print();
    195        
     195
    196196        arch_detect();
    197197        if (arch == ARCH_SUN4U)
     
    199199        else
    200200                subarch = SUBARCH_UNKNOWN;
    201        
     201
    202202        bootinfo.physmem_start = ofw_get_physmem_start();
    203203        ofw_memmap(&bootinfo.memmap);
     
    205205        if (arch == ARCH_SUN4V)
    206206                sun4v_fixups();
    207        
     207
    208208        void *bootinfo_pa = ofw_translate(&bootinfo);
    209209        void *kernel_address_pa = ofw_translate((void *) KERNEL_ADDRESS);
    210210        void *loader_address_pa = ofw_translate((void *) LOADER_ADDRESS);
    211        
     211
    212212        printf("\nMemory statistics (total %" PRIu64 " MB, starting at %p)\n",
    213213            bootinfo.memmap.total >> 20, (void *) bootinfo.physmem_start);
     
    217217        printf(" %p|%p: loader entry point\n",
    218218            (void *) LOADER_ADDRESS, (void *) loader_address_pa);
    219        
     219
    220220        size_t i;
    221221        for (i = 0; i < COMPONENTS; i++)
     
    223223                    ofw_translate(components[i].addr), components[i].name,
    224224                    components[i].inflated, components[i].size);
    225        
     225
    226226        void *dest[COMPONENTS];
    227227        size_t top = KERNEL_ADDRESS;
     
    230230        for (i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) {
    231231                top = ALIGN_UP(top, PAGE_SIZE);
    232                
     232
    233233                if (i > 0) {
    234234                        bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].addr =
     
    236236                        bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].size =
    237237                            components[i].inflated;
    238                        
     238
    239239                        str_cpy(bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].name,
    240240                            BOOTINFO_TASK_NAME_BUFLEN, components[i].name);
    241                        
     241
    242242                        bootinfo.taskmap.cnt++;
    243243                }
    244                
     244
    245245                dest[i] = (void *) top;
    246246                top += components[i].inflated;
    247247                cnt++;
    248248        }
    249        
     249
    250250        printf("\nInflating components ... ");
    251        
     251
    252252        for (i = cnt; i > 0; i--) {
    253253                printf("%s ", components[i - 1].name);
    254                
     254
    255255                /*
    256256                 * At this point, we claim and map the physical memory that we
     
    263263                ofw_claim_phys(bootinfo.physmem_start + dest[i - 1],
    264264                    ALIGN_UP(components[i - 1].inflated, PAGE_SIZE));
    265                
     265
    266266                ofw_map(bootinfo.physmem_start + dest[i - 1], dest[i - 1],
    267267                    ALIGN_UP(components[i - 1].inflated, PAGE_SIZE), -1);
    268                
     268
    269269                int err = inflate(components[i - 1].addr, components[i - 1].size,
    270270                    dest[i - 1], components[i - 1].inflated);
    271                
     271
    272272                if (err != EOK) {
    273273                        printf("\n%s: Inflating error %d, halting.\n",
     
    276276                }
    277277        }
    278        
     278
    279279        printf(".\n");
    280        
     280
    281281        /*
    282282         * Claim and map the physical memory for the boot allocator.
     
    290290        balloc_init(&bootinfo.ballocs, balloc_base, (uintptr_t) balloc_base,
    291291            BALLOC_MAX_SIZE);
    292        
     292
    293293        printf("Setting up screens ...\n");
    294294        ofw_setup_screens();
    295        
     295
    296296        printf("Canonizing OpenFirmware device tree ...\n");
    297297        bootinfo.ofw_root = ofw_tree_build();
    298        
     298
    299299        if (arch == ARCH_SUN4U)
    300300                sun4u_smp();
    301        
     301
    302302        printf("Booting the kernel ...\n");
    303303        jump_to_kernel(bootinfo.physmem_start | BSP_PROCESSOR, &bootinfo, subarch,
  • boot/arch/sparc64/src/ofw.c

    r3061bc1 ra35b458  
    4747        if (ch == '\n')
    4848                ofw_putchar('\r');
    49        
     49
    5050        if (ascii_check(ch))
    5151                ofw_putchar(ch);
     
    7272{
    7373        size_t cpus;
    74        
     74
    7575        for (cpus = 0; (child != 0) && (child != (phandle) -1);
    7676            child = ofw_get_peer_node(child), cpus++) {
    7777                char type_name[OFW_TREE_PROPERTY_MAX_VALUELEN];
    78                
     78
    7979                if (ofw_get_property(child, "device_type", type_name,
    8080                    OFW_TREE_PROPERTY_MAX_VALUELEN) > 0) {
    8181                        type_name[OFW_TREE_PROPERTY_MAX_VALUELEN - 1] = 0;
    82                        
     82
    8383                        if (str_cmp(type_name, "cpu") == 0) {
    8484                                uint32_t mid;
    85                                
     85
    8686                                /*
    8787                                 * "upa-portid" for US, "portid" for US-III,
     
    9292                                    && (ofw_get_property(child, "cpuid", &mid, sizeof(mid)) <= 0))
    9393                                        continue;
    94                                
     94
    9595                                if (current_mid != mid) {
    9696                                        /*
     
    104104                }
    105105        }
    106        
     106
    107107        return cpus;
    108108}
     
    115115        /* Get the current CPU MID */
    116116        uint64_t current_mid;
    117        
     117
    118118        asm volatile (
    119119                "ldxa [%[zero]] %[asi], %[current_mid]\n"
     
    122122                  [asi] "i" (ASI_ICBUS_CONFIG)
    123123        );
    124        
     124
    125125        current_mid >>= ICBUS_CONFIG_MID_SHIFT;
    126126        current_mid &= mid_mask;
    127        
     127
    128128        /* Wake up the CPUs */
    129        
     129
    130130        phandle cpus_parent = ofw_find_device("/ssm@0,0");
    131131        if ((cpus_parent == 0) || (cpus_parent == (phandle) -1))
    132132                cpus_parent = ofw_find_device("/");
    133        
     133
    134134        phandle node = ofw_get_child_node(cpus_parent);
    135135        size_t cpus = wake_cpus_in_node(node, current_mid, physmem_start);
    136        
     136
    137137        while ((node != 0) && (node != (phandle) -1)) {
    138138                char name[OFW_TREE_PROPERTY_MAX_VALUELEN];
    139                
     139
    140140                if (ofw_get_property(node, "name", name,
    141141                    OFW_TREE_PROPERTY_MAX_VALUELEN) > 0) {
    142142                        name[OFW_TREE_PROPERTY_MAX_VALUELEN - 1] = 0;
    143                        
     143
    144144                        if (str_cmp(name, "cmp") == 0) {
    145145                                phandle subnode = ofw_get_child_node(node);
     
    148148                        }
    149149                }
    150                
     150
    151151                node = ofw_get_peer_node(node);
    152152        }
    153        
     153
    154154        if (cpus == 0)
    155155                printf("Warning: Unable to get CPU properties.\n");
     
    169169                halt();
    170170        }
    171        
     171
    172172        return ((((uintptr_t) memreg[0]) << 32) | memreg[1]);
    173173}
  • boot/genarch/include/genarch/ofw_tree.h

    r3061bc1 ra35b458  
    4545        struct ofw_tree_node *peer;
    4646        struct ofw_tree_node *child;
    47        
     47
    4848        phandle node_handle;            /**< Old OpenFirmware node handle. */
    49        
     49
    5050        char *da_name;                  /**< Disambigued name. */
    51        
     51
    5252        size_t properties;              /**< Number of properties. */
    5353        ofw_tree_property_t *property;
    54        
     54
    5555        void *device;                   /**< Member used solely by the kernel. */
    5656} ofw_tree_node_t;
  • boot/genarch/src/division.c

    r3061bc1 ra35b458  
    4040        unsigned int result;
    4141        int steps = sizeof(unsigned int) * 8;
    42        
     42
    4343        *remainder = 0;
    4444        result = 0;
    45        
     45
    4646        if (b == 0) {
    4747                /* FIXME: division by zero */
    4848                return 0;
    4949        }
    50        
     50
    5151        if (a < b) {
    5252                *remainder = a;
    5353                return 0;
    5454        }
    55        
     55
    5656        for (; steps > 0; steps--) {
    5757                /* shift one bit to remainder */
    5858                *remainder = ((*remainder) << 1) | (( a >> 31) & 0x1);
    5959                result <<= 1;
    60                
     60
    6161                if (*remainder >= b) {
    6262                        *remainder -= b;
     
    6565                a <<= 1;
    6666        }
    67        
     67
    6868        return result;
    6969}
     
    7474        unsigned long long result;
    7575        int steps = sizeof(unsigned long long) * 8;
    76        
     76
    7777        *remainder = 0;
    7878        result = 0;
    79        
     79
    8080        if (b == 0) {
    8181                /* FIXME: division by zero */
    8282                return 0;
    8383        }
    84        
     84
    8585        if (a < b) {
    8686                *remainder = a;
    8787                return 0;
    8888        }
    89        
     89
    9090        for (; steps > 0; steps--) {
    9191                /* shift one bit to remainder */
    9292                *remainder = ((*remainder) << 1) | ((a >> 63) & 0x1);
    9393                result <<= 1;
    94                
     94
    9595                if (*remainder >= b) {
    9696                        *remainder -= b;
     
    9999                a <<= 1;
    100100        }
    101        
     101
    102102        return result;
    103103}
     
    108108        unsigned int rem;
    109109        int result = (int) divandmod32(ABSVAL(a), ABSVAL(b), &rem);
    110        
     110
    111111        if (SGN(a) == SGN(b))
    112112                return result;
    113        
     113
    114114        return -result;
    115115}
     
    120120        unsigned long long rem;
    121121        long long result = (long long) divandmod64(ABSVAL(a), ABSVAL(b), &rem);
    122        
     122
    123123        if (SGN(a) == SGN(b))
    124124                return result;
    125        
     125
    126126        return -result;
    127127}
     
    146146        unsigned int rem;
    147147        divandmod32(a, b, &rem);
    148        
     148
    149149        /* if divident is negative, remainder must be too */
    150150        if (!(SGN(a)))
    151151                return -((int) rem);
    152        
     152
    153153        return (int) rem;
    154154}
     
    159159        unsigned long long rem;
    160160        divandmod64(a, b, &rem);
    161        
     161
    162162        /* if divident is negative, remainder must be too */
    163163        if (!(SGN(a)))
    164164                return -((long long) rem);
    165        
     165
    166166        return (long long) rem;
    167167}
     
    187187        unsigned int rem;
    188188        int result = (int) divandmod32(ABSVAL(a), ABSVAL(b), &rem);
    189        
     189
    190190        if (SGN(a) == SGN(b)) {
    191191                *c = rem;
    192192                return result;
    193193        }
    194        
     194
    195195        *c = -rem;
    196196        return -result;
     
    207207        unsigned long long rem;
    208208        long long result = (int) divandmod64(ABSVAL(a), ABSVAL(b), &rem);
    209        
     209
    210210        if (SGN(a) == SGN(b)) {
    211211                *c = rem;
    212212                return result;
    213213        }
    214        
     214
    215215        *c = -rem;
    216216        return -result;
  • boot/genarch/src/multiplication.c

    r3061bc1 ra35b458  
    5050        unsigned int b1 = b >> 16;
    5151        unsigned int b2 = b & UINT16_MAX;
    52        
     52
    5353        unsigned long long t1 = a1 * b1;
    5454        unsigned long long t2 = a1 * b2;
    5555        t2 += a2 * b1;
    5656        unsigned long long t3 = a2 * b2;
    57        
     57
    5858        t3 = (((t1 << 16) + t2) << 16) + t3;
    59        
     59
    6060        return t3;
    6161}
     
    6767{
    6868        char neg = 0;
    69        
     69
    7070        if (a < 0) {
    7171                neg = !neg;
    7272                a = -a;
    7373        }
    74        
     74
    7575        if (b < 0) {
    7676                neg = !neg;
    7777                b = -b;
    7878        }
    79        
     79
    8080        unsigned long long a1 = a >> 32;
    8181        unsigned long long b1 = b >> 32;
    82        
     82
    8383        unsigned long long a2 = a & (UINT32_MAX);
    8484        unsigned long long b2 = b & (UINT32_MAX);
    85        
     85
    8686        if (SOFTINT_CHECK_OF && (a1 != 0) && (b1 != 0)) {
    8787                /* Error (overflow) */
    8888                return (neg ? INT64_MIN : INT64_MAX);
    8989        }
    90        
     90
    9191        /* (if OF checked) a1 or b1 is zero => result fits in 64 bits,
    9292         * no need to another overflow check
    9393         */
    9494        unsigned long long t1 = mul(a1, b2) + mul(b1, a2);
    95        
     95
    9696        if ((SOFTINT_CHECK_OF) && (t1 > UINT32_MAX)) {
    9797                /* Error (overflow) */
    9898                return (neg ? INT64_MIN : INT64_MAX);
    9999        }
    100        
     100
    101101        t1 = t1 << 32;
    102102        unsigned long long t2 = mul(a2, b2);
    103103        t2 += t1;
    104        
     104
    105105        /* t2 & (1ull << 63) - if this bit is set in unsigned long long,
    106106         * result does not fit in signed one
     
    110110                return (neg ? INT64_MIN : INT64_MAX);
    111111        }
    112        
     112
    113113        long long result = t2;
    114114        if (neg)
    115115                result = -result;
    116        
     116
    117117        return result;
    118118}
  • boot/genarch/src/ofw.c

    r3061bc1 ra35b458  
    6262        if (ofw_chosen == (phandle) -1)
    6363                halt();
    64        
     64
    6565        if ((ofw_ret_t) ofw_get_property(ofw_chosen, "stdout", &ofw_stdout,
    6666            sizeof(ofw_stdout)) <= 0)
    6767                ofw_stdout = 0;
    68        
     68
    6969        ofw_root = ofw_find_device("/");
    7070        if (ofw_root == (phandle) -1) {
     
    7272                halt();
    7373        }
    74        
     74
    7575        if ((ofw_ret_t) ofw_get_property(ofw_chosen, "mmu", &ofw_mmu,
    7676            sizeof(ofw_mmu)) <= 0) {
     
    8383                halt();
    8484        }
    85        
     85
    8686        ofw_memory = ofw_find_device("/memory");
    8787        if (ofw_memory == (phandle) -1) {
     
    110110        args.nargs = nargs;
    111111        args.nret = nret;
    112        
     112
    113113        va_list list;
    114114        va_start(list, rets);
    115        
     115
    116116        size_t i;
    117117        for (i = 0; i < nargs; i++)
    118118                args.args[i] = va_arg(list, ofw_arg_t);
    119        
     119
    120120        va_end(list);
    121        
     121
    122122        for (i = 0; i < nret; i++)
    123123                args.args[i + nargs] = 0;
    124        
     124
    125125        (void) ofw(&args);
    126        
     126
    127127        for (i = 1; i < nret; i++)
    128128                rets[i - 1] = args.args[i + nargs];
    129        
     129
    130130        return args.args[nargs];
    131131}
     
    161161{
    162162        ofw_prop_t ret = 1;
    163        
     163
    164164        if ((ofw_ret_t) ofw_get_property(device, "#address-cells", &ret,
    165165            sizeof(ret)) <= 0)
     
    167167                    sizeof(ret)) <= 0)
    168168                        ret = OFW_ADDRESS_CELLS;
    169        
     169
    170170        return (size_t) ret;
    171171}
     
    174174{
    175175        ofw_prop_t ret = 1;
    176        
     176
    177177        if ((ofw_ret_t) ofw_get_property(device, "#size-cells", &ret,
    178178            sizeof(ret)) <= 0)
     
    180180                    sizeof(ret)) <= 0)
    181181                        ret = OFW_SIZE_CELLS;
    182        
     182
    183183        return (size_t) ret;
    184184}
     
    198198        if (ofw_stdout == 0)
    199199                return;
    200        
     200
    201201        ofw_call("write", 3, 1, NULL, ofw_stdout, &ch, 1);
    202202}
     
    210210                halt();
    211211        }
    212        
     212
    213213        if (result[0] == false) {
    214214                printf("Error: Unable to translate virtual address %p, halting.\n",
     
    216216                halt();
    217217        }
    218        
     218
    219219#ifdef __32_BITS__
    220220        return (void *) result[2];
    221221#endif
    222        
     222
    223223#ifdef __64_BITS__
    224224        return (void *) ((result[2] << 32) | result[3]);
     
    235235                halt();
    236236        }
    237        
     237
    238238        return (void *) addr;
    239239}
     
    252252{
    253253        void *addr = ofw_claim_virt_internal(NULL, len, alignment);
    254        
     254
    255255        if (addr == NULL) {
    256256                printf("Error: Unable to claim %zu bytes in virtual memory, halting.\n",
     
    258258                halt();
    259259        }
    260        
     260
    261261        return addr;
    262262}
     
    276276         * purposes.
    277277         */
    278        
     278
    279279#ifdef __32_BITS__
    280280        ofw_arg_t retaddr[1];
     
    284284                halt();
    285285        }
    286        
     286
    287287        return (void *) retaddr[0];
    288288#endif
    289        
     289
    290290#ifdef __64_BITS__
    291291        ofw_arg_t retaddr[2];
     
    296296                halt();
    297297        }
    298        
     298
    299299        return (void *) ((retaddr[0] << 32) | retaddr[1]);
    300300#endif
     
    319319                halt();
    320320        }
    321        
     321
    322322        return addr;
    323323}
     
    328328        ofw_arg_t phys_hi;
    329329        ofw_arg_t phys_lo;
    330        
     330
    331331#ifdef __32_BITS__
    332332        phys_hi = (ofw_arg_t) phys;
    333333        phys_lo = 0;
    334334#endif
    335        
     335
    336336#ifdef __64_BITS__
    337337        phys_hi = (ofw_arg_t) phys >> 32;
    338338        phys_lo = (ofw_arg_t) phys & 0xffffffff;
    339339#endif
    340        
     340
    341341        ofw_arg_t ret = ofw_call("call-method", 7, 1, NULL, "map", ofw_mmu, mode,
    342342            ALIGN_UP(size, PAGE_SIZE), virt, phys_hi, phys_lo);
    343        
     343
    344344        if (ret != 0) {
    345345                printf("Error: Unable to map %p to %p (size %zu), halting.\n",
     
    360360        size_t sc = ofw_get_size_cells(ofw_memory) /
    361361            (sizeof(uintptr_t) / sizeof(uint32_t));
    362        
     362
    363363        uintptr_t buf[((ac + sc) * MEMMAP_MAX_RECORDS)];
    364        
     364
    365365        /* The number of bytes read */
    366366        ofw_ret_t ret = (ofw_ret_t) ofw_get_property(ofw_memory, "reg", buf,
     
    370370                halt();
    371371        }
    372        
     372
    373373        size_t pos;
    374374        map->total = 0;
     
    378378                void *start = (void *) (buf[pos + ac - 1]);
    379379                uintptr_t size = buf[pos + ac + sc - 1];
    380                
     380
    381381                /*
    382382                 * This is a hot fix of the issue which occurs on machines
     
    389389                    map->zones[map->cnt - 1].size < start))
    390390                        break;
    391                
     391
    392392                if (size > 0) {
    393393                        map->zones[map->cnt].start = start;
     
    397397                }
    398398        }
    399        
     399
    400400        if (map->total == 0) {
    401401                printf("Error: No physical memory detected, halting.\n");
     
    421421                *base_pa = ofw_claim_phys_any(size, PAGE_SIZE);
    422422        } while (*base_pa <= min_pa);
    423        
     423
    424424        *base = ofw_claim_virt_any(size, PAGE_SIZE);
    425425        ofw_map(*base_pa, *base, ALIGN_UP(size, PAGE_SIZE), (ofw_arg_t) -1);
     
    433433            OFW_TREE_PROPERTY_MAX_VALUELEN) <= 0)
    434434                return;
    435        
     435
    436436        device_type[OFW_TREE_PROPERTY_MAX_VALUELEN - 1] = '\0';
    437437        if (str_cmp(device_type, "display") != 0)
    438438                return;
    439        
     439
    440440        /* Check for 8 bit depth */
    441441        ofw_prop_t depth;
     
    443443            sizeof(depth)) <= 0)
    444444                depth = 0;
    445        
     445
    446446        /* Get device path */
    447447        ofw_arg_t len = ofw_package_to_path(handle, path, OFW_TREE_PATH_MAX_LEN);
    448448        if (len == (ofw_arg_t) -1)
    449449                return;
    450        
     450
    451451        path[len] = '\0';
    452        
     452
    453453        /* Open the display to initialize it */
    454454        ihandle screen = ofw_open(path);
    455455        if (screen == (ihandle) -1)
    456456                return;
    457        
     457
    458458        if (depth == 8) {
    459459                /* Setup the palette so that the (inverted) 3:2:3 scheme is usable */
     
    470470        while ((current != 0) && (current != (phandle) -1)) {
    471471                ofw_setup_screen(current);
    472                
     472
    473473                /*
    474474                 * Recursively process the potential child node.
     
    477477                if ((child != 0) && (child != (phandle) -1))
    478478                        ofw_setup_screens_internal(child);
    479                
     479
    480480                /*
    481481                 * Iteratively process the next peer node.
     
    493493                        continue;
    494494                }
    495                
     495
    496496                /*
    497497                 * No more peers on this level.
  • boot/genarch/src/ofw_tree.c

    r3061bc1 ra35b458  
    6565        if (addr)
    6666                addr[size] = '\0';
    67        
     67
    6868        return addr;
    6969}
     
    9898                current_node->property = NULL;
    9999                current_node->device = NULL;
    100                
     100
    101101                /*
    102102                 * Get the disambigued name.
     
    105105                if (len == (size_t) -1)
    106106                        return;
    107                
     107
    108108                path[len] = '\0';
    109                
     109
    110110                /* Find last slash */
    111111                size_t i;
    112112                for (i = len; (i > 0) && (path[i - 1] != '/'); i--);
    113                
     113
    114114                /* Do not include the slash */
    115115                len -= i;
    116                
     116
    117117                /* Add space for trailing '\0' */
    118118                char *da_name = ofw_tree_space_alloc(len + 1);
    119119                if (!da_name)
    120120                        return;
    121                
     121
    122122                memcpy(da_name, &path[i], len);
    123123                da_name[len] = '\0';
    124124                current_node->da_name = (char *) balloc_rebase(da_name);
    125                
     125
    126126                /*
    127127                 * Recursively process the potential child node.
     
    137137                        }
    138138                }
    139                
     139
    140140                /*
    141141                 * Count properties.
     
    146146                        memcpy(name, name2, OFW_TREE_PROPERTY_MAX_NAMELEN);
    147147                }
    148                
     148
    149149                if (!current_node->properties)
    150150                        return;
    151                
     151
    152152                /*
    153153                 * Copy properties.
     
    157157                if (!property)
    158158                        return;
    159                
     159
    160160                name[0] = '\0';
    161161                for (i = 0; ofw_next_property(current, name, name2) == 1; i++) {
    162162                        if (i == current_node->properties)
    163163                                break;
    164                        
     164
    165165                        memcpy(name, name2, OFW_TREE_PROPERTY_MAX_NAMELEN);
    166166                        memcpy(property[i].name, name, OFW_TREE_PROPERTY_MAX_NAMELEN);
    167167                        property[i].name[OFW_TREE_PROPERTY_MAX_NAMELEN - 1] = '\0';
    168                        
     168
    169169                        size_t size = ofw_get_proplen(current, name);
    170170                        property[i].size = size;
    171                        
     171
    172172                        if (size) {
    173173                                void *buf = ofw_tree_space_alloc(size);
     
    182182                                property[i].value = NULL;
    183183                }
    184                
     184
    185185                /* Just in case we ran out of memory. */
    186186                current_node->properties = i;
    187187                current_node->property = (ofw_tree_property_t *) balloc_rebase(property);
    188                
     188
    189189                /*
    190190                 * Iteratively process the next peer node.
     
    207207                        }
    208208                }
    209                
     209
    210210                /*
    211211                 * No more peers on this level.
     
    225225        if (root)
    226226                ofw_tree_node_process(root, NULL, ofw_root);
    227        
     227
    228228        /*
    229229         * The firmware client interface does not automatically include the
     
    241241                }
    242242        }
    243        
     243
    244244        return (ofw_tree_node_t *) balloc_rebase(root);
    245245}
  • boot/generic/include/printf_core.h

    r3061bc1 ra35b458  
    4040        /* String output function, returns number of printed characters or EOF */
    4141        int (*str_write)(const char *, size_t, void *);
    42        
     42
    4343        /* User data - output stream specification, state, locks, etc. */
    4444        void *data;
  • boot/generic/src/balloc.c

    r3061bc1 ra35b458  
    4949        if (alignment == 0)
    5050                return NULL;
    51        
     51
    5252        /* Enforce minimal alignment. */
    5353        alignment = ALIGN_UP(alignment, 4);
    54        
     54
    5555        uintptr_t addr = phys_base + ALIGN_UP(ballocs->size, alignment);
    56        
     56
    5757        if (ALIGN_UP(ballocs->size, alignment) + size >= max_size)
    5858                return NULL;
    59        
     59
    6060        ballocs->size = ALIGN_UP(ballocs->size, alignment) + size;
    61        
     61
    6262        return (void *) addr;
    6363}
  • boot/generic/src/inflate.c

    r3061bc1 ra35b458  
    103103        size_t destlen;   /**< Output buffer size */
    104104        size_t destcnt;   /**< Position in the output buffer */
    105        
     105
    106106        uint8_t *src;     /**< Input buffer */
    107107        size_t srclen;    /**< Input buffer size */
    108108        size_t srccnt;    /**< Position in the input buffer */
    109        
     109
    110110        uint16_t bitbuf;  /**< Bit buffer */
    111111        size_t bitlen;    /**< Number of bits in the bit buffer */
    112        
     112
    113113        bool overrun;     /**< Overrun condition */
    114114} inflate_state_t;
     
    240240        /* Bit accumulator for at least 20 bits */
    241241        uint32_t val = state->bitbuf;
    242        
     242
    243243        while (state->bitlen < cnt) {
    244244                if (state->srccnt == state->srclen) {
     
    246246                        return 0;
    247247                }
    248                
     248
    249249                /* Load 8 more bits */
    250250                val |= ((uint32_t) state->src[state->srccnt]) << state->bitlen;
     
    252252                state->bitlen += 8;
    253253        }
    254        
     254
    255255        /* Update bits in the buffer */
    256256        state->bitbuf = (uint16_t) (val >> cnt);
    257257        state->bitlen -= cnt;
    258        
     258
    259259        return ((uint16_t) (val & ((1 << cnt) - 1)));
    260260}
     
    275275        state->bitbuf = 0;
    276276        state->bitlen = 0;
    277        
     277
    278278        if (state->srccnt + 4 > state->srclen)
    279279                return ELIMIT;
    280        
     280
    281281        uint16_t len =
    282282            state->src[state->srccnt] | (state->src[state->srccnt + 1] << 8);
    283283        uint16_t len_compl =
    284284            state->src[state->srccnt + 2] | (state->src[state->srccnt + 3] << 8);
    285        
     285
    286286        /* Check block length and its complement */
    287287        if (((int16_t) len) != ~((int16_t) len_compl))
    288288                return EINVAL;
    289        
     289
    290290        state->srccnt += 4;
    291        
     291
    292292        /* Check input buffer size */
    293293        if (state->srccnt + len > state->srclen)
    294294                return ELIMIT;
    295        
     295
    296296        /* Check output buffer size */
    297297        if (state->destcnt + len > state->destlen)
    298298                return ENOMEM;
    299        
     299
    300300        /* Copy data */
    301301        memcpy(state->dest + state->destcnt, state->src + state->srccnt, len);
    302302        state->srccnt += len;
    303303        state->destcnt += len;
    304        
     304
    305305        return EOK;
    306306}
     
    323323        size_t index = 0;  /* Index of the first code of the given length
    324324                              in the symbol table */
    325        
     325
    326326        size_t len;  /* Current number of bits in the code */
    327327        for (len = 1; len <= MAX_HUFFMAN_BIT; len++) {
     
    329329                code |= get_bits(state, 1);
    330330                CHECK_OVERRUN(*state);
    331                
     331
    332332                uint16_t count = huffman->count[len];
    333333                if (code < first + count) {
     
    336336                        return EOK;
    337337                }
    338                
     338
    339339                /* Update for next length */
    340340                index += count;
     
    343343                code <<= 1;
    344344        }
    345        
     345
    346346        return EINVAL;
    347347}
     
    364364        for (len = 0; len <= MAX_HUFFMAN_BIT; len++)
    365365                huffman->count[len] = 0;
    366        
     366
    367367        /* We assume that the lengths are within bounds */
    368368        size_t symbol;
    369369        for (symbol = 0; symbol < n; symbol++)
    370370                huffman->count[length[symbol]]++;
    371        
     371
    372372        if (huffman->count[0] == n) {
    373373                /* The code is complete, but decoding will fail */
    374374                return 0;
    375375        }
    376        
     376
    377377        /* Check for an over-subscribed or incomplete set of lengths */
    378378        int16_t left = 1;
     
    385385                }
    386386        }
    387        
     387
    388388        /* Generate offsets into symbol table */
    389389        uint16_t offs[MAX_HUFFMAN_BIT + 1];
    390        
     390
    391391        offs[1] = 0;
    392392        for (len = 1; len < MAX_HUFFMAN_BIT; len++)
    393393                offs[len + 1] = offs[len] + huffman->count[len];
    394        
     394
    395395        for (symbol = 0; symbol < n; symbol++) {
    396396                if (length[symbol] != 0) {
     
    399399                }
    400400        }
    401        
     401
    402402        return left;
    403403}
     
    422422{
    423423        uint16_t symbol;
    424        
     424
    425425        do {
    426426                int err = huffman_decode(state, len_code, &symbol);
     
    429429                        return err;
    430430                }
    431                
     431
    432432                if (symbol < 256) {
    433433                        /* Write out literal */
    434434                        if (state->destcnt == state->destlen)
    435435                                return ENOMEM;
    436                        
     436
    437437                        state->dest[state->destcnt] = (uint8_t) symbol;
    438438                        state->destcnt++;
     
    442442                        if (symbol >= 29)
    443443                                return EINVAL;
    444                        
     444
    445445                        size_t len = lens[symbol] + get_bits(state, lens_ext[symbol]);
    446446                        CHECK_OVERRUN(*state);
    447                        
     447
    448448                        /* Get distance */
    449449                        err = huffman_decode(state, dist_code, &symbol);
    450450                        if (err != EOK)
    451451                                return err;
    452                        
     452
    453453                        size_t dist = dists[symbol] + get_bits(state, dists_ext[symbol]);
    454454                        if (dist > state->destcnt)
    455455                                return ENOENT;
    456                        
     456
    457457                        if (state->destcnt + len > state->destlen)
    458458                                return ENOMEM;
    459                        
     459
    460460                        while (len > 0) {
    461461                                /* Copy len bytes from distance bytes back */
     
    467467                }
    468468        } while (symbol != 256);
    469        
     469
    470470        return EOK;
    471471}
     
    510510        huffman_t dyn_len_code;
    511511        huffman_t dyn_dist_code;
    512        
     512
    513513        dyn_len_code.count = dyn_len_count;
    514514        dyn_len_code.symbol = dyn_len_symbol;
    515        
     515
    516516        dyn_dist_code.count = dyn_dist_count;
    517517        dyn_dist_code.symbol = dyn_dist_symbol;
    518        
     518
    519519        /* Get number of bits in each table */
    520520        uint16_t nlen = get_bits(state, 5) + 257;
    521521        CHECK_OVERRUN(*state);
    522        
     522
    523523        uint16_t ndist = get_bits(state, 5) + 1;
    524524        CHECK_OVERRUN(*state);
    525        
     525
    526526        uint16_t ncode = get_bits(state, 4) + 4;
    527527        CHECK_OVERRUN(*state);
    528        
     528
    529529        if ((nlen > MAX_LITLEN) || (ndist > MAX_DIST)
    530530            || (ncode > MAX_ORDER))
    531531                return EINVAL;
    532        
     532
    533533        /* Read code length code lengths */
    534534        uint16_t index;
     
    537537                CHECK_OVERRUN(*state);
    538538        }
    539        
     539
    540540        /* Set missing lengths to zero */
    541541        for (index = ncode; index < MAX_ORDER; index++)
    542542                length[order[index]] = 0;
    543        
     543
    544544        /* Build Huffman code */
    545545        int16_t rc = huffman_construct(&dyn_len_code, length, MAX_ORDER);
    546546        if (rc != 0)
    547547                return EINVAL;
    548        
     548
    549549        /* Read length/literal and distance code length tables */
    550550        index = 0;
     
    554554                if (err != EOK)
    555555                        return EOK;
    556                
     556
    557557                if (symbol < 16) {
    558558                        length[index] = symbol;
     
    560560                } else {
    561561                        uint16_t len = 0;
    562                        
     562
    563563                        if (symbol == 16) {
    564564                                if (index == 0)
    565565                                        return EINVAL;
    566                                
     566
    567567                                len = length[index - 1];
    568568                                symbol = get_bits(state, 2) + 3;
     
    575575                                CHECK_OVERRUN(*state);
    576576                        }
    577                        
     577
    578578                        if (index + symbol > nlen + ndist)
    579579                                return EINVAL;
    580                        
     580
    581581                        while (symbol > 0) {
    582582                                length[index] = len;
     
    586586                }
    587587        }
    588        
     588
    589589        /* Check for end-of-block code */
    590590        if (length[256] == 0)
    591591                return EINVAL;
    592        
     592
    593593        /* Build Huffman tables for literal/length codes */
    594594        rc = huffman_construct(&dyn_len_code, length, nlen);
    595595        if ((rc < 0) || ((rc > 0) && (dyn_len_code.count[0] + 1 != nlen)))
    596596                return EINVAL;
    597        
     597
    598598        /* Build Huffman tables for distance codes */
    599599        rc = huffman_construct(&dyn_dist_code, length + nlen, ndist);
    600600        if ((rc < 0) || ((rc > 0) && (dyn_dist_code.count[0] + 1 != ndist)))
    601601                return EINVAL;
    602        
     602
    603603        return inflate_codes(state, &dyn_len_code, &dyn_dist_code);
    604604}
     
    622622        /* Initialize the state */
    623623        inflate_state_t state;
    624        
     624
    625625        state.dest = (uint8_t *) dest;
    626626        state.destlen = destlen;
    627627        state.destcnt = 0;
    628        
     628
    629629        state.src = (uint8_t *) src;
    630630        state.srclen = srclen;
    631631        state.srccnt = 0;
    632        
     632
    633633        state.bitbuf = 0;
    634634        state.bitlen = 0;
    635        
     635
    636636        state.overrun = false;
    637        
     637
    638638        uint16_t last;
    639639        int ret = 0;
    640        
     640
    641641        do {
    642642                /* Last block is indicated by a non-zero bit */
    643643                last = get_bits(&state, 1);
    644644                CHECK_OVERRUN(state);
    645                
     645
    646646                /* Block type */
    647647                uint16_t type = get_bits(&state, 2);
    648648                CHECK_OVERRUN(state);
    649                
     649
    650650                switch (type) {
    651651                case 0:
     
    662662                }
    663663        } while ((!last) && (ret == 0));
    664        
     664
    665665        return ret;
    666666}
  • boot/generic/src/memstr.c

    r3061bc1 ra35b458  
    4646        uint8_t *dp = (uint8_t *) dst;
    4747        const uint8_t *sp = (uint8_t *) src;
    48        
     48
    4949        while (cnt-- != 0)
    5050                *dp++ = *sp++;
    51        
     51
    5252        return dst;
    5353}
     
    6767{
    6868        uint8_t *dp = (uint8_t *) dst;
    69        
     69
    7070        while (cnt-- != 0)
    7171                *dp++ = val;
    72        
     72
    7373        return dst;
    7474}
     
    9191        if (src == dst)
    9292                return dst;
    93        
     93
    9494        /* Non-overlapping? */
    9595        if ((dst >= src + cnt) || (src >= dst + cnt))
    9696                return memcpy(dst, src, cnt);
    97        
     97
    9898        uint8_t *dp;
    9999        const uint8_t *sp;
    100        
     100
    101101        /* Which direction? */
    102102        if (src > dst) {
     
    104104                dp = dst;
    105105                sp = src;
    106                
     106
    107107                while (cnt-- != 0)
    108108                        *dp++ = *sp++;
     
    111111                dp = dst + (cnt - 1);
    112112                sp = src + (cnt - 1);
    113                
     113
    114114                while (cnt-- != 0)
    115115                        *dp-- = *sp--;
    116116        }
    117        
     117
    118118        return dst;
    119119}
  • boot/generic/src/printf.c

    r3061bc1 ra35b458  
    3737        int ret;
    3838        va_list args;
    39        
     39
    4040        va_start(args, fmt);
    41        
     41
    4242        ret = vprintf(fmt, args);
    43        
     43
    4444        va_end(args);
    45        
     45
    4646        return ret;
    4747}
  • boot/generic/src/printf_core.c

    r3061bc1 ra35b458  
    138138        if (str == NULL)
    139139                return printf_putnchars(nullstr, str_size(nullstr), ps);
    140        
     140
    141141        return ps->str_write((void *) str, str_size(str), ps->data);
    142142}
     
    154154        if (!ascii_check(ch))
    155155                return ps->str_write((void *) &invalch, 1, ps->data);
    156        
     156
    157157        return ps->str_write(&ch, 1, ps->data);
    158158}
     
    180180                }
    181181        }
    182        
     182
    183183        if (printf_putchar(ch, ps) > 0)
    184184                counter++;
    185        
     185
    186186        while (--width > 0) {
    187187                /*
     
    192192                        counter++;
    193193        }
    194        
     194
    195195        return (int) (counter);
    196196}
     
    210210        if (str == NULL)
    211211                return printf_putstr(nullstr, ps);
    212        
     212
    213213        /* Print leading spaces. */
    214214        size_t strw = str_length(str);
    215215        if ((precision == 0) || (precision > strw))
    216216                precision = strw;
    217        
     217
    218218        /* Left padding */
    219219        size_t counter = 0;
     
    225225                }
    226226        }
    227        
     227
    228228        /* Part of @a str fitting into the alloted space. */
    229229        int retval;
     
    231231        if ((retval = printf_putnchars(str, size, ps)) < 0)
    232232                return -counter;
    233        
     233
    234234        counter += retval;
    235        
     235
    236236        /* Right padding */
    237237        while (width-- > 0) {
     
    264264        else
    265265                digits = digits_small;
    266        
     266
    267267        char data[PRINT_NUMBER_BUFFER_SIZE];
    268268        char *ptr = &data[PRINT_NUMBER_BUFFER_SIZE - 1];
    269        
     269
    270270        /* Size of number with all prefixes and signs */
    271271        int size = 0;
    272        
     272
    273273        /* Put zero at end of string */
    274274        *ptr-- = 0;
    275        
     275
    276276        if (num == 0) {
    277277                *ptr-- = '0';
     
    283283                } while (num /= base);
    284284        }
    285        
     285
    286286        /* Size of plain number */
    287287        int number_size = size;
    288        
     288
    289289        /*
    290290         * Collect the sum of all prefixes/signs/etc. to calculate padding and
     
    305305                }
    306306        }
    307        
     307
    308308        char sgn = 0;
    309309        if (flags & __PRINTF_FLAG_SIGNED) {
     
    319319                }
    320320        }
    321        
     321
    322322        if (flags & __PRINTF_FLAG_LEFTALIGNED)
    323323                flags &= ~__PRINTF_FLAG_ZEROPADDED;
    324        
     324
    325325        /*
    326326         * If the number is left-aligned or precision is specified then
     
    331331                        precision = width - size + number_size;
    332332        }
    333        
     333
    334334        /* Print leading spaces */
    335335        if (number_size > precision) {
     
    337337                precision = number_size;
    338338        }
    339        
     339
    340340        width -= precision + size - number_size;
    341341        size_t counter = 0;
    342        
     342
    343343        if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) {
    344344                while (width-- > 0) {
     
    347347                }
    348348        }
    349        
     349
    350350        /* Print sign */
    351351        if (sgn) {
     
    353353                        counter++;
    354354        }
    355        
     355
    356356        /* Print prefix */
    357357        if (flags & __PRINTF_FLAG_PREFIX) {
     
    386386                }
    387387        }
    388        
     388
    389389        /* Print leading zeroes */
    390390        precision -= number_size;
     
    393393                        counter++;
    394394        }
    395        
     395
    396396        /* Print the number itself */
    397397        int retval;
    398398        if ((retval = printf_putstr(++ptr, ps)) > 0)
    399399                counter += retval;
    400        
     400
    401401        /* Print trailing spaces */
    402        
     402
    403403        while (width-- > 0) {
    404404                if (printf_putchar(' ', ps) == 1)
    405405                        counter++;
    406406        }
    407        
     407
    408408        return ((int) counter);
    409409}
     
    497497        size_t nxt = 0;  /* Index of the next character from fmt */
    498498        size_t j = 0;    /* Index to the first not printed nonformating character */
    499        
     499
    500500        size_t counter = 0;   /* Number of characters printed */
    501501        int retval;           /* Return values from nested functions */
    502        
     502
    503503        while (true) {
    504504                i = nxt;
    505505                wchar_t uc = str_decode(fmt, &nxt, STR_NO_LIMIT);
    506                
     506
    507507                if (uc == 0)
    508508                        break;
    509                
     509
    510510                /* Control character */
    511511                if (uc == '%') {
     
    519519                                counter += retval;
    520520                        }
    521                        
     521
    522522                        j = i;
    523                        
     523
    524524                        /* Parse modifiers */
    525525                        uint32_t flags = 0;
    526526                        bool end = false;
    527                        
     527
    528528                        do {
    529529                                i = nxt;
     
    549549                                };
    550550                        } while (!end);
    551                        
     551
    552552                        /* Width & '*' operator */
    553553                        int width = 0;
     
    556556                                        width *= 10;
    557557                                        width += uc - '0';
    558                                        
     558
    559559                                        i = nxt;
    560560                                        uc = str_decode(fmt, &nxt, STR_NO_LIMIT);
     
    575575                                }
    576576                        }
    577                        
     577
    578578                        /* Precision and '*' operator */
    579579                        int precision = 0;
     
    585585                                                precision *= 10;
    586586                                                precision += uc - '0';
    587                                                
     587
    588588                                                i = nxt;
    589589                                                uc = str_decode(fmt, &nxt, STR_NO_LIMIT);
     
    604604                                }
    605605                        }
    606                        
     606
    607607                        qualifier_t qualifier;
    608                        
     608
    609609                        switch (uc) {
    610610                        case 't':
     
    653653                                qualifier = PrintfQualifierInt;
    654654                        }
    655                        
     655
    656656                        unsigned int base = 10;
    657                        
     657
    658658                        switch (uc) {
    659659                        /*
     
    662662                        case 's':
    663663                                retval = print_str(va_arg(ap, char *), width, precision, flags, ps);
    664                                
     664
    665665                                if (retval < 0) {
    666666                                        counter = -counter;
    667667                                        goto out;
    668668                                }
    669                                
     669
    670670                                counter += retval;
    671671                                j = nxt;
     
    673673                        case 'c':
    674674                                retval = print_char(va_arg(ap, unsigned int), width, flags, ps);
    675                                
     675
    676676                                if (retval < 0) {
    677677                                        counter = -counter;
    678678                                        goto out;
    679679                                };
    680                                
     680
    681681                                counter += retval;
    682682                                j = nxt;
    683683                                goto next_char;
    684                        
     684
    685685                        /*
    686686                         * Integer values
     
    714714                                base = 16;
    715715                                break;
    716                        
     716
    717717                        /* Percentile itself */
    718718                        case '%':
    719719                                j = i;
    720720                                goto next_char;
    721                        
     721
    722722                        /*
    723723                         * Bad formatting.
     
    730730                                goto next_char;
    731731                        }
    732                        
     732
    733733                        /* Print integers */
    734734                        size_t size;
    735735                        uint64_t number;
    736                        
     736
    737737                        switch (qualifier) {
    738738                        case PrintfQualifierByte:
     
    774774                                goto out;
    775775                        }
    776                        
     776
    777777                        if ((retval = print_number(number, width, precision,
    778778                            base, flags, ps)) < 0) {
     
    780780                                goto out;
    781781                        }
    782                        
     782
    783783                        counter += retval;
    784784                        j = nxt;
     
    787787                ;
    788788        }
    789        
     789
    790790        if (i > j) {
    791791                if ((retval = printf_putnchars(&fmt[j], i - j, ps)) < 0) {
     
    796796                counter += retval;
    797797        }
    798        
     798
    799799out:
    800800        return ((int) counter);
  • boot/generic/src/str.c

    r3061bc1 ra35b458  
    141141        if (*offset + 1 > size)
    142142                return 0;
    143        
     143
    144144        /* First byte read from string */
    145145        uint8_t b0 = (uint8_t) str[(*offset)++];
    146        
     146
    147147        /* Determine code length */
    148        
     148
    149149        unsigned int b0_bits;  /* Data bits in first byte */
    150150        unsigned int cbytes;   /* Number of continuation bytes */
    151        
     151
    152152        if ((b0 & 0x80) == 0) {
    153153                /* 0xxxxxxx (Plain ASCII) */
     
    170170                return U_SPECIAL;
    171171        }
    172        
     172
    173173        if (*offset + cbytes > size)
    174174                return U_SPECIAL;
    175        
     175
    176176        wchar_t ch = b0 & LO_MASK_8(b0_bits);
    177        
     177
    178178        /* Decode continuation bytes */
    179179        while (cbytes > 0) {
    180180                uint8_t b = (uint8_t) str[(*offset)++];
    181                
     181
    182182                /* Must be 10xxxxxx */
    183183                if ((b & 0xc0) != 0x80)
    184184                        return U_SPECIAL;
    185                
     185
    186186                /* Shift data bits to ch */
    187187                ch = (ch << CONT_BITS) | (wchar_t) (b & LO_MASK_8(CONT_BITS));
    188188                cbytes--;
    189189        }
    190        
     190
    191191        return ch;
    192192}
     
    211211        if (*offset >= size)
    212212                return EOVERFLOW;
    213        
     213
    214214        if (!chr_check(ch))
    215215                return EINVAL;
    216        
     216
    217217        /* Unsigned version of ch (bit operations should only be done
    218218           on unsigned types). */
    219219        uint32_t cc = (uint32_t) ch;
    220        
     220
    221221        /* Determine how many continuation bytes are needed */
    222        
     222
    223223        unsigned int b0_bits;  /* Data bits in first byte */
    224224        unsigned int cbytes;   /* Number of continuation bytes */
    225        
     225
    226226        if ((cc & ~LO_MASK_32(7)) == 0) {
    227227                b0_bits = 7;
     
    240240                return EINVAL;
    241241        }
    242        
     242
    243243        /* Check for available space in buffer */
    244244        if (*offset + cbytes >= size)
    245245                return EOVERFLOW;
    246        
     246
    247247        /* Encode continuation bytes */
    248248        unsigned int i;
     
    251251                cc = cc >> CONT_BITS;
    252252        }
    253        
     253
    254254        /* Encode first byte */
    255255        str[*offset] = (cc & LO_MASK_32(b0_bits)) | HI_MASK_8(8 - b0_bits - 1);
    256        
     256
    257257        /* Advance offset */
    258258        *offset += cbytes + 1;
    259        
     259
    260260        return EOK;
    261261}
     
    274274{
    275275        size_t size = 0;
    276        
     276
    277277        while (*str++ != 0)
    278278                size++;
    279        
     279
    280280        return size;
    281281}
     
    298298        size_t len = 0;
    299299        size_t offset = 0;
    300        
     300
    301301        while (len < max_len) {
    302302                if (str_decode(str, &offset, STR_NO_LIMIT) == 0)
    303303                        break;
    304                
     304
    305305                len++;
    306306        }
    307        
     307
    308308        return offset;
    309309}
     
    320320        size_t len = 0;
    321321        size_t offset = 0;
    322        
     322
    323323        while (str_decode(str, &offset, STR_NO_LIMIT) != 0)
    324324                len++;
    325        
     325
    326326        return len;
    327327}
     
    336336        if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 127))
    337337                return true;
    338        
     338
    339339        return false;
    340340}
     
    349349        if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 1114111))
    350350                return true;
    351        
     351
    352352        return false;
    353353}
     
    375375        wchar_t c1 = 0;
    376376        wchar_t c2 = 0;
    377        
     377
    378378        size_t off1 = 0;
    379379        size_t off2 = 0;
    380        
     380
    381381        while (true) {
    382382                c1 = str_decode(s1, &off1, STR_NO_LIMIT);
    383383                c2 = str_decode(s2, &off2, STR_NO_LIMIT);
    384                
     384
    385385                if (c1 < c2)
    386386                        return -1;
    387                
     387
    388388                if (c1 > c2)
    389389                        return 1;
    390                
     390
    391391                if ((c1 == 0) || (c2 == 0))
    392392                        break;
    393393        }
    394        
     394
    395395        return 0;
    396396}
     
    412412        size_t src_off = 0;
    413413        size_t dest_off = 0;
    414        
     414
    415415        wchar_t ch;
    416416        while ((ch = str_decode(src, &src_off, STR_NO_LIMIT)) != 0) {
     
    418418                        break;
    419419        }
    420        
     420
    421421        dest[dest_off] = '\0';
    422422}
  • boot/generic/src/vprintf.c

    r3061bc1 ra35b458  
    4040        size_t offset = 0;
    4141        size_t chars = 0;
    42        
     42
    4343        while (offset < size) {
    4444                putchar(str_decode(str, &offset, size));
    4545                chars++;
    4646        }
    47        
     47
    4848        return chars;
    4949}
     
    5454        size_t chars = 0;
    5555        wchar_t uc;
    56        
     56
    5757        while ((uc = str_decode(str, &offset, STR_NO_LIMIT)) != 0) {
    5858                putchar(uc);
    5959                chars++;
    6060        }
    61        
     61
    6262        return chars;
    6363}
     
    6969                NULL
    7070        };
    71        
     71
    7272        int ret = printf_core(fmt, &ps, ap);
    73        
     73
    7474        return ret;
    7575}
Note: See TracChangeset for help on using the changeset viewer.