mirror of https://github.com/0Nera/BMOSP.git
Добавлена ширина в форматированный вывод
This commit is contained in:
parent
bb86ea4071
commit
36d28d5f90
|
@ -35,7 +35,7 @@ enum colors {
|
||||||
|
|
||||||
#ifndef NO_DEBUG
|
#ifndef NO_DEBUG
|
||||||
#define LOG(...) \
|
#define LOG(...) \
|
||||||
fb_printf("[%u]%s() (%s:%d) ", GET_TICK_BIG, __func__, __FILE__, __LINE__); \
|
fb_printf("[%4u]%s() (%s:%d) ", GET_TICK_BIG, __func__, __FILE__, __LINE__); \
|
||||||
fb_printf(__VA_ARGS__)
|
fb_printf(__VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
#define LOG(...)
|
#define LOG(...)
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
#define VERSION_MAJOR 0
|
#define VERSION_MAJOR 0
|
||||||
#define VERSION_MINOR 1
|
#define VERSION_MINOR 1
|
||||||
#define VERSION_BUILD 896
|
#define VERSION_BUILD 897
|
||||||
|
|
|
@ -121,17 +121,56 @@ void tool_uint_to_str(uint64_t i, uint8_t base, char *buf) {
|
||||||
tool_reverse_str(buf);
|
tool_reverse_str(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tool_uint_to_wstr(uint64_t i, uint8_t base, char *buf, uint64_t width) {
|
||||||
|
uint64_t index = 0;
|
||||||
|
// Деление с остатком для преобразования числа в нужную систему счисления
|
||||||
|
do {
|
||||||
|
uint64_t remainder = i % base;
|
||||||
|
// Преобразовываем остаток в символ и добавляем его в строку
|
||||||
|
buf[index++] =
|
||||||
|
(remainder > 9) ? (remainder - 10) + 'A' : remainder + '0'; // Если остаток > 9, добавляем заглавную букву А
|
||||||
|
i /= base;
|
||||||
|
} while (i > 0);
|
||||||
|
|
||||||
|
while (index < width) {
|
||||||
|
buf[index++] = ' '; // Добавляем пробелы слева до заданной ширины
|
||||||
|
}
|
||||||
|
|
||||||
|
// Добавляем нулевой символ в конец строки, чтобы завершить ее
|
||||||
|
buf[index] = '\0';
|
||||||
|
|
||||||
|
// Переворачиваем строку, чтобы цифры были в правильном порядке
|
||||||
|
tool_reverse_str(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
int is_digit(char c) {
|
||||||
|
if (c >= '0' && c <= '9') { return 1; }
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int char_to_digit(char c) {
|
||||||
|
if (is_digit(c)) { return (int)(c - '0'); }
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// Функция для форматированного вывода
|
// Функция для форматированного вывода
|
||||||
void tool_format(void (*putc)(char c), const char *format_string, va_list args) {
|
void tool_format(void (*putc)(char c), const char *format_string, va_list args) {
|
||||||
while (*format_string != '\0') {
|
while (*format_string != '\0') {
|
||||||
if (*format_string == '%') {
|
if (*format_string == '%') {
|
||||||
char buf[48];
|
char buf[48];
|
||||||
uint64_t point = 0;
|
uint64_t point = 0;
|
||||||
const char *arg_s;
|
char *arg_s;
|
||||||
int64_t arg_d = 0;
|
int64_t arg_d = 0;
|
||||||
uint64_t arg_u = 0;
|
uint64_t arg_u = 0;
|
||||||
|
uint64_t width = 0;
|
||||||
|
|
||||||
format_string++;
|
format_string++;
|
||||||
|
|
||||||
|
if (is_digit(*format_string)) {
|
||||||
|
width = char_to_digit(*format_string);
|
||||||
|
format_string++;
|
||||||
|
}
|
||||||
|
|
||||||
if (*format_string == '\0') {
|
if (*format_string == '\0') {
|
||||||
break; // Неожиданный конец строки формата
|
break; // Неожиданный конец строки формата
|
||||||
}
|
}
|
||||||
|
@ -140,7 +179,7 @@ void tool_format(void (*putc)(char c), const char *format_string, va_list args)
|
||||||
case '%': putc('%'); break;
|
case '%': putc('%'); break;
|
||||||
case 'c': putc(va_arg(args, int)); break;
|
case 'c': putc(va_arg(args, int)); break;
|
||||||
case 's':
|
case 's':
|
||||||
arg_s = va_arg(args, const char *);
|
arg_s = va_arg(args, char *);
|
||||||
// Вывод каждого символа строки
|
// Вывод каждого символа строки
|
||||||
while (*arg_s != '\0') {
|
while (*arg_s != '\0') {
|
||||||
putc(*arg_s);
|
putc(*arg_s);
|
||||||
|
@ -154,11 +193,10 @@ void tool_format(void (*putc)(char c), const char *format_string, va_list args)
|
||||||
putc(buf[point]);
|
putc(buf[point]);
|
||||||
point++;
|
point++;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
arg_u = va_arg(args, uint64_t);
|
arg_u = va_arg(args, uint64_t);
|
||||||
tool_uint_to_str(arg_u, 10, buf);
|
tool_uint_to_wstr(arg_u, 10, buf, width);
|
||||||
while (buf[point] != '\0') {
|
while (buf[point] != '\0') {
|
||||||
putc(buf[point]);
|
putc(buf[point]);
|
||||||
point++;
|
point++;
|
||||||
|
@ -166,15 +204,7 @@ void tool_format(void (*putc)(char c), const char *format_string, va_list args)
|
||||||
break;
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
arg_u = va_arg(args, uint64_t);
|
arg_u = va_arg(args, uint64_t);
|
||||||
tool_uint_to_str(arg_u, 16, buf);
|
tool_uint_to_wstr(arg_u, 16, buf, width);
|
||||||
while (buf[point] != '\0') {
|
|
||||||
putc(buf[point]);
|
|
||||||
point++;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'l':
|
|
||||||
arg_u = va_arg(args, uint64_t);
|
|
||||||
tool_uint_to_str(arg_u, 16, buf);
|
|
||||||
while (buf[point] != '\0') {
|
while (buf[point] != '\0') {
|
||||||
putc(buf[point]);
|
putc(buf[point]);
|
||||||
point++;
|
point++;
|
||||||
|
|
|
@ -83,8 +83,8 @@ static inline void scan( ) {
|
||||||
uint16_t device_id = get_device_id(bus, slot, function);
|
uint16_t device_id = get_device_id(bus, slot, function);
|
||||||
uint16_t class_id = get_class_id(bus, slot, function);
|
uint16_t class_id = get_class_id(bus, slot, function);
|
||||||
|
|
||||||
/*
|
|
||||||
uint16_t status = pci_read_word(bus, slot, function, 0x6);
|
uint16_t status = pci_read_word(bus, slot, function, 0x6);
|
||||||
|
/*
|
||||||
uint32_t mem_addr_0 = pci_read_word(bus, slot, function, 0x1C);
|
uint32_t mem_addr_0 = pci_read_word(bus, slot, function, 0x1C);
|
||||||
uint32_t mem_addr_1 = pci_read_word(bus, slot, function, 0x24);
|
uint32_t mem_addr_1 = pci_read_word(bus, slot, function, 0x24);
|
||||||
uint32_t mem_lim_0 = pci_read_word(bus, slot, function, 0x20);
|
uint32_t mem_lim_0 = pci_read_word(bus, slot, function, 0x20);
|
||||||
|
@ -96,17 +96,18 @@ static inline void scan( ) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *name = find_vendor(vendor);
|
char *name = find_vendor(vendor);
|
||||||
fb_printf("[%u] %x [%s], устройство: %x, %u.%u.%u | ", devices, vendor, name, device_id, bus, slot,
|
fb_printf("[%4u] %4x [%s], устройство: %x, %u.%u.%u | ", devices, vendor, name, device_id, bus, slot,
|
||||||
function);
|
function);
|
||||||
fb_printf("%s\n", get_class_name(class_id));
|
fb_printf("%s", get_class_name(class_id));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
fb_printf(" | 0x%x : 0x%x", mem_addr_0, mem_lim_0);
|
fb_printf(" | %8x : %8x", mem_addr_0, mem_lim_0);
|
||||||
fb_printf(" | 0x%x : 0x%x", mem_addr_1, mem_lim_1);
|
fb_printf(" | %8x : %8x", mem_addr_1, mem_lim_1);
|
||||||
fb_printf(" | 0x%x : 0x%x", io_addr_0, io_lim_0);
|
fb_printf(" | %8x : %8x", io_addr_0, io_lim_0);
|
||||||
fb_printf(" | 0x%x : 0x%x", io_addr_1, io_lim_1);
|
fb_printf(" | %8x : %8x", io_addr_1, io_lim_1);
|
||||||
fb_printf(" | 0x%x\n", status);
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
fb_printf(" | %4x\n", status);
|
||||||
devices++;
|
devices++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ if "^.M" in output:
|
||||||
|
|
||||||
ARCH_FLAGS = "-m64 -march=x86-64 -mabi=sysv -mno-red-zone -mcmodel=kernel -MMD -MP"
|
ARCH_FLAGS = "-m64 -march=x86-64 -mabi=sysv -mno-red-zone -mcmodel=kernel -MMD -MP"
|
||||||
WARN_FLAGS = "-Wall -Wextra -nostdlib"
|
WARN_FLAGS = "-Wall -Wextra -nostdlib"
|
||||||
STANDART_FLAGS = f"-std=gnu11 -DKERNEL_GIT_TAG=\\\"{__VERSION}\\\" -DNO_DEBUG=1" #
|
STANDART_FLAGS = f"-std=gnu11 -DKERNEL_GIT_TAG=\\\"{__VERSION}\\\"" # -DNO_DEBUG=1
|
||||||
PROTECT_FLAGS = "-O0 -g -pipe -ffreestanding -fno-stack-protector -fno-lto -fno-stack-check -fno-PIC -fno-PIE"
|
PROTECT_FLAGS = "-O0 -g -pipe -ffreestanding -fno-stack-protector -fno-lto -fno-stack-check -fno-PIC -fno-PIE"
|
||||||
PROTECT_FLAGS += " -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx"
|
PROTECT_FLAGS += " -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx"
|
||||||
CHARSET_FLAGS = "-finput-charset=UTF-8 -fexec-charset=cp1251"
|
CHARSET_FLAGS = "-finput-charset=UTF-8 -fexec-charset=cp1251"
|
||||||
|
|
Loading…
Reference in New Issue