Пример #1
0
void init_kernel() 
{
    terminal_initialize();

    init_serial(COM1);
    terminal_enable_serial_echo(COM1);

    terminal_printf("fOS version %s\n\n\n", KERNEL_VERSION);

    kinit(end + 4096, end + 4096 + (100 * 4096));

    init_gdt();
    load_gdt();


    load_idt();
    load_isrs();

    irq_install();
    asm volatile ( "sti" );

    timer_install();
    sleep(1);

    keyboard_install();

    init_paging();
    switch_to_paging();
}
Пример #2
0
void kmain(multiboot_info_t* mbd, unsigned int magic){
	// kernel entry point.
	//unsigned char* videoram = (unsigned char*) 0xb8000;
	//videoram[0] = 65;
	//videoram[1] = 0x07;
	//setMode(0x13);
	setMode(320, 200, 8); // HOLY SHIT THIS WORKS
	clrscr();
	gdt_install();
	idt_install();
	isrs_install();
	irq_install();
	timer_install();
	start_paging(mbd);
	keyboard_install();
	init_genrand(get_timer_ticks());
	__asm__ __volatile__ ("sti");
	kprint("Hello, We have booted successfully!\n\tTip: type help for command info\n");
		
	while(1){
		if(todo != NULL){
			void(*function)() = todo;
			function(todoCP);
			todo = NULL;
		}
	}
	
}
Пример #3
0
int kmain(/*struct multiboot *mboot_ptr*/)
{
	init_descriptor_tables();
	keyboard_install();
	
	initfs();

	shell();
	return 0xDEADBADA;
}
Пример #4
0
/*
 * Called from boot.S, after global constructor
 */
