- Timestamp:
- 2018-03-02T20:10:49Z (8 years ago)
- 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)
- Location:
- boot
- Files:
-
- 34 edited
-
arch/arm32/src/asm.S (modified) (3 diffs)
-
arch/arm32/src/main.c (modified) (6 diffs)
-
arch/arm32/src/mm.c (modified) (3 diffs)
-
arch/ia64/src/main.c (modified) (14 diffs)
-
arch/ia64/src/pal.c (modified) (1 diff)
-
arch/ia64/src/pal_asm.S (modified) (3 diffs)
-
arch/ia64/src/sal.c (modified) (1 diff)
-
arch/ia64/src/sal_asm.S (modified) (3 diffs)
-
arch/ia64/src/ski.c (modified) (2 diffs)
-
arch/mips32/src/asm.S (modified) (3 diffs)
-
arch/mips32/src/boot.S (modified) (1 diff)
-
arch/mips32/src/main.c (modified) (7 diffs)
-
arch/ppc32/src/asm.S (modified) (7 diffs)
-
arch/ppc32/src/main.c (modified) (10 diffs)
-
arch/ppc32/src/ofw.c (modified) (1 diff)
-
arch/riscv64/src/asm.S (modified) (3 diffs)
-
arch/riscv64/src/main.c (modified) (6 diffs)
-
arch/riscv64/src/ucb.c (modified) (2 diffs)
-
arch/sparc64/src/asm.S (modified) (5 diffs)
-
arch/sparc64/src/main.c (modified) (13 diffs)
-
arch/sparc64/src/ofw.c (modified) (8 diffs)
-
genarch/include/genarch/ofw_tree.h (modified) (1 diff)
-
genarch/src/division.c (modified) (10 diffs)
-
genarch/src/multiplication.c (modified) (3 diffs)
-
genarch/src/ofw.c (modified) (30 diffs)
-
genarch/src/ofw_tree.c (modified) (10 diffs)
-
generic/include/printf_core.h (modified) (1 diff)
-
generic/src/balloc.c (modified) (1 diff)
-
generic/src/inflate.c (modified) (24 diffs)
-
generic/src/memstr.c (modified) (5 diffs)
-
generic/src/printf.c (modified) (1 diff)
-
generic/src/printf_core.c (modified) (33 diffs)
-
generic/src/str.c (modified) (13 diffs)
-
generic/src/vprintf.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
boot/arch/arm32/src/asm.S
r3061bc1 ra35b458 67 67 #ifndef PROCESSOR_ARCH_armv7_a 68 68 mrc p15, 0, r4, c1, c0, 0 69 69 70 70 # Disable D-cache before the kernel is started. 71 71 bic r4, r4, #(1 << CP15_C1_DC) … … 76 76 bic r4, r4, #(1 << CP15_C1_BP) 77 77 #endif 78 78 79 79 mcr p15, 0, r4, c1, c0, 0 80 80 #endif 81 81 82 82 # Wait for the operations to complete 83 83 #ifdef PROCESSOR_ARCH_armv7_a … … 88 88 mcr p15, 0, r4, c7, c10, 4 89 89 #endif 90 90 91 91 # Clean ICache and BPredictors, r4 ignored (SBZ) 92 92 mov r4, #0 -
boot/arch/arm32/src/main.c
r3061bc1 ra35b458 89 89 mmu_start(); 90 90 version_print(); 91 91 92 92 printf("Boot data: %p -> %p\n", &bdata_start, &bdata_end); 93 93 printf("\nMemory statistics\n"); … … 97 97 printf(" %p|%p: kernel entry point\n", 98 98 (void *) PA2KA(BOOT_OFFSET), (void *) BOOT_OFFSET); 99 99 100 100 for (size_t i = 0; i < COMPONENTS; i++) { 101 101 printf(" %p|%p: %s image (%u/%u bytes)\n", components[i].addr, … … 103 103 components[i].size); 104 104 } 105 105 106 106 void *dest[COMPONENTS]; 107 107 size_t top = 0; … … 110 110 for (size_t i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) { 111 111 top = ALIGN_UP(top, PAGE_SIZE); 112 112 113 113 if (i > 0) { 114 114 bootinfo.tasks[bootinfo.cnt].addr = TOP2ADDR(top); 115 115 bootinfo.tasks[bootinfo.cnt].size = components[i].inflated; 116 116 117 117 str_cpy(bootinfo.tasks[bootinfo.cnt].name, 118 118 BOOTINFO_TASK_NAME_BUFLEN, components[i].name); 119 119 120 120 bootinfo.cnt++; 121 121 } 122 122 123 123 dest[i] = TOP2ADDR(top); 124 124 top += components[i].inflated; 125 125 cnt++; 126 126 } 127 127 128 128 printf("\nInflating components ... "); 129 129 130 130 for (size_t i = cnt; i > 0; i--) { 131 131 void *tail = components[i - 1].addr + components[i - 1].size; … … 135 135 halt(); 136 136 } 137 137 138 138 printf("%s ", components[i - 1].name); 139 139 140 140 int err = inflate(components[i - 1].addr, components[i - 1].size, 141 141 dest[i - 1], components[i - 1].inflated); … … 147 147 clean_dcache_poc(dest[i - 1], components[i - 1].inflated); 148 148 } 149 149 150 150 printf(".\n"); 151 151 152 152 /* Flush PT too. We need this if we disable caches later */ 153 153 clean_dcache_poc(boot_pt, PTL0_ENTRIES * PTL0_ENTRY_SIZE); 154 154 155 155 printf("Booting the kernel...\n"); 156 156 jump_to_kernel((void *) PA2KA(BOOT_OFFSET), &bootinfo); -
boot/arch/arm32/src/mm.c
r3061bc1 ra35b458 209 209 /* Current settings */ 210 210 "mrc p15, 0, r0, c1, c0, 0\n" 211 211 212 212 /* Enable ICache, DCache, BPredictors and MMU, 213 213 * we disable caches before jumping to kernel … … 221 221 "ldr r1, =0x00001805\n" 222 222 #endif 223 223 224 224 "orr r0, r0, r1\n" 225 225 … … 228 228 */ 229 229 "mcr p15, 0, r0, c8, c7, 0\n" 230 230 231 231 /* Store settings, enable the MMU */ 232 232 "mcr p15, 0, r0, c1, c0, 0\n" -
boot/arch/ia64/src/main.c
r3061bc1 ra35b458 67 67 memmap_item_t *memmap = bootinfo.memmap; 68 68 size_t items = 0; 69 69 70 70 if (!bootpar) { 71 71 /* Fake-up a memory map for simulators. */ … … 83 83 size_t mm_size = bootpar->efi_memmap_sz; 84 84 size_t md_size = bootpar->efi_memdesc_sz; 85 85 86 86 /* 87 87 * Walk the EFI memory map using the V1 memory descriptor … … 109 109 continue; 110 110 } 111 111 112 112 memmap[items].base = md->phys_start; 113 113 memmap[items].size = md->pages * EFI_PAGE_SIZE; … … 115 115 } 116 116 } 117 117 118 118 bootinfo.memmap_items = items; 119 119 } … … 134 134 efi_guid_t sal_guid = SAL_SYSTEM_TABLE_GUID; 135 135 sal_system_table_header_t *sal_st; 136 136 137 137 sal_st = efi_vendor_table_find( 138 138 (efi_system_table_t *) bootpar->efi_system_table, sal_guid); 139 139 140 140 sal_system_table_parse(sal_st); 141 141 142 142 bootinfo.sys_freq = sal_base_clock_frequency(); 143 143 } else { … … 150 150 { 151 151 version_print(); 152 152 153 153 printf(" %p|%p: boot info structure\n", &bootinfo, &bootinfo); 154 154 printf(" %p|%p: kernel entry point\n", … … 156 156 printf(" %p|%p: loader entry point\n", 157 157 (void *) LOADER_ADDRESS, (void *) LOADER_ADDRESS); 158 158 159 159 size_t i; 160 160 for (i = 0; i < COMPONENTS; i++) … … 162 162 components[i].addr, components[i].name, 163 163 components[i].inflated, components[i].size); 164 164 165 165 void *dest[COMPONENTS]; 166 166 size_t top = KERNEL_ADDRESS; … … 169 169 for (i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) { 170 170 top = ALIGN_UP(top, PAGE_SIZE); 171 171 172 172 if (i > 0) { 173 173 bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].addr = … … 175 175 bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].size = 176 176 components[i].inflated; 177 177 178 178 str_cpy(bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].name, 179 179 BOOTINFO_TASK_NAME_BUFLEN, components[i].name); 180 180 181 181 bootinfo.taskmap.cnt++; 182 182 } 183 183 184 184 dest[i] = (void *) top; 185 185 top += components[i].inflated; 186 186 cnt++; 187 187 } 188 188 189 189 printf("\nInflating components ... "); 190 190 191 191 /* 192 192 * We will use the next available address for a copy of each component to … … 197 197 for (i = cnt; i > 0; i--) { 198 198 printf("%s ", components[i - 1].name); 199 199 200 200 /* 201 201 * Copy the component to a location which is guaranteed not to … … 203 203 */ 204 204 memmove((void *) top, components[i - 1].addr, components[i - 1].size); 205 205 206 206 int err = inflate((void *) top, components[i - 1].size, 207 207 dest[i - 1], components[i - 1].inflated); 208 208 209 209 if (err != EOK) { 210 210 printf("\n%s: Inflating error %d, halting.\n", … … 213 213 } 214 214 } 215 215 216 216 printf(".\n"); 217 217 … … 219 219 read_sal_configuration(); 220 220 read_pal_configuration(); 221 221 222 222 printf("Booting the kernel ...\n"); 223 223 jump_to_kernel(&bootinfo); -
boot/arch/ia64/src/pal.c
r3061bc1 ra35b458 35 35 { 36 36 uint64_t proc_ratio; 37 37 38 38 pal_static_call_0_1(PAL_FREQ_RATIOS, &proc_ratio); 39 39 40 40 return proc_ratio; 41 41 } -
boot/arch/ia64/src/pal_asm.S
r3061bc1 ra35b458 38 38 srlz.i 39 39 srlz.d 40 40 41 41 mov loc2 = gp 42 42 mov loc3 = rp 43 43 44 44 addl loc4 = @gprel(pal_proc), gp 45 45 … … 48 48 mov r30 = in2 49 49 mov r31 = in3 ;; 50 50 51 51 ld8 loc4 = [loc4] 52 52 movl loc5 = 0f ;; … … 64 64 cmp.ne p8,p0 = 0, in5 65 65 cmp.ne p9,p0 = 0, in6 ;; 66 66 67 67 (p7) st8 [in4] = r9 68 68 (p8) st8 [in5] = r10 69 69 (p9) st8 [in6] = r11 70 70 71 71 mov gp = loc2 72 72 mov rp = loc3 ;; 73 73 74 74 mov ar.pfs = loc0 75 75 br.ret.sptk.many rp -
boot/arch/ia64/src/sal.c
r3061bc1 ra35b458 75 75 { 76 76 uint64_t freq; 77 77 78 78 sal_call_1_1(SAL_FREQ_BASE, 0, &freq); 79 79 80 80 return freq; 81 81 } -
boot/arch/ia64/src/sal_asm.S
r3061bc1 ra35b458 45 45 FUNCTION_BEGIN(sal_call) 46 46 alloc loc0 = ar.pfs, 8, 8, 8, 0 47 47 48 48 adds sp = -STACK_SCRATCH_AREA, sp 49 49 50 50 mov loc1 = gp 51 51 mov loc2 = rp 52 52 53 53 addl loc3 = @gprel(sal_proc), gp 54 54 addl loc4 = @gprel(sal_proc_gp), gp 55 55 56 56 mov out0 = in0 57 57 mov out1 = in1 … … 62 62 mov out6 = in6 63 63 mov out7 = in7 ;; 64 64 65 65 ld8 loc3 = [loc3] 66 66 ld8 gp = [loc4] … … 73 73 ld8 loc6 = [r15] 74 74 ld8 loc7 = [r16] 75 75 76 76 mov b6 = loc3 ;; 77 77 br.call.sptk.many rp = b6 78 78 79 79 cmp.ne p7,p0 = 0, loc5 80 80 cmp.ne p8,p0 = 0, loc6 81 81 cmp.ne p9,p0 = 0, loc7 ;; 82 82 83 83 (p7) st8 [loc5] = r9 84 84 (p8) st8 [loc6] = r10 85 85 (p9) st8 [loc7] = r11 86 86 87 87 mov gp = loc1 88 88 mov rp = loc2 89 89 90 90 adds sp = STACK_SCRATCH_AREA, sp ;; 91 91 92 92 mov ar.pfs = loc0 93 93 br.ret.sptk.many rp -
boot/arch/ia64/src/ski.c
r3061bc1 ra35b458 37 37 { 38 38 static bool initialized = false; 39 39 40 40 if (initialized) 41 41 return; … … 48 48 : "r15", "r8" 49 49 ); 50 50 51 51 initialized = true; 52 52 } -
boot/arch/mips32/src/asm.S
r3061bc1 ra35b458 55 55 sw $a3, 0($a0) 56 56 #endif 57 57 58 58 /* 59 59 * Setup CPU map (on msim this code … … 62 62 */ 63 63 la $a0, PA2KA(CPUMAP_OFFSET) 64 64 65 65 sw $zero, 0($a0) 66 66 sw $zero, 4($a0) 67 67 sw $zero, 8($a0) 68 68 sw $zero, 12($a0) 69 69 70 70 sw $zero, 16($a0) 71 71 sw $zero, 20($a0) 72 72 sw $zero, 24($a0) 73 73 sw $zero, 28($a0) 74 74 75 75 sw $zero, 32($a0) 76 76 sw $zero, 36($a0) 77 77 sw $zero, 40($a0) 78 78 sw $zero, 44($a0) 79 79 80 80 sw $zero, 48($a0) 81 81 sw $zero, 52($a0) 82 82 sw $zero, 56($a0) 83 83 sw $zero, 60($a0) 84 84 85 85 sw $zero, 64($a0) 86 86 sw $zero, 68($a0) 87 87 sw $zero, 72($a0) 88 88 sw $zero, 76($a0) 89 89 90 90 sw $zero, 80($a0) 91 91 sw $zero, 84($a0) 92 92 sw $zero, 88($a0) 93 93 sw $zero, 92($a0) 94 94 95 95 sw $zero, 96($a0) 96 96 sw $zero, 100($a0) 97 97 sw $zero, 104($a0) 98 98 sw $zero, 108($a0) 99 99 100 100 sw $zero, 112($a0) 101 101 sw $zero, 116($a0) 102 102 sw $zero, 120($a0) 103 103 sw $zero, 124($a0) 104 104 105 105 lui $a1, 1 106 106 107 107 #ifdef MACHINE_msim 108 108 109 109 /* Read dorder value */ 110 110 la $k0, MSIM_DORDER_ADDRESS 111 111 lw $k1, ($k0) 112 112 113 113 /* 114 114 * If we are not running on BSP … … 117 117 beq $k1, $zero, bsp 118 118 nop 119 119 120 120 /* Record CPU presence */ 121 121 sll $a2, $k1, 2 122 122 addu $a2, $a2, $a0 123 123 sw $a1, ($a2) 124 124 125 125 loop: 126 126 j loop 127 127 nop 128 128 129 129 #endif 130 130 131 131 bsp: 132 132 /* Record CPU presence */ 133 133 sw $a1, ($a0) 134 134 135 135 /* Setup initial stack */ 136 136 la $sp, PA2KA(STACK_OFFSET) 137 137 138 138 j bootstrap 139 139 nop -
boot/arch/mips32/src/boot.S
r3061bc1 ra35b458 38 38 .global start 39 39 start: 40 40 41 41 /* Setup CPU map (on msim this code 42 42 is executed in parallel on all CPUs, 43 43 but it not an issue) */ 44 44 la $a0, CPUMAP 45 45 46 46 sw $zero, 0($a0) 47 47 sw $zero, 4($a0) 48 48 sw $zero, 8($a0) 49 49 sw $zero, 12($a0) 50 50 51 51 sw $zero, 16($a0) 52 52 sw $zero, 20($a0) 53 53 sw $zero, 24($a0) 54 54 sw $zero, 28($a0) 55 55 56 56 sw $zero, 32($a0) 57 57 sw $zero, 36($a0) 58 58 sw $zero, 40($a0) 59 59 sw $zero, 44($a0) 60 60 61 61 sw $zero, 48($a0) 62 62 sw $zero, 52($a0) 63 63 sw $zero, 56($a0) 64 64 sw $zero, 60($a0) 65 65 66 66 sw $zero, 64($a0) 67 67 sw $zero, 68($a0) 68 68 sw $zero, 72($a0) 69 69 sw $zero, 76($a0) 70 70 71 71 sw $zero, 80($a0) 72 72 sw $zero, 84($a0) 73 73 sw $zero, 88($a0) 74 74 sw $zero, 92($a0) 75 75 76 76 sw $zero, 96($a0) 77 77 sw $zero, 100($a0) 78 78 sw $zero, 104($a0) 79 79 sw $zero, 108($a0) 80 80 81 81 sw $zero, 112($a0) 82 82 sw $zero, 116($a0) 83 83 sw $zero, 120($a0) 84 84 sw $zero, 124($a0) 85 85 86 86 lui $a1, 1 87 87 88 88 #ifdef MACHINE_msim 89 89 90 90 /* Read dorder value */ 91 91 la $k0, MSIM_DORDER_ADDRESS 92 92 lw $k1, ($k0) 93 93 94 94 /* If we are not running on BSP 95 95 then end in an infinite loop */ 96 96 beq $k1, $zero, bsp 97 97 nop 98 98 99 99 /* Record CPU presence */ 100 100 sll $a2, $k1, 2 101 101 addu $a2, $a2, $a0 102 102 sw $a1, ($a2) 103 103 104 104 loop: 105 105 j loop 106 106 nop 107 107 108 108 #endif 109 109 110 110 bsp: 111 111 /* Record CPU presence */ 112 112 sw $a1, ($a0) 113 113 114 114 /* Setup initial stack */ 115 115 la $sp, INITIAL_STACK 116 116 117 117 j bootstrap 118 118 nop -
boot/arch/mips32/src/main.c
r3061bc1 ra35b458 49 49 { 50 50 version_print(); 51 51 52 52 printf("\nMemory statistics\n"); 53 53 printf(" %p|%p: CPU map\n", (void *) PA2KA(CPUMAP_OFFSET), … … 61 61 printf(" %p|%p: bootloader entry point\n", 62 62 (void *) PA2KA(LOADER_OFFSET), (void *) LOADER_OFFSET); 63 63 64 64 size_t i; 65 65 for (i = 0; i < COMPONENTS; i++) … … 70 70 components[i].name, components[i].inflated, 71 71 components[i].size); 72 72 73 73 void *dest[COMPONENTS]; 74 74 size_t top = 0; … … 77 77 for (i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) { 78 78 top = ALIGN_UP(top, PAGE_SIZE); 79 79 80 80 if (i > 0) { 81 81 bootinfo->tasks[bootinfo->cnt].addr = TOP2ADDR(top); 82 82 bootinfo->tasks[bootinfo->cnt].size = components[i].inflated; 83 83 84 84 str_cpy(bootinfo->tasks[bootinfo->cnt].name, 85 85 BOOTINFO_TASK_NAME_BUFLEN, components[i].name); 86 86 87 87 bootinfo->cnt++; 88 88 } 89 89 90 90 dest[i] = TOP2ADDR(top); 91 91 top += components[i].inflated; 92 92 cnt++; 93 93 } 94 94 95 95 printf("\nInflating components ... "); 96 96 97 97 for (i = cnt; i > 0; i--) { 98 98 #ifdef MACHINE_msim … … 104 104 } 105 105 #endif 106 106 107 107 printf("%s ", components[i - 1].name); 108 108 109 109 int err = inflate(components[i - 1].addr, components[i - 1].size, 110 110 dest[i - 1], components[i - 1].inflated); 111 111 112 112 if (err != EOK) { 113 113 printf("\n%s: Inflating error %d, halting.\n", … … 116 116 } 117 117 } 118 118 119 119 printf(".\n"); 120 120 121 121 printf("Copying CPU map ... \n"); 122 122 123 123 bootinfo->cpumap = 0; 124 124 for (i = 0; i < CPUMAP_MAX_RECORDS; i++) { … … 126 126 bootinfo->cpumap |= (1 << i); 127 127 } 128 128 129 129 printf("Booting the kernel ... \n"); 130 130 jump_to_kernel((void *) PA2KA(BOOT_OFFSET), bootinfo); -
boot/arch/ppc32/src/asm.S
r3061bc1 ra35b458 48 48 li \reg, 0 49 49 sync 50 50 51 51 .rept 64 52 52 tlbie \reg 53 53 addi \reg, \reg, 0x1000 54 54 .endr 55 55 56 56 eieio 57 57 tlbsync … … 61 61 .macro BAT_COMPUTE base size mask lower upper 62 62 # less than 128 KB -> no BAT 63 63 64 64 lis \upper, 0x0002 65 65 cmpw \size, \upper 66 66 blt no_bat 67 67 68 68 # mask = total >> 18 69 69 70 70 li \upper, 18 71 71 srw \mask, \size, \upper 72 72 73 73 # create Block Length mask by replicating 74 74 # the leading logical one 14 times 75 75 76 76 li \upper, 14 77 77 mtctr \mask 78 78 li \upper, 1 79 79 80 80 0: 81 81 # mask = (mask >> 1) | mask 82 82 83 83 srw \lower, \mask, \upper 84 84 or \mask, \mask, \lower 85 85 86 86 bdnz 0b 87 87 88 88 # mask = mask & 0x07ff 89 89 # (BAT can map up to 256 MB) 90 90 91 91 andi. \mask, \mask, 0x07ff 92 92 93 93 # mask = (mask << 2) | 0x0002 94 94 # (priviledged access only) 95 95 96 96 li \upper, 2 97 97 slw \mask, \mask, \upper 98 98 ori \mask, \mask, 0x0002 99 99 100 100 lis \upper, (0x8000 + \base) 101 101 or \upper, \upper, \mask 102 102 103 103 lis \lower, \base 104 104 ori \lower, \lower, 0x0002 … … 111 111 addi r4, r4, ofw_cif@l 112 112 stw r5, 0(r4) 113 113 114 114 bl ofw_init 115 115 b bootstrap … … 127 127 # r5 = pages to translate 128 128 # r6 = real mode meeting point (physical address) 129 129 130 130 # disable interrupts 131 131 132 132 mfmsr r31 133 133 rlwinm r31, r31, 0, 17, 15 134 134 mtmsr r31 135 135 136 136 # set real mode meeting point physical address 137 137 138 138 mtspr srr0, r6 139 139 140 140 # jump to real_mode 141 141 142 142 mfmsr r31 143 143 lis r30, ~0@h … … 145 145 and r31, r31, r30 146 146 mtspr srr1, r31 147 147 148 148 sync 149 149 isync … … 155 155 .align PAGE_WIDTH 156 156 SYMBOL(real_mode) 157 157 158 158 # arguments: 159 159 # r3 = bootinfo (physical address) 160 160 # r4 = translate table (physical address) 161 161 # r5 = pages to translate 162 162 163 163 # move the images of components to the proper 164 164 # location using the translate table 165 165 166 166 li r31, PAGE_SIZE >> 2 167 167 li r30, 0 168 168 169 169 page_copy: 170 170 171 171 cmpwi r5, 0 172 172 beq copy_end 173 173 174 174 mtctr r31 175 175 lwz r29, 0(r4) 176 176 177 177 copy_loop: 178 178 179 179 lwz r28, 0(r29) 180 180 stw r28, 0(r30) 181 181 182 182 SMC_COHERENCY r30 183 183 184 184 addi r29, r29, 4 185 185 addi r30, r30, 4 186 186 187 187 bdnz copy_loop 188 188 189 189 addi r4, r4, 4 190 190 subi r5, r5, 1 191 191 b page_copy 192 192 193 193 copy_end: 194 194 195 195 # initially fill segment registers 196 196 197 197 li r31, 0 198 198 199 199 li r29, 8 200 200 mtctr r29 201 201 li r30, 0 # ASID 0 (VSIDs 0 .. 7) 202 202 203 203 seg_fill_uspace: 204 204 205 205 mtsrin r30, r31 206 206 addi r30, r30, 1 207 207 addis r31, r31, 0x1000 # move to next SR 208 208 209 209 bdnz seg_fill_uspace 210 210 211 211 li r29, 8 212 212 mtctr r29 213 213 lis r30, 0x4000 # priviledged access only 214 214 ori r30, r30, 8 # ASID 0 (VSIDs 8 .. 15) 215 215 216 216 seg_fill_kernel: 217 217 218 218 mtsrin r30, r31 219 219 addi r30, r30, 1 220 220 addis r31, r31, 0x1000 # move to next SR 221 221 222 222 bdnz seg_fill_kernel 223 223 224 224 # invalidate block address translation registers 225 225 226 226 li r30, 0 227 227 228 228 mtspr ibat0u, r30 229 229 mtspr ibat0l, r30 230 230 231 231 mtspr ibat1u, r30 232 232 mtspr ibat1l, r30 233 233 234 234 mtspr ibat2u, r30 235 235 mtspr ibat2l, r30 236 236 237 237 mtspr ibat3u, r30 238 238 mtspr ibat3l, r30 239 239 240 240 mtspr dbat0u, r30 241 241 mtspr dbat0l, r30 242 242 243 243 mtspr dbat1u, r30 244 244 mtspr dbat1l, r30 245 245 246 246 mtspr dbat2u, r30 247 247 mtspr dbat2l, r30 248 248 249 249 mtspr dbat3u, r30 250 250 mtspr dbat3l, r30 251 251 252 252 # create empty Page Hash Table 253 253 # on top of memory, size 64 KB 254 254 255 255 lwz r31, 4(r3) # r31 = memory size 256 256 257 257 lis r30, 65536@h 258 258 ori r30, r30, 65536@l # r30 = 65536 259 259 260 260 subi r29, r30, 1 # r29 = 65535 261 261 262 262 sub r31, r31, r30 263 263 andc r31, r31, r29 # pht = ALIGN_DOWN(memory_size - 65536, 65536) 264 264 265 265 mtsdr1 r31 266 266 267 267 li r29, 2 268 268 srw r30, r30, r29 # r30 = 16384 269 269 li r29, 0 270 270 271 271 pht_clear: 272 272 273 273 # write zeroes 274 274 275 275 stw r29, 0(r31) 276 276 FLUSH_DCACHE r31 277 277 278 278 addi r31, r31, 4 279 279 subi r30, r30, 4 280 280 281 281 cmpwi r30, 0 282 282 beq clear_end 283 283 284 284 bdnz pht_clear 285 285 286 286 clear_end: 287 287 288 288 # create BAT identity mapping 289 289 290 290 lwz r31, 4(r3) # r31 = memory size 291 291 292 292 lis r30, 268435456@h 293 293 ori r30, r30, 268435456@l # r30 = 256 MB 294 294 295 295 # BAT0 296 296 297 297 # r29 = min(r31, r30) 298 298 299 299 cmpw r31, r30 300 300 blt bat0_r31 301 301 302 302 mr r29, r30 303 303 b bat0_r30 304 304 305 305 bat0_r31: 306 306 307 307 mr r29, r31 308 308 309 309 bat0_r30: 310 310 311 311 BAT_COMPUTE 0x0000 r29 r28 r27 r26 312 312 mtspr ibat0u, r26 313 313 mtspr ibat0l, r27 314 314 315 315 mtspr dbat0u, r26 316 316 mtspr dbat0l, r27 317 317 318 318 # BAT1 319 319 320 320 sub r31, r31, r29 # r31 = r31 - r29 321 321 322 322 # r29 = min(r31, r30) 323 323 324 324 cmpw r31, r30 325 325 blt bat1_r31 326 326 327 327 mr r29, r30 328 328 b bat1_r30 329 329 330 330 bat1_r31: 331 331 332 332 mr r29, r31 333 333 334 334 bat1_r30: 335 335 336 336 BAT_COMPUTE 0x1000 r29 r28 r27 r26 337 337 mtspr ibat1u, r26 338 338 mtspr ibat1l, r27 339 339 340 340 mtspr dbat1u, r26 341 341 mtspr dbat1l, r27 342 342 343 343 # BAT2 344 344 345 345 sub r31, r31, r29 # r31 = r31 - r29 346 346 347 347 # r29 = min(r31, r30) 348 348 349 349 cmpw r31, r30 350 350 blt bat2_r31 351 351 352 352 mr r29, r30 353 353 b bat2_r30 354 354 355 355 bat2_r31: 356 356 357 357 mr r29, r31 358 358 359 359 bat2_r30: 360 360 361 361 BAT_COMPUTE 0x2000 r29 r28 r27 r26 362 362 mtspr ibat2u, r26 363 363 mtspr ibat2l, r27 364 364 365 365 mtspr dbat2u, r26 366 366 mtspr dbat2l, r27 367 367 368 368 # BAT3 369 369 370 370 sub r31, r31, r29 # r31 = r31 - r29 371 371 372 372 # r29 = min(r31, r30) 373 373 374 374 cmpw r31, r30 375 375 blt bat3_r31 376 376 377 377 mr r29, r30 378 378 b bat3_r30 379 379 380 380 bat3_r31: 381 381 382 382 mr r29, r31 383 383 384 384 bat3_r30: 385 385 386 386 BAT_COMPUTE 0x3000 r29 r28 r27 r26 387 387 mtspr ibat3u, r26 388 388 mtspr ibat3l, r27 389 389 390 390 mtspr dbat3u, r26 391 391 mtspr dbat3l, r27 392 392 393 393 no_bat: 394 394 395 395 # flush TLB 396 396 397 397 TLB_FLUSH r31 398 398 399 399 # start the kernel 400 400 # … … 404 404 # sprg3 = physical memory size 405 405 # sp = 0 (enforces the usage of sprg0 as exception stack) 406 406 407 407 lis r31, PA2KA(BOOT_OFFSET)@ha 408 408 addi r31, r31, PA2KA(BOOT_OFFSET)@l 409 409 mtspr srr0, r31 410 410 411 411 lis r31, BOOT_OFFSET@ha 412 412 addi r31, r31, BOOT_OFFSET@l 413 413 mtsprg0 r31 414 414 415 415 # bootinfo starts with a 64 bit integer containing 416 416 # the physical memory size, get the lower 4 bytes 417 417 418 418 lwz r31, 4(r3) 419 419 mtsprg3 r31 420 420 421 421 li sp, 0 422 422 423 423 mfmsr r31 424 424 ori r31, r31, (msr_ir | msr_dr)@l 425 425 mtspr srr1, r31 426 426 427 427 sync 428 428 isync -
boot/arch/ppc32/src/main.c
r3061bc1 ra35b458 60 60 version_print(); 61 61 ofw_memmap(&bootinfo.memmap); 62 62 63 63 void *bootinfo_pa = ofw_translate(&bootinfo); 64 64 void *real_mode_pa = ofw_translate(&real_mode); 65 65 void *loader_address_pa = ofw_translate((void *) LOADER_ADDRESS); 66 66 67 67 printf("\nMemory statistics (total %llu MB)\n", bootinfo.memmap.total >> 20); 68 68 printf(" %p|%p: real mode trampoline\n", &real_mode, real_mode_pa); … … 72 72 printf(" %p|%p: loader entry point\n", 73 73 (void *) LOADER_ADDRESS, loader_address_pa); 74 74 75 75 size_t i; 76 76 for (i = 0; i < COMPONENTS; i++) … … 78 78 ofw_translate(components[i].addr), components[i].name, 79 79 components[i].inflated, components[i].size); 80 80 81 81 size_t dest[COMPONENTS]; 82 82 size_t top = 0; … … 85 85 for (i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) { 86 86 top = ALIGN_UP(top, PAGE_SIZE); 87 87 88 88 if (i > 0) { 89 89 bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].addr = … … 91 91 bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].size = 92 92 components[i].inflated; 93 93 94 94 str_cpy(bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].name, 95 95 BOOTINFO_TASK_NAME_BUFLEN, components[i].name); 96 96 97 97 bootinfo.taskmap.cnt++; 98 98 } 99 99 100 100 dest[i] = top; 101 101 top += components[i].inflated; 102 102 cnt++; 103 103 } 104 104 105 105 if (top >= (size_t) loader_address_pa) { 106 106 printf("Inflated components overlap loader area.\n"); … … 108 108 halt(); 109 109 } 110 110 111 111 void *balloc_base; 112 112 void *balloc_base_pa; … … 114 114 BALLOC_MAX_SIZE, loader_address_pa); 115 115 printf(" %p|%p: boot allocator area\n", balloc_base, balloc_base_pa); 116 116 117 117 void *inflate_base; 118 118 void *inflate_base_pa; … … 120 120 loader_address_pa); 121 121 printf(" %p|%p: inflate area\n", inflate_base, inflate_base_pa); 122 122 123 123 uintptr_t balloc_start = ALIGN_UP(top, PAGE_SIZE); 124 124 size_t pages = (balloc_start + ALIGN_UP(BALLOC_MAX_SIZE, PAGE_SIZE)) … … 129 129 pages * sizeof(void *), loader_address_pa); 130 130 printf(" %p|%p: translate table\n", transtable, transtable_pa); 131 131 132 132 check_overlap("boot allocator area", balloc_base_pa, pages); 133 133 check_overlap("inflate area", inflate_base_pa, pages); 134 134 check_overlap("translate table", transtable_pa, pages); 135 135 136 136 printf("\nInflating components ... "); 137 137 138 138 for (i = cnt; i > 0; i--) { 139 139 printf("%s ", components[i - 1].name); 140 140 141 141 int err = inflate(components[i - 1].addr, components[i - 1].size, 142 142 inflate_base + dest[i - 1], components[i - 1].inflated); 143 143 144 144 if (err != EOK) { 145 145 printf("\n%s: Inflating error %d, halting.\n", … … 148 148 } 149 149 } 150 150 151 151 printf(".\n"); 152 152 153 153 printf("Setting up boot allocator ...\n"); 154 154 balloc_init(&bootinfo.ballocs, balloc_base, PA2KA(balloc_start), 155 155 BALLOC_MAX_SIZE); 156 156 157 157 printf("Setting up screens ...\n"); 158 158 ofw_setup_screens(); 159 159 160 160 printf("Canonizing OpenFirmware device tree ...\n"); 161 161 bootinfo.ofw_root = ofw_tree_build(); 162 162 163 163 printf("Setting up translate table ...\n"); 164 164 for (i = 0; i < pages; i++) { 165 165 uintptr_t off = i << PAGE_WIDTH; 166 166 void *phys; 167 167 168 168 if (off < balloc_start) 169 169 phys = ofw_translate(inflate_base + off); 170 170 else 171 171 phys = ofw_translate(balloc_base + off - balloc_start); 172 172 173 173 ((void **) transtable)[i] = phys; 174 174 } 175 175 176 176 printf("Booting the kernel...\n"); 177 177 jump_to_kernel(bootinfo_pa, transtable_pa, pages, real_mode_pa); -
boot/arch/ppc32/src/ofw.c
r3061bc1 ra35b458 43 43 if (ch == '\n') 44 44 ofw_putchar('\r'); 45 45 46 46 if (ascii_check(ch)) 47 47 ofw_putchar(ch); -
boot/arch/riscv64/src/asm.S
r3061bc1 ra35b458 85 85 li x30, 0 86 86 li x31, 0 87 87 88 88 /* Set up stack, create stack frame */ 89 89 la sp, boot_stack + BOOT_STACK_SIZE 90 90 addi sp, sp, -16 91 91 92 92 j bootstrap 93 93 … … 97 97 /* Enable performance counters access in supervisor mode */ 98 98 csrsi mcounteren, MCOUNTEREN_CY_MASK | MCOUNTEREN_TM_MASK | MCOUNTEREN_IR_MASK 99 99 100 100 /* Setup SV48 paging for supervisor mode */ 101 101 la t0, ptl_0 102 102 srli t0, t0, 12 103 103 104 104 li t1, SATP_PFN_MASK 105 105 and t0, t0, t1 106 106 107 107 li t1, SATP_MODE_SV48 108 108 or t0, t0, t1 109 109 110 110 csrw sptbr, t0 111 111 112 112 /* Jump to supervisor mode */ 113 113 csrr t0, mstatus 114 114 115 115 li t1, ~MSTATUS_MPP_MASK 116 116 and t0, t0, t1 117 117 118 118 /* 119 119 * TODO: Enable running with Supervisor User Mode … … 122 122 li t1, MSTATUS_MPP_SUPERVISOR | MSTATUS_SUM_MASK 123 123 or t0, t0, t1 124 124 125 125 csrw mstatus, t0 126 126 127 127 li ra, PA2KA(BOOT_OFFSET) 128 128 csrw mepc, ra 129 129 130 130 mret 131 131 FUNCTION_END(jump_to_kernel) -
boot/arch/riscv64/src/main.c
r3061bc1 ra35b458 48 48 { 49 49 version_print(); 50 50 51 51 bootinfo.htif_frame = ((uintptr_t) &htif_page) >> PAGE_WIDTH; 52 52 bootinfo.pt_frame = ((uintptr_t) &pt_page) >> PAGE_WIDTH; 53 53 54 54 bootinfo.ucbinfo.tohost = 55 55 (volatile uint64_t *) PA2KA((uintptr_t) &tohost); 56 56 bootinfo.ucbinfo.fromhost = 57 57 (volatile uint64_t *) PA2KA((uintptr_t) &fromhost); 58 58 59 59 // FIXME TODO: read from device tree 60 60 bootinfo.physmem_start = PHYSMEM_START; … … 63 63 bootinfo.memmap.zones[0].start = (void *) PHYSMEM_START; 64 64 bootinfo.memmap.zones[0].size = PHYSMEM_SIZE; 65 65 66 66 printf("\nMemory statistics (total %lu MB, starting at %p)\n\n", 67 67 bootinfo.memmap.total >> 20, (void *) bootinfo.physmem_start); 68 68 printf(" %p: boot info structure\n", &bootinfo); 69 69 70 70 uintptr_t top = BOOT_OFFSET; 71 71 72 72 for (size_t i = 0; i < COMPONENTS; i++) { 73 73 printf(" %p: %s image (%zu/%zu bytes)\n", components[i].addr, 74 74 components[i].name, components[i].inflated, 75 75 components[i].size); 76 76 77 77 uintptr_t tail = (uintptr_t) components[i].addr + 78 78 components[i].size; … … 83 83 } 84 84 } 85 85 86 86 printf(" %p: inflate area\n", (void *) top); 87 87 88 88 void *kernel_entry = NULL; 89 89 void *dest[COMPONENTS]; 90 90 size_t cnt = 0; 91 91 bootinfo.taskmap.cnt = 0; 92 92 93 93 for (size_t i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) { 94 94 top = ALIGN_UP(top, PAGE_SIZE); 95 95 96 96 if (i > 0) { 97 97 bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].addr = … … 99 99 bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].size = 100 100 components[i].inflated; 101 101 102 102 str_cpy(bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].name, 103 103 BOOTINFO_TASK_NAME_BUFLEN, components[i].name); 104 104 105 105 bootinfo.taskmap.cnt++; 106 106 } else 107 107 kernel_entry = (void *) PA2KA(top); 108 108 109 109 dest[i] = (void *) top; 110 110 top += components[i].inflated; 111 111 cnt++; 112 112 } 113 113 114 114 printf(" %p: kernel entry point\n", kernel_entry); 115 115 116 116 if (top >= bootinfo.physmem_start + bootinfo.memmap.total) { 117 117 printf("Not enough physical memory available.\n"); … … 119 119 halt(); 120 120 } 121 121 122 122 printf("\nInflating components ... "); 123 123 124 124 for (size_t i = cnt; i > 0; i--) { 125 125 printf("%s ", components[i - 1].name); 126 126 127 127 int err = inflate(components[i - 1].addr, components[i - 1].size, 128 128 dest[i - 1], components[i - 1].inflated); 129 129 130 130 if (err != EOK) { 131 131 printf("\n%s: Inflating error %d, halting.\n", … … 134 134 } 135 135 } 136 136 137 137 printf(".\n"); 138 138 139 139 printf("Booting the kernel...\n"); 140 140 jump_to_kernel(PA2KA(&bootinfo)); -
boot/arch/riscv64/src/ucb.c
r3061bc1 ra35b458 39 39 if (!val) 40 40 return; 41 41 42 42 fromhost = 0; 43 43 } … … 48 48 (((uint64_t) cmd) << 48) | 49 49 (payload & UINT64_C(0xffffffffffff)); 50 50 51 51 while (tohost) 52 52 poll_fromhost(); 53 53 54 54 tohost = val; 55 55 } -
boot/arch/sparc64/src/asm.S
r3061bc1 ra35b458 65 65 1: 66 66 ! Disable interrupts and disable address masking. 67 67 68 68 wrpr %g0, PSTATE_PRIV_BIT, %pstate 69 69 70 70 wrpr %g0, NWINDOWS - 2, %cansave ! Set maximum saveable windows 71 71 wrpr %g0, 0, %canrestore ! Get rid of windows we will never need again 72 72 wrpr %g0, 0, %otherwin ! Make sure the window state is consistent 73 73 wrpr %g0, NWINDOWS - 1, %cleanwin ! Prevent needless clean_window traps for kernel 74 74 75 75 set initial_stack, %sp 76 76 add %sp, -STACK_BIAS, %sp 77 77 78 78 set ofw_cif, %l0 79 79 80 80 ! Initialize OpenFirmware 81 81 82 82 call ofw_init 83 83 stx %o4, [%l0] 84 84 85 85 ba %xcc, bootstrap 86 86 nop … … 105 105 * 3. Flush instruction pipeline. 106 106 */ 107 107 108 108 /* 109 109 * US3 processors have a write-invalidate cache, so explicitly … … 115 115 be %xcc, 1f 116 116 nop 117 117 118 118 0: 119 119 call icache_flush 120 120 nop 121 121 122 122 1: 123 123 membar #StoreStore 124 124 125 125 /* 126 126 * Flush the instruction pipeline. 127 127 */ 128 128 flush %i7 129 129 130 130 ! Jump to kernel 131 131 jmp %o3 … … 138 138 set ((ICACHE_SIZE - ICACHE_LINE_SIZE) | ICACHE_SET_BIT), %g1 139 139 stxa %g0, [%g1] ASI_ICACHE_TAG 140 140 141 141 0: 142 142 membar #Sync 143 143 subcc %g1, ICACHE_LINE_SIZE, %g1 144 144 bnz,pt %xcc, 0b 145 145 146 146 stxa %g0, [%g1] ASI_ICACHE_TAG 147 147 membar #Sync 148 148 retl 149 149 150 150 ! SF Erratum #51 151 151 152 152 nop 153 153 #else … … 161 161 set ofw_cif, %l0 162 162 ldx [%l0], %l0 163 163 164 164 rdpr %pstate, %l1 165 165 and %l1, ~PSTATE_AM_BIT, %l2 166 166 wrpr %l2, 0, %pstate 167 167 168 168 jmpl %l0, %o7 169 169 mov %i0, %o0 170 170 171 171 wrpr %l1, 0, %pstate 172 172 173 173 ret 174 174 restore %o0, 0, %o0 -
boot/arch/sparc64/src/main.c
r3061bc1 ra35b458 86 86 phandle root = ofw_find_device("/"); 87 87 char compatible[OFW_TREE_PROPERTY_MAX_VALUELEN]; 88 88 89 89 if (ofw_get_property(root, "compatible", compatible, 90 90 OFW_TREE_PROPERTY_MAX_VALUELEN) <= 0) { … … 93 93 return; 94 94 } 95 95 96 96 if (str_cmp(compatible, "sun4v") != 0) { 97 97 /* … … 122 122 : [ver] "=r" (ver) 123 123 ); 124 124 125 125 ver = (ver << 16) >> 48; 126 126 127 127 if ((ver >= FIRST_US3_CPU) && (ver <= LAST_US3_CPU)) { 128 128 subarch = SUBARCH_US3; 129 129 130 130 if (ver == US_IIIi_CODE) 131 131 mid_mask = (1 << 5) - 1; 132 132 else 133 133 mid_mask = (1 << 10) - 1; 134 134 135 135 } else if (ver < FIRST_US3_CPU) { 136 136 subarch = SUBARCH_US; … … 193 193 { 194 194 version_print(); 195 195 196 196 arch_detect(); 197 197 if (arch == ARCH_SUN4U) … … 199 199 else 200 200 subarch = SUBARCH_UNKNOWN; 201 201 202 202 bootinfo.physmem_start = ofw_get_physmem_start(); 203 203 ofw_memmap(&bootinfo.memmap); … … 205 205 if (arch == ARCH_SUN4V) 206 206 sun4v_fixups(); 207 207 208 208 void *bootinfo_pa = ofw_translate(&bootinfo); 209 209 void *kernel_address_pa = ofw_translate((void *) KERNEL_ADDRESS); 210 210 void *loader_address_pa = ofw_translate((void *) LOADER_ADDRESS); 211 211 212 212 printf("\nMemory statistics (total %" PRIu64 " MB, starting at %p)\n", 213 213 bootinfo.memmap.total >> 20, (void *) bootinfo.physmem_start); … … 217 217 printf(" %p|%p: loader entry point\n", 218 218 (void *) LOADER_ADDRESS, (void *) loader_address_pa); 219 219 220 220 size_t i; 221 221 for (i = 0; i < COMPONENTS; i++) … … 223 223 ofw_translate(components[i].addr), components[i].name, 224 224 components[i].inflated, components[i].size); 225 225 226 226 void *dest[COMPONENTS]; 227 227 size_t top = KERNEL_ADDRESS; … … 230 230 for (i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) { 231 231 top = ALIGN_UP(top, PAGE_SIZE); 232 232 233 233 if (i > 0) { 234 234 bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].addr = … … 236 236 bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].size = 237 237 components[i].inflated; 238 238 239 239 str_cpy(bootinfo.taskmap.tasks[bootinfo.taskmap.cnt].name, 240 240 BOOTINFO_TASK_NAME_BUFLEN, components[i].name); 241 241 242 242 bootinfo.taskmap.cnt++; 243 243 } 244 244 245 245 dest[i] = (void *) top; 246 246 top += components[i].inflated; 247 247 cnt++; 248 248 } 249 249 250 250 printf("\nInflating components ... "); 251 251 252 252 for (i = cnt; i > 0; i--) { 253 253 printf("%s ", components[i - 1].name); 254 254 255 255 /* 256 256 * At this point, we claim and map the physical memory that we … … 263 263 ofw_claim_phys(bootinfo.physmem_start + dest[i - 1], 264 264 ALIGN_UP(components[i - 1].inflated, PAGE_SIZE)); 265 265 266 266 ofw_map(bootinfo.physmem_start + dest[i - 1], dest[i - 1], 267 267 ALIGN_UP(components[i - 1].inflated, PAGE_SIZE), -1); 268 268 269 269 int err = inflate(components[i - 1].addr, components[i - 1].size, 270 270 dest[i - 1], components[i - 1].inflated); 271 271 272 272 if (err != EOK) { 273 273 printf("\n%s: Inflating error %d, halting.\n", … … 276 276 } 277 277 } 278 278 279 279 printf(".\n"); 280 280 281 281 /* 282 282 * Claim and map the physical memory for the boot allocator. … … 290 290 balloc_init(&bootinfo.ballocs, balloc_base, (uintptr_t) balloc_base, 291 291 BALLOC_MAX_SIZE); 292 292 293 293 printf("Setting up screens ...\n"); 294 294 ofw_setup_screens(); 295 295 296 296 printf("Canonizing OpenFirmware device tree ...\n"); 297 297 bootinfo.ofw_root = ofw_tree_build(); 298 298 299 299 if (arch == ARCH_SUN4U) 300 300 sun4u_smp(); 301 301 302 302 printf("Booting the kernel ...\n"); 303 303 jump_to_kernel(bootinfo.physmem_start | BSP_PROCESSOR, &bootinfo, subarch, -
boot/arch/sparc64/src/ofw.c
r3061bc1 ra35b458 47 47 if (ch == '\n') 48 48 ofw_putchar('\r'); 49 49 50 50 if (ascii_check(ch)) 51 51 ofw_putchar(ch); … … 72 72 { 73 73 size_t cpus; 74 74 75 75 for (cpus = 0; (child != 0) && (child != (phandle) -1); 76 76 child = ofw_get_peer_node(child), cpus++) { 77 77 char type_name[OFW_TREE_PROPERTY_MAX_VALUELEN]; 78 78 79 79 if (ofw_get_property(child, "device_type", type_name, 80 80 OFW_TREE_PROPERTY_MAX_VALUELEN) > 0) { 81 81 type_name[OFW_TREE_PROPERTY_MAX_VALUELEN - 1] = 0; 82 82 83 83 if (str_cmp(type_name, "cpu") == 0) { 84 84 uint32_t mid; 85 85 86 86 /* 87 87 * "upa-portid" for US, "portid" for US-III, … … 92 92 && (ofw_get_property(child, "cpuid", &mid, sizeof(mid)) <= 0)) 93 93 continue; 94 94 95 95 if (current_mid != mid) { 96 96 /* … … 104 104 } 105 105 } 106 106 107 107 return cpus; 108 108 } … … 115 115 /* Get the current CPU MID */ 116 116 uint64_t current_mid; 117 117 118 118 asm volatile ( 119 119 "ldxa [%[zero]] %[asi], %[current_mid]\n" … … 122 122 [asi] "i" (ASI_ICBUS_CONFIG) 123 123 ); 124 124 125 125 current_mid >>= ICBUS_CONFIG_MID_SHIFT; 126 126 current_mid &= mid_mask; 127 127 128 128 /* Wake up the CPUs */ 129 129 130 130 phandle cpus_parent = ofw_find_device("/ssm@0,0"); 131 131 if ((cpus_parent == 0) || (cpus_parent == (phandle) -1)) 132 132 cpus_parent = ofw_find_device("/"); 133 133 134 134 phandle node = ofw_get_child_node(cpus_parent); 135 135 size_t cpus = wake_cpus_in_node(node, current_mid, physmem_start); 136 136 137 137 while ((node != 0) && (node != (phandle) -1)) { 138 138 char name[OFW_TREE_PROPERTY_MAX_VALUELEN]; 139 139 140 140 if (ofw_get_property(node, "name", name, 141 141 OFW_TREE_PROPERTY_MAX_VALUELEN) > 0) { 142 142 name[OFW_TREE_PROPERTY_MAX_VALUELEN - 1] = 0; 143 143 144 144 if (str_cmp(name, "cmp") == 0) { 145 145 phandle subnode = ofw_get_child_node(node); … … 148 148 } 149 149 } 150 150 151 151 node = ofw_get_peer_node(node); 152 152 } 153 153 154 154 if (cpus == 0) 155 155 printf("Warning: Unable to get CPU properties.\n"); … … 169 169 halt(); 170 170 } 171 171 172 172 return ((((uintptr_t) memreg[0]) << 32) | memreg[1]); 173 173 } -
boot/genarch/include/genarch/ofw_tree.h
r3061bc1 ra35b458 45 45 struct ofw_tree_node *peer; 46 46 struct ofw_tree_node *child; 47 47 48 48 phandle node_handle; /**< Old OpenFirmware node handle. */ 49 49 50 50 char *da_name; /**< Disambigued name. */ 51 51 52 52 size_t properties; /**< Number of properties. */ 53 53 ofw_tree_property_t *property; 54 54 55 55 void *device; /**< Member used solely by the kernel. */ 56 56 } ofw_tree_node_t; -
boot/genarch/src/division.c
r3061bc1 ra35b458 40 40 unsigned int result; 41 41 int steps = sizeof(unsigned int) * 8; 42 42 43 43 *remainder = 0; 44 44 result = 0; 45 45 46 46 if (b == 0) { 47 47 /* FIXME: division by zero */ 48 48 return 0; 49 49 } 50 50 51 51 if (a < b) { 52 52 *remainder = a; 53 53 return 0; 54 54 } 55 55 56 56 for (; steps > 0; steps--) { 57 57 /* shift one bit to remainder */ 58 58 *remainder = ((*remainder) << 1) | (( a >> 31) & 0x1); 59 59 result <<= 1; 60 60 61 61 if (*remainder >= b) { 62 62 *remainder -= b; … … 65 65 a <<= 1; 66 66 } 67 67 68 68 return result; 69 69 } … … 74 74 unsigned long long result; 75 75 int steps = sizeof(unsigned long long) * 8; 76 76 77 77 *remainder = 0; 78 78 result = 0; 79 79 80 80 if (b == 0) { 81 81 /* FIXME: division by zero */ 82 82 return 0; 83 83 } 84 84 85 85 if (a < b) { 86 86 *remainder = a; 87 87 return 0; 88 88 } 89 89 90 90 for (; steps > 0; steps--) { 91 91 /* shift one bit to remainder */ 92 92 *remainder = ((*remainder) << 1) | ((a >> 63) & 0x1); 93 93 result <<= 1; 94 94 95 95 if (*remainder >= b) { 96 96 *remainder -= b; … … 99 99 a <<= 1; 100 100 } 101 101 102 102 return result; 103 103 } … … 108 108 unsigned int rem; 109 109 int result = (int) divandmod32(ABSVAL(a), ABSVAL(b), &rem); 110 110 111 111 if (SGN(a) == SGN(b)) 112 112 return result; 113 113 114 114 return -result; 115 115 } … … 120 120 unsigned long long rem; 121 121 long long result = (long long) divandmod64(ABSVAL(a), ABSVAL(b), &rem); 122 122 123 123 if (SGN(a) == SGN(b)) 124 124 return result; 125 125 126 126 return -result; 127 127 } … … 146 146 unsigned int rem; 147 147 divandmod32(a, b, &rem); 148 148 149 149 /* if divident is negative, remainder must be too */ 150 150 if (!(SGN(a))) 151 151 return -((int) rem); 152 152 153 153 return (int) rem; 154 154 } … … 159 159 unsigned long long rem; 160 160 divandmod64(a, b, &rem); 161 161 162 162 /* if divident is negative, remainder must be too */ 163 163 if (!(SGN(a))) 164 164 return -((long long) rem); 165 165 166 166 return (long long) rem; 167 167 } … … 187 187 unsigned int rem; 188 188 int result = (int) divandmod32(ABSVAL(a), ABSVAL(b), &rem); 189 189 190 190 if (SGN(a) == SGN(b)) { 191 191 *c = rem; 192 192 return result; 193 193 } 194 194 195 195 *c = -rem; 196 196 return -result; … … 207 207 unsigned long long rem; 208 208 long long result = (int) divandmod64(ABSVAL(a), ABSVAL(b), &rem); 209 209 210 210 if (SGN(a) == SGN(b)) { 211 211 *c = rem; 212 212 return result; 213 213 } 214 214 215 215 *c = -rem; 216 216 return -result; -
boot/genarch/src/multiplication.c
r3061bc1 ra35b458 50 50 unsigned int b1 = b >> 16; 51 51 unsigned int b2 = b & UINT16_MAX; 52 52 53 53 unsigned long long t1 = a1 * b1; 54 54 unsigned long long t2 = a1 * b2; 55 55 t2 += a2 * b1; 56 56 unsigned long long t3 = a2 * b2; 57 57 58 58 t3 = (((t1 << 16) + t2) << 16) + t3; 59 59 60 60 return t3; 61 61 } … … 67 67 { 68 68 char neg = 0; 69 69 70 70 if (a < 0) { 71 71 neg = !neg; 72 72 a = -a; 73 73 } 74 74 75 75 if (b < 0) { 76 76 neg = !neg; 77 77 b = -b; 78 78 } 79 79 80 80 unsigned long long a1 = a >> 32; 81 81 unsigned long long b1 = b >> 32; 82 82 83 83 unsigned long long a2 = a & (UINT32_MAX); 84 84 unsigned long long b2 = b & (UINT32_MAX); 85 85 86 86 if (SOFTINT_CHECK_OF && (a1 != 0) && (b1 != 0)) { 87 87 /* Error (overflow) */ 88 88 return (neg ? INT64_MIN : INT64_MAX); 89 89 } 90 90 91 91 /* (if OF checked) a1 or b1 is zero => result fits in 64 bits, 92 92 * no need to another overflow check 93 93 */ 94 94 unsigned long long t1 = mul(a1, b2) + mul(b1, a2); 95 95 96 96 if ((SOFTINT_CHECK_OF) && (t1 > UINT32_MAX)) { 97 97 /* Error (overflow) */ 98 98 return (neg ? INT64_MIN : INT64_MAX); 99 99 } 100 100 101 101 t1 = t1 << 32; 102 102 unsigned long long t2 = mul(a2, b2); 103 103 t2 += t1; 104 104 105 105 /* t2 & (1ull << 63) - if this bit is set in unsigned long long, 106 106 * result does not fit in signed one … … 110 110 return (neg ? INT64_MIN : INT64_MAX); 111 111 } 112 112 113 113 long long result = t2; 114 114 if (neg) 115 115 result = -result; 116 116 117 117 return result; 118 118 } -
boot/genarch/src/ofw.c
r3061bc1 ra35b458 62 62 if (ofw_chosen == (phandle) -1) 63 63 halt(); 64 64 65 65 if ((ofw_ret_t) ofw_get_property(ofw_chosen, "stdout", &ofw_stdout, 66 66 sizeof(ofw_stdout)) <= 0) 67 67 ofw_stdout = 0; 68 68 69 69 ofw_root = ofw_find_device("/"); 70 70 if (ofw_root == (phandle) -1) { … … 72 72 halt(); 73 73 } 74 74 75 75 if ((ofw_ret_t) ofw_get_property(ofw_chosen, "mmu", &ofw_mmu, 76 76 sizeof(ofw_mmu)) <= 0) { … … 83 83 halt(); 84 84 } 85 85 86 86 ofw_memory = ofw_find_device("/memory"); 87 87 if (ofw_memory == (phandle) -1) { … … 110 110 args.nargs = nargs; 111 111 args.nret = nret; 112 112 113 113 va_list list; 114 114 va_start(list, rets); 115 115 116 116 size_t i; 117 117 for (i = 0; i < nargs; i++) 118 118 args.args[i] = va_arg(list, ofw_arg_t); 119 119 120 120 va_end(list); 121 121 122 122 for (i = 0; i < nret; i++) 123 123 args.args[i + nargs] = 0; 124 124 125 125 (void) ofw(&args); 126 126 127 127 for (i = 1; i < nret; i++) 128 128 rets[i - 1] = args.args[i + nargs]; 129 129 130 130 return args.args[nargs]; 131 131 } … … 161 161 { 162 162 ofw_prop_t ret = 1; 163 163 164 164 if ((ofw_ret_t) ofw_get_property(device, "#address-cells", &ret, 165 165 sizeof(ret)) <= 0) … … 167 167 sizeof(ret)) <= 0) 168 168 ret = OFW_ADDRESS_CELLS; 169 169 170 170 return (size_t) ret; 171 171 } … … 174 174 { 175 175 ofw_prop_t ret = 1; 176 176 177 177 if ((ofw_ret_t) ofw_get_property(device, "#size-cells", &ret, 178 178 sizeof(ret)) <= 0) … … 180 180 sizeof(ret)) <= 0) 181 181 ret = OFW_SIZE_CELLS; 182 182 183 183 return (size_t) ret; 184 184 } … … 198 198 if (ofw_stdout == 0) 199 199 return; 200 200 201 201 ofw_call("write", 3, 1, NULL, ofw_stdout, &ch, 1); 202 202 } … … 210 210 halt(); 211 211 } 212 212 213 213 if (result[0] == false) { 214 214 printf("Error: Unable to translate virtual address %p, halting.\n", … … 216 216 halt(); 217 217 } 218 218 219 219 #ifdef __32_BITS__ 220 220 return (void *) result[2]; 221 221 #endif 222 222 223 223 #ifdef __64_BITS__ 224 224 return (void *) ((result[2] << 32) | result[3]); … … 235 235 halt(); 236 236 } 237 237 238 238 return (void *) addr; 239 239 } … … 252 252 { 253 253 void *addr = ofw_claim_virt_internal(NULL, len, alignment); 254 254 255 255 if (addr == NULL) { 256 256 printf("Error: Unable to claim %zu bytes in virtual memory, halting.\n", … … 258 258 halt(); 259 259 } 260 260 261 261 return addr; 262 262 } … … 276 276 * purposes. 277 277 */ 278 278 279 279 #ifdef __32_BITS__ 280 280 ofw_arg_t retaddr[1]; … … 284 284 halt(); 285 285 } 286 286 287 287 return (void *) retaddr[0]; 288 288 #endif 289 289 290 290 #ifdef __64_BITS__ 291 291 ofw_arg_t retaddr[2]; … … 296 296 halt(); 297 297 } 298 298 299 299 return (void *) ((retaddr[0] << 32) | retaddr[1]); 300 300 #endif … … 319 319 halt(); 320 320 } 321 321 322 322 return addr; 323 323 } … … 328 328 ofw_arg_t phys_hi; 329 329 ofw_arg_t phys_lo; 330 330 331 331 #ifdef __32_BITS__ 332 332 phys_hi = (ofw_arg_t) phys; 333 333 phys_lo = 0; 334 334 #endif 335 335 336 336 #ifdef __64_BITS__ 337 337 phys_hi = (ofw_arg_t) phys >> 32; 338 338 phys_lo = (ofw_arg_t) phys & 0xffffffff; 339 339 #endif 340 340 341 341 ofw_arg_t ret = ofw_call("call-method", 7, 1, NULL, "map", ofw_mmu, mode, 342 342 ALIGN_UP(size, PAGE_SIZE), virt, phys_hi, phys_lo); 343 343 344 344 if (ret != 0) { 345 345 printf("Error: Unable to map %p to %p (size %zu), halting.\n", … … 360 360 size_t sc = ofw_get_size_cells(ofw_memory) / 361 361 (sizeof(uintptr_t) / sizeof(uint32_t)); 362 362 363 363 uintptr_t buf[((ac + sc) * MEMMAP_MAX_RECORDS)]; 364 364 365 365 /* The number of bytes read */ 366 366 ofw_ret_t ret = (ofw_ret_t) ofw_get_property(ofw_memory, "reg", buf, … … 370 370 halt(); 371 371 } 372 372 373 373 size_t pos; 374 374 map->total = 0; … … 378 378 void *start = (void *) (buf[pos + ac - 1]); 379 379 uintptr_t size = buf[pos + ac + sc - 1]; 380 380 381 381 /* 382 382 * This is a hot fix of the issue which occurs on machines … … 389 389 map->zones[map->cnt - 1].size < start)) 390 390 break; 391 391 392 392 if (size > 0) { 393 393 map->zones[map->cnt].start = start; … … 397 397 } 398 398 } 399 399 400 400 if (map->total == 0) { 401 401 printf("Error: No physical memory detected, halting.\n"); … … 421 421 *base_pa = ofw_claim_phys_any(size, PAGE_SIZE); 422 422 } while (*base_pa <= min_pa); 423 423 424 424 *base = ofw_claim_virt_any(size, PAGE_SIZE); 425 425 ofw_map(*base_pa, *base, ALIGN_UP(size, PAGE_SIZE), (ofw_arg_t) -1); … … 433 433 OFW_TREE_PROPERTY_MAX_VALUELEN) <= 0) 434 434 return; 435 435 436 436 device_type[OFW_TREE_PROPERTY_MAX_VALUELEN - 1] = '\0'; 437 437 if (str_cmp(device_type, "display") != 0) 438 438 return; 439 439 440 440 /* Check for 8 bit depth */ 441 441 ofw_prop_t depth; … … 443 443 sizeof(depth)) <= 0) 444 444 depth = 0; 445 445 446 446 /* Get device path */ 447 447 ofw_arg_t len = ofw_package_to_path(handle, path, OFW_TREE_PATH_MAX_LEN); 448 448 if (len == (ofw_arg_t) -1) 449 449 return; 450 450 451 451 path[len] = '\0'; 452 452 453 453 /* Open the display to initialize it */ 454 454 ihandle screen = ofw_open(path); 455 455 if (screen == (ihandle) -1) 456 456 return; 457 457 458 458 if (depth == 8) { 459 459 /* Setup the palette so that the (inverted) 3:2:3 scheme is usable */ … … 470 470 while ((current != 0) && (current != (phandle) -1)) { 471 471 ofw_setup_screen(current); 472 472 473 473 /* 474 474 * Recursively process the potential child node. … … 477 477 if ((child != 0) && (child != (phandle) -1)) 478 478 ofw_setup_screens_internal(child); 479 479 480 480 /* 481 481 * Iteratively process the next peer node. … … 493 493 continue; 494 494 } 495 495 496 496 /* 497 497 * No more peers on this level. -
boot/genarch/src/ofw_tree.c
r3061bc1 ra35b458 65 65 if (addr) 66 66 addr[size] = '\0'; 67 67 68 68 return addr; 69 69 } … … 98 98 current_node->property = NULL; 99 99 current_node->device = NULL; 100 100 101 101 /* 102 102 * Get the disambigued name. … … 105 105 if (len == (size_t) -1) 106 106 return; 107 107 108 108 path[len] = '\0'; 109 109 110 110 /* Find last slash */ 111 111 size_t i; 112 112 for (i = len; (i > 0) && (path[i - 1] != '/'); i--); 113 113 114 114 /* Do not include the slash */ 115 115 len -= i; 116 116 117 117 /* Add space for trailing '\0' */ 118 118 char *da_name = ofw_tree_space_alloc(len + 1); 119 119 if (!da_name) 120 120 return; 121 121 122 122 memcpy(da_name, &path[i], len); 123 123 da_name[len] = '\0'; 124 124 current_node->da_name = (char *) balloc_rebase(da_name); 125 125 126 126 /* 127 127 * Recursively process the potential child node. … … 137 137 } 138 138 } 139 139 140 140 /* 141 141 * Count properties. … … 146 146 memcpy(name, name2, OFW_TREE_PROPERTY_MAX_NAMELEN); 147 147 } 148 148 149 149 if (!current_node->properties) 150 150 return; 151 151 152 152 /* 153 153 * Copy properties. … … 157 157 if (!property) 158 158 return; 159 159 160 160 name[0] = '\0'; 161 161 for (i = 0; ofw_next_property(current, name, name2) == 1; i++) { 162 162 if (i == current_node->properties) 163 163 break; 164 164 165 165 memcpy(name, name2, OFW_TREE_PROPERTY_MAX_NAMELEN); 166 166 memcpy(property[i].name, name, OFW_TREE_PROPERTY_MAX_NAMELEN); 167 167 property[i].name[OFW_TREE_PROPERTY_MAX_NAMELEN - 1] = '\0'; 168 168 169 169 size_t size = ofw_get_proplen(current, name); 170 170 property[i].size = size; 171 171 172 172 if (size) { 173 173 void *buf = ofw_tree_space_alloc(size); … … 182 182 property[i].value = NULL; 183 183 } 184 184 185 185 /* Just in case we ran out of memory. */ 186 186 current_node->properties = i; 187 187 current_node->property = (ofw_tree_property_t *) balloc_rebase(property); 188 188 189 189 /* 190 190 * Iteratively process the next peer node. … … 207 207 } 208 208 } 209 209 210 210 /* 211 211 * No more peers on this level. … … 225 225 if (root) 226 226 ofw_tree_node_process(root, NULL, ofw_root); 227 227 228 228 /* 229 229 * The firmware client interface does not automatically include the … … 241 241 } 242 242 } 243 243 244 244 return (ofw_tree_node_t *) balloc_rebase(root); 245 245 } -
boot/generic/include/printf_core.h
r3061bc1 ra35b458 40 40 /* String output function, returns number of printed characters or EOF */ 41 41 int (*str_write)(const char *, size_t, void *); 42 42 43 43 /* User data - output stream specification, state, locks, etc. */ 44 44 void *data; -
boot/generic/src/balloc.c
r3061bc1 ra35b458 49 49 if (alignment == 0) 50 50 return NULL; 51 51 52 52 /* Enforce minimal alignment. */ 53 53 alignment = ALIGN_UP(alignment, 4); 54 54 55 55 uintptr_t addr = phys_base + ALIGN_UP(ballocs->size, alignment); 56 56 57 57 if (ALIGN_UP(ballocs->size, alignment) + size >= max_size) 58 58 return NULL; 59 59 60 60 ballocs->size = ALIGN_UP(ballocs->size, alignment) + size; 61 61 62 62 return (void *) addr; 63 63 } -
boot/generic/src/inflate.c
r3061bc1 ra35b458 103 103 size_t destlen; /**< Output buffer size */ 104 104 size_t destcnt; /**< Position in the output buffer */ 105 105 106 106 uint8_t *src; /**< Input buffer */ 107 107 size_t srclen; /**< Input buffer size */ 108 108 size_t srccnt; /**< Position in the input buffer */ 109 109 110 110 uint16_t bitbuf; /**< Bit buffer */ 111 111 size_t bitlen; /**< Number of bits in the bit buffer */ 112 112 113 113 bool overrun; /**< Overrun condition */ 114 114 } inflate_state_t; … … 240 240 /* Bit accumulator for at least 20 bits */ 241 241 uint32_t val = state->bitbuf; 242 242 243 243 while (state->bitlen < cnt) { 244 244 if (state->srccnt == state->srclen) { … … 246 246 return 0; 247 247 } 248 248 249 249 /* Load 8 more bits */ 250 250 val |= ((uint32_t) state->src[state->srccnt]) << state->bitlen; … … 252 252 state->bitlen += 8; 253 253 } 254 254 255 255 /* Update bits in the buffer */ 256 256 state->bitbuf = (uint16_t) (val >> cnt); 257 257 state->bitlen -= cnt; 258 258 259 259 return ((uint16_t) (val & ((1 << cnt) - 1))); 260 260 } … … 275 275 state->bitbuf = 0; 276 276 state->bitlen = 0; 277 277 278 278 if (state->srccnt + 4 > state->srclen) 279 279 return ELIMIT; 280 280 281 281 uint16_t len = 282 282 state->src[state->srccnt] | (state->src[state->srccnt + 1] << 8); 283 283 uint16_t len_compl = 284 284 state->src[state->srccnt + 2] | (state->src[state->srccnt + 3] << 8); 285 285 286 286 /* Check block length and its complement */ 287 287 if (((int16_t) len) != ~((int16_t) len_compl)) 288 288 return EINVAL; 289 289 290 290 state->srccnt += 4; 291 291 292 292 /* Check input buffer size */ 293 293 if (state->srccnt + len > state->srclen) 294 294 return ELIMIT; 295 295 296 296 /* Check output buffer size */ 297 297 if (state->destcnt + len > state->destlen) 298 298 return ENOMEM; 299 299 300 300 /* Copy data */ 301 301 memcpy(state->dest + state->destcnt, state->src + state->srccnt, len); 302 302 state->srccnt += len; 303 303 state->destcnt += len; 304 304 305 305 return EOK; 306 306 } … … 323 323 size_t index = 0; /* Index of the first code of the given length 324 324 in the symbol table */ 325 325 326 326 size_t len; /* Current number of bits in the code */ 327 327 for (len = 1; len <= MAX_HUFFMAN_BIT; len++) { … … 329 329 code |= get_bits(state, 1); 330 330 CHECK_OVERRUN(*state); 331 331 332 332 uint16_t count = huffman->count[len]; 333 333 if (code < first + count) { … … 336 336 return EOK; 337 337 } 338 338 339 339 /* Update for next length */ 340 340 index += count; … … 343 343 code <<= 1; 344 344 } 345 345 346 346 return EINVAL; 347 347 } … … 364 364 for (len = 0; len <= MAX_HUFFMAN_BIT; len++) 365 365 huffman->count[len] = 0; 366 366 367 367 /* We assume that the lengths are within bounds */ 368 368 size_t symbol; 369 369 for (symbol = 0; symbol < n; symbol++) 370 370 huffman->count[length[symbol]]++; 371 371 372 372 if (huffman->count[0] == n) { 373 373 /* The code is complete, but decoding will fail */ 374 374 return 0; 375 375 } 376 376 377 377 /* Check for an over-subscribed or incomplete set of lengths */ 378 378 int16_t left = 1; … … 385 385 } 386 386 } 387 387 388 388 /* Generate offsets into symbol table */ 389 389 uint16_t offs[MAX_HUFFMAN_BIT + 1]; 390 390 391 391 offs[1] = 0; 392 392 for (len = 1; len < MAX_HUFFMAN_BIT; len++) 393 393 offs[len + 1] = offs[len] + huffman->count[len]; 394 394 395 395 for (symbol = 0; symbol < n; symbol++) { 396 396 if (length[symbol] != 0) { … … 399 399 } 400 400 } 401 401 402 402 return left; 403 403 } … … 422 422 { 423 423 uint16_t symbol; 424 424 425 425 do { 426 426 int err = huffman_decode(state, len_code, &symbol); … … 429 429 return err; 430 430 } 431 431 432 432 if (symbol < 256) { 433 433 /* Write out literal */ 434 434 if (state->destcnt == state->destlen) 435 435 return ENOMEM; 436 436 437 437 state->dest[state->destcnt] = (uint8_t) symbol; 438 438 state->destcnt++; … … 442 442 if (symbol >= 29) 443 443 return EINVAL; 444 444 445 445 size_t len = lens[symbol] + get_bits(state, lens_ext[symbol]); 446 446 CHECK_OVERRUN(*state); 447 447 448 448 /* Get distance */ 449 449 err = huffman_decode(state, dist_code, &symbol); 450 450 if (err != EOK) 451 451 return err; 452 452 453 453 size_t dist = dists[symbol] + get_bits(state, dists_ext[symbol]); 454 454 if (dist > state->destcnt) 455 455 return ENOENT; 456 456 457 457 if (state->destcnt + len > state->destlen) 458 458 return ENOMEM; 459 459 460 460 while (len > 0) { 461 461 /* Copy len bytes from distance bytes back */ … … 467 467 } 468 468 } while (symbol != 256); 469 469 470 470 return EOK; 471 471 } … … 510 510 huffman_t dyn_len_code; 511 511 huffman_t dyn_dist_code; 512 512 513 513 dyn_len_code.count = dyn_len_count; 514 514 dyn_len_code.symbol = dyn_len_symbol; 515 515 516 516 dyn_dist_code.count = dyn_dist_count; 517 517 dyn_dist_code.symbol = dyn_dist_symbol; 518 518 519 519 /* Get number of bits in each table */ 520 520 uint16_t nlen = get_bits(state, 5) + 257; 521 521 CHECK_OVERRUN(*state); 522 522 523 523 uint16_t ndist = get_bits(state, 5) + 1; 524 524 CHECK_OVERRUN(*state); 525 525 526 526 uint16_t ncode = get_bits(state, 4) + 4; 527 527 CHECK_OVERRUN(*state); 528 528 529 529 if ((nlen > MAX_LITLEN) || (ndist > MAX_DIST) 530 530 || (ncode > MAX_ORDER)) 531 531 return EINVAL; 532 532 533 533 /* Read code length code lengths */ 534 534 uint16_t index; … … 537 537 CHECK_OVERRUN(*state); 538 538 } 539 539 540 540 /* Set missing lengths to zero */ 541 541 for (index = ncode; index < MAX_ORDER; index++) 542 542 length[order[index]] = 0; 543 543 544 544 /* Build Huffman code */ 545 545 int16_t rc = huffman_construct(&dyn_len_code, length, MAX_ORDER); 546 546 if (rc != 0) 547 547 return EINVAL; 548 548 549 549 /* Read length/literal and distance code length tables */ 550 550 index = 0; … … 554 554 if (err != EOK) 555 555 return EOK; 556 556 557 557 if (symbol < 16) { 558 558 length[index] = symbol; … … 560 560 } else { 561 561 uint16_t len = 0; 562 562 563 563 if (symbol == 16) { 564 564 if (index == 0) 565 565 return EINVAL; 566 566 567 567 len = length[index - 1]; 568 568 symbol = get_bits(state, 2) + 3; … … 575 575 CHECK_OVERRUN(*state); 576 576 } 577 577 578 578 if (index + symbol > nlen + ndist) 579 579 return EINVAL; 580 580 581 581 while (symbol > 0) { 582 582 length[index] = len; … … 586 586 } 587 587 } 588 588 589 589 /* Check for end-of-block code */ 590 590 if (length[256] == 0) 591 591 return EINVAL; 592 592 593 593 /* Build Huffman tables for literal/length codes */ 594 594 rc = huffman_construct(&dyn_len_code, length, nlen); 595 595 if ((rc < 0) || ((rc > 0) && (dyn_len_code.count[0] + 1 != nlen))) 596 596 return EINVAL; 597 597 598 598 /* Build Huffman tables for distance codes */ 599 599 rc = huffman_construct(&dyn_dist_code, length + nlen, ndist); 600 600 if ((rc < 0) || ((rc > 0) && (dyn_dist_code.count[0] + 1 != ndist))) 601 601 return EINVAL; 602 602 603 603 return inflate_codes(state, &dyn_len_code, &dyn_dist_code); 604 604 } … … 622 622 /* Initialize the state */ 623 623 inflate_state_t state; 624 624 625 625 state.dest = (uint8_t *) dest; 626 626 state.destlen = destlen; 627 627 state.destcnt = 0; 628 628 629 629 state.src = (uint8_t *) src; 630 630 state.srclen = srclen; 631 631 state.srccnt = 0; 632 632 633 633 state.bitbuf = 0; 634 634 state.bitlen = 0; 635 635 636 636 state.overrun = false; 637 637 638 638 uint16_t last; 639 639 int ret = 0; 640 640 641 641 do { 642 642 /* Last block is indicated by a non-zero bit */ 643 643 last = get_bits(&state, 1); 644 644 CHECK_OVERRUN(state); 645 645 646 646 /* Block type */ 647 647 uint16_t type = get_bits(&state, 2); 648 648 CHECK_OVERRUN(state); 649 649 650 650 switch (type) { 651 651 case 0: … … 662 662 } 663 663 } while ((!last) && (ret == 0)); 664 664 665 665 return ret; 666 666 } -
boot/generic/src/memstr.c
r3061bc1 ra35b458 46 46 uint8_t *dp = (uint8_t *) dst; 47 47 const uint8_t *sp = (uint8_t *) src; 48 48 49 49 while (cnt-- != 0) 50 50 *dp++ = *sp++; 51 51 52 52 return dst; 53 53 } … … 67 67 { 68 68 uint8_t *dp = (uint8_t *) dst; 69 69 70 70 while (cnt-- != 0) 71 71 *dp++ = val; 72 72 73 73 return dst; 74 74 } … … 91 91 if (src == dst) 92 92 return dst; 93 93 94 94 /* Non-overlapping? */ 95 95 if ((dst >= src + cnt) || (src >= dst + cnt)) 96 96 return memcpy(dst, src, cnt); 97 97 98 98 uint8_t *dp; 99 99 const uint8_t *sp; 100 100 101 101 /* Which direction? */ 102 102 if (src > dst) { … … 104 104 dp = dst; 105 105 sp = src; 106 106 107 107 while (cnt-- != 0) 108 108 *dp++ = *sp++; … … 111 111 dp = dst + (cnt - 1); 112 112 sp = src + (cnt - 1); 113 113 114 114 while (cnt-- != 0) 115 115 *dp-- = *sp--; 116 116 } 117 117 118 118 return dst; 119 119 } -
boot/generic/src/printf.c
r3061bc1 ra35b458 37 37 int ret; 38 38 va_list args; 39 39 40 40 va_start(args, fmt); 41 41 42 42 ret = vprintf(fmt, args); 43 43 44 44 va_end(args); 45 45 46 46 return ret; 47 47 } -
boot/generic/src/printf_core.c
r3061bc1 ra35b458 138 138 if (str == NULL) 139 139 return printf_putnchars(nullstr, str_size(nullstr), ps); 140 140 141 141 return ps->str_write((void *) str, str_size(str), ps->data); 142 142 } … … 154 154 if (!ascii_check(ch)) 155 155 return ps->str_write((void *) &invalch, 1, ps->data); 156 156 157 157 return ps->str_write(&ch, 1, ps->data); 158 158 } … … 180 180 } 181 181 } 182 182 183 183 if (printf_putchar(ch, ps) > 0) 184 184 counter++; 185 185 186 186 while (--width > 0) { 187 187 /* … … 192 192 counter++; 193 193 } 194 194 195 195 return (int) (counter); 196 196 } … … 210 210 if (str == NULL) 211 211 return printf_putstr(nullstr, ps); 212 212 213 213 /* Print leading spaces. */ 214 214 size_t strw = str_length(str); 215 215 if ((precision == 0) || (precision > strw)) 216 216 precision = strw; 217 217 218 218 /* Left padding */ 219 219 size_t counter = 0; … … 225 225 } 226 226 } 227 227 228 228 /* Part of @a str fitting into the alloted space. */ 229 229 int retval; … … 231 231 if ((retval = printf_putnchars(str, size, ps)) < 0) 232 232 return -counter; 233 233 234 234 counter += retval; 235 235 236 236 /* Right padding */ 237 237 while (width-- > 0) { … … 264 264 else 265 265 digits = digits_small; 266 266 267 267 char data[PRINT_NUMBER_BUFFER_SIZE]; 268 268 char *ptr = &data[PRINT_NUMBER_BUFFER_SIZE - 1]; 269 269 270 270 /* Size of number with all prefixes and signs */ 271 271 int size = 0; 272 272 273 273 /* Put zero at end of string */ 274 274 *ptr-- = 0; 275 275 276 276 if (num == 0) { 277 277 *ptr-- = '0'; … … 283 283 } while (num /= base); 284 284 } 285 285 286 286 /* Size of plain number */ 287 287 int number_size = size; 288 288 289 289 /* 290 290 * Collect the sum of all prefixes/signs/etc. to calculate padding and … … 305 305 } 306 306 } 307 307 308 308 char sgn = 0; 309 309 if (flags & __PRINTF_FLAG_SIGNED) { … … 319 319 } 320 320 } 321 321 322 322 if (flags & __PRINTF_FLAG_LEFTALIGNED) 323 323 flags &= ~__PRINTF_FLAG_ZEROPADDED; 324 324 325 325 /* 326 326 * If the number is left-aligned or precision is specified then … … 331 331 precision = width - size + number_size; 332 332 } 333 333 334 334 /* Print leading spaces */ 335 335 if (number_size > precision) { … … 337 337 precision = number_size; 338 338 } 339 339 340 340 width -= precision + size - number_size; 341 341 size_t counter = 0; 342 342 343 343 if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) { 344 344 while (width-- > 0) { … … 347 347 } 348 348 } 349 349 350 350 /* Print sign */ 351 351 if (sgn) { … … 353 353 counter++; 354 354 } 355 355 356 356 /* Print prefix */ 357 357 if (flags & __PRINTF_FLAG_PREFIX) { … … 386 386 } 387 387 } 388 388 389 389 /* Print leading zeroes */ 390 390 precision -= number_size; … … 393 393 counter++; 394 394 } 395 395 396 396 /* Print the number itself */ 397 397 int retval; 398 398 if ((retval = printf_putstr(++ptr, ps)) > 0) 399 399 counter += retval; 400 400 401 401 /* Print trailing spaces */ 402 402 403 403 while (width-- > 0) { 404 404 if (printf_putchar(' ', ps) == 1) 405 405 counter++; 406 406 } 407 407 408 408 return ((int) counter); 409 409 } … … 497 497 size_t nxt = 0; /* Index of the next character from fmt */ 498 498 size_t j = 0; /* Index to the first not printed nonformating character */ 499 499 500 500 size_t counter = 0; /* Number of characters printed */ 501 501 int retval; /* Return values from nested functions */ 502 502 503 503 while (true) { 504 504 i = nxt; 505 505 wchar_t uc = str_decode(fmt, &nxt, STR_NO_LIMIT); 506 506 507 507 if (uc == 0) 508 508 break; 509 509 510 510 /* Control character */ 511 511 if (uc == '%') { … … 519 519 counter += retval; 520 520 } 521 521 522 522 j = i; 523 523 524 524 /* Parse modifiers */ 525 525 uint32_t flags = 0; 526 526 bool end = false; 527 527 528 528 do { 529 529 i = nxt; … … 549 549 }; 550 550 } while (!end); 551 551 552 552 /* Width & '*' operator */ 553 553 int width = 0; … … 556 556 width *= 10; 557 557 width += uc - '0'; 558 558 559 559 i = nxt; 560 560 uc = str_decode(fmt, &nxt, STR_NO_LIMIT); … … 575 575 } 576 576 } 577 577 578 578 /* Precision and '*' operator */ 579 579 int precision = 0; … … 585 585 precision *= 10; 586 586 precision += uc - '0'; 587 587 588 588 i = nxt; 589 589 uc = str_decode(fmt, &nxt, STR_NO_LIMIT); … … 604 604 } 605 605 } 606 606 607 607 qualifier_t qualifier; 608 608 609 609 switch (uc) { 610 610 case 't': … … 653 653 qualifier = PrintfQualifierInt; 654 654 } 655 655 656 656 unsigned int base = 10; 657 657 658 658 switch (uc) { 659 659 /* … … 662 662 case 's': 663 663 retval = print_str(va_arg(ap, char *), width, precision, flags, ps); 664 664 665 665 if (retval < 0) { 666 666 counter = -counter; 667 667 goto out; 668 668 } 669 669 670 670 counter += retval; 671 671 j = nxt; … … 673 673 case 'c': 674 674 retval = print_char(va_arg(ap, unsigned int), width, flags, ps); 675 675 676 676 if (retval < 0) { 677 677 counter = -counter; 678 678 goto out; 679 679 }; 680 680 681 681 counter += retval; 682 682 j = nxt; 683 683 goto next_char; 684 684 685 685 /* 686 686 * Integer values … … 714 714 base = 16; 715 715 break; 716 716 717 717 /* Percentile itself */ 718 718 case '%': 719 719 j = i; 720 720 goto next_char; 721 721 722 722 /* 723 723 * Bad formatting. … … 730 730 goto next_char; 731 731 } 732 732 733 733 /* Print integers */ 734 734 size_t size; 735 735 uint64_t number; 736 736 737 737 switch (qualifier) { 738 738 case PrintfQualifierByte: … … 774 774 goto out; 775 775 } 776 776 777 777 if ((retval = print_number(number, width, precision, 778 778 base, flags, ps)) < 0) { … … 780 780 goto out; 781 781 } 782 782 783 783 counter += retval; 784 784 j = nxt; … … 787 787 ; 788 788 } 789 789 790 790 if (i > j) { 791 791 if ((retval = printf_putnchars(&fmt[j], i - j, ps)) < 0) { … … 796 796 counter += retval; 797 797 } 798 798 799 799 out: 800 800 return ((int) counter); -
boot/generic/src/str.c
r3061bc1 ra35b458 141 141 if (*offset + 1 > size) 142 142 return 0; 143 143 144 144 /* First byte read from string */ 145 145 uint8_t b0 = (uint8_t) str[(*offset)++]; 146 146 147 147 /* Determine code length */ 148 148 149 149 unsigned int b0_bits; /* Data bits in first byte */ 150 150 unsigned int cbytes; /* Number of continuation bytes */ 151 151 152 152 if ((b0 & 0x80) == 0) { 153 153 /* 0xxxxxxx (Plain ASCII) */ … … 170 170 return U_SPECIAL; 171 171 } 172 172 173 173 if (*offset + cbytes > size) 174 174 return U_SPECIAL; 175 175 176 176 wchar_t ch = b0 & LO_MASK_8(b0_bits); 177 177 178 178 /* Decode continuation bytes */ 179 179 while (cbytes > 0) { 180 180 uint8_t b = (uint8_t) str[(*offset)++]; 181 181 182 182 /* Must be 10xxxxxx */ 183 183 if ((b & 0xc0) != 0x80) 184 184 return U_SPECIAL; 185 185 186 186 /* Shift data bits to ch */ 187 187 ch = (ch << CONT_BITS) | (wchar_t) (b & LO_MASK_8(CONT_BITS)); 188 188 cbytes--; 189 189 } 190 190 191 191 return ch; 192 192 } … … 211 211 if (*offset >= size) 212 212 return EOVERFLOW; 213 213 214 214 if (!chr_check(ch)) 215 215 return EINVAL; 216 216 217 217 /* Unsigned version of ch (bit operations should only be done 218 218 on unsigned types). */ 219 219 uint32_t cc = (uint32_t) ch; 220 220 221 221 /* Determine how many continuation bytes are needed */ 222 222 223 223 unsigned int b0_bits; /* Data bits in first byte */ 224 224 unsigned int cbytes; /* Number of continuation bytes */ 225 225 226 226 if ((cc & ~LO_MASK_32(7)) == 0) { 227 227 b0_bits = 7; … … 240 240 return EINVAL; 241 241 } 242 242 243 243 /* Check for available space in buffer */ 244 244 if (*offset + cbytes >= size) 245 245 return EOVERFLOW; 246 246 247 247 /* Encode continuation bytes */ 248 248 unsigned int i; … … 251 251 cc = cc >> CONT_BITS; 252 252 } 253 253 254 254 /* Encode first byte */ 255 255 str[*offset] = (cc & LO_MASK_32(b0_bits)) | HI_MASK_8(8 - b0_bits - 1); 256 256 257 257 /* Advance offset */ 258 258 *offset += cbytes + 1; 259 259 260 260 return EOK; 261 261 } … … 274 274 { 275 275 size_t size = 0; 276 276 277 277 while (*str++ != 0) 278 278 size++; 279 279 280 280 return size; 281 281 } … … 298 298 size_t len = 0; 299 299 size_t offset = 0; 300 300 301 301 while (len < max_len) { 302 302 if (str_decode(str, &offset, STR_NO_LIMIT) == 0) 303 303 break; 304 304 305 305 len++; 306 306 } 307 307 308 308 return offset; 309 309 } … … 320 320 size_t len = 0; 321 321 size_t offset = 0; 322 322 323 323 while (str_decode(str, &offset, STR_NO_LIMIT) != 0) 324 324 len++; 325 325 326 326 return len; 327 327 } … … 336 336 if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 127)) 337 337 return true; 338 338 339 339 return false; 340 340 } … … 349 349 if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 1114111)) 350 350 return true; 351 351 352 352 return false; 353 353 } … … 375 375 wchar_t c1 = 0; 376 376 wchar_t c2 = 0; 377 377 378 378 size_t off1 = 0; 379 379 size_t off2 = 0; 380 380 381 381 while (true) { 382 382 c1 = str_decode(s1, &off1, STR_NO_LIMIT); 383 383 c2 = str_decode(s2, &off2, STR_NO_LIMIT); 384 384 385 385 if (c1 < c2) 386 386 return -1; 387 387 388 388 if (c1 > c2) 389 389 return 1; 390 390 391 391 if ((c1 == 0) || (c2 == 0)) 392 392 break; 393 393 } 394 394 395 395 return 0; 396 396 } … … 412 412 size_t src_off = 0; 413 413 size_t dest_off = 0; 414 414 415 415 wchar_t ch; 416 416 while ((ch = str_decode(src, &src_off, STR_NO_LIMIT)) != 0) { … … 418 418 break; 419 419 } 420 420 421 421 dest[dest_off] = '\0'; 422 422 } -
boot/generic/src/vprintf.c
r3061bc1 ra35b458 40 40 size_t offset = 0; 41 41 size_t chars = 0; 42 42 43 43 while (offset < size) { 44 44 putchar(str_decode(str, &offset, size)); 45 45 chars++; 46 46 } 47 47 48 48 return chars; 49 49 } … … 54 54 size_t chars = 0; 55 55 wchar_t uc; 56 56 57 57 while ((uc = str_decode(str, &offset, STR_NO_LIMIT)) != 0) { 58 58 putchar(uc); 59 59 chars++; 60 60 } 61 61 62 62 return chars; 63 63 } … … 69 69 NULL 70 70 }; 71 71 72 72 int ret = printf_core(fmt, &ps, ap); 73 73 74 74 return ret; 75 75 }
Note:
See TracChangeset
for help on using the changeset viewer.
