initial creation of trunk directory
git-svn-id: svn://anubis/hos/trunk@1 5b3e749e-e535-0410-8002-a9bb6afbdfca
This commit is contained in:
1 parent
0aaf5db5ad
commit
43d1ca0e18
113 files changed
-12671
No files matched your search
@@ -1,42 +0,0 @@
|
||||
// cmos.c
|
||||
// Author: Josh Holtrop
|
||||
// Created: 02/26/04
|
||||
// Implements various CMOS function calls
|
||||
|
||||
#include "hos_defines.h"
|
||||
#include "sys/cmos.h"
|
||||
#include "sys/io.h"
|
||||
|
||||
//Returns the cmos type of floppy disk drive 0 (0 = not present)
|
||||
unsigned char cmos_getfd0()
|
||||
{
|
||||
outportb(0x70, 0x10);
|
||||
return (inportb(0x71) >> 4);
|
||||
}
|
||||
|
||||
|
||||
//Returns the cmos type of floppy disk drive 1 (0 = not present)
|
||||
unsigned char cmos_getfd1()
|
||||
{
|
||||
outportb(0x70, 0x10);
|
||||
return (inportb(0x71) & 0x0F);
|
||||
}
|
||||
|
||||
|
||||
//Returns the cmos type of hard disk drive 0 (0 = not present)
|
||||
unsigned char cmos_gethd0()
|
||||
{
|
||||
outportb(0x70, 0x12);
|
||||
return (inportb(0x71) >> 4);
|
||||
}
|
||||
|
||||
|
||||
//Returns the cmos type of hard disk drive 1 (0 = not present)
|
||||
unsigned char cmos_gethd1()
|
||||
{
|
||||
outportb(0x70, 0x12);
|
||||
return (inportb(0x71) & 0x0F);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
// cmos.h
|
||||
// Author: Josh Holtrop
|
||||
// Created: 02/26/04
|
||||
// Implements various CMOS function calls
|
||||
|
||||
#include "hos_defines.h"
|
||||
|
||||
#ifndef __HOS_CMOS__
|
||||
#define __HOS_CMOS__ __HOS_CMOS__
|
||||
|
||||
unsigned char cmos_getfd0();
|
||||
unsigned char cmos_getfd1();
|
||||
unsigned char cmos_gethd0();
|
||||
unsigned char cmos_gethd1();
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
// io.h
|
||||
// Author: Josh Holtrop
|
||||
// Created: 02/26/04
|
||||
// Implements basic port input/output functions
|
||||
|
||||
#ifndef __HOS_IO__
|
||||
#define __HOS_IO__ __HOS_IO__
|
||||
|
||||
#include "hos_defines.h"
|
||||
|
||||
//void outportb(unsigned int port, unsigned char value);
|
||||
//inline void outportw(unsigned int port, unsigned int value);
|
||||
//inline unsigned char inportb(unsigned short port);
|
||||
|
||||
//Writes a byte out to a port
|
||||
static inline void outportb(unsigned int port, unsigned int value) // Output a byte to a port
|
||||
{
|
||||
asm volatile ("outb %%al,%%dx"::"d" (port), "a" (value));
|
||||
}
|
||||
|
||||
//Writes a word out to a port
|
||||
static inline void outportw(unsigned int port, unsigned int value) // Output a word to a port
|
||||
{
|
||||
asm volatile ("outw %%ax,%%dx"::"d" (port), "a" (value));
|
||||
}
|
||||
|
||||
//Writes a dword out to a port
|
||||
static inline void outportd(unsigned int port, unsigned int value) // Output a word to a port
|
||||
{
|
||||
asm volatile ("outl %%eax,%%dx"::"d" (port), "a" (value));
|
||||
}
|
||||
|
||||
//Reads a byte from a port
|
||||
static inline unsigned char inportb(unsigned int port)
|
||||
{
|
||||
unsigned char ret_val;
|
||||
asm volatile("inb %w1,%b0" : "=a"(ret_val) : "d"(port));
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
//Reads a word from a port
|
||||
static inline unsigned short inportw(unsigned int port)
|
||||
{
|
||||
unsigned int ret_val;
|
||||
asm volatile("inw %w1,%w0" : "=a"(ret_val) : "d"(port));
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
//Reads a dword from a port
|
||||
static inline unsigned int inportd(unsigned int port)
|
||||
{
|
||||
unsigned int ret_val;
|
||||
asm volatile("inl %w1,%0" : "=a"(ret_val) : "d"(port));
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
// pci.cpp
|
||||
// Author: Josh Holtrop
|
||||
// Date: 07/13/05
|
||||
// Modified: 07/17/05
|
||||
|
||||
extern "C" {
|
||||
#include "hos_defines.h"
|
||||
#include "display/kout.h"
|
||||
#include "sys/io.h"
|
||||
}
|
||||
|
||||
#include "pci.h"
|
||||
#include "lang/vector.h"
|
||||
|
||||
vector<pci_header_t> *pci_devices;
|
||||
|
||||
int pci_init()
|
||||
{
|
||||
pci_devices = new vector<pci_header_t>;
|
||||
pci_scanBus(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void pci_scanBus(u32_t bus)
|
||||
{
|
||||
pci_header_t pciHdr;
|
||||
u32_t dev, func, off, reg, numFuncs;
|
||||
for (dev = 0; dev < 32; dev++)
|
||||
{
|
||||
numFuncs = 1;
|
||||
for (func = 0; func < 8; func++)
|
||||
{
|
||||
reg = pci_readConfigRegister(bus, dev, func, 0);
|
||||
if (reg != 0 && reg != 0xFFFFFFFF)
|
||||
{
|
||||
for (off = 0; off < 0x40; off += 4)
|
||||
*((u32_t *)(((u32_t)&pciHdr)+off)) = pci_readConfigRegister(bus, dev, func, off);
|
||||
pci_devices->add(pciHdr);
|
||||
if (func == 0 && (pciHdr.header & 0x80))
|
||||
numFuncs = 8;
|
||||
kprintf("PCI device %d.%d.%d:\t(%s)\n", bus, dev, func, pci_getDeviceClass(pciHdr.cls, pciHdr.subclass, pciHdr.progif));
|
||||
if ((pciHdr.header & 0x7F) == 1)
|
||||
pci_scanBus(pciHdr.h1_bus1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
u32_t pci_readConfigRegister(u32_t bus, u32_t dev, u32_t func, u32_t offset)
|
||||
{
|
||||
outportd(PCI_CONFIG_ADDRESS,
|
||||
0x80000000 |
|
||||
((bus & 0xFF) << 16) |
|
||||
((dev & 0x1F) << 11) |
|
||||
((func & 0x7) << 8) |
|
||||
(offset & 0xFC));
|
||||
return inportd(PCI_CONFIG_DATA);
|
||||
}
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
// pci.h
|
||||
// Author: Josh Holtrop
|
||||
// Date: 07/13/05
|
||||
// Modified: 07/13/05
|
||||
|
||||
#ifndef __HOS_PCI__
|
||||
#define __HOS_PCI__ __HOS_PCI__
|
||||
|
||||
#define PCI_CONFIG_ADDRESS 0xCF8
|
||||
#define PCI_CONFIG_DATA 0xCFC
|
||||
#define PCI_HEADER_MF_MASK 0x80
|
||||
|
||||
#include "hos_defines.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8_t subclass;
|
||||
u8_t progif;
|
||||
char *desc;
|
||||
} pci_class_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u16_t vendorID; /* 0x00 Vender ID Number */
|
||||
u16_t deviceID; /* 0x02 Device ID Number */
|
||||
u16_t command; /* 0x04 Command Register */
|
||||
u16_t status; /* 0x06 Status Register */
|
||||
u8_t revision; /* 0x08 Revision ID */
|
||||
u8_t progif; /* 0x09 Programming Interface */
|
||||
u8_t subclass; /* 0x0A Subclass Number */
|
||||
u8_t cls; /* 0x0B PCI Device Class */
|
||||
u8_t cacheLineSize; /* 0x0C Cache Line Size (for DMA) */
|
||||
u8_t latency; /* 0x0D Latency Timer (PCI Bus cycles) */
|
||||
u8_t header; /* 0x0E bit7:multifunc, 0-6: header format */
|
||||
u8_t bist; /* 0x0F Built-In Self Test Result */
|
||||
/* Header-specific fields */
|
||||
u32_t bar0; /* 0x10 */
|
||||
u32_t bar1; /* 0x14 */
|
||||
union { /* 0x18 */
|
||||
u32_t bar2;
|
||||
struct {
|
||||
u8_t h1_bus0;
|
||||
u8_t h1_bus1;
|
||||
u8_t h1_secBus;
|
||||
u8_t h1_secLatency;
|
||||
};
|
||||
};
|
||||
u32_t bar3; /* 0x1C */
|
||||
u32_t bar4; /* 0x20 */
|
||||
u32_t bar5; /* 0x24 */
|
||||
u32_t cardbusCIS; /* 0x28 ro */
|
||||
u16_t ssVendorID; /* 0x2C */
|
||||
u16_t ssID; /* 0x2E */
|
||||
u32_t expansionAddr; /* 0x30 */
|
||||
u32_t reserved[2]; /* 0x34 */
|
||||
u8_t irq; /* 0x3C IRQ Number, 0 if none */
|
||||
u8_t intPin; /* 0x3D Interrupt Pin, 0 if none, ro */
|
||||
u8_t minGrant; /* 0x3E 250ns units, ro */
|
||||
u8_t maxLatency; /* 0x3F 250ns units, ro */
|
||||
} pci_header_t;
|
||||
|
||||
#ifdef _HOS_CPP_
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int pci_init();
|
||||
u32_t pci_readConfigRegister(u32_t bus, u32_t dev, u32_t func, u32_t offset);
|
||||
char *pci_getDeviceClass(u8_t cls, u8_t sub, u8_t progif);
|
||||
void pci_scanBus(u32_t bus);
|
||||
|
||||
#ifdef _HOS_CPP_
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,112 +0,0 @@
|
||||
// pci_classes.c
|
||||
// Author: Josh Holtrop
|
||||
// Date: 07/21/05
|
||||
// Modified: 07/21/05
|
||||
// Had to be a C file because g++ doesn't like pci_classes declaration
|
||||
|
||||
#include "hos_defines.h"
|
||||
#include "pci.h"
|
||||
|
||||
pci_class_t* pci_classes[] =
|
||||
{
|
||||
(pci_class_t[]) {
|
||||
{1, 1, "Generic PCI VGA Device"},
|
||||
{0xFF, 0xFF, "Generic PCI Device"}
|
||||
},
|
||||
(pci_class_t[]) {
|
||||
{0, 0, "SCSI Controller"},
|
||||
{1, 0xFF, "IDE Controller"},
|
||||
{2, 0, "Floppy Disk Controller"},
|
||||
{3, 0, "IPI Controller"},
|
||||
{4, 0, "RAID Controller"},
|
||||
{0xFF, 0xFF, "Generic Mass Storage Controller"}
|
||||
},
|
||||
(pci_class_t[]) {
|
||||
{0, 0, "Ethernet Controller"},
|
||||
{1, 0, "Token Ring Network Controller"},
|
||||
{2, 0, "FDDI Controller"},
|
||||
{3, 0, "ATM Controller"},
|
||||
{0xFF, 0xFF, "Generic Network Controller"}
|
||||
},
|
||||
(pci_class_t[]) {
|
||||
{0, 0, "VGA Compatible Controller"},
|
||||
{0, 1, "8514 Compatible Display Controller"},
|
||||
{1, 0, "XGA Controller"},
|
||||
{0xFF, 0xFF, "Generic Display Controller"}
|
||||
},
|
||||
(pci_class_t[]) {
|
||||
{0, 0, "Multimedia Video Device"},
|
||||
{0, 0, "Multimedia Audio Device"},
|
||||
{0xFF, 0xFF, "Generic Multimedia Device"}
|
||||
},
|
||||
(pci_class_t[]) {
|
||||
{0, 0, "RAM Controller"},
|
||||
{1, 0, "Flash Memory Controller"},
|
||||
{0xFF, 0xFF, "Generic Memory Controller"}
|
||||
},
|
||||
(pci_class_t[]) {
|
||||
{0, 0, "Host/PCI Bridge"},
|
||||
{1, 0, "PCI/ISA Bridge"},
|
||||
{2, 0, "PCI/EISA Bridge"},
|
||||
{3, 0, "PCI/Micro Channel Bridge"},
|
||||
{4, 0, "PCI/PCI Bridge"},
|
||||
{5, 0, "PCI/PCMCIA Bridge"},
|
||||
{6, 0, "PCI/NuBus Bridge"},
|
||||
{7, 0, "PCI/CardBus Bridge"},
|
||||
{0xFF, 0xFF, "Generic Bridge"}
|
||||
},
|
||||
(pci_class_t[]) {
|
||||
{0, 0xFF, "Serial Controller"},
|
||||
{1, 0xFF, "Parallel Port"},
|
||||
{0xFF, 0xFF, "Generic Communications Device"}
|
||||
},
|
||||
(pci_class_t[]) {
|
||||
{0, 0xFF, "Programmable Interrupt Controller"},
|
||||
{1, 0xFF, "DMA Controller"},
|
||||
{2, 0xFF, "System Timer"},
|
||||
{3, 0xFF, "RTC Controller"},
|
||||
{0xFF, 0xFF, "Generic System Peripheral"}
|
||||
},
|
||||
(pci_class_t[]) {
|
||||
{0, 0, "Keyboard Controller"},
|
||||
{1, 0, "Digitizer (Pen)"},
|
||||
{2, 0, "Mouse Controller"},
|
||||
{0xFF, 0xFF, ""}
|
||||
},
|
||||
(pci_class_t[]) {
|
||||
{0xFF, 0xFF, "Docking Station"}
|
||||
},
|
||||
(pci_class_t[]) {
|
||||
{0, 0, "386 Processor"},
|
||||
{1, 0, "486 Processor"},
|
||||
{2, 0, "Pentium Processor"},
|
||||
{0x10, 0, "Alpha Processor"},
|
||||
{0x20, 0, "PowerPC Processor"},
|
||||
{0x40, 0, "Co-Processor"},
|
||||
{0xFF, 0xFF, "Generic Processor"}
|
||||
},
|
||||
(pci_class_t[]) {
|
||||
{0, 0, "Firewire (IEEE 1394) Controller"},
|
||||
{1, 0, "ACCESS Bus Controller"},
|
||||
{2, 0, "SSA (Serial Storage Architecture) Controller"},
|
||||
{3, 0, "USB Controller"},
|
||||
{0xFF, 0xFF, "Generic Serial Bus Controller"}
|
||||
}
|
||||
};
|
||||
|
||||
char *pci_getDeviceClass(u8_t cls, u8_t sub, u8_t progif)
|
||||
{
|
||||
if (cls < sizeof(pci_classes)/sizeof(pci_class_t *))
|
||||
{
|
||||
pci_class_t *pcls = pci_classes[cls];
|
||||
for (;;)
|
||||
{
|
||||
if ( (pcls->subclass == 0xFF || pcls->subclass == sub)
|
||||
&& (pcls->progif == 0xFF || pcls->progif == progif) )
|
||||
return pcls->desc;
|
||||
pcls++;
|
||||
}
|
||||
}
|
||||
return "Unknown PCI Device";
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
// pic.c
|
||||
// Author: Josh Holtrop
|
||||
// Created: 02/26/04
|
||||
|
||||
#include "hos_defines.h"
|
||||
#include "pic.h"
|
||||
#include "sys/io.h"
|
||||
|
||||
//Re-maps the Programmable Interrupr Controllers so IRQ0->pic1 base address, IRG8->pic2 base address
|
||||
void pic_remap(int pic1, int pic2)
|
||||
{
|
||||
byte a1, a2;
|
||||
|
||||
a1 = inportb(PIC1_DATA); //0x21
|
||||
a2 = inportb(PIC2_DATA); //0xA1
|
||||
|
||||
outportb(PIC1_COMMAND, ICW1_INIT+ICW1_ICW4); //0x20, 0x10+0x01 00010001b
|
||||
outportb(PIC2_COMMAND, ICW1_INIT+ICW1_ICW4); //0xA0, 0x10+0x01 00010001b
|
||||
outportb(PIC1_DATA, pic1); //0x21, pic1
|
||||
outportb(PIC2_DATA, pic2); //0xA1, pic2
|
||||
outportb(PIC1_DATA, 4); //0x21, 0x04 00000100b
|
||||
outportb(PIC2_DATA, 2); //0xA1, 0x02 00000010b
|
||||
outportb(PIC1_DATA, ICW4_8086); //0x21, 0x01 00000001b
|
||||
outportb(PIC2_DATA, ICW4_8086); //0xA1, 0x01 00000001b
|
||||
|
||||
outportb(PIC1_DATA, a1); //0x21
|
||||
outportb(PIC2_DATA, a2); //0xA1
|
||||
}
|
||||
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
// pic.h
|
||||
// Author: Josh Holtrop
|
||||
// Created: 02/26/04
|
||||
|
||||
#ifndef __HOS_PIC__
|
||||
#define __HOS_PIC__ __HOS_PIC__
|
||||
|
||||
#include "hos_defines.h"
|
||||
#include "sys/io.h"
|
||||
|
||||
#define PIC1 0x20
|
||||
#define PIC2 0xA0
|
||||
#define PIC1_COMMAND PIC1
|
||||
#define PIC1_DATA (PIC1+1)
|
||||
#define PIC2_COMMAND PIC2
|
||||
#define PIC2_DATA (PIC2+1)
|
||||
#define PIC_EOI 0x20
|
||||
|
||||
#define ICW1_ICW4 0x01 /* ICW4 (not) needed */
|
||||
#define ICW1_SINGLE 0x02 /* Single (cascade) mode */
|
||||
#define ICW1_INTERVAL4 0x04 /* Call address interval 4 (8) */
|
||||
#define ICW1_LEVEL 0x08 /* Level triggered (edge) mode */
|
||||
#define ICW1_INIT 0x10 /* Initialization - required! */
|
||||
|
||||
#define ICW4_8086 0x01 /* 8086/88 (MCS-80/85) mode */
|
||||
#define ICW4_AUTO 0x02 /* Auto (normal) EOI */
|
||||
#define ICW4_BUF_SLAVE 0x08 /* Buffered mode/slave */
|
||||
#define ICW4_BUF_MASTER 0x0C /* Buffered mode/master */
|
||||
#define ICW4_SFNM 0x10 /* Special fully nested (not) */
|
||||
|
||||
void pic_remap(int pic1, int pic2);
|
||||
//inline void pic_mask1(byte mask);
|
||||
//inline void pic_mask2(byte mask);
|
||||
//inline void pic_eoi();
|
||||
//inline void pic_eoi2();
|
||||
|
||||
//Masks interrupts on first Programmable Interrupt Controller
|
||||
static inline void pic_mask1(byte mask)
|
||||
{
|
||||
outportb(PIC1_DATA, mask); //0x21, maskfield *OCW1*
|
||||
}
|
||||
|
||||
//Masks interrupts on second Programmable Interrupt Controller
|
||||
static inline void pic_mask2(byte mask)
|
||||
{
|
||||
outportb(PIC2_DATA, mask); //0xA1, maskfield *OCW1*
|
||||
}
|
||||
|
||||
|
||||
//Signals an End Of Interrupt signal to the first PIC
|
||||
static inline void pic_eoi()
|
||||
{
|
||||
outportb(0x20, 0x20);
|
||||
}
|
||||
|
||||
//Signals an End Of Interrupt signal to both the second and first PIC unit
|
||||
static inline void pic_eoi2()
|
||||
{
|
||||
outportb(0xA0, 0x20);
|
||||
outportb(0x20, 0x20);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
// rtc.c
|
||||
// Author: Josh Holtrop
|
||||
// Created: 02/26/04
|
||||
// Implements Real-Time Clock function calls
|
||||
// These functions are for reading and writing various values stored on the CMOS Real Time Clock
|
||||
// Parameters / return values are in BCD format
|
||||
|
||||
#include "hos_defines.h"
|
||||
#include "sys/rtc.h"
|
||||
#include "sys/io.h"
|
||||
|
||||
unsigned char rtc_readDay()
|
||||
{
|
||||
outportb(0x70, 7);
|
||||
return inportb(0x71);
|
||||
}
|
||||
|
||||
unsigned char rtc_readMonth()
|
||||
{
|
||||
outportb(0x70, 8);
|
||||
return inportb(0x71);
|
||||
}
|
||||
|
||||
unsigned char rtc_readYear()
|
||||
{
|
||||
outportb(0x70, 9);
|
||||
return inportb(0x71);
|
||||
}
|
||||
|
||||
unsigned char rtc_readSecond()
|
||||
{
|
||||
outportb(0x70, 0);
|
||||
return inportb(0x71);
|
||||
}
|
||||
|
||||
unsigned char rtc_readMinute()
|
||||
{
|
||||
outportb(0x70, 2);
|
||||
return inportb(0x71);
|
||||
}
|
||||
|
||||
unsigned char rtc_readHour()
|
||||
{
|
||||
outportb(0x70, 4);
|
||||
return inportb(0x71);
|
||||
}
|
||||
|
||||
void rtc_setDay(unsigned char day)
|
||||
{
|
||||
outportb(0x70, 7);
|
||||
outportb(0x71, day);
|
||||
}
|
||||
|
||||
void rtc_setMonth(unsigned char month)
|
||||
{
|
||||
outportb(0x70, 8);
|
||||
outportb(0x71, month);
|
||||
}
|
||||
|
||||
void rtc_setYear(unsigned char year)
|
||||
{
|
||||
outportb(0x70, 9);
|
||||
outportb(0x71, year);
|
||||
}
|
||||
|
||||
void rtc_setSecond(unsigned char second)
|
||||
{
|
||||
outportb(0x70, 0);
|
||||
outportb(0x71, second);
|
||||
}
|
||||
|
||||
void rtc_setMinute(unsigned char minute)
|
||||
{
|
||||
outportb(0x70, 2);
|
||||
outportb(0x71, minute);
|
||||
}
|
||||
|
||||
void rtc_setHour(unsigned char hour)
|
||||
{
|
||||
outportb(0x70, 4);
|
||||
outportb(0x71, hour);
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
// rtc.h
|
||||
// Author: Josh Holtrop
|
||||
// Created: 02/26/04
|
||||
// Implements Real-Time Clock function calls
|
||||
// These functions are for reading and writing various values stored on the CMOS Real Time Clock
|
||||
// Parameters / return values are in BCD format
|
||||
|
||||
#ifndef __HOS_RTC__
|
||||
#define __HOS_RTC__ __HOS_RTC__
|
||||
|
||||
#include "hos_defines.h"
|
||||
|
||||
unsigned char rtc_readDay();
|
||||
unsigned char rtc_readMonth();
|
||||
unsigned char rtc_readYear();
|
||||
unsigned char rtc_readSecond();
|
||||
unsigned char rtc_readMinute();
|
||||
unsigned char rtc_readHour();
|
||||
void rtc_setDay(unsigned char dat);
|
||||
void rtc_setMonth(unsigned char month);
|
||||
void rtc_setYear(unsigned char year);
|
||||
void rtc_setSecond(unsigned char second);
|
||||
void rtc_setMinute(unsigned char minute);
|
||||
void rtc_setHour(unsigned char hour);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in new issue
Block a user