Ejemplo n.º 1
0
static void wait_on_buffer(struct buffer_head *bh)
{
    disable_int();
    while(bh->b_lock)
        sleep_on(&bh->b_wait);
    enable_int();
}
Ejemplo n.º 2
0
/*
 ****************************************************************
 *	Chamada ao sistema "mutime"				*
 ****************************************************************
 */
int
mutime (MUTM *tp)
{
	register int	ticks;
	register int	PIT_val;
	MUTM		mutm;

	/*
	 *	Falta pensar sobre as CPUs N
	 */
	disable_int ();

	write_port (0x00, 0x43);	/* Latch */
	PIT_val = read_port (0x40) + (read_port (0x40) << 8);

	mutm.mu_time = time; 	ticks = hz;

	enable_int ();

	/*
	 *	Agora faz o cálculo
	 */
	mutm.mu_utime = mul_div_64 (ticks, MILHAO, scb.y_hz) +
			mul_div_64 (PIT_init - PIT_val, MILHAO, PIT_FREQ);

	if (unimove (tp, &mutm, sizeof (MUTM), SU) < 0)
		u.u_error = EFAULT;

	return (UNDEF);

}	/* end mutime */
Ejemplo n.º 3
0
/*
函数功能:MM的exit配套函数。用于销毁子进程的filp
输入参数:子进程pid	cpid
输出参数:无
*/
void fs_do_exit(int cpid)
{
	TCB*	p_tcb	= cpid + task_table;
	int	fd;
	for(fd = 0;fd < MAX_TASK_FILE;fd++)
	{
		if(p_tcb->filp[fd] == 0)
			continue;
		assert(p_tcb->filp[fd]->fd_inode->i_cnt > 0);
		
		if(--p_tcb->filp[fd]->fd_inode->i_cnt == 0)	// inode共享者计数减一。如果没有其他进程使用该文件,则释放inode
		{
			if(p_tcb->filp[fd]->fd_inode->i_mode == I_MODE_CHAR)	// 字符设备文件
				{
					MSG 	msg;
					msg.type				= TTY_MSG_UNION;
					msg.msg_union.tty_msg.para		= DEV_CLOSE;
					msg.msg_union.tty_msg.sub_device	= MINOR(p_tcb->filp[fd]->fd_inode->i_start_sect);
					disable_int();
					if(tty_has_msg_tmp == 0)
						assert(sendrecv(BOTH,dd_map[MAJAR(p_tcb->filp[fd]->fd_inode->i_start_sect)],&msg) == 0);
					enable_int();
				}
		}
		p_tcb->filp[fd]->fd_inode = 0;	// 释放file_desc
	//	p_tcb->filp[fd] = 0;		// 释放filp
	}
}
Ejemplo n.º 4
0
Archivo: driver.c Proyecto: mcaos/sOS
int get_loaded()
{
    disable_int(__FILE__, __LINE__);
    int val=drivers_loaded;
    enable_int();
    return val;
}
Ejemplo n.º 5
0
void some_serial_stuff()
{
	disable_int();

	printk("COM1: setting up\n");

	outb(PORT + 1, 0x00);
	outb(PORT + 3, 0x80);
	outb(PORT + 0, 0x03);
	outb(PORT + 1, 0x00);
	outb(PORT + 3, 0x03);
	outb(PORT + 2, 0xc7);
	//outb(PORT + 2, 0x07); // debugging: trigger every byte
	outb(PORT + 4, 0x0b);

	set_int(0x24, &a_irq4_handler);
	irq_mask(4, 0);

	enable_int();

	serial_started = 1;

	printk("COM1: should be upset now\n");

	serial_poll();
}
Ejemplo n.º 6
0
/*======================================================================*
                            get_byte_from_kb_buf
 *----------------------------------------------------------------------*
 * 作用:从键盘缓冲区中读取下一个字节
 *======================================================================*/
