-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kvm, test: add PIT 8254 and PIC 8259 test code
8254 ticks at 100HZ. Signed-off-by: Asias He <[email protected]> Signed-off-by: Pekka Enberg <[email protected]>
- Loading branch information
Showing
1 changed file
with
79 additions
and
0 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 |
---|---|---|
@@ -0,0 1,79 @@ | ||
#define IO_PIC 0x20 | ||
#define IRQ_OFFSET 32 | ||
#define IO_PIT 0x40 | ||
#define TIMER_FREQ 1193182 | ||
#define TIMER_DIV(x) ((TIMER_FREQ (x)/2)/(x)) | ||
|
||
.code16gcc | ||
.text | ||
.globl _start | ||
.type _start, @function | ||
_start: | ||
mov $0x3f8,%dx | ||
cs lea msg, %si | ||
mov $(msg_end-msg), %cx | ||
cs rep/outsb | ||
|
||
set_idt: | ||
xor %ax, %ax | ||
movw %ax, %es | ||
movw $timer_isr, %es:(IRQ_OFFSET*4) | ||
movw %cs, %es:(IRQ_OFFSET*4 2) | ||
|
||
set_pic: | ||
# ICW1 | ||
mov $0x11, %al | ||
mov $(IO_PIC), %dx | ||
out %al,%dx | ||
# ICW2 | ||
mov $(IRQ_OFFSET), %al | ||
mov $(IO_PIC 1), %dx | ||
out %al, %dx | ||
# ICW3 | ||
mov $0x00, %al | ||
mov $(IO_PIC 1), %dx | ||
out %al, %dx | ||
# ICW4 | ||
mov $0x3, %al | ||
mov $(IO_PIC 1), %dx | ||
out %al, %dx | ||
|
||
set_pit: | ||
# set 8254 mode | ||
mov $(IO_PIT 3), %dx | ||
mov $0x34, %al | ||
outb %al, %dx | ||
# set 8254 freq 100Hz | ||
mov $(IO_PIT), %dx | ||
movb $(TIMER_DIV(100) % 256), %al | ||
outb %al, %dx | ||
movb $(TIMER_DIV(100) / 256), %al | ||
outb %al, %dx | ||
|
||
enable_irq0: | ||
mov $0xfe, %al | ||
mov $(IO_PIC 1), %dx | ||
out %al, %dx | ||
sti | ||
loop: | ||
1: | ||
jmp 1b | ||
|
||
timer_isr: | ||
pushaw | ||
mov $0x3f8,%dx | ||
mov $0x49, %al # I | ||
out %al,%dx | ||
mov $0x53, %al # S | ||
out %al,%dx | ||
mov $0x52, %al # R | ||
out %al,%dx | ||
mov $0x0a, %al # \n | ||
out %al, %dx | ||
popaw | ||
iretw | ||
|
||
msg: | ||
.ascii "This is PVM.\nPIC 8259 and PIT 8254 test.\n" | ||
.asciz "---------------------------------------------------\n" | ||
msg_end: |