2019-05-31 08:19:02 +03:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdarg.h>
|
2020-11-05 02:50:01 +03:00
|
|
|
#include <lib/libc.h>
|
2020-01-22 07:02:12 +03:00
|
|
|
#include <lib/blib.h>
|
2020-05-10 01:38:27 +03:00
|
|
|
#include <lib/print.h>
|
2020-11-15 19:56:10 +03:00
|
|
|
#include <lib/trace.h>
|
2020-12-19 15:52:29 +03:00
|
|
|
#include <lib/real.h>
|
2020-10-01 03:12:13 +03:00
|
|
|
|
2021-02-25 10:45:03 +03:00
|
|
|
uint64_t build_id = BUILD_ID;
|
|
|
|
stage3_data uint64_t stage3_build_id = BUILD_ID;
|
|
|
|
|
2020-10-17 07:23:11 +03:00
|
|
|
uint8_t boot_drive;
|
2020-12-09 15:02:05 +03:00
|
|
|
int boot_partition = -1;
|
2020-10-17 07:23:11 +03:00
|
|
|
|
2020-12-29 03:01:38 +03:00
|
|
|
bool booted_from_pxe = false;
|
2021-02-21 05:45:24 +03:00
|
|
|
bool booted_from_cd = false;
|
2021-02-22 08:14:27 +03:00
|
|
|
bool stage3_loaded = false;
|
2020-12-29 03:01:38 +03:00
|
|
|
|
2020-11-09 14:31:47 +03:00
|
|
|
bool parse_resolution(int *width, int *height, int *bpp, const char *buf) {
|
|
|
|
int res[3] = {0};
|
|
|
|
|
|
|
|
const char *first = buf;
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
const char *last;
|
|
|
|
int x = strtoui(first, &last, 10);
|
|
|
|
if (first == last)
|
|
|
|
break;
|
|
|
|
res[i] = x;
|
|
|
|
if (*last == 0)
|
|
|
|
break;
|
|
|
|
first = last + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (res[0] == 0 || res[1] == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (res[2] == 0)
|
|
|
|
res[2] = 32;
|
|
|
|
|
|
|
|
*width = res[0], *height = res[1], *bpp = res[2];
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-09-30 18:29:07 +03:00
|
|
|
// This integer sqrt implementation has been adapted from:
|
|
|
|
// https://stackoverflow.com/questions/1100090/looking-for-an-efficient-integer-square-root-algorithm-for-arm-thumb2
|
|
|
|
uint64_t sqrt(uint64_t a_nInput) {
|
|
|
|
uint64_t op = a_nInput;
|
|
|
|
uint64_t res = 0;
|
|
|
|
uint64_t one = (uint64_t)1 << 62;
|
|
|
|
|
|
|
|
// "one" starts at the highest power of four <= than the argument.
|
|
|
|
while (one > op) {
|
|
|
|
one >>= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (one != 0) {
|
|
|
|
if (op >= res + one) {
|
|
|
|
op = op - (res + one);
|
|
|
|
res = res + 2 * one;
|
|
|
|
}
|
|
|
|
res >>= 1;
|
|
|
|
one >>= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2020-04-30 22:19:12 +03:00
|
|
|
uint8_t bcd_to_int(uint8_t val) {
|
|
|
|
return (val & 0x0f) + ((val & 0xf0) >> 4) * 10;
|
|
|
|
}
|
|
|
|
|
2020-05-10 01:48:58 +03:00
|
|
|
__attribute__((noreturn)) void panic(const char *fmt, ...) {
|
2020-09-16 18:22:05 +03:00
|
|
|
asm volatile ("cli" ::: "memory");
|
2020-05-10 01:48:58 +03:00
|
|
|
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
|
2020-08-27 01:44:16 +03:00
|
|
|
print("\033[31mPANIC\033[37;1m\033[40m: ");
|
2020-05-10 01:48:58 +03:00
|
|
|
vprint(fmt, args);
|
|
|
|
|
|
|
|
va_end(args);
|
|
|
|
|
2020-11-15 19:56:10 +03:00
|
|
|
print("\n");
|
|
|
|
print_stacktrace(NULL);
|
|
|
|
|
2020-12-19 15:52:29 +03:00
|
|
|
rm_hcf();
|
2020-04-13 09:21:25 +03:00
|
|
|
}
|
|
|
|
|
2020-11-02 11:20:34 +03:00
|
|
|
int digit_to_int(char c) {
|
2020-11-09 14:31:47 +03:00
|
|
|
if (c >= 'a' && c <= 'f') {
|
2020-09-24 22:48:49 +03:00
|
|
|
return (c - 'a') + 10;
|
|
|
|
}
|
2020-11-09 14:31:47 +03:00
|
|
|
if (c >= 'A' && c <= 'F') {
|
2020-09-24 22:48:49 +03:00
|
|
|
return (c - 'A') + 10;
|
|
|
|
}
|
|
|
|
if (c >= '0' && c <= '9'){
|
|
|
|
return c - '0';
|
|
|
|
}
|
|
|
|
|
2020-10-17 12:08:02 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-11-05 14:50:42 +03:00
|
|
|
uint64_t strtoui(const char *s, const char **end, int base) {
|
2020-01-22 09:13:19 +03:00
|
|
|
uint64_t n = 0;
|
2020-11-05 14:50:42 +03:00
|
|
|
for (size_t i = 0; ; i++) {
|
2020-11-05 03:17:56 +03:00
|
|
|
int d = digit_to_int(s[i]);
|
2020-11-05 14:50:42 +03:00
|
|
|
if (d == -1) {
|
|
|
|
if (end != NULL)
|
|
|
|
*end = &s[i];
|
2020-11-05 03:17:56 +03:00
|
|
|
break;
|
2020-11-05 14:50:42 +03:00
|
|
|
}
|
2020-11-05 03:17:56 +03:00
|
|
|
n = n * base + d;
|
|
|
|
}
|
2020-01-22 09:13:19 +03:00
|
|
|
return n;
|
|
|
|
}
|