PUBLIC t_8 get_byte_from_kb_buf()
{
	t_8 scan_code;

	while (kb_in.count <= 0)
	{
		/* 等待下一个字节到来 */
	}

	disable_int();

	scan_code = *(kb_in.p_tail);

	kb_in.p_tail++;
	if (kb_in.p_tail == kb_in.buf + KB_IN_BYTES)
	{
		kb_in.p_tail = kb_in.buf;
	}

	kb_in.count--;

	enable_int();

	return scan_code;
}
Ejemplo n.º 7
0
/*
函数功能:关闭文件
输入参数:进程指针	p_tcb
	文件fd	fd
输出参数:成功返回0,失败返回-1
*/
int fs_close(int fd,TCB* p_tcb)
{
	if(p_tcb->filp[fd]->fd_inode->i_cnt < 1)
	{
		printk("error! the file has not being open. fd: %d\n",fd);
		return	-1;
	}
	if(p_tcb->filp[fd]->fd_inode->i_cnt == 1)			// inode共享者计数为1,表示没有其他进程使用该文件
	{
		if(p_tcb->filp[fd]->fd_inode->i_mode == I_MODE_CHAR)	// 字符设备文件
		{
			MSG 	msg;
			msg.type				= TTY_MSG_UNION;
			msg.msg_union.tty_msg.para		= DEV_CLOSE;
			msg.msg_union.tty_msg.sub_device	= MINOR(p_tcb->filp[fd]->fd_inode->i_start_sect);
			disable_int();
			if(tty_has_msg_tmp == 0)
				assert(sendrecv(BOTH,dd_map[MAJAR(p_tcb->filp[fd]->fd_inode->i_start_sect)],&msg) == 0);
			enable_int();
		}
		else						// 普通文件。关闭普通文件之前要先“同步文件缓冲”
		{
			sync_buff(p_tcb->filp[fd]->fd_inode,0);		// 0:不释放缓冲	1:同步之后释放缓冲
		}
	}
	p_tcb->filp[fd]->fd_inode->i_cnt--;				// inode共享者计数减一。如果没有其他进程使用该文件,则计数变成0,表示释放inode
	p_tcb->filp[fd]->fd_inode = 0;				// 释放file_desc
	p_tcb->filp[fd] = 0;					// 释放filp
	return	0;
}
Ejemplo n.º 8
0
static inline void lock_buffer(struct buffer_head *bh)
{
    disable_int();
    while(bh->b_lock)
        sleep_on(&bh->b_wait);
    bh->b_lock = 1;
    enable_int();
}
Ejemplo n.º 9
0
/**
 * Print a char in a certain console.
 * 
 * @param con  The console to which the char is printed.
 * @param ch   The char to print.
 *****************************************************************************/
PUBLIC void out_char(CONSOLE* con, char ch)
{
	disable_int();

	u8* pch = (u8*)(V_MEM_BASE + con->cursor * 2);

	assert(con->cursor - con->orig < con->con_size);

	/*
	 * calculate the coordinate of cursor in current console (not in
	 * current screen)
	 */
	int cursor_x = (con->cursor - con->orig) % SCR_WIDTH;
	int cursor_y = (con->cursor - con->orig) / SCR_WIDTH;

	switch(ch) {
	case '\n':
		con->cursor = con->orig + SCR_WIDTH * (cursor_y + 1);
		break;
	case '\b':
		if (con->cursor > con->orig) {
			con->cursor--;
			*(pch - 2) = ' ';
			*(pch - 1) = DEFAULT_CHAR_COLOR;
		}
		break;
	default:
		*pch++ = ch;
		*pch++ = DEFAULT_CHAR_COLOR;
		con->cursor++;
		break;
	}

	if (con->cursor - con->orig >= con->con_size) {
		cursor_x = (con->cursor - con->orig) % SCR_WIDTH;
		cursor_y = (con->cursor - con->orig) / SCR_WIDTH;
		int cp_orig = con->orig + (cursor_y + 1) * SCR_WIDTH - SCR_SIZE;
		w_copy(con->orig, cp_orig, SCR_SIZE - SCR_WIDTH);
		con->crtc_start = con->orig;
		con->cursor = con->orig + (SCR_SIZE - SCR_WIDTH) + cursor_x;
		clear_screen(con->cursor, SCR_WIDTH);
		if (!con->is_full)
			con->is_full = 1;
	}

	assert(con->cursor - con->orig < con->con_size);

	while (con->cursor >= con->crtc_start + SCR_SIZE ||
	       con->cursor < con->crtc_start) {
		scroll_screen(con, SCR_UP);

		clear_screen(con->cursor, SCR_WIDTH);
	}

	flush(con);

	enable_int();
}
Ejemplo n.º 10
0
Archivo: vga.c Proyecto: defsky/FunOS
PUBLIC	void	set_screen(int start_pos)
{
	disable_int();
	out_byte(VGA_CRTC_AR,CRTC_DR_START_H);
	out_byte(VGA_CRTC_DR,(start_pos >> 8) & 0xff);
	out_byte(VGA_CRTC_AR,CRTC_DR_START_L);
	out_byte(VGA_CRTC_DR,(start_pos) & 0xff);
	enable_int();
}
Ejemplo n.º 11
0
/**
 * Routine for hardware screen scrolling.
 * 
 * @param addr  Offset in the video memory.
 *****************************************************************************/
