Exemple #1
0
void ahci_port_rebase(uint8 port_num)
{
	HBA_PORT_t* port = &abar->ports[port_num];

	if (ahci_stop_cmd(port) == false)
	{
		printfln("port %u is not ok due to stop", port_num);
		return;
	}

	// Command list entry size = 32 bytes
	// Command list max entries = 32
	// Command list max size per port = 32 * 32 bytes = 1 KB = 2^10
	port->clb = AHCI_BASE + (port_num << 10);

	if (ahci_is_64bit())
		port->clbu = 0;

	memset((VOID PTR)port->clb, 0, 1024);

	// FIS offset = end_of_command_list (32 KB)
	// FIS entry size = 256 bytes per port
	port->fb = AHCI_BASE + (32 << 10) + (port_num << 8);

	if (ahci_is_64bit())
		port->fbu = 0;

	memset((VOID PTR)port->fb, 0, 256);

	// Command table offset = end_of_FIS (32 KB + 8 KB = 40 KB)
	// Command table size = 256 * 32 entries = 8 KB = 2^13 per port
	HBA_CMD_HEADER_t* cmd = (HBA_CMD_HEADER_t*)(port->clb);
	for (int i = 0; i < 32; i++)
	{
		cmd[i].prdtl = 8;	// 8 prdt entries per table => 256 bytes per command table
		cmd[i].ctba = AHCI_BASE + (40 << 10) + (port_num << 13) + (i << 8);

		if (ahci_is_64bit())
			cmd[i].ctbau = 0;

		memset((VOID PTR)cmd[i].ctba, 0, 256);
	}

	port->serr = (DWORD)-1;		// clear the error status register
	//port->ie = (DWORD)-1;
	if (ahci_start_cmd(port) == false)
	{
		printfln("port %u is not ok due to start", port_num);
		return;
	}
}
int main(int o_argc, const string const* o_argv) {
  struct sembuf _buf;
    
  _buf.sem_num = 0;
  _buf.sem_flg = 0;
  
  string _path = getExecPath("sys_v_sem");
  key_t _key = ftok(_path, 'x');
  asserts(_key, "ftok");
  free(_path);
  _path = NULL;

  /* Try to obtain an id of the set of semaphores. */
  int _semid = semget(_key, 1, S_IRUSR | S_IWUSR);
  asserts(_semid);
    
  /* lock the semaphore */
  _buf.sem_op = -1;
  asserts( semop(_semid, &_buf, 1) );
  
  /* enter critical section */    
  for(size_t i = 0; i < 5; i++) {
    printfln( "Hello!, %ld", cast(ulong)getpid() );
    sleep(1);
  }
  println("");
      
  /* unlock the semaphore */
  _buf.sem_op = 1;
  asserts( semop(_semid, &_buf, 1) );
      
  exit(EXIT_SUCCESS);
}
void parseCommand(const char *cmd){

	if(strcmp(cmd, "reboot") == 0){
		reboot();
	}else if(strcmp(cmd, "kernel") == 0){
		jump_to_kernel();
	}
	else if(strcmp(cmd, "help") == 0){
		help();
	}
	else if(strcmp(cmd, "ramtest") == 0){
		ramtest();
	}
	else if(strcmp(cmd, "flashtest") == 0){
		flashtest();
	}
	else if(strcmp(cmd, "halt") == 0){
		halt();
	}
	else if(strcmp(cmd, "white") == 0){
		vga_white();
	}
	else if(strcmp(cmd, "black") == 0){
		vga_black();
	}
	else{
		printfln("Unknown command... %s", cmd);
	}
}
Exemple #4
0
int ldr_main(struct multiboot_info* boot_info, uint32 krnldr_size_bytes)
{
	SetColor(MakeColor(DARK_BLUE, WHITE));
	ClearScreen();

	if (krnldr_size_bytes > 40 KB)
		PANIC("Kernel Loader is too large");

	init_kallocations(KRN_LDR_BASE + krnldr_size_bytes, KRN_LDR_LIMIT);

	Print("Initializing descriptor tables.");

	INT_OFF;
	init_isr();
	init_descriptor_tables();
	init_pic();
	INT_ON;

	init_pit_timer(50, timer_callback);

	struct kernel_info* k_info = kalloc(sizeof(struct kernel_info));

	//setup AHCI
	HBA_MEM_t* abar = PCIFindAHCI();

	// initialize basic virtual memory
	vmmngr_initialize();

	uint32 ahci_base = kalloc_get_ptr() + 1024 - (uint32)kalloc_get_ptr() % 1024;
	init_ahci(abar, ahci_base);

	uint32 start, _length, position = 0;
	fsysSimpleFind("MeOs.exe", 1, &_length, &start);

	if (start == (uint32)-1 && _length == 0)
		PANIC("Kernel module could not be found!");

	while (position <= _length)
	{
		fsysSimpleRead(start + position / 512, 4096, KERNEL_BASE + position);
		position += 4096;
	}

	// after all the loading is done... enable paging
	vmmngr_paging_enable(true);

	k_info->kernel_size = _length;
	k_info->isr_handlers = interrupt_handlers;
	k_info->gdt_base = gdt_entries;
	k_info->idt_base = idt_entries;

	printfln("Executing kernel\0");
	execute_kernel(boot_info, k_info);

	ClearScreen();
	_asm cli
	_asm hlt
}
void heap_display(heap* h)
{
	if (h == 0)
		return;
	printfln("Heap start: %h with size: %x. Currently using %u blocks.", h->start_address, h->size, h->current_blocks);
	heap_block* block = (heap_block*)h->start_address;

	while (block != 0)
	{
		if (block->magic != HEAP_BLOCK_MAGIC)
			printfln("HEAP ERROR");
		uint32 size = heap_block_size(h, block);
		printf("block at: %h with size: %x, ", block, size);
		if (block->used)
			printfln("used");
		else
			printfln("unused");

		block = block->next;
	}
}
int main(int argc, char **argv){
		char cmd[50];
      
		printfln("========= INSA BOOTLOADER ======== %s \r\n", "salute");
		//uart_println("========= INSA BOOTLOADER ======== \r\n");
		while(1){
			getCommand(cmd, 50);
			parseCommand(cmd);

		}

		// RESET, never reached because of while(1)
		//jump(0x00);
}
void vmmngr_print(pdirectory* dir)
{
	for (int i = 0; i < 1024; i++)
	{
		if (pd_entry_test_attrib(&dir->entries[i], I86_PDE_PRESENT) == false)
			continue;

		ptable* table = (ptable*)PAGE_GET_PHYSICAL_ADDR(&dir->entries[i]);

		printfln("table %i is present at %h", i, table);

		for (int j = 0; j < 1024; j++)
		{
			if (pt_entry_test_attrib(&table->entries[j], I86_PTE_PRESENT) == false)
				continue;

			//printf("page %i is present with frame: %h ", j, pt_entry_get_frame(table->entries[j]));
		}
	}
}
Exemple #8
0
void init_ahci(HBA_MEM_t* _abar, uint32 base)
{
	if (_abar == 0)
		PANIC("null abar");

	//if (ahci_is_enabled() == false)
	//	PANIC("AHCI Silicon is disabled");

	ahci_enable_interrupts(false);

	AHCI_BASE = base;
	abar = _abar;
#define DEBUG_REQUIRED_PORTS 2
	printfln("ports: %u", ahci_get_no_ports());

	for (uint8 i = 1; i < DEBUG_REQUIRED_PORTS; i++)
	{
		if (ahci_is_port_implemented(i))
			ahci_port_rebase(i);
	}
}
int main(int argc, char **argv){
      
		printfln("========= INSA BOOTLOADER ======== %s \r\n", "salute23");
		
		while(1);
}