Exemplo n.º 1
0
/* 
 * keyboard_interruption()
 *
 * Description:
 * Triggered by a keyboard interrupt (routed from the idt).
 *
 * Inputs: none
 *
 * Outputs: none
 */
void keyboard_interruption() {
	
	/* Mask interrupts */
	cli();
	
	/* Scancode (byte) that we receive from the keyboard. */
	uint8_t keyboard_scancode;

	/* Status that we get from keyboard to see if the buffer is full. */
	uint8_t keyboard_status;

	do {
		/* Dequeue the typed character from the keyboard buffer. */
		keyboard_scancode = inb(KEYBOARD_PORT);
		
		/* Process the input from the keyboard. */
		process_keyboard_input(keyboard_scancode);

		/* Print the buffer */
		printthebuffer();
		
		/* Check to see if the keyboard buffer is full. */
		keyboard_status = inb(KEYBOARD_STATUS_PORT);

	/* If the buffer is still full, repeat the process until the buffer 
	 * is empty. */
	} while (keyboard_status & BUFFER_NOT_EMPTY);

	/* Send End-of-Interrupt */
	send_eoi(KEYBOARD_IRQ);

	/* Unmask interrupts */
	sti();

}
Exemplo n.º 2
0
/********************************************************
void													*
rtc_int_handler()										*	
*	Inputs:			void								*
*	Outputs:		writes video memory to screen 	 	*
*	Return Value:	void								*
*	Function: Should execute test_interrupts handler	*
********************************************************/
void rtc_int_handler()
{
	//test_interrupts();								//calls function that writes video memory to screen.
	//test_rtc();
	outb(REG_C, PORT_1);								// select register C
	inb(PORT_2);										// just throw away contents
	interrupt_number++;
	send_eoi(RTC_PORT_NO);
}
Exemplo n.º 3
0
/* void send_eoi(uint32_t irq_num)
 * INPUT: irq_num - the irq line that signaled end of interrupt
 * OUTPUT: none
 * DESCRIPTION: writes the end of interrupt to the pic port
 */