PUBLIC void set_video_start_addr(u32 addr)
{
	disable_int();
	out_byte(CRTC_ADDR_REG, START_ADDR_H);
	out_byte(CRTC_DATA_REG, (addr >> 8) & 0xFF);
	out_byte(CRTC_ADDR_REG, START_ADDR_L);
	out_byte(CRTC_DATA_REG, addr & 0xFF);
	enable_int();
}
Ejemplo n.º 12
0
/**
 * Display the cursor by setting CRTC (6845 compatible) registers.
 * 
 * @param position  Position of the cursor based on the beginning of the video
 *                  memory. Note that it counts in WORDs, not in BYTEs.
 *****************************************************************************/
PUBLIC void set_cursor(unsigned int position)
{
	disable_int();
	out_byte(CRTC_ADDR_REG, CURSOR_H);
	out_byte(CRTC_DATA_REG, (position >> 8) & 0xFF);
	out_byte(CRTC_ADDR_REG, CURSOR_L);
	out_byte(CRTC_DATA_REG, position & 0xFF);
	enable_int();
}
Ejemplo n.º 13
0
void set_cursor_length()
{
	disable_int();
	out_byte(CRTC_ADDR_REG,CURSOR_START_REG);
	out_byte(CRTC_DATA_REG,0x00);
	out_byte(CRTC_ADDR_REG,CURSOR_END_REG);
	out_byte(CRTC_DATA_REG,0x61);
	enable_int();
}
Ejemplo n.º 14
0
Archivo: console.c Proyecto: Zach41/OS
PRIVATE void set_cursor(u32 position) {
    disable_int();

    out_byte(CRTC_ADDR_REG, CURSOR_H);
    out_byte(CRTC_DATA_REG, (position >> 8) & 0xFF);
    out_byte(CRTC_ADDR_REG, CURSOR_L);
    out_byte(CRTC_DATA_REG, (position) & 0xFF);
    enable_int();
}
Ejemplo n.º 15
0
Archivo: vga.c Proyecto: defsky/FunOS
PUBLIC	void	set_cursor(int pos)
{
	disable_int();
	out_byte(VGA_CRTC_AR,CRTC_DR_CURSOR_H);
	out_byte(VGA_CRTC_DR,(pos >> 8) & 0xff);
	out_byte(VGA_CRTC_AR,CRTC_DR_CURSOR_L);
	out_byte(VGA_CRTC_DR,pos & 0xff);
	enable_int();
}
Ejemplo n.º 16
0
void set_video_start_addr(u16 addr)
{
    disable_int();
    io_out8(CRTC_ADDR, START_ADDR_H);
    io_out8(CRTC_DATA, (addr >> 8) & 0xff);
    io_out8(CRTC_ADDR, START_ADDR_L);
    io_out8(CRTC_DATA, addr & 0xff);
    enable_int();
}
Ejemplo n.º 17
0
void writecmos(u8 reg,u8 val)
{
	u8 ifstate=((getcpuflags()&CPU_FLAGS_IF)!=0);
	if(ifstate)disable_int();
	int org=inb(0x70);
	outb(0x70,(org&0b10000000)|(reg&0b01111111));
	outb(0x71,val);
	if(ifstate)enable_int();
}
Ejemplo n.º 18
0
void set_console_start_addr(t_32 addr)
{
	
	disable_int();
	out_byte(CRTC_ADDR_REG,START_ADDR_H );
	out_byte(CRTC_DATA_REG,(addr>>8)&0xFF);
	out_byte(CRTC_ADDR_REG,START_ADDR_L);
	out_byte(CRTC_DATA_REG,(addr)&0xFF);
	enable_int();
}
Ejemplo n.º 19
0
void set_cursor(u16 pos)
{
    disable_int();
    io_out8(CRTC_ADDR, CURSOR_H);
    io_out8(CRTC_DATA, (pos >> 8) & 0xff);

    io_out8(CRTC_ADDR, CURSOR_L);
    io_out8(CRTC_DATA, pos & 0xff);
    enable_int();
}
Ejemplo n.º 20
0
u8 readcmos(u8 reg)
{
	u8 ifstate=((getcpuflags()&CPU_FLAGS_IF)!=0);
	if(ifstate)disable_int();
	int org=inb(0x70);
	outb(0x70,(org&0b10000000)|(reg&0b01111111));
	u8 ret=inb(0x71);
	if(ifstate)enable_int();
	return ret;
}
Ejemplo n.º 21
0
Archivo: queue.c Proyecto: mcaos/sOS
V_TYPE* front(const struct queue* q)
{
    disable_int(__FILE__, __LINE__);
    if(q->length==0)
    {
        enable_int();
        return (V_TYPE*)NULL;
    }
    enable_int();
    return q->first->value;
}
Ejemplo n.º 22
0
void set_cursor_location(t_32 addr)
{//location of cursor
	disable_int();
	
	out_byte(CRTC_ADDR_REG,CURSOR_H );
	out_byte(CRTC_DATA_REG,(addr>>8)&0xFF);
	out_byte(CRTC_ADDR_REG,CURSOR_L);
	out_byte(CRTC_DATA_REG,(addr)&0xFF);

	enable_int();
}
Ejemplo n.º 23
0
/*======================================================================*
				in_process
 *======================================================================*/
