30æ¥OSèªä½å ¥é12æ¥ç®ï¼Win10ï¼
ã¯ããã«
ç®æ¬¡
ã¿ã¤ã-1
ã¿ã¤ãã使ãã(harib09a)
ååã¯ãç¡éã«ã¼ãã§å ¨åãè³ãã¦ã«ã¦ã³ããç¶ãã¦ãã¾ããããããã¯ç¡éã«ã¼ããç¹°ãè¿ããããã³ã«èµ·åãã¦ããã®ã§ã¿ã¤ãã¨ãªããã¯ããããã¾ããã
ããã©ãããâ¦ï¼ã¯ããã¯æ°ã«åããã¦èª¿æ´ããã¦ãããï¼HLTãã§ããªãâ¦ã©ãããâ¦ã£ã¦ãªã®ãä»åã®ããã§ãã
解決æ³ã¯ãã¿ã¤ãå²ãè¾¼ã¿ã¨ãããPCèªä½ã«æéãè¨æ¸¬ããè£ ç½®ãå©ç¨ããæ¹æ³ããããã大ä¸å¤«ã¿ããã§ãã
ããæ¹ã¯ããã¼ãã¼ãããã¦ã¹ã®æã¿ããã«å²ãè¾¼ã¿ãè¨å®ãã¦ããã¦ãtimer.cã«å²ãè¾¼ã¿ã®å¦çå 容ãæ¸ãããã§ãã
#define PIT_CTRL 0x0043 /* ãã¼ãï¼ã³ã³ããã¼ã«ã¬ã¸ã¹ã¿ãæå® */ #define PIT_CNT0 0x0040 /* ãã¼ãï¼ã«ã¦ã³ã¿0ãæå® */ /* IRQ0ã®å²ãè¾¼ã¿å¦çå¤æ´ */ void init_pit(void) { io_out8(PIT_CTRL, 0x34); /* 2é²æ°ã«ã¦ã³ããã¬ã¼ãã¸ã§ãã¬ã¼ã¿ã16bitãªã¼ããã¼ãï¼ä¸ä½8bitãä¸ä½8bitã®é ï¼ãã«ã¦ã³ã¿0 */ io_out8(PIT_CNT0, 0x9c); /* å²ãè¾¼ã¿å¨æã®ä¸ä½8bit */ io_out8(PIT_CNT0, 0x2e); /* å²ãè¾¼ã¿å¨æã®ä¸ä½8bit */ return; }
ããã§PITã®åæè¨å®ãè¡ããä»æ§ã«é¢ãã¦ã¯ä»¥ä¸ã®URLã«è¨è¿°ããã¦ããã
ããã¦ãHarimainã«PITãå«ããåæåã®è¨å®ã追å ãã
init_pit(); /* PITã®åæå */ io_out8(PIC0_IMR, 0xf8); /* PITã¨PIC1ã¨ãã¼ãã¼ãã許å¯ï¼1111_1000ï¼ */
å¾ã¯ãå²ãè¾¼ã¿å¦çã®å 容ã¨ç»é²ãè¡ãã ãã«ãªãã¾ãã
ã¾ããtimer.cã«å¦çããå 容ãè¨è¿°ã
/* IDT20ã®å¦çè¨å® */ void inthandler20(int *esp) { io_out8(PIC0_OCW2, 0x60); /* IRQ-00åä»å®äºãPICã«éç¥ */ /* ã¨ããããä½ãããªã */ return; }
次ã«ãnaskfunc.nasã«IDTã®ã追å ãããã¨ãè¨è¼ãã¾ã
_asm_inthandler20: ;timer PUSH ES PUSH DS PUSHAD MOV EAX,ESP PUSH EAX MOV AX,SS MOV DS,AX MOV ES,AX CALL _inthandler20 POP EAX POPAD POP DS POP ES IRETD
ãã¨ã¯ãdsctbl.cã§IDTã«å²ãè¾¼ã¿ãã³ãã©ã®ç»é²ãè¡ããã¨ã§è¨å®ãçµããã¾ãã
set_gatedesc(idt + 0x20, (int) asm_inthandler20, 2 * 8, AR_INTGATE32); /* 0x20çªç®ã«ã¿ã¤ãã¼å²ãè¾¼ã¿ãè¨å® */
ããã§å®è¡ããã¨â¦
ä½ãèµ·ãã¦ãã¾ãããããã£ããã¨åãã¦ãã¾ãã
æéãè¨ã£ã¦ã¿ãã(harib09b)
ä»åã¯ãè¨å®ããã¿ã¤ãã¼å²ãè¾¼ã¿ãå©ç¨ãã¦ãã¦ã£ã³ãã¦ã«æ°ãã¦ããã¨ããã表示ããããã¨ãã£ãæãã§ãã
ã¾ãã¯ãã«ã¦ã³ããããã¼ã¿ã渡ãããã«ãæ§é ä½ãä½ãã¿ããã§ãã
/* timer.c */ struct TIMERCTL { unsigned int count; };
ããã¦ãtimer.cã«æ§é ä½ã®countã«ã«ã¦ã³ãããããã°ã©ã ãæ¸ããHarimainã®ç¡éã«ã¼ãã«çµã¿è¾¼ãã§ããã°
for (;;) { sprintf(s, "%010d", timerctl.count); boxfill8(buf_win, 160, COL8_C6C6C6, 40, 28, 119, 43); putfonts8_asc(buf_win, 160, 40, 28, COL8_000000, s); sheet_refresh(sht_win, 40, 28, 120, 44);
å®è¡ããã¨
æãå»ãã§ãï¼ pic.twitter.com/SU8yKWrYQj
— ç«(1010) (@Wagahaiha_toto) 2019å¹´12æ26æ¥
ã¿ã¤ã ã¢ã¦ãæ©è½(harib09c)
æéãåå¾ã§ããããã«ãªã£ãã®ã§ãå¦çæéã®è¨æ¸¬çã®å¦çãè¡ããã¨ãã§ããããã«ãªãã¾ãã
ã§ããã®æéãå©ç¨ãã¦ãä½ç§ãã£ããããããã¦ãï¼ï¼Linuxã®cronã¿ãããªï¼ãã¨ãã¿ã¤ã ã¢ã¦ãã¨å¼ã³ã¾ãã
ããããã£ã¦ã¿ããã¨ãã£ãæãã®ããã§ãã
ã¾ãã¯ãã¿ã¤ãã¼ç¨ã®æ§é ä½TIMERCTLã«ã¡ã³ãã追å ãã¾ãã
/* timer.c */ struct TIMERCTL { unsigned int count; unsigned int timeout; struct FIFO8 *fifo; unsigned char data; };
ããã¦ãå¦çå 容ãinthandler20ã«è¨è¿°ã
/* IDT20ã®å¦çè¨å® */ void inthandler20(int *esp) { io_out8(PIC0_OCW2, 0x60); /* IRQ-00åä»å®äºãPICã«éç¥ */ timerctl.count++; /* æå®ã«å¾ãã«ã¦ã³ããã */ if (timerctl.timeout > 0) { timerctl.timeout--; if (timerctl.timeout == 0) { fifo8_put(timerctl.fifo, timerctl.data); /* ã«ã¦ã³ãã0ã«ãªã£ããFIFOãããã¡ã«éã */ } } return; }
ãã¨ã¯ãsettimerã§æ§é ä½ã«å¿ è¦ãªãã¼ã¿ã渡ãã
void settimer(unsigned int timeout, struct FIFO8 *fifo, unsigned char data) { int eflags; eflags = io_load_eflags(); /* ãã©ã°ã¬ã¸ã¹ã¿ã®éé¿ */ io_cli(); /* å²ãè¾¼ã¿ç¦æ¢ */ timerctl.timeout = timeout; timerctl.fifo = fifo; timerctl.data = data; io_store_eflags(eflags); /* ãã©ã°ã¬ã¸ã¹ã¿ãæ»ã(ãã®éIFãã©ã°ãæ»ã) */ return; }
ããã¦ãçµããã«HriMainã®ç¡éã«ã¼ãã«ãã¿ããã§ããã°â¦
è¤æ°ã®ã¿ã¤ãã(harib09d)
ä»åã§ã¯ç¹æ» ããåè§ã¨3ç§ã§è¡¨ç¤ºãããã¼ã¯ãä½ãããã§ãã
ã¾ãæ§é ä½TIMERCTLãè¤æ°ã®ã¿ã¤ããä¿ç®¡ã§ããããã«ããããã§ãã
#define MAX_TIMER 500 struct TIMER { unsigned int timeout, flags; /* flagsï¼ããããã®timerã®ç¶æ ãä¿ç®¡ */ struct FIFO8 *fifo; unsigned char data; }; struct TIMERCTL { unsigned int count; /* ã«ã¦ã³ã¿ */ struct TIMER timer[MAX_TIMER]; /* timeoutã500å管çå¯è½ */ };
ãã¨ã¯ãTimer.cã¨Harimainãç¹æ» ã¨3ç§ç¨ã«å¢ããã°å®æ
å®è¡ããã¨
å²ãè¾¼ã¿å¦çã¯çã(1)(harib09e)
å²ãè¾¼ã¿å¦çãçãããããã®éãã®ï¼ã§ãã
ä¸åç®ã¯é·ããªã£ã¦ãã¾ãå²ãè¾¼ã¿å¦çãå°ãã§ãçããããã¨ããã¿ããã§ããæ¸ç®ããªããæ°ãã¦ããã«ã¦ã³ããäºå®æå»ã«è¨å®ããæ¸ç®ãããªãã¦ãããããã«ãã¦ãã¾ããè¦ã¯ãå²ãè¾¼ã¿å
ã§ã®æ¸ç®ããªãããããä¸å®ã®ç§æ°ã«éãããå²ãè¾¼ã¿ãããã¨ãã£ãæãã¿ããã§ãã
å²ãè¾¼ã¿å¦çã®ä¿®æ£
void inthandler20(int *esp) { int i; io_out8(PIC0_OCW2, 0x60); /* IRQ-00åä»å®äºãPICã«éç¥ */ timerctl.count++; /* æå®ã«å¾ãã«ã¦ã³ããã */ for (i = 0; i < MAX_TIMER; i++) { if (timerctl.timer[i].flags == TIMER_FLAGS_USING) { if (timerctl.timer[i].timeout <= timerctl.count) { /* ããã§æ¸ç®ãã¤ã¤ã¿ã¤ãã¼ã«ãã¦ããã®ããä¸å®ã®æéã«æ¥ããéç¥ããã¨ããä»çµã¿ã«ãããã¨ãã§ãã */ timerctl.timer[i].flags = TIMER_FLAGS_ALLOC; fifo8_put(timerctl.timer[i].fifo, timerctl.timer[i].data); } } } return; }
å²ãè¾¼ã¿äºå®æå»ã®æ¸¬å®
void timer_settime(struct TIMER *timer, unsigned int timeout) { timer->timeout = timeout + timerctl.count; /* å²ãè¾¼ã¿äºå®æå»ãè¨ç®ãã¦ãã */ timer->flags = TIMER_FLAGS_USING; return; }
ããã§å®è¡ãã¦ã¿ãã¨
ä¸ã¨åãæãã§ããâ¦ãã¾ãéãããªã
å²ãè¾¼ã¿å¦çã¯çã(2)(harib09f)
å²ãè¾¼ã¿å¦çãã¾ã é·ãã®ã§ã次ã¯ifæãæ¸ãããã¨ãè¡ãã¿ããã§ãã
æ¸ããæ¹ã¯ã500åãã®ã¿ã¤ããå
¨é¨ifã§ä¸ã
確èªããã®ã¯éå¹ççãªã®ã§ã次ã«ã©ã®ã¿ã¤ããæ¥ãããæ§é ä½ã§è¦ãã¦ãããããã«ä¿®æ£ãè¡ãã¾ãã
struct TIMERCTL { unsigned int count, next; /* count:ã«ã¦ã³ã¿,next:次ã«æ³¨ç®ããã¿ã¤ãã¼ */ struct TIMER timer[MAX_TIMER]; };
ããã«å¯¾å¿ããå²ãè¾¼ã¿ãã³ãã©ãä¿®æ£ããããã§ãã
/* IDT20ã®å¦çè¨å® */ void inthandler20(int *esp) { int i; io_out8(PIC0_OCW2, 0x60); /* IRQ-00åä»å®äºãPICã«éç¥ */ timerctl.count++; /* æå®ã«å¾ãã«ã¦ã³ããã */ if (timerctl.next > timerctl.count) { return; /* ã¾ã 次ã®æå»ã«ãªã£ã¦ããªãã®ã§ãããããã¾ã */ } timerctl.next = 0xffffffff; for (i = 0; i < MAX_TIMER; i++) { if (timerctl.timer[i].flags == TIMER_FLAGS_USING) { if (timerctl.timer[i].timeout <= timerctl.count) { /* ããã§æ¸ç®ãã¤ã¤ã¿ã¤ãã¼ã«ãã¦ããã®ããä¸å®ã®æéã«æ¥ããéç¥ããã¨ããä»çµã¿ã«ãããã¨ãã§ãã */ timerctl.timer[i].flags = TIMER_FLAGS_ALLOC; fifo8_put(timerctl.timer[i].fifo, timerctl.timer[i].data); } else { /* ã¾ã ã¿ã¤ã ã¢ã¦ãã§ã¯ãªã */ if (timerctl.next > timerctl.timer[i].timeout) { timerctl.next = timerctl.timer[i].timeout; } } } } return; }
ãã¨ã¯ãä¾åãã¦ããtimer.cã®é¢æ°ã®ä¿®æ£ãè¡ã£ã¦å®è¡ããã¨
åãç»é¢ã§ãããåãã®ã§æåããã¿ãã
å²ãè¾¼ã¿å¦çã¯çã(3)(harib09g)
ããå°ããããããã®ã¿ã¤ãã®ç®¡çããããã®ã§sheet.cã§ã®ã·ã¼ããã¨ã®ç®¡çã®ããã«ãã¿ã¤ãããããã管çã§ããããã«ä¿®æ£ããããã§ãã
ã¾ããæ§é ä½ã«å種ã¿ã¤ããçªå·ã¨ä½¿ã£ã¦ãããã«é¢ãã¦ã¦ã§ç®¡çã§ããããã«å¤æ´ãè¡ãã¿ããã§
#define MAX_TIMER 500 struct TIMER { unsigned int timeout, flags; struct FIFO8 *fifo; unsigned char data; }; struct TIMERCTL { unsigned int count, next, using; /* count:ã«ã¦ã³ã¿,next:次ã«æ³¨ç®ããã¿ã¤ãã¼,using:使ç¨ä¸ã¿ã¤ãã®åæ° */ struct TIMER *timers[MAX_TIMER]; /* ã¿ã¤ãã¼ãé çªã«ç®¡ç */ struct TIMER timers0[MAX_TIMER]; };
/ IDT20ã®å¦çè¨å® / void inthandler20(int esp) { int i, j; / / io_out8(PIC0_OCW2, 0x60); / IRQ-00åä»å®äºãPICã«éç¥ / timerctl.count++; / æå®ã«å¾ãã«ã¦ã³ããã / if (timerctl.next > timerctl.count) { return; / ã¾ã 次ã®æå»ã«ãªã£ã¦ããªãã®ã§ãããããã¾ã / } for (i = 0;i < timerctl.using; i++) { / timers ã®ã¿ã¤ãã¯å ¨ã¦åä½ä¸ã®ãã®ãªã®ã§ãflagsã確èªããªã / if (timerctl.timers[i]->timeout > timerctl.count) { break; } / ã¿ã¤ã ã¢ã¦ã / timerctl.timers[i]->flags = TIMER_FLAGS_ALLOC; fifo8_put(timerctl.timers[i]->fifo, timerctl.timers[i]->data); } / ã¡ããã©ä¸åã®ã¿ã¤ããã¿ã¤ã ã¢ã¦ããããæ®ãããããã */ timerctl.using -= i; for (j = 0; j < timerctl.using; j++) { timerctl.timers[j] = timerctl.timers[i + j]; } if (timerctl.using > 0) { timerctl.next = timerctl.timers[0]->timeout; } else { timerctl.next = 0xffffffff; } return; }
ããã¦ãä¾åãã¦ããé¢æ°init_pitã¨timer_allocãä¿®æ£ããtimersã¸ã®ç»é²ãè¡ãããã°ã©ã ãæ¸ãã¾ãã
/ timersã¸ã®ç»é²ã追å / void timer_settime(struct TIMER timer, unsigned int timeout) { int e, i, j; timer->timeout = timeout + timerctl.count; timer->flags = TIMER_FLAGS_USING; e = io_load_eflags(); io_cli(); / ã©ãã«å ¥ããã°ããããæ¢ã / for (i = 0; i < timerctl.using; i++) { if (timerctl.timers[i]->timeout >= timer->timeout) { break; } } / ãããã«ããã / for (j = timerctl.using; j > i; j--) { timerctl.timers[j] = timerctl.timers[j - 1]; } timerctl.using++; / 空ããééã«å ¥ãã */ timerctl.timers[i] = timer; timerctl.next = timerctl.timers[0]->timeout; io_store_eflags(e); return; }
ããã§å®è¡ãã㨠[https://twitter.com/Wagahaiha_toto/status/1211146197672480768:embed] å¤ãã£ã¦ã¯ãªãã§ãããåãã¨ãããã¨ã¯æåã¿ããã§ãã #ãããã« ãã©ãµããã¦