char *itoa(char *s, int n);
char *itou(char *s, unsigned int n);
-char *itox(char *s, unsigned int n);
+char *itox(char *s, unsigned int n, int upper);
char *i64tou(char *s, int64_t n);
+char *i64tox(char *s, uint64_t n, int upper);
enum { ALIGN_RIGHT, ALIGN_LEFT };
i64tou(tmp, *((int64_t *)args));
p += write_buf(p, tmp, char_fill, char_cnt, align);
args += 4;
+ } else if (*fmt == 'x' || *fmt == 'X') {
+ // i64tox(tmp, *((uint64_t *)args), *fmt == 'X' ? 1 : 0);
+ i64tox(tmp, *((uint64_t *)args), 1); // x X都强制为大写
+ p += write_buf(p, tmp, char_fill, char_cnt, align);
+ args += 4;
}
break;
case 's':
p += write_buf(p, tmp, char_fill, char_cnt, align);
break;
case 'x':
- itox(tmp, *((unsigned int *)args));
+ case 'X':
+ // itox(tmp, *((unsigned int *)args), *fmt == 'X' ? 1 : 0);
+ itox(tmp, *((unsigned int *)args), 1); // x X都强制为大写
p += write_buf(p, tmp, char_fill, char_cnt, align);
break;
default:
}
}
-char *itox(char *s, unsigned int n) {
+char *itox(char *s, unsigned int n, int upper) {
char *p = s;
char ch;
int i;
ch += '0';
} else {
ch -= 10;
- ch += 'A';
+ ch += upper == 1 ? 'A' : 'a';
+ }
+
+ if (ch != '0') flag = true;
+
+ if (flag || ch != '0') *p++ = ch;
+ }
+
+ if (s == p) *p++ = '0';
+
+ *p = 0;
+
+ return s;
+}
+
+char *i64tox(char *s, uint64_t n, int upper) {
+ char *p = s;
+ char ch;
+ int i;
+ bool flag = false;
+
+ for (i = 60; i >= 0; i -= 4) {
+ ch = (n >> i) & 0x0F;
+
+ if (ch >= 0 && ch <= 9) {
+ ch += '0';
+ } else {
+ ch -= 10;
+ ch += upper == 1 ? 'A' : 'a';
}
if (ch != '0') flag = true;
for (i = 0; i < boot_params.e820map.map_cnt; ++i) {
struct e820_entry *p = boot_params.e820map.map + i;
- printk(" [%02d] 0x%08x - 0x%08x size %- 10d %8dKB %5dMB ", i, p->addr, p->addr + p->size - 1, p->size,
- p->size >> 10, p->size >> 20);
+ printk(" [%02d] 0x%010lX - 0x%010lX size %- 10u %8dKB %5dMB ", i, p->addr, (p->addr + p->size - 1),
+ (uint32_t)p->size, (uint32_t)(p->size >> 10), (uint32_t)(p->size >> 20));
e820_print_type(p->type);
continue;
}
- unsigned long bgn_pfn = PFN_UP(p->addr);
- unsigned long end_pfn = PFN_DW(p->addr + p->size);
-
- // 在x86_64的机器上低32bit可能出现回绕的情况
- // 就算物理内存小于4G也可能出现
- // 这种情况直接忽略
- if (bgn_pfn < bootmem_data.max_pfn) {
+ if (p->addr > 0xFFFFFFFF) {
break;
}
+ if (p->addr + p->size > 0xFFFFFFFF) {
+ p->size = 0xFFFFFFFF + 1 - p->addr;
+ }
+
+ unsigned long bgn_pfn = PFN_UP(p->addr);
+ unsigned long end_pfn = PFN_DW(p->addr + p->size);
if (bootmem_data.min_pfn > bgn_pfn) {
bootmem_data.min_pfn = bgn_pfn;
}
void register_bootmem_pages() {
- unsigned long max_pfn = 0;
for (unsigned int i = 0; i < boot_params.e820map.map_cnt; ++i) {
struct e820_entry *p = boot_params.e820map.map + i;
continue;
}
- unsigned long bgn_pfn = PFN_UP(p->addr);
- unsigned long end_pfn = PFN_DW(p->addr + p->size);
-
- // 在x86_64的机器上低32bit可能出现回绕的情况
- // 就算物理内存小于4G也可能出现
- // 这种情况直接忽略
- if (bgn_pfn < max_pfn) {
+ if (p->addr > 0xFFFFFFFF) {
break;
}
- max_pfn = end_pfn;
-
+ unsigned long bgn_pfn = PFN_UP(p->addr);
+ unsigned long end_pfn = PFN_DW(p->addr + p->size);
#if 1
// 用一个相对快的方式
e820_print_map();
e820_init_bootmem_data();
init_bootmem_allocator();
+ // asm("cli;hlt;");
}
// 由于只有在构建buddy system的时候才会用到