PUBLIC void in_process(TTY* p_tty, u32 key)
{
        if (!(key & FLAG_EXT)) {
		put_key(p_tty, key);
        }
        else {
                int raw_code = key & MASK_RAW;
                switch(raw_code) {
                case ENTER:
			put_key(p_tty, '\n');
			break;
                case BACKSPACE:
			put_key(p_tty, '\b');
			break;
                case UP:
                        if ((key & FLAG_SHIFT_L) || (key & FLAG_SHIFT_R)) {
				scroll_screen(p_tty->p_console, SCR_DN);
                        }
			break;
		case DOWN:
			if ((key & FLAG_SHIFT_L) || (key & FLAG_SHIFT_R)) {
				scroll_screen(p_tty->p_console, SCR_UP);
			}
			break;
		case F1:
		case F2:
		case F3:
		case F4:
		case F5:
		case F6:
		case F7:
		case F8:
		case F9:
		case F10:
		case F11:
		case F12:
			/* Alt + F1~F12 */
			if ((key & FLAG_CTRL_L) || (key & FLAG_CTRL_R)) {
				select_console(raw_code - F1);
			}
			else {
				if (raw_code == F12) {
					disable_int();
					dump_proc(proc_table + 4);
					for(;;);
				}
			}
			break;
                default:
                        break;
                }
        }
}
Ejemplo n.º 24
0
//#START_FUNCTION_HEADER//////////////////////////////////////////////////////
//#	
//# Description: 	
//#					Puts the sensor into factory mode.  This mode
//#		 			is essentially an ultra deep sleep mode that is only brought out
//#					of sleep by one specific interrupt generated by the BLE unit.  
//#
//# Parameters:		None
//#
//# Returns: 		Nothing
//#
//#//END_FUNCTION_HEADER////////////////////////////////////////////////////////
	void set_factory_mode()
	{
		got_slp_wake = false;
		got_data_acc = false;
		got_int_ble = false;
		factory_sleep = true;
		
		enable_int(PCIE0);
		disable_int(PCIE1);
		disable_int(PCIE2);
		acc1.MMA8452Standby();
		acc2.MMA8452Standby();
			
		set_sleep_mode(SLEEP_MODE_PWR_DOWN);
		sleep_enable();
		cli();
		sleep_bod_disable();
		sei();
		sleep_cpu();
		sleep_disable();
		clear_acc_ints();
	}