void send_eoi(uint32_t irq_num)
{
	/* ZR - sending EOI */
	if(irq_num >= IRQ_SLAVE)
	{
		outb((EOI | (irq_num-IRQ_SLAVE)), SLAVE_8259_PORT);
		send_eoi(IRQ_CAS);
	}
	else
		outb((EOI | irq_num), MASTER_8259_PORT);
}
Exemplo n.º 4
0
void context_switch(int new_pid)
{
	if(new_pid == -1)
	{
		send_eoi(0);
		return;
	}

	uint32_t process_bp = _8MB - (_8KB)*(new_pid) - 4;
	pcb_t* new_process = (pcb_t *) (process_bp & 0xFFFFE000);

	set_PDBR(new_process->PD_ptr);

	tss.esp0 = new_process->k_sp;
	uint32_t p_sp = new_process->k_sp;
	uint32_t p_bp = new_process->k_bp;

	process_buf = new_process->file_fds[1].file_pos;

	process_id = new_pid;
	asm volatile("movl %%esp, %0":"=g"(curr_process->k_sp));
	asm volatile("movl %%ebp, %0":"=g"(curr_process->k_bp));
	curr_process = new_process;

	asm volatile("movl %0, %%esp"::"g"(p_sp):"memory");
	asm volatile("movl %0, %%ebp"::"g"(p_bp):"memory");
	// uint32_t process_bp = _8MB - (_8KB)*(new_pid) - 4;
	// pcb_t* new_process = (pcb_t *) (process_bp & 0xFFFFE000);


	// set_PDBR(curr_process->PD_ptr);

	// tss.esp0 = new_process->esp0;
	// tss.ss0 = new_process->ss0;


	send_eoi(0);
	// sti();
	// return;

}
Exemplo n.º 5
0
void kmain(uint32_t magic) {
    if ( magic != 0x2BADB002 )
    {
    	print("Something went not according to specs.");
		exit();
    }

	kclear();
        char printbuf[256];
        snprintf(printbuf, 256, "kernel loaded at %p, ends at %p\n", kernel_start, kernel_end);
        print(printbuf);
        print("initializing GDT...\n");
        init_gdt();
        print("initializing IDT...\n");
        init_idt();
        print("initializing physical memory manager...\n");
        init_pmm();
        if (pmm_is_free((paddr_t)kernel_start) || pmm_is_free((paddr_t)kernel_end)) panic("kernel memory is not reserved");
        if (pmm_is_free((paddr_t)0xb8000)) panic("video ram is not reserved");
        print("initializing virtual memory manager...\n");
        init_vmm();
	print("initializing PICs...\n");
	init_pics(0x20, 0x28);
        print("initializing keyboard...\n");
        init_keyboard();
        print("enabling keyboard interrupts...\n");
        enable_irq(1);
        send_eoi(0);
        __asm__ __volatile__ ("sti");
        print("initializing symbol table...\n");
        init_stacktrace();
        print("initializing timer...\n");
        init_timer(10);
		enable_irq(0);
		print("initializing speaker...\n");
        print("initializing ACPI...\n");
        init_acpi();
        print("reclaiming ACPI memory...\n");
        acpi_reclaim_memory();
        print("initializing shell...\n");
        init_shell_builtins();
	beep(100, 100);
	cprint("Hello OS\n", 2);
	update_cursor();
        shell();
}
Exemplo n.º 6
0
Arquivo: rtc.c Projeto: nwhite20/home
/*
* void do_rtc();
*   Inputs: none
*   Return Value: none
*   Function: Processes an rtc interrupt
*/
void do_rtc() {

	/* stop interrupts */
	cli();

	/* read in trash to get next interrupt */
	outb(REGISTER_C, RTC_PORT);
	inb(RTC_DATA);	
	rtc_flag=1;
	/* flicker screen - COMMENT OUT TO TEST KEYBOARD */
	/*test_interrupts();*/

	/* send eoi and resume interrupts */
	send_eoi(RTC_IRQ);
	sti();

}
Exemplo n.º 7
0
void isr_kbd_int(void) {
  u8 key = get_scancode();

  if (key & 0x80) {
    if (key == 170)
      shift_locked = 0;
  }
  else {
    if (key == 42) {
      shift_locked = 1;
    }
    else if (key == 58)
      shift_locked = !shift_locked;
    else {
      u8 c = scancode_to_ascii(key);
      if (c)
        putchar(c);
    }

  }
  send_eoi(1);
}
Exemplo n.º 8
0
/*
*	Function: init_keyboard_handler()
*	Description: This function reads from the appropriate port on the keyboard to 
*				receive the interrupts generated, parses this information, and 
*				displays the associated character on the screen.
*	inputs:	 nothing
*	outputs: nothing
*	effects: prints character to screen from scancode_map
*/
void 
keyboard_interrupt_handler() {
	cli();
	uint8_t c = 0;
	do {
		if (inb(KEYBOARD_DATA_PORT) != 0) {
			c = inb(KEYBOARD_DATA_PORT);
			if (c > 0) {
				break;
			}
		}
	} while(1);

	switch (c) {
		case LSHIFT_DOWN:
		case RSHIFT_DOWN:
			ENABLE_SHIFT();
			break;
		case LSHIFT_UP:
		case RSHIFT_UP:
			DISABLE_SHIFT();
			break;
		case CAPS_LOCK:
			TOGGLE_CAPS();
			break;
		case BACKSPACE:
			handle_backspace();
			break;
		case ENTER:
			handle_enter();
			break;
		case CTRL_DOWN:
			ctrl_state = PRESSED;
			break;
		case CTRL_UP:
			ctrl_state = UNPRESSED;
			break;
		case ALT_DOWN:
			alt_state = PRESSED;
			break;
		case ALT_UP:
			alt_state = UNPRESSED;
			break;
		case F1_KEY:
			if (alt_state == PRESSED) {
				send_eoi(KEYBOARD_IRQ_LINE);
				launch_term(TERMINAL_ONE);
			}
			break;
		case F2_KEY:
			if (alt_state == PRESSED) {
				send_eoi(KEYBOARD_IRQ_LINE);
				launch_term(TERMINAL_TWO);
			}
			break;
		case F3_KEY:
			if (alt_state == PRESSED) {
				send_eoi(KEYBOARD_IRQ_LINE);
				launch_term(TERMINAL_THREE);
			}
			break;
		default:
			handle_key_press(c);
			break;
	}
	
	send_eoi(KEYBOARD_IRQ_LINE);
	sti();
}
Exemplo n.º 9
0
void isr33_handler(){
	process_scancode();
	send_eoi(1);
}
Exemplo n.º 10
0
void isr32_handler(){
	unsigned static long int ticks = 0;
	ticks++;
	if(!(ticks%60)) tick_cursor();
	send_eoi(0);
}
Exemplo n.º 11
0
/* keyboard_handler()
   An Interrupt Handler that is Called When 
   Key is Pressed on Keyboard
   Input : i -- interrupt vector
   Output : None
   Side Effect : Handle keypress functions
   				 Prints keys Pressed to Screen accordingly
                 Issue EOI(End Of Interrupt) to unmask keyboard interrupt 
*/
void keyboard_handler(int i)
{
	/* Grab Key Pressed*/
	uint8_t keycode;
	keycode = kbd_read_input();

	/* Indicate a key has been pressed */
	key_press = 1;
	int32_t display_terminal= get_displayed_terminal();

	/* Print Only Keys Pressed, NOT Key Release 
	 * No Print for CTRL/SHIFT/Backspace/Caps
	 * Carries out Functionality Instead */
	if(keycode <= KEY_RELEASE_VALUE){
		/* Condition Key Press */
		if (keycode == ALT)
			alt_press += 1;
		else if(keycode == L_SHIFT || keycode == R_SHIFT)	
			shift_press += 1;
		else if (keycode == CTRL)
			ctrl_press += 1;
		else if (keycode == CAPS_LOCK)
			caps_on = !caps_on;

		/* CTRL-L Clear Screen */
		else if(keycode == L && ctrl_press > 0)
			reset_screen();

		/* Backspace */
		else if (keycode == BACKSPACE){
			/* Don't backspace when reading and at start of buffer*/
			if(read_on[display_terminal] == 0 || (index[display_terminal] != 0 && read_on[display_terminal] == 1))
				backspace();
			update_terminal_buf(BACK,keycode);
		}

		/* Return Press During Read */
		else if (read_on[display_terminal] == 1 && keycode == RETURN){
			printf("\n"); 		// New Line for Return Press
			read_return[display_terminal] = 1;
			update_terminal_buf(KEYS,keycode);
		}
		
		/* ALT-Function Press */
		else if(alt_press > 0 && (keycode == F1 || keycode == F2 || keycode == F3)){
			switch(keycode){
				case F1:
					change_terminal(TERMINAL_1);
					break;
				case F2:
					change_terminal(TERMINAL_2);
					break;
				case F3:
					change_terminal(TERMINAL_3);
				default:
					break;
			}
		}

		/* Caps On */
		else if (caps_on == 1){
			caps_on_handler(keycode);
		}

		/* Shift Press */
		else if (shift_press > 0){
			printf("%c", shift_keys[keycode - 1]);
			update_terminal_buf(SHIFT_KEYS, keycode);
		}

		/* Normal Press */
		else{
			printf("%c", keys[keycode - 1]);
			update_terminal_buf(KEYS, keycode);
		}

	}

	/* Condition Key Releases */
	else if (keycode == (ALT + KEY_RELEASE_VALUE))
		alt_press -= 1;
	else if(keycode == (L_SHIFT + KEY_RELEASE_VALUE) || keycode == (R_SHIFT + KEY_RELEASE_VALUE))
		shift_press -= 1;
	else if (keycode == (CTRL + KEY_RELEASE_VALUE))
		ctrl_press -= 1;

	/* Key Press Serviced */
	key_press = 0;
	send_eoi(KEYBOARD_IRQ);
}
Exemplo n.º 12
0
/* change_terminal function
   Function handles switching terminals (ALT + FUNCTION-KEY)
   Input : new_terminal -- terminal to switch into
   Output : None
   Side Effect : Does nothing if the new terminal 
   is the same as the current terminal.
   Else it copies video memory into the correct video buffer
   and the correct video buffer into video memory
*/
void change_terminal(int32_t new_terminal)
{
	/* Check to make sure that the new_terminal is not the same
	   as the terminal displayed now */
	int32_t old_terminal = get_displayed_terminal();
	if(new_terminal == old_terminal){
		LOG("You are already in this terminal! Cannot Switch!\n");
		return;
	}

	/* Case where we try to launch shell with max_num_process already running */
	if(num_progs[TERMINAL_1] + num_progs[TERMINAL_2] + num_progs[TERMINAL_3] >= MAX_NUM_PROCESS && 
	   num_progs[new_terminal] == 0){
	   	printf("Reached maximum number of programs! Can't fire new shell in new terminal!391OS> ");
		return;
	}

	/* Grab the page dir for the old terminal */
	pcb_t* pcb_ptr = top_process[old_terminal]; 
	pde_t* current_pg_dir = pcb_ptr->pg_dir;

	/* Grab the page dir for new terminal */
	pcb_t* top_pcb = top_process[new_terminal];
	pde_t* new_term_pg_dir;
	if(top_pcb == NULL)
		new_term_pg_dir = NULL;
	else
		new_term_pg_dir = top_pcb -> pg_dir;

	/* Copy mem (video->buf) and remap page (USER_VIDEO -> BUF) for the old_terminal*/
	remap_user_video_and_memcpy(get_video_buf_for_terminal(old_terminal), VIDEO, current_pg_dir);
	
	/* Copy mem (buf-> video) and remap page (USER_VIDEO -> VIDEO) for the new_terminal */
	remap_user_video_and_memcpy(VIDEO, get_video_buf_for_terminal(new_terminal), new_term_pg_dir);

	/* Flush TLB */
	set_cr3_reg(get_pcb_ptr() -> pg_dir);

	/* Update the displayed terminal*/
	displayed_terminal = new_terminal;

	/* If the the new terminal is not executing any programs, Execute Shell */
	if(num_progs[new_terminal] == 0){
		key_press = 0;	// Will not return to keyboardhandler, update key_press	

		pcb_t* curr_ptr = get_pcb_ptr();
		uint8_t exec_cmd[15] = "shell";

		/* Save info for scheduling */
		curr_ptr -> esp0 = tss.esp0; 
		asm volatile("movl %%esp, %0;" 
	  		"movl %%ebp, %1;" : 
	  		"=b" (curr_ptr -> esp),
	  		"=c" (curr_ptr -> ebp));

		send_eoi(KEYBOARD_IRQ);		//Send EOI for ALT+FUNCTION-KEY

		/* Execute a Shell */
		if(-1 == sys_execute(exec_cmd)){
			LOG("Executing new shell from new terminal failed!\n");
		}
	}
Exemplo n.º 13
0
/*
 * timeHandler
 *   DESCRIPTION: interupt handler for pit
 *   INPUTS: none
 *   OUTPUTS: none
 *   RETURN VALUE: none
 *   SIDE EFFECTS: schedule() is called every quantum
 */ 
void timeHandler() {
	send_eoi(0);

	schedule();
}
Exemplo n.º 14
0
void timer_handler()
{
//	print_str("timer\n");
	send_eoi(TIMER);
	test_switch_task();
}
Exemplo n.º 15
0
Arquivo: pic.c Projeto: B-Rich/EBBlib
void
lrt_pic_ackipi()
{
  send_eoi();
}