Moar fixes to pci.c and pci.h

This commit is contained in:
Gregory Kenneth Bowne 2023-10-18 19:15:44 -07:00
parent 6809c6f1bf
commit 168f9ebb62
4 changed files with 41 additions and 9 deletions

View File

@ -1,15 +1,21 @@
cmake_minimum_required(VERSION 3.13.4) cmake_minimum_required(VERSION 3.13.4)
project(ClassicOS VERSION 0.0.1 LANGUAGES C) project(ClassicOS
VERSION 0.0.1
DESCRIPTION "An x86 Operating System for your pleasure and enjoyment"
HOMEPAGE_URL "https://github.com/gbowne1/ClassicOS"
LANGUAGES C ASM_NASM)
# Source files # Source files
set(BOOT_SOURCE_FILES set(BOOT_SOURCE_FILES
src/boot/boot.asm src/boot/boot.asm
src/boot/linker.ld src/boot/linker.ld
) )
set(GRUB_SOURCE_FILES set(GRUB_SOURCE_FILES
src/boot/grub/grub.cfg src/boot/grub/grub.cfg
src/boot/grub/menu.lst src/boot/grub/menu.lst
) )
set(DRIVERS_SOURCE_FILES set(DRIVERS_SOURCE_FILES
src/drivers/audio/audio.c src/drivers/audio/audio.c
src/drivers/audio/audio.h src/drivers/audio/audio.h
@ -78,6 +84,7 @@ set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
set(CMAKE_CXX_COMPILER g++) set(CMAKE_CXX_COMPILER g++)
set(CMAKE_ASM_COMPILER nasm) set(CMAKE_ASM_COMPILER nasm)
set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} --32") set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} --32")
set(CMAKE_ASM_NASM_OBJECT_FORMAT bin)
set(CMAKE_SYSTEM_PROCESSOR i386) set(CMAKE_SYSTEM_PROCESSOR i386)
set(CMAKE_SYSTEM_NAME None) set(CMAKE_SYSTEM_NAME None)
set(CMAKE_ASM_NASM_COMPILER nasm) set(CMAKE_ASM_NASM_COMPILER nasm)

View File

@ -1,3 +1,5 @@
[BITS 16]
; Set up the segment registers ; Set up the segment registers
xor ax, ax xor ax, ax
mov ds, ax mov ds, ax

View File

@ -16,18 +16,42 @@
// Initialize the PCI bus // Initialize the PCI bus
void pci_init() void pci_init()
{ {
// Add any necessary initialization code here // Enable PCI bus master
pci_write(PCI_COMMAND_PORT, 0x04);
} }
// Detect and configure PCI devices // Detect and configure PCI devices
void pci_detect_devices() void pci_detect_devices()
{ {
// Scan all PCI buses and devices
for (int bus = 0; bus < 256; bus++) {
for (int device = 0; device < 32; device++) {
for (int function = 0; function < 8; function++) {
uint16_t vendor_id = pci_read(bus, device, function, 0x00);
if (vendor_id != 0xFFFF) {
uint16_t device_id = pci_read(bus, device, function, 0x02);
uint8_t class_code = pci_read(bus, device, function, 0x0B);
uint8_t subclass_code = pci_read(bus, device, function, 0x0A);
uint8_t prog_if = pci_read(bus, device, function, 0x09);
uint8_t header_type = pci_read(bus, device, function, 0x0E);
uint8_t irq_line = pci_read(bus, device, function, 0x3C);
uint32_t bar0 = pci_read(bus, device, function, 0x10);
uint32_t bar1 = pci_read(bus, device, function, 0x14);
uint32_t bar2 = pci_read(bus, device, function, 0x18);
uint32_t bar3 = pci_read(bus, device, function, 0x1C);
uint32_t bar4 = pci_read(bus, device, function, 0x20);
uint32_t bar5 = pci_read(bus, device, function, 0x24);
// Add any necessary device detection and configuration code here // Add any necessary device detection and configuration code here
}
}
}
}
} }
// Read from a PCI device // Read from a PCI device
uint8_t pci_read(uint16_t port) uint8_t pci_read(uint8_t bus, uint8_t device, uint8_t function, uint8_t offset)
{ {
uint16_t port = PCI_BASE_ADDRESS | ((uint16_t)bus << 8) | ((uint16_t)device << 3) | ((uint16_t)function << 0x0B) | ((uint16_t)offset & 0xFC);
uint8_t value; uint8_t value;
// Read from the specified port // Read from the specified port

View File

@ -11,8 +11,7 @@ void pci_init();
// Detect and configure PCI devices // Detect and configure PCI devices
void pci_detect_devices(); void pci_detect_devices();
// Read from a PCI device uint8_t pci_read(uint8_t bus, uint8_t device, uint8_t function, uint8_t offset);
uint8_t pci_read(uint16_t port);
// Write to a PCI device // Write to a PCI device
void pci_write(uint16_t port, uint8_t value); void pci_write(uint16_t port, uint8_t value);