Ejemplo n.º 25
0
/*
 *  割込み要求ラインの属性の設定
 *
 *  ASPカーネルでの利用を想定して,パラメータエラーはアサーションでチェッ
 *  クしている.
 */
Inline void
config_int(INTNO intno, ATR intatr, PRI intpri)
{
	assert(VALID_INTNO(intno));
	assert(TMIN_INTPRI <= intpri && intpri <= TMAX_INTPRI);

	/*
	 *  割込みを禁止
	 *
	 *  割込みを受け付けたまま,レベルトリガ/エッジトリガの設定や,割
	 *  込み優先度の設定を行うのは危険なため,割込み属性にかかわらず,
	 *  一旦マスクする.
	 */
	disable_int(intno);

	/*
	 *  割込みをコンフィギュレーション
	 */
#ifdef TOPPERS_SAFEG_SECURE
	gicd_config_group(intno, 1U);
#endif /* TOPPERS_SAFEG_SECURE */

	if ((intatr & TA_EDGE) != 0U) {
#ifdef GIC_ARM11MPCORE
		gicd_config(intno, GICD_ICFGRn_EDGE|GICD_ICFGRn_1_N);
#else /* GIC_ARM11MPCORE */
		gicd_config(intno, GICD_ICFGRn_EDGE);
#endif /* GIC_ARM11MPCORE */
		clear_int(intno);
	}
	else {
#ifdef GIC_ARM11MPCORE
		gicd_config(intno, GICD_ICFGRn_LEVEL|GICD_ICFGRn_1_N);
#else /* GIC_ARM11MPCORE */
		gicd_config(intno, GICD_ICFGRn_LEVEL);
#endif /* GIC_ARM11MPCORE */
	}

	/*
	 *  割込み優先度とターゲットプロセッサを設定
	 */
	gicd_set_priority(intno, INT_IPM(intpri));
	gicd_set_target(intno, 1U << arm_prc_index());

	/*
	 * 割込みを許可
	 */
	if ((intatr & TA_ENAINT) != 0U) {
		enable_int(intno);
	}
}
Ejemplo n.º 26
0
/*======================================================================*
				in_process
 *======================================================================*/
