|
9 | 9 | init_pit: |
10 | 10 | ; Enable PIT |
11 | 11 | ; Base rate is 1193182 Hz |
12 | | - mov al, 0x36 ; Channel 0 (7:6), Access Mode lo/hi (5:4), Mode 3 (3:1), Binary (0) |
| 12 | + mov al, 0x34 ; Channel 0 (7:6), Access Mode lo/hi (5:4), Mode 2 (3:1), Binary (0) |
13 | 13 | out 0x43, al |
14 | | - mov al, 0x3C ; 60 |
| 14 | + ; Set divisor to 12 (1193182 Hz / 12 = ~99432 Hz) |
| 15 | + ; This gives a precision of ~10 microseconds |
| 16 | + mov al, 0x74 |
15 | 17 | out 0x40, al ; Set low byte of PIT reload value |
16 | 18 | mov al, 0x00 |
17 | 19 | out 0x40, al ; Set high byte of PIT reload value |
18 | | - ; New rate is 19866 Hz (1193182 / 60) |
19 | | - ; 0.050286633812733 milliseconds (ms) |
20 | | - ; 50.28663381273300814 microseconds (us) |
| 20 | + |
| 21 | + ; Create gate for PIT IRQ |
| 22 | + mov edi, 0x20 |
| 23 | + mov eax, pit_irq |
| 24 | + call create_gate |
| 25 | + |
| 26 | + ; Enable PIT Interrupt via the PIC |
| 27 | + in al, 0x21 |
| 28 | + mov al, 11111110b ; Enable PIT |
| 29 | + out 0x21, al |
| 30 | + |
| 31 | + ret |
| 32 | + |
| 33 | + |
| 34 | +; ----------------------------------------------------------------------------- |
| 35 | +; os_pit_delay -- Delay by X microseconds |
| 36 | +; IN: RAX = Time microseconds |
| 37 | +; OUT: All registers preserved |
| 38 | +; Note: There are 1,000,000 microseconds in a second |
| 39 | +; There are 1,000 milliseconds in a second |
| 40 | +os_pit_delay: |
| 41 | + push rdx |
| 42 | + push rcx |
| 43 | + push rbx |
| 44 | + push rax |
| 45 | + |
| 46 | + ; The PIT only gives us a precision of ~10 microseconds |
| 47 | + ; We need to divide RAX by 10 |
| 48 | + mov ecx, 10 |
| 49 | + xor edx, edx |
| 50 | + div rcx |
| 51 | + |
| 52 | + add rax, [p_Counter_Timer] |
| 53 | + |
| 54 | +os_pit_delay_loop: |
| 55 | + mov rbx, [p_Counter_Timer] |
| 56 | + cmp rax, rbx |
| 57 | + jae os_pit_delay_loop |
| 58 | + |
| 59 | + pop rax |
| 60 | + pop rbx |
| 61 | + pop rcx |
| 62 | + pop rdx |
21 | 63 | ret |
| 64 | +; ----------------------------------------------------------------------------- |
22 | 65 |
|
23 | 66 |
|
24 | 67 | ; ============================================================================= |
|
0 commit comments