Changeset a35b458 in mainline for boot/genarch/src
- Timestamp:
- 2018-03-02T20:10:49Z (7 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/genarch/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.