More work

This commit is contained in:
pjht 2019-03-12 17:26:19 -05:00
parent 99d7fed783
commit f2ebc5e31e
7 changed files with 44 additions and 18 deletions

View File

@ -105,6 +105,20 @@ static void write_tss(int32_t num, uint16_t ss0, uint32_t esp0) {
tss.ss = tss.ds = tss.es = tss.fs = tss.gs = 0x13; tss.ss = tss.ds = tss.es = tss.fs = tss.gs = 0x13;
} }
void allow_all_ports() {
for (int i=0;i<8192;i++) {
tss.iopb[i]=0;
}
}
void block_all_ports() {
for (int i=0;i<8192;i++) {
tss.iopb[i]=0xFF;
}
}
void gdt_init() { void gdt_init() {
set_entry(0,0,0,0); set_entry(0,0,0,0);
set_entry(1,0,0xFFFFF,0x9A); set_entry(1,0,0xFFFFF,0x9A);

View File

@ -3,5 +3,6 @@
void gdt_init(); void gdt_init();
void tss_stack_reset(); void tss_stack_reset();
void allow_all_ports();
void block_all_ports();
#endif #endif

View File

@ -80,11 +80,8 @@ void* alloc_pages(int num_pages) {
} }
} }
if (remaining_blks!=0) { if (remaining_blks!=0) {
return NULL; klog("PANIC","Out of memory");
} }
// for (int i=0;i<num_pages;i++) {
// vmem_set_bmap_bit(bmap_index+i);
// }
void* addr=(void*)(bmap_index<<12); void* addr=(void*)(bmap_index<<12);
map_pages(addr,phys_addr,num_pages,1,1); map_pages(addr,phys_addr,num_pages,1,1);
return addr; return addr;

View File

@ -138,5 +138,10 @@ void tasking_yield() {
1: \ 1: \
"); ");
} }
if (task->priv) {
allow_all_ports();
} else {
block_all_ports();
}
switchTask(&oldCurr->regs, &currentTask->regs); switchTask(&oldCurr->regs, &currentTask->regs);
} }

View File

