diff options
author | Robert Morris <[email protected]> | 2019-07-25 05:35:03 -0400 |
---|---|---|
committer | Robert Morris <[email protected]> | 2019-07-25 05:35:03 -0400 |
commit | 5d5e4e065f4e593c9e396a52b8e599cdc62c9e7d (patch) | |
tree | 0eaa24e2b0f489a65eae959c5f3b7b419a9ea214 /kernel/start.c | |
parent | aef3e0f5a41c3b45eeb47e407cacb6cfa59168a0 (diff) | |
download | xv6-labs-5d5e4e065f4e593c9e396a52b8e599cdc62c9e7d.tar.gz xv6-labs-5d5e4e065f4e593c9e396a52b8e599cdc62c9e7d.tar.bz2 xv6-labs-5d5e4e065f4e593c9e396a52b8e599cdc62c9e7d.zip |
comments for timer setup
Diffstat (limited to 'kernel/start.c')
-rw-r--r-- | kernel/start.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/kernel/start.c b/kernel/start.c index ea896eb..6dc106d 100644 --- a/kernel/start.c +++ b/kernel/start.c @@ -37,16 +37,26 @@ start() w_mideleg(0xffff); // set up to receive timer interrupts in machine mode, - // for pre-emptive switching and (on hart 0) to drive time. + // which arrive at machinevec in kernelvec.S, + // which turns them into software interrupts for + // devintr() in trap.c. int id = r_mhartid(); - uint64 *scratch = &mscratch0[32 * id]; + // ask the CLINT for a timer interrupt 10,000 cycles from now. *(uint64*)CLINT_MTIMECMP(id) = *(uint64*)CLINT_MTIME + 10000; + // prepare information in scratch[] for machinevec. + // scratch[0..3] : space for machinevec to save registers. + // scratch[4] : address of CLINT MTIMECMP register. + // scratch[5] : desired interval (in cycles) between timer interrupts. + uint64 *scratch = &mscratch0[32 * id]; scratch[4] = CLINT_MTIMECMP(id); scratch[5] = 10000000; w_mscratch((uint64)scratch); + // set the machine-mode trap handler. w_mtvec((uint64)machinevec); + // enable machine-mode interrupts. w_mstatus(r_mstatus() | MSTATUS_MIE); - w_mie(r_mie() | MIE_MTIE); + // enable machine-mode timer interrupts. + w_mie(r_mie() | MIE_MTIE); // keep each CPU's hartid in its tp register, for cpuid(). w_tp(id); |