Compare commits
No commits in common. "ecab248cd6643a5427ffbb21795477ab35c48427" and "c9a036bfbb73c47fa820cd5a869281e122b0c957" have entirely different histories.
ecab248cd6
...
c9a036bfbb
@ -99,9 +99,11 @@ isPaging:
|
|||||||
|
|
||||||
# Unmap the identity mapping as it is now unnecessary
|
# Unmap the identity mapping as it is now unnecessary
|
||||||
# movl $0, boot_page_directory + 0
|
# movl $0, boot_page_directory + 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
call kernel
|
|
||||||
|
call early_main
|
||||||
|
|
||||||
cli
|
cli
|
||||||
1: hlt
|
1: hlt
|
||||||
@ -113,18 +115,4 @@ isPaging:
|
|||||||
.include "./source/kernel/irq_table.s"
|
.include "./source/kernel/irq_table.s"
|
||||||
.include "./source/kernel/interrupts/idt.s"
|
.include "./source/kernel/interrupts/idt.s"
|
||||||
|
|
||||||
.globl jump_usermode
|
|
||||||
jump_usermode:
|
|
||||||
mov $((4*8) | 3) , %ax
|
|
||||||
mov %ax, %ds
|
|
||||||
mov %ax, %es
|
|
||||||
mov %ax, %fs
|
|
||||||
mov %ax, %gs
|
|
||||||
|
|
||||||
mov %esp, %eax
|
|
||||||
push $( (3*8) | 3)
|
|
||||||
push %eax
|
|
||||||
pushf
|
|
||||||
push $( ( 3 * 8) | 3)
|
|
||||||
push startSuperVisorTerminal
|
|
||||||
iret
|
|
||||||
|
@ -4,6 +4,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#define __DEBUG__ false
|
#define __DEBUG__ false
|
||||||
#define KERNEL_VERSION 0.03
|
#define KERNEL_VERSION 0
|
||||||
|
|
||||||
#define ARCHITECTURE "I386"
|
#define ARCHITECTURE "I386"
|
||||||
|
@ -56,7 +56,7 @@ inline void TestIDEController(){
|
|||||||
int device =1 , function = 1;
|
int device =1 , function = 1;
|
||||||
PCIBusAddress IDEControllerPCIAddress = PCIBusAddress{bus,device, function};
|
PCIBusAddress IDEControllerPCIAddress = PCIBusAddress{bus,device, function};
|
||||||
|
|
||||||
uint8_t ProgIF = PCI::GetProgIF(IDEControllerPCIAddress);
|
uint8_t ProgIF = GetProgIF(IDEControllerPCIAddress);
|
||||||
printf( "ProgIF: 0x%x\n" ,ProgIF);
|
printf( "ProgIF: 0x%x\n" ,ProgIF);
|
||||||
|
|
||||||
//CheckProgIF(ProgIF);
|
//CheckProgIF(ProgIF);
|
||||||
@ -66,15 +66,15 @@ inline void TestIDEController(){
|
|||||||
|
|
||||||
uint32_t BAR0,BAR1,BAR2,BAR3, BAR4;
|
uint32_t BAR0,BAR1,BAR2,BAR3, BAR4;
|
||||||
|
|
||||||
BAR0 = PCI::ReadBAR(IDEControllerPCIAddress, 0);
|
BAR0 = ReadBAR(IDEControllerPCIAddress, 0);
|
||||||
|
|
||||||
BAR1 = PCI::ReadBAR(IDEControllerPCIAddress, 1);
|
BAR1 = ReadBAR(IDEControllerPCIAddress, 1);
|
||||||
|
|
||||||
BAR2 = PCI::ReadBAR(IDEControllerPCIAddress, 2);
|
BAR2 = ReadBAR(IDEControllerPCIAddress, 2);
|
||||||
|
|
||||||
BAR3 = PCI::ReadBAR(IDEControllerPCIAddress, 3);
|
BAR3 = ReadBAR(IDEControllerPCIAddress, 3);
|
||||||
|
|
||||||
BAR4 = PCI::ReadBAR(IDEControllerPCIAddress, 4);
|
BAR4 = ReadBAR(IDEControllerPCIAddress, 4);
|
||||||
|
|
||||||
// All bars are return 0xffffff for some as of yet mysterious reason!
|
// All bars are return 0xffffff for some as of yet mysterious reason!
|
||||||
printf( "BAR 0: 0x%x\n", BAR0);
|
printf( "BAR 0: 0x%x\n", BAR0);
|
||||||
|
@ -1,66 +1,107 @@
|
|||||||
#include "pci.h"
|
#include "pci.h"
|
||||||
|
|
||||||
void PCI::Scan(){
|
#define PCI_BUS_ADDR_SHIFT 16
|
||||||
|
#define PCI_DEVICE_ADDR_SHIFT 11
|
||||||
int devicesFound = 0;
|
#define PCI_FUNCTION_ADDR_SHIFT 8
|
||||||
|
#define PCI_ENABLE_ADDR_SHIFT 31
|
||||||
|
|
||||||
printf("Start finding devices, Found: %d devices");
|
const char* GetClassCodeName (uint64_t ClassCode ) {
|
||||||
// loop through all possible busses, devices and their functions;
|
|
||||||
for( int bus = 0 ; bus < 256 ; bus++)
|
switch (ClassCode)
|
||||||
{
|
{
|
||||||
|
case 0x0 :
|
||||||
for(int device = 0; device < 32 ; device ++)
|
return "Unclassified";
|
||||||
{
|
break;
|
||||||
int function = 0;
|
|
||||||
|
|
||||||
uint64_t DeviceIdentify = PCI::ConfigReadWord(bus, device, function,0x0);
|
case 0x1:
|
||||||
uint32_t DeviceID = GetDevice(bus, device, function) >> 16;
|
return "Mass Storage Controller";
|
||||||
|
break;
|
||||||
|
|
||||||
if( DeviceID != 0xFFFF){
|
case 0x2:
|
||||||
PCIBusAddress busAddress =
|
return "Network Controller";
|
||||||
PCIBusAddress{bus, device, function };
|
break;
|
||||||
|
|
||||||
PrintPCIDevice(busAddress);
|
case 0x3:
|
||||||
|
return "Display Controller";
|
||||||
|
break;
|
||||||
|
|
||||||
// iterate over the functions if it is a multi function device!
|
case 0x4:
|
||||||
if( PCI::IsMultiFunctionDevice(busAddress) ){
|
return "Multimedia Controller";
|
||||||
printf("Multi function device! \n");
|
break;
|
||||||
printf("Check remaining Functions\n");
|
|
||||||
for ( function = 1 ; function < 8; function++)
|
|
||||||
{
|
|
||||||
uint32_t DeviceID = GetDevice(bus, device, function) >> 16;
|
|
||||||
|
|
||||||
if( DeviceID != 0xFFFF){
|
case 0x5:
|
||||||
PCIBusAddress busAddress2 = PCIBusAddress{bus, device, function};
|
return "Memory Controller";
|
||||||
PrintPCIDevice(busAddress2);
|
break;
|
||||||
devicesFound++;
|
|
||||||
}
|
case 0x6:
|
||||||
}
|
return "Bridge";
|
||||||
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
|
case 0x7 :
|
||||||
devicesFound++;
|
return "Simple Communication Controller";
|
||||||
}
|
break;
|
||||||
}
|
|
||||||
|
case 0x8:
|
||||||
|
return "Base System Peripheral";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0x9:
|
||||||
|
return "Input Device Controller";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0xA:
|
||||||
|
return "Docking station";
|
||||||
|
break;
|
||||||
|
case 0xB:
|
||||||
|
return "Processor";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0xC:
|
||||||
|
return "Serial Bus Controller";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0xD:
|
||||||
|
return "Wireless Controller";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0xE:
|
||||||
|
return "Intelligent Controller";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0xF:
|
||||||
|
return "Satellite Communication Controller";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0x10:
|
||||||
|
return "Encryption Controller";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0x11:
|
||||||
|
return "Signal Processing Controller";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0x12:
|
||||||
|
return "Processing Accelerator";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0x13:
|
||||||
|
return "Non-Essential Instrumentation";
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return "Unknown";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Found %d PCI devices!\n", devicesFound);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* PCI::getClassName (uint8_t ClassCode){
|
const char* getVendor( uint32_t VendorID){
|
||||||
bool isKnown = (ClassCode < PCI::KnownClassCodes);
|
|
||||||
return isKnown ? PCI::ClassCodeNames[ClassCode].name : "Unknown ClassCode";
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* PCI::getVendor( uint32_t VendorID){
|
|
||||||
switch (VendorID)
|
switch (VendorID)
|
||||||
{
|
{
|
||||||
case 0x8086:
|
case 0x8086:
|
||||||
return "Intel Corporation";
|
return "Intel Corporation";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x10DE:
|
case 0x10DE:
|
||||||
return "NVIDIA Corporation";
|
return "NVIDIA Corporation";
|
||||||
break;
|
break;
|
||||||
@ -88,77 +129,125 @@ const char* PCI::getVendor( uint32_t VendorID){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t PCI::GetDevice (int bus, int device, int function ){
|
uint32_t ConfigReadWord ( PCIBusAddress& PCIDeviceAddress , uint8_t offset){
|
||||||
return PCI::ConfigReadWord(bus, device, function,0x0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PCI::IsMultiFunctionDevice(PCIBusAddress& PCIDeviceAddress)
|
|
||||||
{
|
|
||||||
uint32_t header_information = ConfigReadWord(PCIDeviceAddress, 0xC);
|
|
||||||
return (((header_information>>16)
|
|
||||||
& 0x80)
|
|
||||||
>> 7 );
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t PCI::GetClassCodes( PCIBusAddress& PCIDeviceAddress ){
|
|
||||||
return (uint16_t)(ConfigReadWord(PCIDeviceAddress, 0x8) >> 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t PCI::GetHeaderType( PCIBusAddress& PCIDeviceAddress ){
|
|
||||||
uint32_t header_information = ConfigReadWord(PCIDeviceAddress , 0xC);
|
|
||||||
return (uint8_t) (
|
|
||||||
((header_information >> 16) //Get higher half
|
|
||||||
& 0x00FF) // Select the last two bytes
|
|
||||||
& 0x7F ); // Mask bit 7 as it indicates if the device is a mulit function device!
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t PCI::ConfigReadWord (uint8_t bus, uint8_t device, uint8_t func, uint8_t offset){
|
|
||||||
uint32_t address;
|
|
||||||
|
|
||||||
address = (uint32_t) (
|
|
||||||
((uint32_t) 1 << PCI_ENABLE_ADDR_SHIFT) |
|
|
||||||
((uint32_t)bus << PCI_BUS_ADDR_SHIFT) |
|
|
||||||
((uint32_t)device << PCI_DEVICE_ADDR_SHIFT) |
|
|
||||||
((uint32_t)func << PCI_FUNCTION_ADDR_SHIFT) |
|
|
||||||
offset );
|
|
||||||
|
|
||||||
outl(CONFIG_ADDRESS, address);
|
|
||||||
|
|
||||||
|
|
||||||
return inl(CONFIG_DATA);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t PCI::GetProgIF (PCIBusAddress& PCIDeviceAddress){
|
|
||||||
uint32_t data = ConfigReadWord(PCIDeviceAddress, 0x8);
|
|
||||||
return ((data >> 8) & 0xFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t PCI::ConfigReadWord ( PCIBusAddress& PCIDeviceAddress , uint8_t offset){
|
|
||||||
outl(CONFIG_ADDRESS , PCIDeviceAddress.getAddress() | offset );
|
outl(CONFIG_ADDRESS , PCIDeviceAddress.getAddress() | offset );
|
||||||
return inl(CONFIG_DATA);
|
return inl(CONFIG_DATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t GetProgIF (PCIBusAddress& PCIDeviceAddress){
|
||||||
uint32_t PCI::ReadBAR ( PCIBusAddress& PCIDeviceAddress, int bar_number){
|
uint32_t data = ConfigReadWord(PCIDeviceAddress, 0x8);
|
||||||
int offsetToBar = 0x10 + (bar_number* 0x4);
|
return ((data >> 8) & 0xFF);
|
||||||
return ConfigReadWord(PCIDeviceAddress, offsetToBar);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PCI::PrintPCIDevice (PCIBusAddress& PCIDeviceAddress)
|
uint32_t ReadBAR ( PCIBusAddress& PCIDeviceAddress, int bar_number){
|
||||||
|
int offsetToBar = 0x10 + (bar_number* 0x4);
|
||||||
|
return ConfigReadWord(PCIDeviceAddress, offsetToBar);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t ConfigReadWord (uint8_t bus, uint8_t device, uint8_t func, uint8_t offset){
|
||||||
|
uint32_t address;
|
||||||
|
|
||||||
|
address = (uint32_t) (
|
||||||
|
((uint32_t) 1 << PCI_ENABLE_ADDR_SHIFT) |
|
||||||
|
((uint32_t)bus << PCI_BUS_ADDR_SHIFT) |
|
||||||
|
((uint32_t)device << PCI_DEVICE_ADDR_SHIFT) |
|
||||||
|
((uint32_t)func << PCI_FUNCTION_ADDR_SHIFT) |
|
||||||
|
offset );
|
||||||
|
|
||||||
|
outl(CONFIG_ADDRESS, address);
|
||||||
|
|
||||||
|
|
||||||
|
return inl(CONFIG_DATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t GetHeaderType( PCIBusAddress& PCIDeviceAddress ){
|
||||||
|
uint32_t header_information = ConfigReadWord(PCIDeviceAddress , 0xC);
|
||||||
|
return (uint8_t) (
|
||||||
|
((header_information >> 16) //Get higher half
|
||||||
|
& 0x00FF) // Select the last two bytes
|
||||||
|
& 0x7F ); // Mask bit 7 as it indicates if the device is a mulit function device!
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t GetClassCodes( PCIBusAddress& PCIDeviceAddress ){
|
||||||
|
uint32_t classcodes = ConfigReadWord(PCIDeviceAddress, 0x8);
|
||||||
|
return (uint16_t)((uint32_t)classcodes >> 16);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsMultiFunctionDevice(PCIBusAddress& PCIDeviceAddress){
|
||||||
|
uint32_t header_information = ConfigReadWord(PCIDeviceAddress, 0xC);
|
||||||
|
return (((header_information>>16)
|
||||||
|
& 0x80)
|
||||||
|
>> 7 );
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintPCIDeviceInfo (PCIBusAddress& PCIDeviceAddress)
|
||||||
{
|
{
|
||||||
uint32_t DeviceID = (PCI::GetDevice(PCIDeviceAddress.bus, PCIDeviceAddress.device, PCIDeviceAddress.function) >> 16);
|
uint32_t DeviceID = (GetDevice(PCIDeviceAddress.bus, PCIDeviceAddress.device, PCIDeviceAddress.function) >> 16);
|
||||||
uint32_t VendorID = PCI::GetDevice(PCIDeviceAddress.bus, PCIDeviceAddress.device, PCIDeviceAddress.function) & 0xFFFF;
|
uint32_t VendorID = GetDevice(PCIDeviceAddress.bus, PCIDeviceAddress.device, PCIDeviceAddress.function) & 0xFFFF;
|
||||||
printf("Device found!\n");
|
printf("Device found!\n");
|
||||||
printf("Bus: %d, Device: %d, function: %d \n", PCIDeviceAddress.bus, PCIDeviceAddress.device, PCIDeviceAddress.function);
|
printf("Bus: %d, Device: %d, function: %d \n", PCIDeviceAddress.bus, PCIDeviceAddress.device, PCIDeviceAddress.function);
|
||||||
printf("DeviceID: 0x%x, Vendor: %s\n",
|
printf("DeviceID: 0x%x, Vendor: %s\n",
|
||||||
DeviceID
|
DeviceID
|
||||||
, PCI::getVendor(VendorID) );
|
, getVendor(VendorID) );
|
||||||
|
|
||||||
uint8_t header_type = PCI::GetHeaderType(PCIDeviceAddress);
|
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t header_type = GetHeaderType(PCIDeviceAddress);
|
||||||
printf( "Header type: 0x%x\n", header_type);
|
printf( "Header type: 0x%x\n", header_type);
|
||||||
|
|
||||||
uint16_t deviceClasses = PCI::GetClassCodes(PCIDeviceAddress);
|
uint16_t deviceClasses = GetClassCodes(PCIDeviceAddress);
|
||||||
|
printf("class: %s, subClass: %d\n\n", GetClassCodeName((deviceClasses >>8)), deviceClasses & 0xFF);
|
||||||
|
|
||||||
printf("class: %s, subClass: %d\n\n", PCI::getClassName((deviceClasses >> 8)), deviceClasses & 0xFF);
|
}
|
||||||
|
|
||||||
|
void PCI_Enumerate(){
|
||||||
|
|
||||||
|
int devicesFound = 0;
|
||||||
|
|
||||||
|
printf("Start finding devices, Found: %d devices");
|
||||||
|
// loop through all possible busses, devices and their functions;
|
||||||
|
for( int bus = 0 ; bus < 256 ; bus++)
|
||||||
|
{
|
||||||
|
|
||||||
|
for(int device = 0; device < 32 ; device ++)
|
||||||
|
{
|
||||||
|
int function = 0;
|
||||||
|
|
||||||
|
uint64_t DeviceIdentify = ConfigReadWord(bus, device, function,0x0);
|
||||||
|
uint32_t DeviceID = GetDevice(bus, device, function) >> 16;
|
||||||
|
|
||||||
|
if( DeviceID != 0xFFFF){
|
||||||
|
PCIBusAddress busAddress =
|
||||||
|
PCIBusAddress{bus, device, function };
|
||||||
|
|
||||||
|
PrintPCIDeviceInfo(busAddress);
|
||||||
|
|
||||||
|
// iterate over the functions if it is a multi function device!
|
||||||
|
if( IsMultiFunctionDevice(busAddress) ){
|
||||||
|
printf("Multi function device! \n");
|
||||||
|
printf("Check remaining Functions\n");
|
||||||
|
for ( function = 1 ; function < 8; function++)
|
||||||
|
{
|
||||||
|
uint32_t DeviceID = GetDevice(bus, device, function) >> 16;
|
||||||
|
|
||||||
|
if( DeviceID != 0xFFFF){
|
||||||
|
PCIBusAddress busAddress2 = PCIBusAddress{bus, device, function};
|
||||||
|
PrintPCIDeviceInfo(busAddress2);
|
||||||
|
devicesFound++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
devicesFound++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Found %d PCI devices!\n", devicesFound);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
@ -7,55 +7,30 @@
|
|||||||
// Configuration Space Access Mechanism #1
|
// Configuration Space Access Mechanism #1
|
||||||
#define CONFIG_ADDRESS 0xCF8 // Configuration adress that is to be accessed
|
#define CONFIG_ADDRESS 0xCF8 // Configuration adress that is to be accessed
|
||||||
#define CONFIG_DATA 0xCFC // Will do the actual configuration operation
|
#define CONFIG_DATA 0xCFC // Will do the actual configuration operation
|
||||||
#define PCI_BUS_ADDR_SHIFT 16
|
|
||||||
#define PCI_DEVICE_ADDR_SHIFT 11
|
|
||||||
#define PCI_FUNCTION_ADDR_SHIFT 8
|
|
||||||
#define PCI_ENABLE_ADDR_SHIFT 31
|
|
||||||
|
|
||||||
class PCI {
|
extern const char* ClassCodeTable [0x13];
|
||||||
public:
|
|
||||||
static void Scan();
|
|
||||||
static uint32_t ConfigReadWord ( PCIBusAddress& PCIDeviceAddress , uint8_t offset);
|
|
||||||
static uint8_t GetProgIF (PCIBusAddress& PCIDeviceAddress);
|
|
||||||
static uint32_t ReadBAR ( PCIBusAddress& PCIDeviceAddress, int bar_number);
|
|
||||||
static uint32_t ConfigReadWord (uint8_t bus, uint8_t device, uint8_t func, uint8_t offset);
|
|
||||||
static uint8_t GetHeaderType( PCIBusAddress& PCIDeviceAddress );
|
|
||||||
static uint16_t GetClassCodes( PCIBusAddress& PCIDeviceAddress );
|
|
||||||
static bool IsMultiFunctionDevice(PCIBusAddress& PCIDeviceAddress);
|
|
||||||
static uint64_t GetDevice (int bus, int device, int function );
|
|
||||||
|
|
||||||
|
// Note: this could be used to make the api for receiving PCI class codes a bit
|
||||||
|
// nicer.
|
||||||
|
struct ClassCodes {
|
||||||
|
uint8_t ClassCode;
|
||||||
|
uint8_t DeviceClass;
|
||||||
|
}__attribute__((packed));
|
||||||
|
|
||||||
static const char* getClassName (uint8_t ClassCode);
|
uint32_t ConfigReadWord (uint8_t bus, uint8_t device, uint8_t func, uint8_t offset);
|
||||||
static const char* getVendor( uint32_t VendorID);
|
uint32_t ConfigReadWord ( PCIBusAddress& PCIDeviceAddress , uint8_t offset);
|
||||||
static void PrintPCIDevice(PCIBusAddress& PCIDevice);
|
|
||||||
|
|
||||||
private:
|
inline uint64_t GetDevice (int bus, int device, int function ){
|
||||||
struct ClassCode {
|
return ConfigReadWord(bus, device, function,0x0);
|
||||||
const char* name;
|
}
|
||||||
uint8_t code;
|
|
||||||
};
|
|
||||||
static constexpr ClassCode ClassCodeNames []= {
|
|
||||||
{"Unclassified", 0x0},
|
|
||||||
{"MassStorage Controller", 0x1},
|
|
||||||
{"Network Controller", 0x2},
|
|
||||||
{"Display Controller", 0x3},
|
|
||||||
{"Multimedia Controller", 0x4},
|
|
||||||
{"Memory Controller", 0x5},
|
|
||||||
{"Bridge", 0x6},
|
|
||||||
{"Simple Communication Controller", 0x7},
|
|
||||||
{"Base System Peripheral", 0x8},
|
|
||||||
{"Input Device Controller", 0x9},
|
|
||||||
{"Docking Station", 0xA},
|
|
||||||
{"Processor", 0xB},
|
|
||||||
{"Serial Bus Controller", 0xC},
|
|
||||||
{ "Wireless Controller", 0xD},
|
|
||||||
{"Intelligent Controller", 0xE},
|
|
||||||
{"Satellite Communication Controller", 0xF},
|
|
||||||
{"Encryption Controller", 0x10},
|
|
||||||
{"Signal Processing Controller", 0x11},
|
|
||||||
{ "Processing Accelerator", 0x12},
|
|
||||||
{ "Non-Essential Instrumentation", 0x13}
|
|
||||||
};
|
|
||||||
static const uint8_t KnownClassCodes = sizeof(ClassCodeNames) / sizeof(ClassCode);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
uint8_t GetHeaderType( PCIBusAddress& PCIDeviceAddress );
|
||||||
|
|
||||||
|
uint16_t GetClassCodes( PCIBusAddress& PICDeviceAddress );
|
||||||
|
const char* getVendor( uint64_t VendorID);
|
||||||
|
const char* GetClassCodeName (uint64_t ClassCode );
|
||||||
|
|
||||||
|
uint8_t GetProgIF (PCIBusAddress& PCIDeviceAddress);
|
||||||
|
void PCI_Enumerate();
|
||||||
|
|
||||||
|
uint32_t ReadBAR ( PCIBusAddress& PCIDeviceAddress, int bar_number);
|
@ -1,16 +1,22 @@
|
|||||||
/*
|
|
||||||
Copyright © Nigel Barink 2023
|
extern "C"
|
||||||
*/
|
{
|
||||||
extern "C"{
|
#include "../lib/include/string.h"
|
||||||
#include "../lib/include/string.h"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "prekernel/bootstructure.h"
|
||||||
|
|
||||||
#include "memory/memory.h"
|
#include "memory/memory.h"
|
||||||
|
#include "memory/memoryinfo.h"
|
||||||
|
#include "memory/memory.h"
|
||||||
|
#include "memory/VirtualMemoryManager.h"
|
||||||
#include "memory/KernelHeap.h"
|
#include "memory/KernelHeap.h"
|
||||||
#include "memory/gdt/gdtc.h"
|
#include "memory/gdt/gdtc.h"
|
||||||
#include "memory/TaskStateSegment.h"
|
#include "memory/TaskStateSegment.h"
|
||||||
|
|
||||||
#include "supervisorterminal/superVisorTerminal.h"
|
#include "supervisorterminal/superVisorTerminal.h"
|
||||||
|
|
||||||
|
#include "drivers/io/io.h"
|
||||||
#include "drivers/vga/VBE.h"
|
#include "drivers/vga/VBE.h"
|
||||||
#include "drivers/pci/pci.h"
|
#include "drivers/pci/pci.h"
|
||||||
#include "drivers/pit/pit.h"
|
#include "drivers/pit/pit.h"
|
||||||
@ -18,59 +24,74 @@ extern "C"{
|
|||||||
#include "drivers/ide/ide.h"
|
#include "drivers/ide/ide.h"
|
||||||
|
|
||||||
#include "terminal/kterm.h"
|
#include "terminal/kterm.h"
|
||||||
|
|
||||||
|
#include "prekernel/multiboot.h"
|
||||||
|
#include "bootinfo.h"
|
||||||
|
|
||||||
|
#include "bootcheck.h"
|
||||||
|
|
||||||
#include "interrupts/idt.h"
|
#include "interrupts/idt.h"
|
||||||
|
#include "time.h"
|
||||||
|
#include "cpu.h"
|
||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
|
#include "time.h"
|
||||||
|
#include "definitions.h"
|
||||||
extern "C" void LoadGlobalDescriptorTable();
|
extern "C" void LoadGlobalDescriptorTable();
|
||||||
extern "C" void jump_usermode();
|
|
||||||
|
|
||||||
void set_protected_bit()
|
|
||||||
|
/*
|
||||||
|
Copyright © Nigel Barink 2023
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern "C" void kernel_main ()
|
||||||
{
|
{
|
||||||
// Set the protected bit of control register 0
|
/*
|
||||||
// this will put the CPU into protected mode
|
* Show a little banner for cuteness
|
||||||
// NOTE: This should really be a assembly procedure
|
*/
|
||||||
// We cant directly write to control register 0
|
printf("|=== BarinkOS ===|\n");
|
||||||
// therefor we copy the value of control register 0 into eax
|
startSuperVisorTerminal();
|
||||||
// once we are done manipulating the value we write the value in
|
}
|
||||||
// eax back to control register 0
|
|
||||||
|
|
||||||
asm volatile("mov %cr0, %eax ");
|
extern "C" void early_main()
|
||||||
asm volatile("or $1, %eax");
|
|
||||||
asm volatile("mov %eax, %cr0");
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" void kernel ()
|
|
||||||
{
|
{
|
||||||
|
|
||||||
init_serial();
|
init_serial();
|
||||||
kterm_init();
|
kterm_init();
|
||||||
|
|
||||||
|
|
||||||
setup_tss();
|
setup_tss();
|
||||||
initGDT();
|
initGDT();
|
||||||
initidt();
|
initidt();
|
||||||
LoadGlobalDescriptorTable();
|
LoadGlobalDescriptorTable();
|
||||||
flush_tss();
|
flush_tss();
|
||||||
printf("Memory setup complete!\n");
|
printf("Memory setup complete!\n");
|
||||||
|
|
||||||
// Enable interrupts
|
// Enable interrupts
|
||||||
asm volatile("STI");
|
asm volatile("STI");
|
||||||
initHeap();
|
|
||||||
|
ACPI::initialize();
|
||||||
|
PCI_Enumerate();
|
||||||
|
|
||||||
|
TestIDEController();
|
||||||
|
|
||||||
|
initHeap();
|
||||||
|
|
||||||
|
printf("Enable Protected mode and jump to kernel main\n");
|
||||||
|
|
||||||
|
|
||||||
|
// Set the protected bit of control register 0
|
||||||
|
// this will put the CPU into protected mode
|
||||||
|
// NOTE: This should really be a assembly procedure
|
||||||
|
// We cant directly write to control register 0
|
||||||
|
// therefor we copy the value of control register 0 into eax
|
||||||
|
// once we are done manipulating the value we write the value in
|
||||||
|
// eax back to control register 0
|
||||||
|
|
||||||
|
asm volatile("mov %cr0, %eax ");
|
||||||
|
asm volatile("or $1, %eax");
|
||||||
|
asm volatile("mov %eax, %cr0");
|
||||||
|
|
||||||
pit_initialise();
|
pit_initialise();
|
||||||
|
|
||||||
ACPI::initialize();
|
kernel_main();
|
||||||
PCI::Scan();
|
|
||||||
|
}
|
||||||
TestIDEController();
|
|
||||||
|
|
||||||
printf("Enable Protected mode and jump to kernel main\n");
|
|
||||||
|
|
||||||
set_protected_bit();
|
|
||||||
|
|
||||||
#ifdef USERMODE_RELEASE
|
|
||||||
// Lets jump into user mode
|
|
||||||
jump_usermode();
|
|
||||||
#else
|
|
||||||
startSuperVisorTerminal();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -4,13 +4,7 @@
|
|||||||
#include "../filesystem/FAT/BiosParameterBlock.h"
|
#include "../filesystem/FAT/BiosParameterBlock.h"
|
||||||
#include "../filesystem/FAT/DirectoryEntry.h"
|
#include "../filesystem/FAT/DirectoryEntry.h"
|
||||||
bool isRunning = true;
|
bool isRunning = true;
|
||||||
extern "C" void startSuperVisorTerminal()
|
void startSuperVisorTerminal(){
|
||||||
{
|
|
||||||
/*
|
|
||||||
* Show a little banner for cuteness
|
|
||||||
*/
|
|
||||||
printf("|=== BarinkOS ===|\n");
|
|
||||||
|
|
||||||
while (isRunning){
|
while (isRunning){
|
||||||
|
|
||||||
printf("SUPERVISOR:>$ " );
|
printf("SUPERVISOR:>$ " );
|
||||||
@ -121,7 +115,7 @@ extern "C" void startSuperVisorTerminal()
|
|||||||
uint16_t biosparameterblock[256];
|
uint16_t biosparameterblock[256];
|
||||||
ATA_DEVICE::Read(BUS_PORT::Primary, DEVICE_DRIVE::MASTER, mbr->TableEntries[0].LBA_partition_start, biosparameterblock);
|
ATA_DEVICE::Read(BUS_PORT::Primary, DEVICE_DRIVE::MASTER, mbr->TableEntries[0].LBA_partition_start, biosparameterblock);
|
||||||
|
|
||||||
auto* bpb = (BiosParameterBlock*) biosparameterblock;
|
BiosParameterBlock* bpb = (BiosParameterBlock*) biosparameterblock;
|
||||||
|
|
||||||
|
|
||||||
printf("\nBPB: Bytes per Sector %d\n", bpb->BytesPerSector );
|
printf("\nBPB: Bytes per Sector %d\n", bpb->BytesPerSector );
|
||||||
@ -144,8 +138,8 @@ extern "C" void startSuperVisorTerminal()
|
|||||||
ATA_DEVICE::Read(BUS_PORT::Primary, DEVICE_DRIVE::MASTER, FATAddress, FAT );
|
ATA_DEVICE::Read(BUS_PORT::Primary, DEVICE_DRIVE::MASTER, FATAddress, FAT );
|
||||||
|
|
||||||
// Show data in terminal
|
// Show data in terminal
|
||||||
for(unsigned short i : FAT) {
|
for(int i = 0; i < 256; i++ ) {
|
||||||
printf("%x ", i);
|
printf("%x ", FAT[i]);
|
||||||
}
|
}
|
||||||
kterm_put('\n');
|
kterm_put('\n');
|
||||||
|
|
||||||
@ -155,35 +149,33 @@ extern "C" void startSuperVisorTerminal()
|
|||||||
|
|
||||||
uint16_t data2 [256];
|
uint16_t data2 [256];
|
||||||
ATA_DEVICE::Read(BUS_PORT::Primary, DEVICE_DRIVE::MASTER, RootDirectoryRegion, data2 );
|
ATA_DEVICE::Read(BUS_PORT::Primary, DEVICE_DRIVE::MASTER, RootDirectoryRegion, data2 );
|
||||||
auto* RootDirectory = (DirectoryEntry*) data2;
|
DirectoryEntry* RootDirectory = (DirectoryEntry*) data2;
|
||||||
// List files in root
|
// List files in root
|
||||||
for(int i= 0; i < bpb->NumberOfDirectoryEntries ; i++ )
|
for(int i= 0; i < bpb->NumberOfDirectoryEntries ; i++ )
|
||||||
{
|
{
|
||||||
auto* entry = (DirectoryEntry*)((uint32_t) RootDirectory + (i * sizeof(DirectoryEntry)));
|
DirectoryEntry* entry = (DirectoryEntry*)((uint32_t) RootDirectory + (i * sizeof(DirectoryEntry)));
|
||||||
|
|
||||||
if( entry->filename[0] == (uint8_t) 0x00 )
|
if( entry->filename[0] == (uint8_t) 0x00 )
|
||||||
break; // There are no more entries in this directory or the entry is free
|
break; // There are no more entries in this directory or the entry is free
|
||||||
|
|
||||||
if( (entry->attribute & 0x01) == 0x01 || (entry->attribute & 0x20) == 0x20)
|
if( entry->attribute & 0x01 == 0x01 || entry->attribute & 0x20 == 0x20)
|
||||||
continue; // Skip listing if hidden or Achieve flag is set
|
continue; // Skip listing if hidden or Achieve flag is set
|
||||||
|
|
||||||
// Print the filename;
|
// Print the filename;
|
||||||
for(char n : entry->filename){
|
for( int n = 0; n < 8; n++ ){
|
||||||
if(n == 0x20)
|
if(entry->filename[n] == 0x20)
|
||||||
break;
|
break;
|
||||||
kterm_put(n);
|
kterm_put(entry->filename[n]);
|
||||||
}
|
}kterm_put('\n');
|
||||||
kterm_put('\n');
|
|
||||||
|
|
||||||
for(unsigned char n : entry->Extension){
|
for( int n = 0; n < 3; n++){
|
||||||
kterm_put(n);
|
kterm_put(entry->Extension[n]);
|
||||||
}
|
}kterm_put('\n');
|
||||||
kterm_put('\n');
|
|
||||||
|
|
||||||
printf("Attribute: %x \n" , entry->attribute);
|
printf("Attribute: %x \n" , entry->attribute);
|
||||||
printf("FileSize: %d Bytes\n", entry->FilesizeInBytes);
|
printf("FileSize: %d Bytes\n", entry->FilesizeInBytes);
|
||||||
|
|
||||||
if( entry->FilesizeInBytes != 0x0 || (entry->attribute & 0x8) == 0x0){
|
if( entry->FilesizeInBytes != 0x0 || entry->attribute & 0x8 == 0x0){
|
||||||
printf("Show contents");
|
printf("Show contents");
|
||||||
|
|
||||||
printf( "Start cluster of the file: 0x%x\n" , entry->StartingCluster);
|
printf( "Start cluster of the file: 0x%x\n" , entry->StartingCluster);
|
||||||
@ -195,11 +187,11 @@ extern "C" void startSuperVisorTerminal()
|
|||||||
|
|
||||||
uint16_t dataBlob [256];
|
uint16_t dataBlob [256];
|
||||||
ATA_DEVICE::Read(BUS_PORT::Primary, DEVICE_DRIVE::MASTER, sector, dataBlob );
|
ATA_DEVICE::Read(BUS_PORT::Primary, DEVICE_DRIVE::MASTER, sector, dataBlob );
|
||||||
for(unsigned short n : dataBlob)
|
for( int n = 0; n < 256; n++)
|
||||||
{
|
{
|
||||||
kterm_put(n & 0x00ff);
|
kterm_put(dataBlob[n] & 0x00ff);
|
||||||
|
|
||||||
kterm_put(n >> 8);
|
kterm_put(dataBlob[n] >> 8);
|
||||||
}kterm_put('\n');
|
}kterm_put('\n');
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,4 +8,4 @@ extern "C" {
|
|||||||
#include "../../lib/include/string.h"
|
#include "../../lib/include/string.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void startSuperVisorTerminal();
|
void startSuperVisorTerminal();
|
Loading…
x
Reference in New Issue
Block a user