Skip to content

Commit 002020f

Browse files
Completely cleaned up PCI, added vsnprintf and snprintf.
1 parent 3949c8b commit 002020f

7 files changed

Lines changed: 665 additions & 314 deletions

File tree

source/includes/graphics.h

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,6 @@ void printdec(int num);
103103
*/
104104
void printbin(uint8_t value);
105105

106-
/**
107-
* @brief Prints Hexadecimal number
108-
*
109-
* @param hex the hexadecimal number to be printed.
110-
*/
111-
void printhex(signed int num, bool caps);
112-
113106
/**
114107
* @brief Prints with formatting supported.
115108
*
@@ -151,6 +144,28 @@ void printfnoln_internal(cstring file, cstring func, int64 line, cstring format,
151144
*/
152145
void vprintf_internal(cstring file, cstring func, int64 line, bool newline, cstring format, va_list argp);
153146

147+
/**
148+
* @brief Formats a string into a buffer using a va_list.
149+
*
150+
* @param buf destination buffer.
151+
* @param size buffer size in bytes.
152+
* @param fmt format string.
153+
* @param args variable argument list.
154+
* @return number of characters written (excluding null terminator).
155+
*/
156+
int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
157+
158+
/**
159+
* @brief Formats a string into a fixed-size buffer.
160+
*
161+
* @param buf destination buffer.
162+
* @param size buffer size in bytes.
163+
* @param fmt format string.
164+
* @return number of characters written (excluding null terminator).
165+
*/
166+
int snprintf(char *buf, size_t size, const char *fmt, ...);
167+
168+
154169
/**
155170
* @brief Prints a char, using print(&c);
156171
*

source/includes/pci.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,15 @@
1717
#include <graphics.h>
1818
#include <drivers/rtl8139.h>
1919
#include <debugger.h>
20+
#include <ahci.h>
21+
#include <hal.h>
22+
#include <isr.h>
2023

2124
extern cstring display_adapter_name;
2225
extern cstring GPUName[1]; //Max 2 GPUs allowed
2326
extern string using_graphics_card;
2427
extern int64* graphics_base_Address;
2528

26-
typedef struct {
27-
int16 vendor;
28-
int16 device;
29-
int8 classid;
30-
string name;
31-
int8 is_gpu;
32-
} pci_id_entry_t;
33-
3429
// Define the base address for the PCI configuration space
3530
#define PCI_CONFIG_ADDRESS 0xCF8
3631
#define PCI_CONFIG_DATA 0xCFC

source/includes/pci_id.h

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* @file pci_id.h
3+
* @author Pradosh (pradoshgame@gmail.com)
4+
* @brief The list of all officially recognized devices.
5+
* @version 0.1
6+
* @date 2025-12-27
7+
*
8+
* @copyright Copyright (c) Pradosh 2025
9+
*
10+
*/
11+
12+
#ifndef PCI_ID_H
13+
#define PCI_ID_H
14+
15+
#include <basics.h>
16+
#include <pci_id.h>
17+
18+
typedef void (*pci_probe_fn)(uint8_t bus, uint8_t slot, uint8_t function);
19+
20+
typedef struct {
21+
uint16_t vendor;
22+
uint16_t device;
23+
uint8_t classid; // 0xFF = ignore
24+
const char* name;
25+
uint8_t is_gpu;
26+
pci_probe_fn probe; // optional device-specific init
27+
} pci_id_entry_t;
28+
29+
/**
30+
* @brief Gets the vendor id and gives the appropriate name.
31+
*
32+
* @param vendor vendor id
33+
* @return string vendor name
34+
*/
35+
string parse_vendor(int16 vendor);
36+
37+
/**
38+
* @brief Gets the class id and gives the appropriate class name.
39+
*
40+
* @param classid class id
41+
* @return string class name
42+
*/
43+
string parse_class(int16 classid);
44+
45+
/**
46+
* @brief A Simplified and clean PCI lookup function.
47+
*
48+
* @param vendor The vendor id.
49+
* @param device The device id.
50+
* @param classid The class id.
51+
* @return const pci_id_entry_t*;s
52+
*/
53+
const pci_id_entry_t* pci_lookup(uint16_t vendor, uint16_t device, uint8_t classid);
54+
55+
/**
56+
* @brief Finds the AHCI BAR and handles it.
57+
*
58+
* @param bus
59+
* @param slot
60+
* @param function
61+
*/
62+
void probe_ahci(uint8_t bus, uint8_t slot, uint8_t function);
63+
64+
/**
65+
* @brief Finds the RTL8139 card and handles it.
66+
*
67+
* @param bus
68+
* @param slot
69+
* @param function
70+
*/
71+
void probe_rtl8139(uint8_t bus, uint8_t slot, uint8_t function);
72+
73+
/**
74+
* @brief Automatically names the unknown GPU with vendor name and its device id.
75+
*
76+
* @param vendor the vendor id.
77+
* @param device devide id.
78+
* @return cstring; gpu name.
79+
*/
80+
cstring auto_name_gpu(uint16_t vendor, uint16_t device);
81+
82+
#endif

0 commit comments

Comments
 (0)