Пример #1
0
Файл: queue.c Проект: 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;
}
Пример #2
0
static void wait_on_buffer(struct buffer_head *bh)
{
    disable_int();
    while(bh->b_lock)
        sleep_on(&bh->b_wait);
    enable_int();
}
Пример #3
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;
}
Пример #4
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;
}
Пример #5
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 */
Пример #6
0
Файл: driver.c Проект: mcaos/sOS
int get_loaded()
{
    disable_int(__FILE__, __LINE__);
    int val=drivers_loaded;
    enable_int();
    return val;
}
Пример #7
0
int main ()
{
	adc_request_t ADC1, ADC2, ADC3;
	adc_init();
        VT100_clr();
	USART0_init(9600);
	Timer0_pwm_init(0);
	Timer1_pwm_init(0);
	Timer2_pwm_init(0);
        enable_int();
	
	adc_request_init(&ADC1, 'R', 0);
	adc_request_init(&ADC2, 'B', 1);
	adc_request_init(&ADC3, 'G', 2);

	while (1)
	{
		adc_request_start(&ADC1);
		adc_request_start(&ADC2);
		adc_request_start(&ADC3);
		
		if ( adc_request_complete(&ADC1) ) consume_adc_data('R', adc_request_data(&ADC1));
		if ( adc_request_complete(&ADC2) ) consume_adc_data('B', adc_request_data(&ADC2));
		if ( adc_request_complete(&ADC3) ) consume_adc_data('G', adc_request_data(&ADC3));
		
		adc_process();
		
	}

	return 0;
}
Пример #8
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
	}
}
Пример #9
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();
}
Пример #10
0
  main(void)
{

  set_eflags();

  /* Define the kernel segment registers */
  set_seg_regs(__KERNEL_DS, __KERNEL_DS, INITIAL_ESP);

  printk("Kernel Loaded!    ");

  /* Initialize hardware data */
  setGdt(); /* Definicio de la taula de segments de memoria */
  setIdt(); /* Definicio del vector de interrupcions */
  setTSS(); /* Definicio de la TSS */

  /* Initialize Memory */
  init_mm();

/* Initialize an address space to be used for the monoprocess version of ZeOS */

  /* monoprocess_init_addr_space(); TO BE DELETED WHEN ADDED THE PROCESS MANAGEMENT CODE TO BECOME MULTIPROCESS */

  /* Initialize Scheduling */
  init_sched();

  /* Initialize idle task data */
  init_idle();

  /* Initialize task 1 data */
  init_task1();

  /* Initialize keyboard buffer */
  init_keyboard_buffer();

  /* Move user code/data now (after the page table initialization) */
  copy_data((void *) KERNEL_START + *p_sys_size, usr_main, *p_usr_size);

  /* Adds this call in order to perform test suite provided by lab course */
  zeos_init_auxjp();

  printk("Entering user mode...");

  /*
   * zeos_ticks must be initialized after memory initialization and just before
   * enabling interrupts in order to measure the correct elapsed time
   */
  zeos_ticks = 0;

  enable_int();

  /*
   * We return from a 'theorical' call to a 'call gate' to reduce our privileges
   * and going to execute 'magically' at 'usr_main'...
   */
  return_gate(__USER_DS, __USER_DS, USER_ESP, __USER_CS, L_USER_START);

  /* The execution never arrives to this point */
  return 0;
}
Пример #11
0
int main(void)
{
        Timer0_pwm_int(10);
        enable_int1();
        enable_int();
        busy_wait();
        return 0;
}
Пример #12
0
//--------------------------------------------------------------------------------------------------*/
// 从缓冲区中取扫描码
U8 get_byte_from_kbuf(void)
{
	U8 scan_code;
repeat:	while(k_buf.n <=0 );	// 确保缓冲区中有可用数据
	// 注意:此处操作需要原子性
	//------------------------------------------------/
	// 读取缓冲区
	disable_int();
	if(k_buf.n <= 0) {enable_int();goto repeat;}
	scan_code = *k_buf.tail & 0xff;
	k_buf.n--;
	if(++k_buf.tail >= k_buf.buf + KB_IN_BYTES)
		k_buf.tail -= KB_IN_BYTES;
	enable_int();
	//printk("%x\n",scan_code);
	return scan_code;
}
Пример #13
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();
}
Пример #14
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();
}
Пример #15
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();
}
Пример #16
0
Файл: vga.c Проект: 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();
}
Пример #17
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();
}
Пример #18
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();
}
Пример #19
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();
}
Пример #20
0
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();
}
Пример #21
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();
}
Пример #22
0
Файл: vga.c Проект: 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();
}
Пример #23
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();
}
Пример #24
0
Файл: queue.c Проект: mcaos/sOS
void pop(struct queue* q)
{
    disable_int(__FILE__, __LINE__);
    if(q->length==0)
    {
        enable_int();
        return;
    }

    struct q_node* new_first=q->first->next;

    kfree(q->first->value, __FILE__, __LINE__);// We allocated this in push by copying!
    kfree(q->first, __FILE__, __LINE__);
    q->length--;
    q->first=new_first;
    if(q->length==1)
        q->last=q->first;
    enable_int();
}
Пример #25
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();
}
Пример #26
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;
}
Пример #27
0
/*
函数功能:读文件
输入参数:进程指针	p_tcb
	文件fd	fd
	读缓冲	buf
	读大小	count	字节
输出参数:对于普通文件,输出实际读取字节数。
	对于字符设备:0 请求成功,-1 请求失败(有其他进程正在请求输入)
*/
int fs_read(int fd,void * buf,int offset,int count,TCB* p_tcb)
{
	File_Desc*	p_fd;
	Inode*		p_inode;
	buf	= va2pa(p_tcb->pdb,buf);
	p_fd	= p_tcb->filp[fd];
	p_inode	= p_fd->fd_inode;
	//----------------------------------------------------------
	// 字符设备文件
	if(p_inode->i_mode == I_MODE_CHAR)
	{
		MSG 	msg;
		msg.type				= TTY_MSG_UNION;
		msg.msg_union.tty_msg.para		= DEV_READ;
		msg.msg_union.tty_msg.sub_device	= MINOR(p_inode->i_start_sect);
		msg.msg_union.tty_msg.req_caller	= TASK_FS_PID;
		msg.msg_union.tty_msg.req_PID		= p_tcb - task_table;
		msg.msg_union.tty_msg.req_buf		= buf;
		msg.msg_union.tty_msg.req_count	= count;
		disable_int();
		if(tty_has_msg_tmp == 0)
		{
			if(sendrecv(SEND,dd_map[MAJAR(p_inode->i_start_sect)],&msg) == 0)
			{
				no_answer	= 1;	// 通知主循环将用户进程挂起
				enable_int();
				return	0;	// 0 消息发送成功
			}			// 请求是否成功在这里还不能判断,需要在主循环中收到tty发来的消息才知道
		}
		enable_int();
		return	-1;			// -1 发送消息失败(可能构成死锁)
	}
	//----------------------------------------------------------
	// 以下是普通文件
	int	cnt = file_buff_read(	buf,
					p_fd->fd_inode,
					offset + p_fd->fd_pos,
					count);
	assert(cnt != -1);
	p_fd->fd_pos	+= offset + cnt;
	return	cnt;
}
Пример #28
0
//#START_FUNCTION_HEADER//////////////////////////////////////////////////////
//#	
//# Description: 	Puts the unit into sleep while enabling proper interrupts to 
//#					exit sleep mode.  In normal mode, we want to sleep in between
//#					data ready aquisitions to maximize power.  When no motion is present,
//#					we only want to be woken up by BLE or movement again, not data
//#					ready.
//#
//# Parameters:		still --> 	true = disable acc data interrupts
//#								false = enable acc data interrupts
//#
//# Returns: 		Nothing
//#
//#//END_FUNCTION_HEADER////////////////////////////////////////////////////////
	void sleep_handler(bool still)
	{
		got_slp_wake = false;
		got_data_acc = false;
		got_int_ble = false;
		factory_sleep = false;

		set_sleep_mode(SLEEP_MODE_PWR_DOWN);
		sleep_enable();
		cli();
		sleep_bod_disable();
		enable_int(PCIE0);
		enable_int(PCIE1);
		still ? disable_int(PCIE2) : enable_int(PCIE2);	//if we want to sleep in between data reads AND when no motion occurs
		clear_acc_ints();
		sei();
		sleep_cpu();
		sleep_disable();
		enable_int(PCIE2);
	}
