-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from bassaer/develop
[ver 1.12.0] add sleep command
- Loading branch information
Showing
14 changed files
with
184 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
# CHANGELOG | ||
|
||
## ver 1.12.0 | ||
- add sleep command | ||
|
||
## ver 1.11.0 | ||
- support paging | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef MYOS_SLEEP_H | ||
#define MYOS_SLEEP_H | ||
|
||
int sleep(char *args[], int size); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <sleep.h> | ||
|
||
#include <console.h> | ||
#include <exit.h> | ||
#include <io.h> | ||
#include <timer.h> | ||
#include <lib/queue.h> | ||
#include <lib/string.h> | ||
|
||
void usage_sleep() { | ||
printf("usage : sleep <timeout>\n"); | ||
} | ||
|
||
|
||
int sleep(char *args[], int size) { | ||
if (size != 2) { | ||
usage_sleep(); | ||
return EXIT_FAILURE; | ||
} | ||
|
||
struct Queue queue; | ||
unsigned char buf[8]; | ||
init_queue(&queue, 8, buf); | ||
int timeout = atoi(args[1]) * 100; | ||
|
||
set_timer(timeout, &queue, 1); | ||
|
||
while(1) { | ||
// 割り込み無効化 | ||
io_cli(); | ||
if (queue_status(&queue) != 0) { | ||
// 割り込み有効化 + HLT | ||
io_stihlt(); | ||
} else { | ||
// 割り込み有効化 | ||
io_sti(); | ||
break; | ||
} | ||
} | ||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef MYOS_TIMER_H | ||
#define MYOS_TIMER_H | ||
|
||
#include <lib/queue.h> | ||
|
||
struct timer_ctrl { | ||
unsigned int count; | ||
unsigned int timeout; | ||
struct Queue *queue; | ||
unsigned char data; | ||
} timer; | ||
|
||
void init_pit(); | ||
|
||
void handle_intr20(int *esp); | ||
|
||
void set_timer(unsigned int timeout, struct Queue *queue, unsigned char data); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include <timer.h> | ||
|
||
#include <intr.h> | ||
#include <io.h> | ||
#include <lib/queue.h> | ||
|
||
#include <console.h> | ||
|
||
#define PIT_CTRL 0x0043 | ||
#define PIT_CNT0 0x0040 | ||
|
||
/** | ||
* (PIT)Programmable Interval Timer | ||
* AT互換機ではPITに1.19318MHzのクロックが与えられている | ||
* | ||
* IRQ0の割り込み周期変更 | ||
* AL = 0x34; OUT(0x43, AL); | ||
* AL = 割り込み周期の下位8bit; OUT(0x40, AL); | ||
* AL = 割り込み周期の上位8bit; OUT(0x40, AL); | ||
*/ | ||
void init_pit() { | ||
/** | ||
* IRQ0の割り込み周期変更 | ||
* 割り込み頻度は クロック/設定カウント値 | ||
*/ | ||
outb_p(PIT_CTRL, 0x34); | ||
/** | ||
* 11932を設定することで100Hzになる | ||
* 11932=0x2e9c | ||
*/ | ||
outb_p(PIT_CNT0, 0x9c); | ||
outb_p(PIT_CNT0, 0x2e); | ||
timer.count++; | ||
} | ||
|
||
/** | ||
* IRQ0用割り込みハンドラ | ||
*/ | ||
void handle_intr20(int *esp) { | ||
outb_p(PIC0_OCW2, 0x60); // IRQ-00受付完了をPICに通知 | ||
timer.count++; | ||
// タイムアウトが設定されている場合 | ||
if (timer.timeout > 0) { | ||
timer.timeout--; | ||
if (timer.timeout == 0 ){//&& queue_status(timer.queue) != 0) { | ||
unsigned char buf[8]; | ||
dequeue(timer.queue, buf); | ||
} | ||
} | ||
} | ||
|
||
void set_timer(unsigned int timeout, struct Queue *queue, unsigned char data) { | ||
// EFLAGSは32bit拡張のレジスタ | ||
// キャリーフラグや割り込みフラグなどを保持する | ||
int eflags = io_load_eflags(); | ||
// 設定中の割り込みを禁止する | ||
io_cli(); | ||
timer.timeout = timeout; | ||
timer.queue = queue; | ||
timer.data = data; | ||
enqueue(timer.queue, timer.data); | ||
// 割り込み状態を元の状態に戻す | ||
io_store_eflags(eflags); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters