.global asm_pit_tick .global asm_pit_get_ticks .global asm_pit_sleep_50ms .global asm_pit_sleep_40ms .global asm_pit_sleep_10ms .global asm_pit_sleep_1ms .global asm_pit_rate_50ms .global asm_pit_rate_40ms .global asm_pit_rate_10ms .global asm_pit_rate_1ms ticks: .int 0 asm_pit_get_ticks: mov (ticks),%eax ret asm_pit_tick: push %eax // persist // INC TICK COUNTER mov $ticks, %eax incl (%eax) pop %eax // load original ret .macro asm_pit_rate val mov $0b00110100, %al // chan 0 / mode 2 outb %al,$0x43 // LSB first mov \val, %dx out %al, $0x40 xchg %ah,%al out %al, $0x40 ret .endm .macro asm_pit_sleep val mov $0b00110000, %al // chan 0 / mode 0 outb %al,$0x43 // LSB first mov \val, %ax out %al, $0x40 xchg %ah,%al out %al, $0x40 //sleep until finished //7th bit (0-7) determines if finished sleep\val: // read back command mov $0b11100010, %al outb %al,$0x43 inb $0x40, %al and $0b10000000, %al cmp $0b10000000, %al jne sleep\val ret .endm /* decrements at 1.193182Mhz 0xE90B // 50ms - 20 Hz 0xBA6F // 40ms - 25 Hz 0x2E9C // 10ms - 100 Hz 0x04A9 // 1ms - 1000 Hz */ asm_pit_sleep_50ms: asm_pit_sleep $0xE90B asm_pit_sleep_40ms: asm_pit_sleep $0xBA6F asm_pit_sleep_10ms: asm_pit_sleep $0x2E9C asm_pit_sleep_1ms: asm_pit_sleep $0x04A9 asm_pit_rate_50ms: asm_pit_rate $0xE90B asm_pit_rate_40ms: asm_pit_rate $0xBA6F asm_pit_rate_10ms: asm_pit_rate $0x2E9C asm_pit_rate_1ms: asm_pit_rate $0x04A9