Example #1
0
// First C-function to be called
void KernelMain(uint16_t* InfoTableAddress)
{
	// InfoTable is our custom structure which has some essential information about the system
	// gained during system boot; and the information that is best found out about in real mode.
	InfoTable = InfoTableAddress;

	// Do memory setup
	if (!InitializePhysicalMemory())
	{
		KernelPanic(SystemInitializationFailed);
	}
	if (!InitializeVirtualMemory(SystemInitializationFailed))
	{
		KernelPanic();
	}

	// Get basic interrupts and exceptions setup
	// Initializing ACPI will generate page faults while parsing ACPI tables
	// so we must first fill the IDT with offsets to basic exceptions and interrupts
	PopulateIDTWithOffsets();
	if(!InitializeACPI3())
	{
		KernelPanic(SystemInitializationFailed);
	}
	if(!SetupHardwareInterrupts())
	{
		KernelPanic(SystemInitializationFailed);
	}

	TerminalSetCursorPosition(33,12);
	TerminalPrintString(HelloWorld, strlen(HelloWorld));
}
Example #2
0
void * ConsumerMain( void * arg )
{
  struct CONSUMER_CONTEXT * context = (struct CONSUMER_CONTEXT *) arg;
  PIPE_READ reader = context->Reader;
  INDEX timeIndex;
  COUNT bufferIndex;
  char myBuffer[RANDOM_VALUES_SIZE];
  BOOL assending;
  COUNT length;

  timeIndex = 0;
  assending = TRUE;

  WatchdogAddFlag(context->WatchdogId);

  while(1)
  {
    //Set Buffer up with values which will fail if a bug occurs.
    for( bufferIndex = 0; bufferIndex < RANDOM_VALUES_SIZE; bufferIndex++ )
    {
      if( assending )
        myBuffer[bufferIndex] = 0;
      else
        myBuffer[bufferIndex] = RANDOM_VALUES_SIZE;
    }

    length = RandomNumbers[timeIndex];

    //Perform read
    PipeReadStruct(
        myBuffer,
        length,
        reader);

    //validate direction of buffer.
    for( bufferIndex = 0; bufferIndex+1 < length; bufferIndex++)
    {
      if( assending )
      {
        if( myBuffer[bufferIndex] >= myBuffer[bufferIndex+1] )
          KernelPanic();
      }
      else
      {
        if( myBuffer[bufferIndex] <= myBuffer[bufferIndex+1] )
          KernelPanic();
      }
    }

    //Setup next value.
    timeIndex = ( timeIndex + 1 ) % RANDOM_VALUES_SIZE;
    assending = !assending;
    WatchdogNotify(context->WatchdogId);
  }
  return NULL;
}
Example #3
0
File: init.c Project: d33tah/whitix
initcode int PhysInit()
{
	DWORD maxPfn, memSize;
	
	PhysReadMemoryMap();

	maxPfn = GetMaxPfn();
		
	if (maxPfn >= PFN_MAX)
	{
		KePrint(KERN_INFO "PHYS: Your machine has more than 4GB of RAM. Limiting to 4GB for the moment.\n");
		maxPfn = PFN_MAX - 1;
	}
			
	PageEarlyInit(maxPfn);

	/* Print memory size for information purposes */
	memSize=(maxPfn >> 8);
	KePrint(KERN_INFO "PHYS: %umb physical memory available\n", memSize);

	if (memSize < 8)
		KernelPanic("Less than 8mb memory available. Whitix requires more than this\n");

	/* So that appropriate areas of the memory are reserved when setting up the page stack */
	DoReserveAreas(maxPfn);

	/* Set up the page allocation (memory/page_alloc.c) */
	PageInit();

	return 0;
}
Example #4
0
void WorkerWakeOnLock( struct LOCKING_CONTEXT * context )
{
        struct WORKER_ITEM * worker;
        struct WORKER_QUEUE * queue;

        worker = BASE_OBJECT( context,
                        struct WORKER_ITEM,
                        LockingContext);
        queue = worker->Queue;

        switch( context->State )
        {
                case LOCKING_STATE_READY:
                        //we acquired the lock right away.
                        //mark is acquired.
                        context->State = LOCKING_STATE_ACQUIRED;
                        break;

                case LOCKING_STATE_BLOCKING:
                        //We acquired the lock after blocking.
                        //mark as acquired and add to work queue.
                        WorkerAddItem( queue, worker );
                        context->State = LOCKING_STATE_ACQUIRED;
                        break;

                case LOCKING_STATE_ACQUIRED:
                default:
                        KernelPanic();
                        break;
        }
}
Example #5
0
File: fat.c Project: d33tah/whitix
DWORD FatAccess(struct VfsSuperBlock* sBlock,DWORD clusterNum,int newVal)
{
	struct FatSbInfo* fatInfo=FatGetSbPriv(sBlock);
	DWORD first=0,last=0,retVal=0;
	BYTE *pFirst=NULL,*pLast=NULL;
	struct Buffer* buff,*buff2,*copyBuff,*copyBuff2;
	DWORD i;
	int block;

	if (clusterNum > fatInfo->totalDataSectors)
	{
		KePrint("PANIC: FatAccess : cluster number (%#X) > totalDataSectors from %#X\n",clusterNum,__builtin_return_address(0));
		KernelPanic("FatAccess: cluster number > total data sectors");
		cli(); hlt();
	}

	/* Due to the lovely FAT12 format, where entries can strech over blocks, 
	 * 2 blocks have to be read in in the worst case scenario */

	/* Get the index number into the FAT */
	if (fatInfo->fatType == 12)
	{
		first=clusterNum*3/2;
		last=first+1;
	}else if (fatInfo->fatType == 16)
		last=first=clusterNum*2; /* Never goes over a sector boundary */
	else
		/* FAT32 */
		last = first = clusterNum * 4;

	/* Read in the FAT sector(s) concerned */
	buff=BlockRead(sBlock->sDevice,fatInfo->fatStart+(first/BYTES_PER_SECTOR(sBlock)));
	if (!buff)
	{
		KePrint("Failed to read buffer in FatAccess\n");
		return 0;
	}

	/* Is the entry on the same sector? */
	if ((first/BYTES_PER_SECTOR(sBlock)) == (last/BYTES_PER_SECTOR(sBlock)))
		buff2=buff;
	else{
		buff2=BlockRead(sBlock->sDevice,(fatInfo->fatStart+(first/BYTES_PER_SECTOR(sBlock)))+1);
		if (!buff2)
		{
			BlockFree(buff);
			KePrint("Failed to read buffer 2 in FatAccess\n");
			return 0;
		}
	}

	if (fatInfo->fatType == 12)
	{
		/* Slightly confusing */
		pFirst=&((BYTE*)buff->data)[first % BYTES_PER_SECTOR(sBlock)];
		pLast=&((BYTE*)buff2->data)[(first+1) % BYTES_PER_SECTOR(sBlock)];
		if (clusterNum & 1)
			retVal=((*pFirst >> 4) | (*pLast << 4)) & 0xFFF;
		else
Example #6
0
void StallThreadMain( void * arg )
{
	while(TRUE)
	{
		if(StallCount != 0 )
		{
			KernelPanic();
		}

		StallCount++;
		TotalStall++;
		SchedulerStartCritical();
		SchedulerBlockThread();
		SchedulerForceSwitch();
	}

	//We should never get here.
	KernelPanic();
}
Example #7
0
void DeathThreadMain( void * arg )
{
	if( DeathCount != 0 )
	{
		KernelPanic();
	}

	DeathCount++;
	TotalDeath++;
}
Example #8
0
void ContextBootstrap(void * arg)
{
        struct CONTEXT * context = arg;

        //Here is where we end up if the kernel context switches to a new thread.
        //i.e. this is the same state as the line after HalContextSwitch.
        IsrEnable(IRQ_LEVEL_MAX);

        context->Main(context->MainArg);
        //Should never return.
        KernelPanic();
}
Example #9
0
void MultibootDumpInfo(multiboot_info_t* multiboot_info) {
    printf("Multiboot Information:\n");
    printf("    Flags: 0x%X\n", multiboot_info->flags);
    printf("    Bootloader: %s\n", multiboot_info->boot_loader_name);
    if(BIT_CHECK(multiboot_info->flags, 0)) {
        printf("    Lower memory: %uKB\n", multiboot_info->mem_lower);
        uint32_t mem_upper_mb = multiboot_info->mem_upper / 1024;
        printf("    Upper memory: %uKB (%uMB)\n", multiboot_info->mem_upper, mem_upper_mb);
    }
    if(BIT_CHECK(multiboot_info->flags, 1)) {
        printf("    Boot device: 0x%X\n", multiboot_info->boot_device);
    }
    if(BIT_CHECK(multiboot_info->flags, 2)) {
        printf("    Command line: %s\n", multiboot_info->cmdline);
    }
    if(BIT_CHECK(multiboot_info->flags, 3)) {
        printf("    Module Information:\n");
        printf("        Count: %d\n", multiboot_info->mods_count);
        printf("        Modules start at: 0x%X\n", multiboot_info->mods_addr);
        multiboot_module_t* module = (multiboot_module_t*) multiboot_info->mods_addr;
        for(size_t i = 0; i < multiboot_info->mods_count; i++) {
            printf("        Module #%d, Start: 0x%X, End: 0x%X, Cmdline: %s\n", i, module->mod_start, module->mod_end, module->cmdline);
            module++;
        }
    }
    if(BIT_CHECK(multiboot_info->flags, 4) && BIT_CHECK(multiboot_info->flags, 5)) {
        KernelPanic("Invalid Mutliboot flags! Bits 4 and 5 both set.\n", NULL);
    }
    if(BIT_CHECK(multiboot_info->flags, 4)) {
        multiboot_aout_symbol_table_t* aout_symbol_table = &(multiboot_info->u.aout_sym);
    }
    if(BIT_CHECK(multiboot_info->flags, 5)) {
        multiboot_elf_section_header_table_t* elf_header = &(multiboot_info->u.elf_sec);
    }
    if(BIT_CHECK(multiboot_info->flags, 6)) {
        printf("    Memory Map Information:\n");
        printf("        Map address: 0x%X\n", multiboot_info->mmap_addr);
        printf("        Map length: 0x%X\n", multiboot_info->mmap_length);
        multiboot_memory_map_t* memory_map = (multiboot_memory_map_t*) multiboot_info->mmap_addr;
        for(; memory_map < multiboot_info->mmap_addr + multiboot_info->mmap_length;
                memory_map = (multiboot_memory_map_t*) ((uint32_t) memory_map + memory_map->size + sizeof(memory_map->size))) {
            printf("        Size: 0x%X, Base Address: 0x%X%X, Length: 0x%X%X, Type: 0x%X\n",
                   memory_map->size,
                   memory_map->base_addr >> 32, memory_map->base_addr & 0xFFFFFFFF,
                   memory_map->length >> 32, memory_map->length & 0xFFFFFFFF,
                   memory_map->type);
        }
    }
Example #10
0
void Reader( void * arg )
{
	INDEX index;

	int first,second;
	BOOL ready = FALSE;

	while( ! ready )
	{
		SchedulerStartCritical();
		if( TimesWritten > 0 )
		{
			ready = TRUE;
			SchedulerEndCritical();
		}
		else
		{
			SchedulerForceSwitch();	
		}
	}

	while(1)
	{
		ResourceLockShared( &BufferLock, NULL );

		//the resource should be shared
		ASSERT( BufferLock.State == RESOURCE_SHARED );

		for(index=1 ; index < BUFFER_SIZE; index++)
		{
			first = Buffer[index-1];
			second = Buffer[index];
			if( (first +1) != second )
			{
				KernelPanic( );
			}
		}

		ResourceUnlockShared( &BufferLock );

		SchedulerStartCritical();
		TimesRead++;
		SchedulerForceSwitch();
	}
}
Example #11
0
void WatchdogInterrupt()
{
        //NOTICE THAT WE DON'T UPDATE ISR HERE.
        KernelPanic();
}