@ -31,50 +31,56 @@ static void write_config(uint8_t bus,uint8_t device,uint8_t func,uint8_t offset,
} }
pci_dev_common_info* pci_get_dev_info(uint8_t bus,uint8_t device,uint8_t func) { pci_dev_common_info* pci_get_dev_info(uint8_t bus,uint8_t device,uint8_t func) {
uint32_t* info=malloc(sizeof(uint32_t)*4); uint32_t* info=malloc(sizeof(uint32_t)*5);
info[0]=read_config(bus,device,func,0); info[0]=read_config(bus,device,func,0);
info[1]=read_config(bus,device,func,4); info[1]=read_config(bus,device,func,4);
info[2]=read_config(bus,device,func,8); info[2]=read_config(bus,device,func,8);
info[3]=read_config(bus,device,func,0xC); info[3]=read_config(bus,device,func,0xC);
return (pci_dev_common_info*)info; pci_dev_common_info* pci_info=(pci_dev_common_info*)info;
pci_info->bus=bus;
pci_info->device=device;
pci_info->func=func;
return pci_info;
} }
void pci_set_dev_info(uint8_t bus,uint8_t device,uint8_t func,pci_dev_common_info* inf) { void pci_set_dev_info(pci_dev_common_info* inf) {
uint32_t* info=(uint32_t*)inf; uint32_t* info=(uint32_t*)inf;
write_config(bus,device,func,0,info[0]); write_config(inf->bus,inf->device,inf->func,0,info[0]);
write_config(bus,device,func,4,info[1]); write_config(inf->bus,inf->device,inf->func,4,info[1]);
write_config(bus,device,func,8,info[2]); write_config(inf->bus,inf->device,inf->func,8,info[2]);
write_config(bus,device,func,0xC,info[3]); write_config(inf->bus,inf->device,inf->func,0xC,info[3]);
} }
static void checkFunction(uint8_t bus,uint8_t device,uint8_t func,pci_dev_common_info* info); static void checkFunction(pci_dev_common_info* info);
static void checkDevice(uint8_t bus, uint8_t device) { static void checkDevice(uint8_t bus, uint8_t device) {
pci_dev_common_info* info=pci_get_dev_info(bus,device,0); pci_dev_common_info* info=pci_get_dev_info(bus,device,0);
if(info->vend_id==0xFFFF||info->class_code==0xFF) { if(info->vend_id==0xFFFF||info->class_code==0xFF) {
return; return;
} }
checkFunction(bus,device,0,info); checkFunction(info);
if((info->header_type&0x80)!=0) { if((info->header_type&0x80)!=0) {
for(uint8_t function=1;function<8;function++) { for(uint8_t function=1;function<8;function++) {
pci_dev_common_info* info=pci_get_dev_info(bus,device,function); pci_dev_common_info* info=pci_get_dev_info(bus,device,function);
if(info->vend_id!=0xFFFF&&info->class_code!=0xFF) { if(info->vend_id!=0xFFFF&&info->class_code!=0xFF) {
checkFunction(bus,device,function,info); checkFunction(info);
} }
} }
} }
} }
static void checkFunction(uint8_t bus,uint8_t device,uint8_t func,pci_dev_common_info* info) { static void checkFunction(pci_dev_common_info* info) {
if (pci_num_devs==max_devs) { if (pci_num_devs==max_devs) {
max_devs+=32; max_devs+=32;
pci_devs=malloc(sizeof(pci_dev_common_info)*max_devs); pci_devs=malloc(sizeof(pci_dev_common_info)*max_devs);
} }
// pci_devs[pci_num_devs]=info;
// pci_num_devs++;
klog("INFO","Found PCI device. Class code:%x, Subclass:%x Prog IF:%x",info->class_code,info->subclass,info->prog_if); klog("INFO","Found PCI device. Class code:%x, Subclass:%x Prog IF:%x",info->class_code,info->subclass,info->prog_if);
klog("INFO","Vendor ID:%x, Device ID:%x",info->vend_id,info->dev_id); klog("INFO","Vendor ID:%x, Device ID:%x",info->vend_id,info->dev_id);
if ((info->header_type&0x7f)==0) { if ((info->header_type&0x7f)==0) {
for (uint8_t offset=0x10;offset<0x10+4*6;offset+=4) { for (uint8_t offset=0x10;offset<0x10+4*6;offset+=4) {
uint32_t bar=read_config(bus,device,func,offset); uint32_t bar=read_config(info->bus,info->device,info->func,offset);
if (bar!=0) { if (bar!=0) {
if (bar&0x1) { if (bar&0x1) {
klog("INFO","IO BAR%d:%x",(offset-0x10)/4,bar&0xFFFFFFFC); klog("INFO","IO BAR%d:%x",(offset-0x10)/4,bar&0xFFFFFFFC);

View File

@ -8,6 +8,6 @@
#define PCI_CONFIG_DATA 0xCFC #define PCI_CONFIG_DATA 0xCFC
pci_dev_common_info* pci_get_dev_info(uint8_t bus,uint8_t device,uint8_t func); pci_dev_common_info* pci_get_dev_info(uint8_t bus,uint8_t device,uint8_t func);
void pci_set_dev_info(uint8_t bus,uint8_t device,uint8_t func,pci_dev_common_info* inf); void pci_set_dev_info(pci_dev_common_info* inf);
#endif #endif

View File

@ -16,6 +16,9 @@ typedef struct {
uint8_t lat_timer; uint8_t lat_timer;
uint8_t header_type; uint8_t header_type;
uint8_t bist; uint8_t bist;
uint16_t bus;
uint8_t device;
uint8_t func;
} __attribute__((packed)) pci_dev_common_info; } __attribute__((packed)) pci_dev_common_info;
typedef enum { typedef enum {