void kernel_main(multiboot_info *mbt)
{
	/*
	 * second argument is an 8 bit flag. low bit sets verbosity.
	 */
	boot_info(mbt,MB_DRIVE | MB_DEV);
	printf ("Setting up Global Descriptor Table... ");
	gdt_install();
	puts ("OK");
	printf ("Setting up Interrupt Descriptor Table... ");
	idt_install();
	puts ("OK");
	printf ("Setting up IRQ... ");
	irq_install();
	puts ("OK");
	printf ("Configuring system clock... ");
	timer_install(100);
	puts ("OK");
	printf ("Enabling keyboard... ");
	keyboard_install();
	puts ("OK");
	printf ("Enabling interrupts... ");
	irq_enable();
	if (irq_on()) {
		puts ("OK");
	} else {
		abort();
	}
	/*
	 * Testing cr0 register
	 */
	uint32_t _cr0 = cr0();
	printf("PE (Protection Enabled, lowest bit of cr0 register) set? 0x%lx, %s\n",
			_cr0,_cr0&0x00000001?"yes":"no");

	printf("Rho version %d.%d.%d booted\n",RHO_MAJOR,RHO_MINOR,RHO_PATCH);
	checkAllBuses();
	/*
	 * Wait until interrupted
	 */
//	mem_inspect(1024,1536);
	while ( 1 ) {
		/*
		 * Update the cursos position
		 */
		upd_c();
		/*
		 * Wait for interrupts
		 */
		irq_wait();
	}
	/* */
}
Пример #5
0
void main()
{
	gdt_install(3) ;
	init_video(&sc) ;  
	idt_install() ; 
	isrs_install() ; 
	irq_install() ; 
	timer_install() ; 
	keyboard_install() ;
	__asm__ __volatile__ ("sti"); 
	int state = 0 ; 
	screen sc  ;  
	//puts(&sc, "Hello world in new functions\n") ; 
	print_int(&sc, state) ;  
	/* Since there is no support for newlines in terminal_putchar yet, \n will
	   produce some VGA specific character instead. This is normal. */
}
Пример #6
0
int kernel_main(uint32_t esp) {
  initial_esp = esp;

  gdt_install();
  idt_install();
  isrs_install();
  irq_install();

  asm volatile("sti");

  timer_install();

  keyboard_install();

  ASSERT(mboot_ptr != 0);
  ASSERT(mboot_ptr->mods_count > 0);
  uint32_t initrd_location = *((uint32_t*)mboot_ptr->mods_addr);
  uint32_t initrd_end = *(uint32_t*)(mboot_ptr->mods_addr + 4);
  // move the start of our kernel heap to past the initrd
  placement_address = initrd_end;

  initialize_paging();

  initialize_tasking();

  fs_root = initialize_initrd(initrd_location);

  // Create a new process in a new address space which is a clone of this.
  int ret = fork();

  printf("fork() returned %x, ", ret);
  printf(" getpid() returned %x\n", getpid());

  printf("Loading initial ramdisk...\n");

  asm volatile("cli");
  traverse_initrd();
  asm volatile("sti");

  printf("That's all folks\n");

  for(;;);

  return 0;
}
Пример #7
0
void main(void)
{

   gdt_install();
   idt_install();
   isrs_install();
   irq_install();
   timer_install();
   keyboard_install();
   mouse_install();

   __asm__ __volatile__ ("sti");

   clear_keyboard_buffers();
   clear(BLACK,BLACK);
   bscreen();
   for (;;);
}
Пример #8
0
void kernel_main(){

    console_initialize();

    gdt_install();
    idt_install();
    isrs_install();
    irq_install();
    timer_install();
    keyboard_install();
    __asm__ __volatile__ ("sti");
    
	console_putString("Hello, kernel World!\n");

    for (;;){
        
    }
}
Пример #9
0
void kmain ( void* mbd, unsigned int magic )
{
        if ( magic != 0x2BADB002 )
        {
		/* there is something wrong */
        } 
	else 
	{
		clearscreen();
		printline ("akv's - code is running");
		gdt_install ();
		idt_install ();
		isrs_install ();
		irq_install ();
		__asm__ __volatile__ ("sti");
		timer_install (2);
		keyboard_install ();
		for(;;);
	}
}
Пример #10
0
void kmain( void* mbd, unsigned int magic )
{
	/* Installations */
	gdt_install();
	idt_install();
	isrs_install();
	irq_install();
	timer_install();
	keyboard_install();
	init_video();
	
	__asm__ __volatile__ ("sti"); // Disable interrupts

	settextcolor(0x0F, 0x00);

	unsigned char string[] = "Welcome to Gulinux 0.01. For a list of commands, type help.\n";

	putsa(string);
	for(;;);
}
Пример #11
0
void kernel_main() {
  gdt_install();
  idt_install();
  isrs_install();
  irq_install();
  terminal_initialize();
  memory_manager_init();
  enable_interrupts();
  timer_install();
  keyboard_install();
  shell_init();

  terminal_writestring("Hello, kernel World!\n");
  terminal_writestring("Here is some text in a new line\n");
  terminal_writestring("Here is some more text\n");
  terminal_writestring("Here is a new line\n");
  terminal_writestring("Here is some text after terminal scroll\n");
  char str[] = "A string";
  char ch = 'c';
  int integer = 45;
  printf("This is a test for printf.\nThis is a char %c and this a string %s\n", ch, str);
  printf("This is an int %d. This is the same in hex %x\n", integer, integer);

  for (size_t i = 0; i < 5; i++) {
    printf("This is line number %d\n", i);
  }

  puts("waiting for 2 sec\n");
  timer_wait(2);
  puts("waiting complete\n");

  char buffer[200];
  gets(buffer);
  printf("%s\n", buffer);
  while(1) {
    shell();
  }

}
Пример #12
0
void boot(void)
{
	// note: function changes rsp, local stack variables can't be practically used
	register char *temp1, *temp2;
        uint32_t* modulep;
        void* physfree;
	__asm__(
		"movq %%rsp, %0;"
		"movq %1, %%rsp;"
		:"=g"(loader_stack)
		:"r"(&stack[INITIAL_STACK_SIZE])
	);
	setup_tss();
	reload_gdt();
        reload_idt();
        irq_install();
        timer_install();
        keyboard_install();
        __asm__("sti");
        modulep = (uint32_t*)((char*)(uint64_t)loader_stack[3] + (uint64_t)&kernmem - (uint64_t)&physbase);
        physfree = (void*)(uint64_t)loader_stack[4];
        kphysfree = physfree;
        mm_phy_init(modulep);
        vmmgr_init();
        vmmgr_page_allocator_init();
        cls();
        scheduler_init();
	/*start(
		(uint32_t*)((char*)(uint64_t)loader_stack[3] + (uint64_t)&kernmem - (uint64_t)&physbase),
		&physbase,
		(void*)(uint64_t)loader_stack[4]
	);*/
	for(
		temp1 = "!!!!! start() returned !!!!!", temp2 = (char*)0xb8000;
		*temp1;
		temp1 += 1, temp2 += 2
	) *temp2 = *temp1;
	while(1);
}
Пример #13
0
void main()
{
	char *video_memory = (char *)0xb8000;
	*video_memory = 'X';
	some_function();

	init_video();

	idt_install();
	isr_install();
	irq_install();

	timer_install();
	keyboard_install();

	__asm__ __volatile__ ("sti");

	print("Hello World\n");

	print("\n\tFrom Ajay Saini!\n");

	// test : running of exception handlers
	//print(20/0);
}
Пример #14
0
/* This is the entry point to the bulk of the kernel.
 * @mb is a pointer to a <multiboot_info> structure which has important
 * information about the layout of memory which is passed along from the
 * bootloader.
 * First, the kernel sets up the <gdt> or Global Descriptor Table which
 * describes the layout of memory.
 * Next, it installs the <idt> or interrupt descriptor table, which declares
 * which interrupts are available, and whether they can be accessed from user
 * mode.
 * After the basic CPU state has been initialized, logging and the VGA terminal
 * are initialized, and the kernel heap is installed. Next, the physical memory
 * allocator and the keyboard drivers are initialized. Note that the kernel
 * heap must be initialized before the physical memory allocator since certain
 * parts of the allocator live on the heap. Finally the init process page table
 * is created, and multi-processing is initialized.
 * @return this function should never return.
*/
void kernel_main(struct multiboot_info *mb) {
    gdt_install();
    idt_install();
    terminal_initialize();
    initialize_klog();
    kheap_install((struct kheap_metadata*)KHEAP_PHYS_ROOT, PAGE_SIZE);
    physical_allocator_init(mb->mem_upper + mb->mem_lower);
    keyboard_install();
    char *hi = "Hello kernel!\n";
    void *testing = kmalloc(16);
    memcpy(testing, hi, 16);
    kputs(testing);
    klog(testing);
    kfree(testing);
    (void)kernel_page_table_install(mb);

    proc_init();
    struct process *worker_proc = create_proc(worker);
    schedule_proc(worker_proc);

    while (1) {
        klog("kernel\n");
    }
}
Пример #15
0
k_main() // like main
{
	k_clear_screen();

	k_puts("Welcome to MoOS version 0.1 (" BUILDTAG ")\n");
    k_puts("\n");
    if (pci_is_available())
    {
	    k_puts(" Detected a PCI bus\n");
    } else
    {
	    k_puts(" No PCI bus detected\n");
    }
    // Try to find PCI devices
    unsigned int i, j, k;
    for (i=0; i<256; i++)
    {
        for (j=0; j<32; j++)
        {
            for (k=0; k<8; k++)
            {
                unsigned int temp = pci_read_dword(i, j, k, 0);
                if ((temp & 0xffff) != 0xffff)
                {
                    printk("PCI device on bus: %u, slot: %u, function: %u VendorId/DeviceId: %x\n", i, j, k, temp);
                }
            }
        }
    }

// NE2000 code

#define NS_DATAPORT		0x10	/* NatSemi-defined port window offset. */
#define NE_DATAPORT		0x10	/* NatSemi-defined port window offset. */
#define NS_RESET		0x1f	/* Issue a read to reset, a write to clear. */

#define E8390_CMD		0x00	/* The command register (for all pages) */
#define E8390_STOP		0x01	/* Stop and reset the chip */
#define E8390_START		0x02	/* Start the chip, clear reset */
#define E8390_RREAD		0x08	/* Remote read */
#define E8390_NODMA		0x20	/* Remote DMA */
#define E8390_PAGE0		0x00	/* Select page chip registers */
#define E8390_PAGE1		0x40	/* using the two high-order bits */
#define E8390_PAGE2		0x80
#define E8390_PAGE3		0xC0	/* Page 3 is invalid on the real 8390. */

#define E8390_RXOFF 0x20		/* EN0_RXCR: Accept no packets */
#define E8390_TXOFF 0x02		/* EN0_TXCR: Transmitter off */

/* Page 0 register offsets. */
#define EN0_CLDALO		0x01	/* Low byte of current local dma addr  RD */
#define EN0_STARTPG		0x01	/* Starting page of ring bfr WR */
#define EN0_CLDAHI		0x02	/* High byte of current local dma addr	RD */
#define EN0_STOPPG		0x02	/* Ending page +1 of ring bfr WR */
#define EN0_BOUNDARY	0x03	/* Boundary page of ring bfr RD WR */
#define EN0_TSR			0x04	/* Transmit status reg RD */
#define EN0_TPSR		0x04	/* Transmit starting page WR */
#define EN0_NCR			0x05	/* Number of collision reg RD */
#define EN0_TCNTLO		0x05	/* Low	byte of tx byte count WR */
#define EN0_FIFO		0x06	/* FIFO RD */
#define EN0_TCNTHI		0x06	/* High byte of tx byte count WR */
#define EN0_ISR			0x07	/* Interrupt status reg RD WR */
#define EN0_CRDALO		0x08	/* low byte of current remote dma address RD */
#define EN0_RSARLO		0x08	/* Remote start address reg 0 */
#define EN0_CRDAHI		0x09	/* high byte, current remote dma address RD */
#define EN0_RSARHI		0x09	/* Remote start address reg 1 */
#define EN0_RCNTLO		0x0a	/* Remote byte count reg WR */
#define EN0_RCNTHI		0x0b	/* Remote byte count reg WR */
#define EN0_RSR			0x0c	/* rx status reg RD */
#define EN0_RXCR		0x0c	/* RX configuration reg WR */
#define EN0_TXCR		0x0d	/* TX configuration reg WR */
#define EN0_COUNTER0	0x0d	/* Rcv alignment error counter RD */
#define EN0_DCFG		0x0e	/* Data configuration reg WR */
#define EN0_COUNTER1	0x0e	/* Rcv CRC error counter RD */
#define EN0_IMR			0x0f	/* Interrupt mask reg WR */
#define EN0_COUNTER2	0x0f	/* Rcv missed frame error counter RD */

	unsigned char SA_prom[32];

	struct {char value, offset; } program_seq[] = {
		{E8390_NODMA+E8390_PAGE0+E8390_STOP, E8390_CMD}, /* Select page 0*/
		{0x48,	EN0_DCFG},		/* Set byte-wide (0x48) access. */
		{0x00,	EN0_RCNTLO},	/* Clear the count regs. */
		{0x00,	EN0_RCNTHI},
		{0x00,	EN0_IMR},		/* Mask completion irq. */
		{0xFF,	EN0_ISR},
		{E8390_RXOFF, EN0_RXCR},		/* 0x20	 Set to monitor */
		{E8390_TXOFF, EN0_TXCR},		/* 0x02	 and loopback mode. */
		{32,			EN0_RCNTLO},
		{0x00,	EN0_RCNTHI},
		{0x00,	EN0_RSARLO},	/* DMA starting at 0x0000. */
		{0x00,	EN0_RSARHI},
		{E8390_RREAD+E8390_START, E8390_CMD},
	};

	int wordlength = 2;

	/* Read the 16 bytes of station address prom, returning 1 for
	   an eight-bit interface and 2 for a 16-bit interface.
	   We must first initialize registers, similar to NS8390_init(eifdev, 0).
	   We can't reliably read the SAPROM address without this.
	   (I learned the hard way!). */
	for (i = 0; i < sizeof(program_seq)/sizeof(program_seq[0]); i++)
		outportb(0x300 + program_seq[i].offset, program_seq[i].value);

	for(i = 0; i < 32 /*sizeof(SA_prom)*/; i+=2) {
		SA_prom[i] = inportb(0x300 + NE_DATAPORT);
		SA_prom[i+1] = inportb(0x300 + NE_DATAPORT);
		if (SA_prom[i] != SA_prom[i+1])
			wordlength = 1;
	}

	printk("Station Address PROM    0:");
	for(i = 0; i < sizeof(SA_prom)/2; i++)
		printk(" %2.2x", SA_prom[i]);
	printk("\nStation Address PROM %#2x:", i);
	for(; i < sizeof(SA_prom); i++)
		printk(" %2.2x", SA_prom[i]);
	printk("\n");

    printk("NE200 wordlength = %u\n", wordlength);

	if (wordlength == 2) {
		/* We must set the 8390 for word mode, AND RESET IT. */
		int tmp;
		outportb(0x300 + EN0_DCFG, 0x49);
		tmp = inportb(0x300 + NS_RESET);
		outportb(0x300 + NS_RESET, tmp);
		/* Un-double the SA_prom values. */
		for (i = 0; i < 16; i++)
			SA_prom[i] = SA_prom[i+i];
	}
    // Check for NE2000 on I/O address 0x300
    printk("MAC of NE2000 @0x300: ");

    outportb(0x300 + E8390_CMD, E8390_NODMA + E8390_PAGE1);
    for (i = 1; i < 6; i++)
        printk("%2X:", inportb(0x300 + i));
    printk("%2X\n");

// End of NE2000 code

    init_pics(0x20, 0x28);

    idt_install();
    isrs_install();
    irq_install();
    keyboard_install();

    asm volatile ("sti");

    for(;;);
}
Пример #16
0
int window_init(window_t* window) { LOG

    int error;
    int i;

    if (window->draw) {
        /* initialize video */
        if (!vg_init(window->video_mode)) {
            printf("window_init: vg_init failed.\n");
            return -1;
        }
    }

    window->redraw = 0;
    window->done = 0;

    /* init font system */
    error = vg_init_FreeType();
    if (error) {
        printf("window_init: vg_init_FreeType failed with error code %d.\n", error);
        return error;
    }

    error = window_set_title(window, "cnix %s", "0.2");
    if (error) {
        printf("window_init: window_set_title failed with error code %d.\n", error);
        return error;
    }
    
    error = window_set_log_message(window, "");
    if (error) {
        printf("window_init: window_set_log_message failed with error code %d.\n", error);
        return error;
    }

    error = window_set_size(window, window->draw ? vg_get_h_res() : 1024, window->draw ? vg_get_v_res() : 768);
    if (error) {
        printf("window_init: window_set_size failed with error code %d.\n", error);
        return error;
    }

    /* set up tabs */
    window->current_tab = -1;
    for (i = 0; i < TAB_COUNT; ++i)
        window->tabs[i] = NULL;

    //window->tabs[0]  = tab_create("#1");
    //window->tabs[1]  = tab_create("#2");
    //window->tabs[2]  = tab_create("#3");
    //window->tabs[3]  = tab_create("#4");
    //window->tabs[4]  = tab_create("#5");
    //window->tabs[5]  = tab_create("#6");
    //window->tabs[6]  = tab_create("#7");
    //window->tabs[7]  = tab_create("#8");
    //window->tabs[8]  = tab_create("#9");
    //window->tabs[9]  = tab_create("#10");
    //window->tabs[10] = tab_create("#11");
    window->tabs[11] = tab_create("#console");
    window->current_tab = TAB_CONSOLE;
    window->prev_current_tab = window->current_tab;

    window->date = NULL;

    /* initialize interrupt handlers */
    int_init();

    /* install mouse */
    error = window_install_mouse(window);
    if (error) {
        printf("window_init: window_install_mouse failed with error code %d.\n", error);
        return error;
    }
    printf("window_install: mouse installed with success.\n");

    /* install keyboard */
    error = keyboard_install();
    if (error) {
        printf("window_init: keyboard_install failed with error code %d.\n", error);
        return error;
    }
    printf("window_init: keyboard installed with success.\n");

    /* set up buttons */
    new_btn = new_button(869, 5, 20, 20, new_btn_draw, new_btn_click, 1, window);
    open_btn = new_button(894, 5, 20, 20, open_btn_draw, open_btn_click, 1, window);
    save_btn = new_button(919, 5, 20, 20, save_btn_draw, save_btn_click, 1, window);
    make_btn = new_button(944, 5, 20, 20, make_btn_draw, make_btn_click, 1, window);
    run_btn = new_button(969, 5, 20, 20, run_btn_draw, run_btn_click, 1, window);
    close_btn = new_button(994, 5, 20, 20, close_btn_draw, close_btn_click, 1, window);

    window->state = WIN_STATE_NORMAL;
    return 0;
}
Пример #17
0
void KERNEL_CALL
os_main()
{
    vga_install();
    BRAG("Eve successfully switched to P-mode with paging enabled\n");
    put_logo();

    idt_install();
    BRAG("ISRs & IRQs are on-line\n");

    sys_call_table_install();
    BRAG("System call table installed\n");

    timer_install();
    BRAG("PIT firing rate is %d Hz\n", _TIMER_RATE);

    mm_install();
    BRAG("Memory manager is installed\n", _TIMER_RATE);
    //mm_print_info();

    /*{
        char* p;

        SEPARATE
        DBG_DUMP(p = sbrk(2));
        DBG_DUMP(sbrk(0));
        DBG_DUMP(*p);
        DBG_DUMP(p[1]);
        DBG_DUMP(p[4095]); // possable page fault
        //DBG_DUMP(p[4096]); // page fault for sure

        SEPARATE
        DBG_DUMP(p = sbrk(4 * MEGABYTE));
        DBG_DUMP(sbrk(0));
        DBG_DUMP(p[0]);
        DBG_DUMP(p[MEGABYTE]);
        DBG_DUMP(p[4 * MEGABYTE]); // possable page fault
        //DBG_DUMP(p[5 * MEGABYTE]); // page fault for sure

        SEPARATE
        DBG_DUMP(sbrk(-4 * MEGABYTE));
        DBG_DUMP(p = sbrk(0));
        DBG_DUMP(p[0]);     // possable page fault
        //DBG_DUMP(p[MEGABYTE]);  // page fault for sure

        DBG_DUMP(sbrk(-2));
        DBG_DUMP(p = sbrk(0));
        //DBG_DUMP(p[0]); // page fault for sure
    }*/

    /*{
        char* p;
        SEPARATE;
        DUMP(sbrk(0));
        DUMP(p = malloc(2));
        DUMP(sbrk(0));
        DUMP(*p);
        DUMP(p[1]);
        //DUMP(p[4095]); // possable page fault
        //DUMP(p[4096]); // page fault for sure

        char* q;
        SEPARATE;
        DUMP(q = malloc(4 * MEGABYTE));
        DUMP(sbrk(0));
        DUMP(q[0]);
        DUMP(q[MEGABYTE]);
        DUMP(q[4 * MEGABYTE]); // possable page fault
        //DUMP(p[5 * MEGABYTE]); // page fault for sure

        SEPARATE;
        MARK(free(q));
        DUMP(sbrk(0));
        //DUMP(q[0]);     // possable page fault
        //DUMP(p[MEGABYTE]);  // page fault for sure

        MARK(free(p));
        DUMP(sbrk(0));
        //DUMP(p[0]); // page fault for sure
    }*/

	keyboard_install();
    BRAG("Keyboard is on-line (US layout)\n");

    // prepare tss segment
    tss_install();
    //BRAG("TSS is loaded\n");
    // install resource manager before starting multitasking
    rm_install();
    // task manager
    task_ring_node_t* pKernelNode = tm_install();
    BRAG("Multitasking is enabled\n");
    //print_task_tree();

    // load shell app
    gEshTaskOffset = (dword_t)&gKernelEnd;
    tm_load_task((pointer_t) gEshTaskOffset, pKernelNode, ACC_USER, PRIOR_LOW, TRUE);

    extern dword_t gNextTaskOffset;
    gPingTaskOffset = gNextTaskOffset;

    /* from this point on Kernel process will serve as a resources manager */

    rm_start();

    for (;;);
}