Пример #29
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();
}
Пример #30
0
main(void)
{
    
    set_eflags();
    
    /* Define the kernel segment registers  and a stack to execute the 'main' code */
    // It is necessary to use a global static array for the stack, because the
    // compiler will know its final memory location. Otherwise it will try to use the
    // 'ds' register to access the address... but we are not ready for that yet
    // (we are still in real mode).
    set_seg_regs(__KERNEL_DS, __KERNEL_DS, (DWord) &protected_tasks[5]);
    
    printk("Kernel Loaded!    ");
    
    /* Initialize hardware data */
    setGdt(); /* Definicio de la taula de segments de memoria */
    setIdt(); /* Definicio del vector de interrupcions */
    setTSS(); /* Definicio de la TSS */
    
    /* Initialize Memory */
    init_mm();
    
    /* Initialize an address space to be used for the monoprocess version of ZeOS */
    
    monoprocess_init_addr_space(); /* TO BE DELETED WHEN ADDED THE PROCESS MANAGEMENT CODE TO BECOME MULTIPROCESS */
    
    /* Initialize Scheduling */
    init_sched();
    
    /* Initialize idle task  data */
    init_idle();
    /* Initialize task 1 data */
    init_task1();

    /* Initialize semaphores */
    init_semaphores();
    
    /* Move user code/data now (after the page table initialization) */
    copy_data((void *) KERNEL_START + *p_sys_size, usr_main, *p_usr_size);
    
    
    printk("Entering user mode...");
    
    enable_int();
    /*
     * We return from a 'theorical' call to a 'call gate' to reduce our privileges
     * and going to execute 'magically' at 'usr_main'...
     */
    return_gate(__USER_DS, __USER_DS, USER_ESP, __USER_CS, L_USER_START);
    
    /* The execution never arrives to this point */
    return 0;
}