PUBLIC void in_process(TTY* p_tty, u32 key)
{
        char output[2] = {'\0', '\0'};

        if (!(key & FLAG_EXT)) {
		if (p_tty->inbuf_count < TTY_IN_BYTES) {
			*(p_tty->p_inbuf_head) = key;
			p_tty->p_inbuf_head++;
			if (p_tty->p_inbuf_head == p_tty->in_buf + TTY_IN_BYTES) {
				p_tty->p_inbuf_head = p_tty->in_buf;
			}
			p_tty->inbuf_count++;
		}
        }
        else {
                int raw_code = key & MASK_RAW;
                switch(raw_code) {
                case UP:
                        if ((key & FLAG_SHIFT_L) || (key & FLAG_SHIFT_R)) {
                                disable_int();
                                out_byte(CRTC_ADDR_REG, START_ADDR_H);
                                out_byte(CRTC_DATA_REG, ((80*15) >> 8) & 0xFF);
                                out_byte(CRTC_ADDR_REG, START_ADDR_L);
                                out_byte(CRTC_DATA_REG, (80*15) & 0xFF);
                                enable_int();
                        }
			break;
		case DOWN:
			if ((key & FLAG_SHIFT_L) || (key & FLAG_SHIFT_R)) {
				/* Shift+Down, do nothing */
			}
			break;
		case F1:
		case F2:
		case F3:
		case F4:
		case F5:
		case F6:
		case F7:
		case F8:
		case F9:
			/* Ctrl + F1~F9 */
			if ((key & FLAG_CTRL_L)  || (key & FLAG_CTRL_R)) {
				select_console(raw_code - F1);
			}
			break;
                default:
                        break;
                }
        }
Ejemplo n.º 27
0
Archivo: tty.c Proyecto: zf369/Tinix
/*======================================================================*
                            in_process
 *----------------------------------------------------------------------*
 * 作用:对键盘缓冲区读取出来的按键进行操作
 *======================================================================*/
PUBLIC void in_process(TTY *p_tty, t_32 key)
{
	// FLAG_EXT 表示不能打印出来的key
	if (!(key & FLAG_EXT))
	{
		// 将本次键盘输入存储到对应TTY的缓冲区,如果缓冲区已满,直接丢弃
		if (p_tty->inbuf_count < TTY_IN_BYTES)
		{
			*(p_tty->p_inbuf_head) = key;

			p_tty->p_inbuf_head++;
			if (p_tty->p_inbuf_head == p_tty->in_buf + TTY_IN_BYTES)
			{
				p_tty->p_inbuf_head = p_tty->in_buf;
			}

			p_tty->inbuf_count++;
		}
	}
	else
	{
		int raw_code = key & MASK_RAW;
		switch (raw_code)
		{
		case UP:
			if ((key & FLAG_SHIFT_L) || (key & FLAG_SHIFT_R)) 
			{	
				/* Shift + Up */

				// 设置屏幕开始的行数为15行
				disable_int();
				out_byte(CRTC_ADDR_REG, CRTC_DATA_IDX_START_ADDR_H);
				out_byte(CRTC_DATA_REG, ((80*15) >> 8) & 0xFF);
				out_byte(CRTC_ADDR_REG, CRTC_DATA_IDX_START_ADDR_L);
				out_byte(CRTC_DATA_REG, (80*15) & 0xFF);
				enable_int();
			}
			break;

		case DOWN:
			if ((key & FLAG_SHIFT_L) || (key & FLAG_SHIFT_R)) 
			{	
				/* Shift + Down */
			}
			break;

		default:
			break;
		}
	}
Ejemplo n.º 28
0
//--------------------------------------------------------------------------------------------------*/
// 按键中断处理程序
void keyboard_handler(void)
{
	U8 scan_code = in_byte(DAT8042);
	if(k_buf.n < KB_IN_BYTES)
	{	// 注意:此处操作需要原子性
		disable_int();
		k_buf.n++;
		*k_buf.head = scan_code;
		if(++k_buf.head >= k_buf.buf + KB_IN_BYTES)
			k_buf.head -= KB_IN_BYTES;
		enable_int();
	}
	keyboard_int = 1;
}
Ejemplo n.º 29
0
static int get_buf()
{
	unsigned char c;

	/* wait for key presses */
	while(kb_buf.cnt == 0);

	disable_int();
	c = kb_buf.buf[kb_buf.tail];
	kb_buf.tail = (kb_buf.tail + 1) % KB_BUF_SIZE;
	kb_buf.cnt--;
	enable_int();

	return c;
}
Ejemplo n.º 30
0
Archivo: keyboard.c Proyecto: qq53/os
u8 get_byte_from_kbuf()
{
	u8 scan_code;

	while(kb_in.count <= 0){}
	if(kb_in.tail >= KB_IN_BYTES - 1)
		kb_in.tail = -1;

	disable_int();
	scan_code = kb_in.buf[++kb_in.tail];
	--kb_in.count;
	enable_int();

	return scan_code;
}