본문 바로가기

학부_대학원/대학원_학과공부정리

GeekOS - pro0

SMALL

Target : 

5.1 The Assignment

Add code to the kernel to create a new kernel mode thread. The kernel mode thread should print out ”Hello

from xxx” where xxx is your name. It should then call the keyboard input routine Wait_For_Key() repeatly

(and echo each character entered) until the termination character (control-d) is entered.



Wait_For_Key()를 먼저 살펴본다. 

Keycode Wait_For_Key(void)

{

    bool gotKey, iflag;

    Keycode keycode = KEY_UNKNOWN;


    iflag = Begin_Int_Atomic();

    do {

gotKey = !Is_Queue_Empty();

if (gotKey)

    keycode = Dequeue_Keycode();

else

    Wait(&s_waitQueue);

    }

    while (!gotKey);


    End_Int_Atomic(iflag);


    return keycode;

}


함수 원형을 보면 Atomic을 iflag로 한 다음.


Queue를 확인 한 다음, Keycode 구조체를 가져온다.


Data type의 Keycode 구조체는 16bit unsinged 이다.


하위 8bit는 아스키 코드이다.


나머지 bit들은 shift, ctrl release, keypad 이벤트를 확인 할 때 사용한다.


#define LEFT_SHIFT  0x01
#define RIGHT_SHIFT 0x02
#define LEFT_CTRL   0x04
#define RIGHT_CTRL  0x08
#define LEFT_ALT    0x10
#define RIGHT_ALT   0x20
#define SHIFT_MASK  (LEFT_SHIFT | RIGHT_SHIFT)
#define CTRL_MASK   (LEFT_CTRL | RIGHT_CTRL)
#define ALT_MASK    (LEFT_ALT | RIGHT_ALT)

와 같이 정의되어 있다.


그리고 Kernel_Thread를 실행시켜서 해당 동작만 하게 해야한다.

관련 Kernel_Thread원형을 살펴본다.

struct Kernel_Thread* Start_Kernel_Thread(

    Thread_Start_Func startFunc,

    ulong_t arg,

    int priority,

    bool detached

)


와 같은 원형으로 되어있다. Thread_Start는 함수 포인터이다.

그리고 thread의 우선순위는 아래와 같이 정의되어 있다.

#define PRIORITY_IDLE    0

#define PRIORITY_USER    1

#define PRIORITY_LOW     2

#define PRIORITY_NORMAL  5

#define PRIORITY_HIGH   10


해당 코드들은 include 와 src의 geekos 폴더에서 kthread, keyboard 관련 헤더와 코드를 보면 쉽게 확인 가능하다.

간단하지만... 해보는게 중요한..것 같다.

버퍼를 할당하고.. 지우고.. 등 좀 이쁘게 꾸며보려한다. 천천히라도!


void fp_Control_Keyboard();


void Main(struct Boot_Info* bootInfo)
{
    Init_BSS();
    Init_Screen();
    Init_Mem(bootInfo);
    Init_CRC32();
    Init_TSS();
    Init_Interrupts();
    Init_Scheduler();
    Init_Traps();
    Init_Timer();
    Init_Keyboard();


    Set_Current_Attr(ATTRIB(BLACK, GREEN|BRIGHT));
    Print("\nWelcome to GeekOS!\n");
    Print("\nrichong.tistory.com!!\n");

    Set_Current_Attr(ATTRIB(BLACK, GRAY));

    struct Kernel_Thread *thread;
    thread=Start_Kernel_Thread((Thread_Start_Func)&fp_Control_Keyboard,
			0,
			PRIORITY_NORMAL
			,false);



    /* Now this thread is done. */
    Exit(0);
}

void fp_Control_Keyboard(){

        Set_Current_Attr(ATTRIB(BLACK, GREEN|BRIGHT));
	Print("\nStart First Thread\n\n\n");
	Keycode tmp_Keycode;

        Set_Current_Attr(ATTRIB(BLACK, GRAY));
	while(1){

		//condition
		//1. press
		//2. ctrl_d check
		//3. print input buffer
		tmp_Keycode = Wait_For_Key();
		if(tmp_Keycode & KEY_RELEASE_FLAG) { //physical presses
		    //ctrl_d check		    
		    if((tmp_Keycode & KEY_CTRL_FLAG) && //checking the CTRL FLAG
			(tmp_Keycode & 0xff) == 'd') //checking the d
   			{
				Set_Current_Attr(ATTRIB(BLACK, GREEN|BRIGHT));
				Print("\n\ngood bye\n");
				Exit(1);
			}
					
	            Print("%c",tmp_Keycode&0xff);
	        }
	}
}





LIST

'학부_대학원 > 대학원_학과공부정리' 카테고리의 다른 글

[Lecture] LaTeX - 4  (0) 2017.03.04
[Lecture] LaTeX - 3  (0) 2017.03.04
GeekOS - pre knowledge  (0) 2017.03.03
가상화 -xen(2)  (0) 2017.03.03
가상화- xen  (1) 2017.03.02