mirror of
https://github.com/0Nera/BMOSP.git
synced 2025-03-30 05:02:54 +03:00
Поиск соответствий в базе PCI
This commit is contained in:
parent
beb3ab0eb6
commit
86ff34a34a
@ -1,5 +1,5 @@
|
||||
GRAPHICS=yes
|
||||
TIMEOUT=5
|
||||
TIMEOUT=0
|
||||
DEFAULT_ENTRY=0
|
||||
INTERFACE_BRANDING=git.synapseos.ru/Aren/bmosp
|
||||
BACKGROUND_STYLE=stretched
|
||||
|
@ -1,3 +1,3 @@
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 1
|
||||
#define VERSION_BUILD 665
|
||||
#define VERSION_BUILD 722
|
||||
|
10
kernel/mem.c
10
kernel/mem.c
@ -64,9 +64,9 @@ void mem_dump_memory( ) {
|
||||
mem_entry_t *curr = first_node;
|
||||
|
||||
while (curr) {
|
||||
LOG("->0x%x | %u.%u kb | %s | 0x%x\n", &curr->data, (curr->size) / 1024,
|
||||
(curr->size) % 1024, curr->free ? memory_types[0] : memory_types[1],
|
||||
curr->next);
|
||||
fb_printf("->0x%x | %u.%u kb | %s | 0x%x\n", &curr->data,
|
||||
(curr->size) / 1024, (curr->size) % 1024,
|
||||
curr->free ? memory_types[0] : memory_types[1], curr->next);
|
||||
curr = curr->next;
|
||||
}
|
||||
}
|
||||
@ -209,7 +209,9 @@ static void *alloc_align(size_t size, size_t alignment) {
|
||||
|
||||
void *mem_alloc(size_t size) {
|
||||
mem_check_dynamic_memory( );
|
||||
return alloc_align(size, 1);
|
||||
void *data = alloc_align(size, 1);
|
||||
tool_memset(data, 0, size);
|
||||
return data;
|
||||
}
|
||||
|
||||
void mem_free(void *addr) {
|
||||
|
11
kernel/mod.c
11
kernel/mod.c
@ -45,8 +45,10 @@ void mod_list_show( ) {
|
||||
fb_printf("Описание модуля: %s\n", module_list[i].message);
|
||||
fb_printf("Тип модуля: %u\n", module_list[i].type);
|
||||
fb_printf("Код ошибки модуля: %u\n", module_list[i].err_code);
|
||||
fb_printf("Размер данных: %u\n", module_list[i].data_size);
|
||||
fb_printf("Адрес данных: 0x%x\n", module_list[i].data);
|
||||
if (module_list[i].data_size) {
|
||||
fb_printf("Размер данных: %u\n", module_list[i].data_size);
|
||||
fb_printf("Адрес данных: 0x%x\n", module_list[i].data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,10 +116,7 @@ void mod_init( ) {
|
||||
module_list[modules_count].message = ret.message;
|
||||
module_list[modules_count].data_size = ret.data_size;
|
||||
|
||||
if (ret.data_size != 0) {
|
||||
module_list[modules_count].data =
|
||||
(&(ret.data) + (uint64_t)module_ptr->address);
|
||||
}
|
||||
if (ret.data_size != 0) { module_list[modules_count].data = ret.data; }
|
||||
|
||||
modules_count++;
|
||||
}
|
||||
|
@ -20,16 +20,25 @@ static uint64_t strlen(char *str) {
|
||||
return length;
|
||||
}
|
||||
|
||||
static void memcpy(void *dest, void *src, uint64_t n) {
|
||||
static void strcpy(char *dest, char *src) {
|
||||
size_t i = 0;
|
||||
while (src[i] != '\0') {
|
||||
dest[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
dest[i] = '\0'; // добавляем завершающий нулевой символ
|
||||
}
|
||||
|
||||
static void memcpy(void *dest, void *src, size_t n) {
|
||||
char *d = (char *)dest;
|
||||
char *s = (char *)src;
|
||||
|
||||
for (uint64_t i = 0; i < n; i++) { d[i] = s[i]; }
|
||||
for (size_t i = 0; i < n; i++) { d[i] = s[i]; }
|
||||
}
|
||||
|
||||
static void *memset(void *ptr, uint8_t n, uint64_t size) {
|
||||
static void *memset(void *ptr, uint8_t n, size_t size) {
|
||||
uint8_t *p = (uint8_t *)ptr;
|
||||
for (uint64_t i = 0; i < size; i++) { p[i] = n; }
|
||||
for (size_t i = 0; i < size; i++) { p[i] = n; }
|
||||
return ptr;
|
||||
}
|
||||
|
||||
@ -103,9 +112,9 @@ static char *strtok(char *str, char *delim) {
|
||||
return token;
|
||||
}
|
||||
|
||||
static long int strtol(char *str, char **endptr, int base) {
|
||||
long int num = 0;
|
||||
int sign = 1;
|
||||
static size_t strtol(char *str, char **endptr, int64_t base) {
|
||||
size_t num = 0;
|
||||
int64_t sign = 1;
|
||||
|
||||
// Пропускаем пробелы в начале строки
|
||||
while (*str == ' ') { str++; }
|
||||
@ -136,7 +145,7 @@ static long int strtol(char *str, char **endptr, int base) {
|
||||
|
||||
// Преобразование строки в число
|
||||
while (*str != '\0') {
|
||||
int digit;
|
||||
int64_t digit;
|
||||
if (*str >= '0' && *str <= '9') {
|
||||
digit = *str - '0';
|
||||
} else if (*str >= 'A' && *str <= 'Z') {
|
||||
@ -156,7 +165,7 @@ static long int strtol(char *str, char **endptr, int base) {
|
||||
}
|
||||
|
||||
if (endptr != NULL) {
|
||||
*endptr = (char *)str; // Указатель на символ, следующий за числом
|
||||
//*endptr = (char *)str; // Указатель на символ, следующий за числом
|
||||
}
|
||||
|
||||
return num * sign;
|
||||
|
@ -27,4 +27,22 @@ static inline void init_env(env_t *loader_env) {
|
||||
get_module = loader_env->get_module;
|
||||
}
|
||||
|
||||
static void *realloc(void *addr, size_t size) {
|
||||
if (size == 0) {
|
||||
free(addr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (addr == NULL) { return alloc(size); }
|
||||
|
||||
void *new_addr = alloc(size);
|
||||
|
||||
if (new_addr == NULL) { return NULL; }
|
||||
|
||||
memcpy(new_addr, addr, size);
|
||||
free(addr);
|
||||
|
||||
return new_addr;
|
||||
}
|
||||
|
||||
#endif // system.h
|
||||
|
@ -6,6 +6,14 @@ typedef struct {
|
||||
} vendor_t;
|
||||
|
||||
static vendor_t **vendor_list;
|
||||
static uint64_t num_vendors;
|
||||
|
||||
static char *find_vendor(uint16_t id) {
|
||||
for (uint64_t i = 0; i < num_vendors - 1; i++) {
|
||||
if (vendor_list[i]->id == id) { return vendor_list[i]->name; }
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline uint32_t inl(uint16_t port) {
|
||||
uint32_t data;
|
||||
@ -66,10 +74,18 @@ static inline void scan( ) {
|
||||
|
||||
uint16_t device_id = get_device_id(bus, slot, function);
|
||||
uint16_t class_id = get_class_id(bus, slot, function);
|
||||
|
||||
fb_printf("[%u] vendor: 0x%x, device: 0x%x, class: %u\n",
|
||||
devices, vendor, device_id, class_id);
|
||||
|
||||
char *name = find_vendor(vendor);
|
||||
if (name != NULL) {
|
||||
fb_printf("[%u] vendor: [%s], device: 0x%x, class: %u, "
|
||||
"%u.%u.%u\n",
|
||||
devices, name, device_id, class_id, bus, slot,
|
||||
function);
|
||||
} else {
|
||||
fb_printf("[%u] vendor: 0x%x, device: 0x%x, class: %u, "
|
||||
"%u.%u.%u\n",
|
||||
devices, vendor, device_id, class_id, bus, slot,
|
||||
function);
|
||||
}
|
||||
devices++;
|
||||
}
|
||||
}
|
||||
@ -86,6 +102,8 @@ module_info_t __attribute__((section(".minit"))) init(env_t *env) {
|
||||
} else {
|
||||
fb_printf("Записей в базе PCI: %u\n", pci_data->data_size);
|
||||
vendor_list = (vendor_t **)pci_data->data;
|
||||
fb_printf("База PCI: 0x%x\n", vendor_list);
|
||||
fb_printf("База PCI: 0x%x\n", &vendor_list);
|
||||
}
|
||||
|
||||
scan( );
|
||||
|
@ -1,44 +1,63 @@
|
||||
#include <system.h>
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
uint16_t id;
|
||||
} vendor_t;
|
||||
|
||||
static vendor_t *parse_file(char *str, uint64_t num_vendors, uint64_t size) {
|
||||
vendor_t *vendor_list = alloc(num_vendors * sizeof(vendor_t));
|
||||
if (vendor_list == NULL) { return NULL; }
|
||||
static vendor_t **parse_file(char *str, uint64_t num_vendors, uint64_t size) {
|
||||
vendor_t **vendor_list =
|
||||
(vendor_t **)alloc(num_vendors * sizeof(vendor_t *));
|
||||
|
||||
if (vendor_list == NULL) { return NULL; }
|
||||
for (uint64_t i = 0; i < num_vendors; i++) {
|
||||
vendor_list[i] = (vendor_t *)alloc(sizeof(vendor_t));
|
||||
}
|
||||
|
||||
char *line = str;
|
||||
uint64_t i = 0;
|
||||
|
||||
char *line = alloc(strlen(str) + 1);
|
||||
char *temp = alloc(strlen(str) + 1);
|
||||
|
||||
if (line == NULL) { return NULL; }
|
||||
if (temp == NULL) { return NULL; }
|
||||
strcpy(line, str);
|
||||
|
||||
while (line != NULL && i < num_vendors) {
|
||||
char *name = trstr(line, ';');
|
||||
char *id_str = strtok(line, ";");
|
||||
temp = realloc(temp, strlen(line) + 1);
|
||||
strcpy(temp, line);
|
||||
|
||||
char *name = trstr(temp, ';');
|
||||
char *id_str = strtok(temp, ";");
|
||||
|
||||
name = strtok(name, "\n");
|
||||
fb_printf("\t%s, %s\n", id_str, name);
|
||||
name[strlen(name) - 1] = '\0';
|
||||
|
||||
if (id_str != NULL && name != NULL) {
|
||||
fb_printf("\tID: 0x%x, Name: %s\n", strtol(id_str, NULL, 16), name);
|
||||
vendor_list[i].id = strtol(id_str, NULL, 16);
|
||||
vendor_list[i].name = name;
|
||||
vendor_list[i]->id = strtol(id_str, NULL, 16);
|
||||
vendor_list[i]->name = name;
|
||||
i++;
|
||||
}
|
||||
line = trstr(line, '\n');
|
||||
fb_printf(line);
|
||||
temp = trstr(line, '\n');
|
||||
strcpy(line, temp);
|
||||
}
|
||||
|
||||
if (i != num_vendors) {
|
||||
// Ошибка в парсинге данных
|
||||
for (uint64_t j = 0; j < i; j++) { free(vendor_list[j].name); }
|
||||
for (uint64_t j = 0; j < i; j++) { free(vendor_list[j]->name); }
|
||||
free(vendor_list);
|
||||
free(line);
|
||||
free(temp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
free(line);
|
||||
free(temp);
|
||||
return vendor_list;
|
||||
}
|
||||
|
||||
static void print_vendors(uint64_t num_vendors, vendor_t *vendor_list) {
|
||||
static void print_vendors(uint64_t num_vendors, vendor_t **vendor_list) {
|
||||
for (uint64_t i = 0; i < num_vendors; i++) {
|
||||
vendor_t *vendor = &vendor_list[i];
|
||||
vendor_t *vendor = vendor_list[i];
|
||||
fb_printf("ID: 0x%x, Name: %s\n", vendor->id, vendor->name);
|
||||
}
|
||||
}
|
||||
@ -49,21 +68,16 @@ module_info_t __attribute__((section(".minit"))) init(env_t *env) {
|
||||
module_info_t *pci_data = get_module("[PCI][DATA][VENDORS]");
|
||||
|
||||
if (pci_data == NULL) { fb_printf("Модуль PCI данных не найден!\n"); }
|
||||
char *str = pci_data->data;
|
||||
|
||||
uint64_t num_vendors = count_chars(str, ';');
|
||||
|
||||
uint64_t i = 1;
|
||||
char *line = str;
|
||||
while (line != NULL && i < num_vendors) {
|
||||
i++;
|
||||
line = trstr(line, '\n');
|
||||
fb_printf("\t\t%u\n%s\n", i, line);
|
||||
}
|
||||
uint64_t num_vendors = count_chars(pci_data->data, ';');
|
||||
fb_printf("Количество вендоров: %u\n", num_vendors);
|
||||
for (;;) {}
|
||||
|
||||
vendor_t *vendor_list = parse_file(str, num_vendors, pci_data->data_size);
|
||||
vendor_t **vendor_list =
|
||||
parse_file(pci_data->data, num_vendors, pci_data->data_size);
|
||||
fb_printf("База PCI: 0x%x\n", vendor_list);
|
||||
fb_printf("База PCI: 0x%x\n", &vendor_list);
|
||||
fb_printf("База PCI: 0x%x\n", vendor_list[0]);
|
||||
fb_printf("База PCI: 0x%x\n", vendor_list + offset);
|
||||
// print_vendors(num_vendors, vendor_list);
|
||||
return (module_info_t){
|
||||
.name = (char *)"[PCI][ADAPTER]",
|
||||
|
@ -1,23 +1,24 @@
|
||||
0x1002;AMD
|
||||
0x1022;AMD
|
||||
0x10DE;NVIDIA
|
||||
0x10EC;Realtek
|
||||
0x10FA;Truevision
|
||||
0x1234;Technical
|
||||
0x1344;Micron
|
||||
0x1462;MSI
|
||||
0x1AF4;Red Hat
|
||||
0x1B36;Red Hat
|
||||
0x1D6B;Linux Foundation
|
||||
0x1FFF;MCST
|
||||
0x2646;Kingston Technology
|
||||
0x5143;Qualcomm
|
||||
0x8086;Intel
|
||||
0x80EE;VirtualBox
|
||||
0x8800;5553535
|
||||
0xBEEF;Tasty and point
|
||||
0x8966;SynapseOS
|
||||
0xC0A9;Micron/Crucial
|
||||
0xCAFE;TR&D
|
||||
0xDADA;Are you mentally healthy?
|
||||
0xDEAD;Page Fault inc.
|
||||
1002;AMD
|
||||
1022;AMD
|
||||
106B;Apple Inc.
|
||||
10DE;NVIDIA
|
||||
10EC;Realtek
|
||||
10FA;Truevision
|
||||
1234;Technical
|
||||
1344;Micron
|
||||
1462;MSI
|
||||
1AF4;Red Hat
|
||||
1B36;Red Hat
|
||||
1D6B;Linux Foundation
|
||||
1FFF;MCST
|
||||
2646;Kingston Technology
|
||||
5143;Qualcomm
|
||||
8086;Intel
|
||||
80EE;VirtualBox
|
||||
8800;5553535
|
||||
BEEF;Tasty and point
|
||||
8966;SynapseOS
|
||||
C0A9;Micron/Crucial
|
||||
CAFE;TR&D
|
||||
DADA;Are you mentally healthy?
|
||||
DEAD;Page Fault inc.
|
Loading…
x
Reference in New Issue
Block a user