- Changed MODULE_INIT_SUCCESS to MODULE_ERR_OK and added other MODULE_ERR_* values
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)))
+# These are first to make vterm be the first driver initialised (apart
+# its dependencies), allowing logging to exist throughout the loading
+# process.
+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 += 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
-OBJ += $(addprefix vfs/fs/, $(addsuffix .o,$(FILESYSTEMS)))
-OBJ += drv/proc.o drv/fifo.o drv/dma.o drv/iocache.o drv/pci.o drv/kb.o drv/vga.o drv/vterm.o
OBJ += $(addprefix drv/, $(addsuffix .o,$(DRIVERS)))
OBJ := $(addsuffix .$(ARCH), $(OBJ))
MODS += $(addprefix ../Modules/, $(addsuffix .xo.$(ARCH),$(MODULES)))
-BUILD_NUM = 1513
+BUILD_NUM = 1518
int PE_Install(char **Arguments)\r
{\r
Binary_RegisterType(&gPE_Loader);\r
- return 1;\r
+ return MODULE_ERR_OK;\r
}\r
\r
/**\r
int FIFO_Install(char **Options)
{
DevFS_AddDevice( &gFIFO_DriverInfo );
- return MODULE_INIT_SUCCESS;
+ return MODULE_ERR_OK;
}
/**
IRQ_AddHandler(1, KB_IRQHandler);
DevFS_AddDevice( &gKB_DevInfo );
//Log("KB_Install: Installed");
- return 1;
+ return MODULE_ERR_OK;
}
/**
*/\r
#define DEBUG 0\r
#include <acess.h>\r
+#include <modules.h>\r
#include <vfs.h>\r
#include <fs_devfs.h>\r
#include <drv_pci.h>\r
gaPCI_PortBitmap[i] = -1;\r
for( i = 0; i < MAX_RESERVED_PORT % 32; i ++ )\r
gaPCI_PortBitmap[MAX_RESERVED_PORT / 32] = 1 << i;\r
- //LogF("Done.\n");\r
\r
// Scan Busses\r
for( bus = 0; bus < giPCI_BusCount; bus++ )\r
if(tmpPtr != gPCI_Devices)\r
break;\r
}\r
+ \r
+ if(giPCI_DeviceCount == 0)\r
+ return MODULE_ERR_NOTNEEDED;\r
+ \r
tmpPtr = realloc(gPCI_Devices, giPCI_DeviceCount*sizeof(t_pciDevice));\r
if(tmpPtr == NULL)\r
- return 0;\r
+ return MODULE_ERR_MALLOC;\r
gPCI_Devices = tmpPtr;\r
- //LogF("Done.\n");\r
\r
// Complete Driver Structure \r
gPCI_DriverStruct.RootNode.Size = giPCI_DeviceCount;\r
// And add to DevFS\r
DevFS_AddDevice(&gPCI_DriverStruct);\r
\r
- return 1;\r
+ return MODULE_ERR_OK;\r
}\r
\r
/**\r
int SysFS_Install(char **Options)
{
DevFS_AddDevice( &gSysFS_DriverInfo );
- return MODULE_INIT_SUCCESS;
+ return MODULE_ERR_OK;
}
/**
// Install DevFS
DevFS_AddDevice( &gVGA_DevInfo );
- return 1;
+ return MODULE_ERR_OK;
}
/**
// Set kernel output to VT0
Debug_SetKTerminal("/Devices/VTerm/0");
- return MODULE_INIT_SUCCESS;
+ return MODULE_ERR_OK;
}
/**
#define NULL ((void*)0)
#define PACKED __attribute__ ((packed))
+#include <stdint.h>
#include <arch.h>
#include <stdarg.h>
#include "errno.h"
char **Dependencies; // NULL Terminated List
} __attribute__((packed)) tModule;
-#define MODULE_INIT_SUCCESS 1
-#define MODULE_INIT_FAILURE 0
+enum eModuleErrors
+{
+ MODULE_ERR_OK, //!< No Error
+ MODULE_ERR_MISC, //!< Misc Error
+ MODULE_ERR_NOTNEEDED, //!< Module not needed
+ MODULE_ERR_MALLOC, //!< Error with malloc/realloc/calloc
+
+ MODULE_ERR_MAX
+};
/**
* \brief Module Loader definition
int Modules_LoadBuiltins()
{
int i, j, k;
+ int ret;
int numToInit = 0;
Uint8 *baIsLoaded;
char **deps;
+ // Count modules
giNumBuiltinModules = (Uint)&gKernelModulesEnd - (Uint)&gKernelModules;
giNumBuiltinModules /= sizeof(tModule);
+ // Allocate loaded array
baIsLoaded = calloc( giNumBuiltinModules, sizeof(*baIsLoaded) );
- // Pass 1 - Are the dependencies compiled in?
+ // Pass 1 - Check for dependencies
for( i = 0; i < giNumBuiltinModules; i++ )
{
deps = gKernelModules[i].Dependencies;
break;
}
if(k == giNumBuiltinModules) {
- Warning("Unable to find dependency '%s' for '%s' in kernel",
- deps[j], gKernelModules[i].Name);
+ Warning(
+ "[MOD ] Dependency '%s' for module '%s' was not compiled in",
+ deps[j], gKernelModules[i].Name
+ );
baIsLoaded[i] = -1; // Don't Load
break;
numToInit ++;
}
- // Pass 2 - Intialise
+ // Pass 2 - Intialise modules in order
while(numToInit)
{
for( i = 0; i < giNumBuiltinModules; i++ )
break;
}
// `k` is assumed to be less than `giNumBuiltinModules`
+ // We checked this in pass 1
// If a dependency failed, skip and mark as failed
if( baIsLoaded[k] == -1 ) {
numToInit --;
break;
}
- // If a dependency is not intialised, skip
+ // If a dependency is not intialised, skip this module
+ // and come back later
if( !baIsLoaded[k] ) break;
}
- // Check if we broke out
+ // Check for breakouts
if( deps[j] ) continue;
}
// All Dependencies OK? Initialise
StartupPrint(gKernelModules[i].Name);
- Log("Initialising %p '%s' v%i.%i...",
+ Log("[MOD ] Initialising %p '%s' v%i.%i...",
&gKernelModules[i],
gKernelModules[i].Name,
gKernelModules[i].Version>>8, gKernelModules[i].Version & 0xFF
);
- if( gKernelModules[i].Init(NULL) == 0 ) {
- Log("Loading Failed, all modules that depend on this will also fail");
+
+ ret = gKernelModules[i].Init(NULL);
+ if( ret != MODULE_ERR_OK ) {
+ Log("[MOD ] Loading Failed, all modules that depend on this will also fail");
+ switch(ret)
+ {
+ case MODULE_ERR_MISC:
+ Log("[MOD ] Reason: Miscelanious");
+ break;
+ case MODULE_ERR_NOTNEEDED:
+ Log("[MOD ] Reason: Module not needed (probably hardware not found)");
+ break;
+ case MODULE_ERR_MALLOC:
+ Log("[MOD ] Reason: Error in malloc/realloc/calloc, probably not good");
+ break;
+ default:
+ Log("[MOD ] Reason - Unknown code %i", ret);
+ break;
+ }
baIsLoaded[i] = -1;
}
// Mark as loaded
}
}
+ free(baIsLoaded);
+
return 0;
}
int FAT_Install(char **Arguments)\r
{\r
VFS_AddDriver( &gFAT_FSInfo );\r
- return MODULE_INIT_SUCCESS;\r
+ return MODULE_ERR_OK;\r
}\r
\r
/**\r
// NOTE: This driver was written for 0xB0C4, but they seem to be backwards compatable\r
if(bga_version < 0xB0C4 || bga_version > 0xB0C5) {\r
Warning("[BGA ] Bochs Adapter Version is not 0xB0C4 or 0xB0C5, instead 0x%x", bga_version);\r
- return 0;\r
+ return MODULE_ERR_NOTNEEDED;\r
}\r
\r
// Install Device\r
giBGA_DriverId = DevFS_AddDevice( &gBGA_DriverStruct );\r
if(giBGA_DriverId == -1) {\r
Warning("[BGA ] Unable to register with DevFS, maybe already loaded?");\r
- return 0;\r
+ return MODULE_ERR_MISC;\r
}\r
\r
// Map Framebuffer to hardware address\r
gBGA_Framebuffer = (void *) MM_MapHWPage(VBE_DISPI_LFB_PHYSICAL_ADDRESS, 768); // 768 pages (3Mb)\r
\r
- return 1;\r
+ return MODULE_ERR_OK;\r
}\r
\r
/**\r
int Ext2_Install(char **Arguments)\r
{\r
VFS_AddDriver( &gExt2_FSInfo );\r
- return 1;\r
+ return MODULE_ERR_OK;\r
}\r
\r
/**\r
DevFS_AddDevice( &gIP_DriverInfo );
- return 1;
+ return MODULE_ERR_OK;
}
/**
int UDI_Install(char **Arguments)
{
Module_RegisterLoader( &gUDI_Loader );
- return 1;
+ return MODULE_ERR_OK;
}
/**
giNe2k_CardCount += PCI_CountDevices( csaCOMPAT_DEVICES[i].Vendor, csaCOMPAT_DEVICES[i].Device, 0 );
}
+ if( giNe2k_CardCount == 0 ) {
+ Log("[Ne2k ] No cards detected\n");
+ return MODULE_ERR_NOTNEEDED;
+ }
+
// Enumerate Cards
k = 0;
gpNe2k_Cards = calloc( giNe2k_CardCount, sizeof(tCard) );
gNe2k_DriverInfo.RootNode.Size = giNe2k_CardCount;
DevFS_AddDevice( &gNe2k_DriverInfo );
- return 1;
+ return MODULE_ERR_OK;
}
/**
int ret;
ret = ATA_SetupIO();
- if(ret != 1) return ret;
+ if(ret) return ret;
ATA_SetupPartitions();
ATA_SetupVFS();
if( DevFS_AddDevice( &gATA_DriverInfo ) == 0 )
- return MODULE_INIT_FAILURE;
+ return MODULE_ERR_MISC;
- return MODULE_INIT_SUCCESS;
+ return MODULE_ERR_OK;
}
/**
gATA_BusMasterBase = PCI_GetBAR4( ent );
if( gATA_BusMasterBase == 0 ) {
Warning("It seems that there is no Bus Master Controller on this machine. Get one");
- LEAVE('i', MODULE_INIT_FAILURE);
- return MODULE_INIT_FAILURE;
+ LEAVE('i', MODULE_ERR_NOTNEEDED);
+ return MODULE_ERR_NOTNEEDED;
}
+
+ // Map memory
if( !(gATA_BusMasterBase & 1) )
{
if( gATA_BusMasterBase < 0x100000 )
LOG("gATA_BusMasterBase = 0x%x", gATA_BusMasterBase & ~1);
}
+ // Register IRQs and get Buffers
IRQ_AddHandler( gATA_IRQPri, ATA_IRQHandlerPri );
IRQ_AddHandler( gATA_IRQSec, ATA_IRQHandlerSec );
LOG("addr = 0x%x", addr);
ATA_int_BusMasterWriteDWord(12, addr);
+ // Enable controllers
outb(IDE_PRI_BASE+1, 1);
outb(IDE_SEC_BASE+1, 1);
- LEAVE('i', MODULE_INIT_SUCCESS);
- return MODULE_INIT_SUCCESS;
+ // return
+ LEAVE('i', MODULE_ERR_OK);
+ return MODULE_ERR_OK;
}
/**
// Register with devfs\r
DevFS_AddDevice(&gFDD_DriverInfo);\r
\r
- return 1;\r
+ return MODULE_ERR_OK;\r
}\r
\r
/**\r
{
UHCI_Initialise();
Warning("[USB ] Not Complete - Devel Only");
- return 1;
+ return MODULE_ERR_OK;
}
/**
Uint8 *tok = Buf;
int crc = 0; //USB_TokenCRC();
- tok[0] = PID;
- tok[1] = Addr | ((EndP&1)<<7);
- tok[2] = (EndP >> 1) | crc;
+ tok[0] = PID & 0xFF;
+ tok[1] = (Addr & 0x7F) | ((EndP&1)<<7);
+ tok[2] = ((EndP >> 1) & 0x7) | crc;
}
#if 0