OBJ = $(addprefix arch/$(ARCHDIR)/,$(A_OBJ))
OBJ += heap.o messages.o debug.o modules.o lib.o syscalls.o system.o threads.o drvutil.o
OBJ += $(addprefix vfs/fs/, $(addsuffix .o,$(FILESYSTEMS)))
-OBJ += drv/vterm.o drv/proc.o drv/fifo.o drv/dma.o drv/iocache.o drv/pci.o drv/kb.o drv/vga.o
+OBJ += drv/vterm.o drv/proc.o drv/fifo.o drv/iocache.o drv/dma.o drv/pci.o drv/kb.o drv/vga.o
OBJ += binary.o bin/elf.o bin/pe.o
OBJ += vfs/main.o vfs/open.o vfs/acls.o vfs/dir.o vfs/io.o vfs/mount.o vfs/memfile.o vfs/nodecache.o
OBJ += vfs/fs/root.o vfs/fs/devfs.o
-BUILD_NUM = 1531
+BUILD_NUM = 1541
// === MACROS ===
typedef volatile int tSpinlock;
+#define IS_LOCKED(lockptr) (!!(*(tSpinlock*)lockptr))
#define LOCK(lockptr) do {int v=1;\
while(v)__asm__ __volatile__("lock xchgl %%eax, (%%edi)":"=a"(v):"a"(1),"D"(lockptr));}while(0)
#define RELEASE(lockptr) __asm__ __volatile__("lock andl $0, (%%edi)"::"D"(lockptr));
* DMA Driver\r
*/\r
#include <acess.h>\r
+#include <modules.h>\r
\r
#define DMA_SIZE (0x2400)\r
#define DMA_ADDRESS(c) ((c)*DMA_SIZE+0x500) //Save Space for IDT and BDA\r
#define HIB(x) (((x)>>8)&0xFF)\r
#define HIW(x) (((x)>>16)&0xFFFF)\r
\r
-typedef struct {\r
- int mode;\r
+// === TYPES ===\r
+typedef struct\r
+{\r
+ int mode;\r
char *address;\r
} t_dmaChannel;\r
\r
+// === PROTOTYPES ===\r
+ int DMA_Install();\r
+void DMA_SetChannel(int Channel, int length, int read);\r
+ int DMA_ReadData(int channel, int count, void *buffer);\r
+\r
+// === CONSTANTS ===\r
const Uint8 cMASKPORT [8] = { 0x0A, 0x0A, 0x0A, 0x0A, 0xD4, 0xD4, 0xD4, 0xD4 };\r
const Uint8 cMODEPORT [8] = { 0x0B, 0x0B, 0x0B, 0x0B, 0xD6, 0xD6, 0xD6, 0xD6 };\r
const Uint8 cCLEARPORT[8] = { 0x0C, 0x0C, 0x0C, 0x0C, 0xD8, 0xD8, 0xD8, 0xD8 };\r
const Uint8 cADDRPORT [8] = { 0x00, 0x02, 0x04, 0x06, 0xC0, 0xC4, 0xC8, 0xCC };\r
const Uint8 cCOUNTPORT[8] = { 0x01, 0x03, 0x05, 0x07, 0xC2, 0xC6, 0xCA, 0xCE };\r
\r
+// === GLOBALS ===\r
+MODULE_DEFINE(0, 0x0100, ISADMA, DMA_Install, NULL, NULL);\r
char *dma_addresses[8];\r
t_dmaChannel dma_channels[8];\r
\r
+// === CODE ===\r
/**\r
- * \fn void DMA_Install()\r
+ * \fn int DMA_Install()\r
* \brief Initialise DMA channels\r
*/\r
-void DMA_Install()\r
+int DMA_Install()\r
{\r
Uint i;\r
for(i=8;i--;)\r
dma_addresses[i] = (char*)DMA_ADDRESS(i);\r
dma_addresses[i] += KERNEL_BASE;\r
}\r
+ return MODULE_ERR_OK;\r
}\r
\r
/**\r
Uint8 PCI_CfgReadByte(Uint16 bus, Uint16 dev, Uint16 func, Uint16 offset);\r
\r
// === GLOBALS ===\r
-//MODULE_DEFINE(0, 0x0100, PCI, PCI_Install, NULL);\r
+MODULE_DEFINE(0, 0x0100, PCI, PCI_Install, NULL, NULL);\r
int giPCI_BusCount = 1;\r
int giPCI_InodeHandle = -1;\r
int giPCI_DeviceCount = 0;\r
// Scan Busses\r
for( bus = 0; bus < giPCI_BusCount; bus++ )\r
{\r
- for( dev = 0; dev < 10; dev++ ) // 10 Devices per bus\r
+ for( dev = 0; dev < 32; dev++ ) // 32 Devices per bus\r
{\r
- for( fcn = 0; fcn < 8; fcn++ ) // 8 functions per device\r
+ for( fcn = 0; fcn < 8; fcn++ ) // Max 8 functions per device\r
{\r
// Check if the device/function exists\r
if(!PCI_EnumDevice(bus, dev, fcn, &devInfo))\r
- {\r
continue;\r
- }\r
\r
if(giPCI_DeviceCount == space)\r
{\r
if(devInfo.oc == PCI_OC_PCIBRIDGE)\r
{\r
#if LIST_DEVICES\r
- Log("[PCI ] Bridge @ %i,%i:%i (0x%x:0x%x)",\r
+ Log("[PCI ] Bridge @ %i,%i:%i (0x%x:0x%x)",\r
bus, dev, fcn, devInfo.vendor, devInfo.device);\r
#endif\r
giPCI_BusCount++;\r
}\r
+ else\r
+ {\r
+ #if LIST_DEVICES\r
+ Log("[PCI ] Device %i,%i:%i %04x => 0x%04x:0x%04x",\r
+ bus, dev, fcn, devInfo.oc, devInfo.vendor, devInfo.device);\r
+ #endif\r
+ }\r
+ \r
devInfo.Node.Inode = giPCI_DeviceCount;\r
memcpy(&gPCI_Devices[giPCI_DeviceCount], &devInfo, sizeof(tPCIDevice));\r
giPCI_DeviceCount ++;\r
- #if LIST_DEVICES\r
- Log("[PCI ] Device %i,%i:%i => 0x%x:0x%x",\r
- bus, dev, fcn, devInfo.vendor, devInfo.device);\r
- #endif\r
\r
// WTF is this for?\r
+ // Maybe bit 23 must be set for the device to be valid?\r
+ // - Actually, maybe 23 means that there are sub-functions\r
if(fcn == 0) {\r
if( !(devInfo.ConfigCache[3] & 0x800000) )\r
break;\r
\r
for( ; i < giPCI_DeviceCount; i++ )\r
{\r
- if((gPCI_Devices[i].oc & mask) != class) continue;\r
- return i;\r
+ if((gPCI_Devices[i].oc & mask) == class)\r
+ return i;\r
}\r
return -1;\r
}\r
// === IMPORTS ===
extern int Modules_LoadBuiltins();
-extern int PCI_Install();
+//extern int PCI_Install();
extern void DMA_Install();
extern void Debug_SetKTerminal(char *File);
extern void StartupPrint(char *Str);
void System_Init(char *ArgString)
{
// - Start Builtin Drivers & Filesystems
- StartupPrint("Scanning PCI Bus...");
- PCI_Install();
+ //StartupPrint("Scanning PCI Bus...");
+ //PCI_Install();
StartupPrint("Loading DMA...");
DMA_Install();
StartupPrint("Loading staticly compiled modules...");
FILESYSTEMS =
DRIVERS =
MODULES = Storage/ATA Storage/FDD
-MODULES += Network/NE2000
-MODULES += Display/BochsGA
+#MODULES += Network/NE2000
+#MODULES += Display/BochsGA
MODULES += Filesystems/Ext2
MODULES += Filesystems/FAT
-MODULES += IPStack
+#MODULES += IPStack
DYNMODS = USB Interfaces/UDI
#DISTROOT = /mnt/AcessHDD/Acess2
int BGA_Ioctl(tVFS_Node *node, int id, void *data);\r
\r
// === GLOBALS ===\r
-MODULE_DEFINE(0, 0x0032, BochsGA, BGA_Install, NULL, NULL);\r
+MODULE_DEFINE(0, 0x0032, BochsGA, BGA_Install, NULL, "PCI", NULL);\r
tDevFS_Driver gBGA_DriverStruct = {\r
NULL, "BochsGA",\r
{\r
CFLAGS = -Wall -Werror -fno-stack-protector $(CPPFLAGS) -O3
OBJ := $(addsuffix .$(ARCH),$(OBJ))
-BIN = ../$(CATEGORY)_$(NAME).kmd.$(ARCH)
+ifeq ($(CATEGORY),)
+ BIN := ../$(CATEGORY)_$(NAME).kmd.$(ARCH)
+else
+ BIN := ../$(NAME).kmd.$(ARCH)
+endif
KOBJ = ../$(NAME).xo.$(ARCH)
DEPFILES = $(filter %.o.$(ARCH),$(OBJ))
void ATA_int_BusMasterWriteDWord(int Ofs, Uint32 Value);
// === GLOBALS ===
-MODULE_DEFINE(0, 0x0032, i386ATA, ATA_Install, NULL, NULL);
+MODULE_DEFINE(0, 0x0032, i386ATA, ATA_Install, NULL, "PCI", NULL);
tDevFS_Driver gATA_DriverInfo = {
NULL, "ata",
{
int FDD_int_GetDims(int type, int lba, int *c, int *h, int *s, int *spt);\r
\r
// === GLOBALS ===\r
-MODULE_DEFINE(0, FDD_VERSION, FDD, FDD_Install, NULL, NULL);\r
+MODULE_DEFINE(0, FDD_VERSION, FDD, FDD_Install, NULL, "ISADMA", NULL);\r
t_floppyDevice gFDD_Devices[2];\r
tSpinlock glFDD;\r
volatile int gbFDD_IrqFired = 0;\r
\r
Log("[FDD ] Detected Disk 0: %s and Disk 1: %s", cFDD_TYPES[data>>4], cFDD_TYPES[data&0xF]);\r
\r
+ if( data == 0 ) {\r
+ return MODULE_ERR_NOTNEEDED;\r
+ }\r
+ \r
// Clear FDD IRQ Flag\r
FDD_SensInt(0x3F0, NULL, NULL);\r
// Install IRQ6 Handler\r
int i;\r
int lba = SectorAddr;\r
\r
- ENTER("iDisk XSectorAddr pBuffer", disk, SectorAddr, Buffer);\r
+ ENTER("iDisk XSectorAddr pBuffer", Disk, SectorAddr, Buffer);\r
\r
- #if USE_CACHE\r
- FDD_AquireCacheSpinlock();\r
- for( i = 0; i < siFDD_SectorCacheSize; i++ )\r
- {\r
- if(sFDD_SectorCache[i].timestamp == 0) continue;\r
- if( sFDD_SectorCache[i].disk == Disk\r
- && sFDD_SectorCache[i].sector == lba)\r
- {\r
- LOG("Found %i in cache %i", lba, i);\r
- memcpy(Buffer, sFDD_SectorCache[i].data, 512);\r
- sFDD_SectorCache[i].timestamp = now();\r
- FDD_FreeCacheSpinlock();\r
- LEAVE('i', 1);\r
- return 1;\r
- }\r
- }\r
- LOG("Read %i from Disk", lba);\r
- FDD_FreeCacheSpinlock();\r
- #else\r
if( IOCache_Read( gFDD_Devices[Disk].CacheHandle, SectorAddr, Buffer ) == 1 ) {\r
LEAVE('i', 1);\r
return 1;\r
}\r
- #endif\r
\r
base = cPORTBASE[Disk >> 1];\r
\r
LEAVE('i', -1);\r
return -1;\r
}\r
+ LOG("Cyl=%i, Head=%i, Sector=%i", cyl, head, sec);\r
\r
- // Remove Old Timer\r
- Time_RemoveTimer(gFDD_Devices[Disk].timer);\r
- // Check if Motor is on\r
- if(gFDD_Devices[Disk].motorState == 0) FDD_int_StartMotor(Disk);\r
+ LOCK(&glFDD); // Lock to stop the motor stopping on us\r
+ Time_RemoveTimer(gFDD_Devices[Disk].timer); // Remove Old Timer\r
+ // Start motor if needed\r
+ if(gFDD_Devices[Disk].motorState != 2) FDD_int_StartMotor(Disk);\r
+ RELEASE(&glFDD);\r
\r
LOG("Wait for the motor to spin up");\r
\r
// Wait for spinup\r
while(gFDD_Devices[Disk].motorState == 1) Threads_Yield();\r
\r
- LOG("Cyl=%i, Head=%i, Sector=%i", cyl, head, sec);\r
LOG("Acquire Spinlock");\r
- \r
LOCK(&glFDD);\r
\r
// Seek to track\r
void FDD_int_StopMotor(int disk)\r
{\r
Uint8 state;\r
+ if( IS_LOCKED(&glFDD) ) return ;\r
+ ENTER("iDisk", disk);\r
+ \r
state = inb( cPORTBASE[ disk>>1 ] + PORT_DIGOUTPUT );\r
state &= ~( 1 << (4+disk) );\r
outb( cPORTBASE[ disk>>1 ] + PORT_DIGOUTPUT, state );\r
gFDD_Devices[disk].motorState = 0;\r
+ LEAVE('-');\r
}\r