xref: /kvmtool/tests/pit/tick.S (revision b0822113d5247df6cf21e8097d9b4b51a7e2a18e)
119059661SAsias He#define IO_PIC		0x20
219059661SAsias He#define IRQ_OFFSET	32
319059661SAsias He#define IO_PIT		0x40
419059661SAsias He#define TIMER_FREQ	1193182
519059661SAsias He#define TIMER_DIV(x)	((TIMER_FREQ+(x)/2)/(x))
619059661SAsias He
7053b0166SAsias He#define TEST_COUNT	0x0200
8053b0166SAsias He
919059661SAsias He	.code16gcc
1019059661SAsias He	.text
1119059661SAsias He	.globl	_start
1219059661SAsias He	.type	_start, @function
1319059661SAsias He_start:
143ed8a920SCyrill Gorcunov/*
153ed8a920SCyrill Gorcunov * fill up noop handlers
163ed8a920SCyrill Gorcunov */
173ed8a920SCyrill Gorcunov	xorw	%ax, %ax
183ed8a920SCyrill Gorcunov	xorw	%di, %di
1919059661SAsias He	movw	%ax, %es
203ed8a920SCyrill Gorcunov	movw	$256, %cx
213ed8a920SCyrill Gorcunovfill_noop_idt:
223ed8a920SCyrill Gorcunov	movw	$noop_handler, %es:(%di)
233ed8a920SCyrill Gorcunov	movw	%cs, %es:2(%di)
243ed8a920SCyrill Gorcunov	add	$4, %di
253ed8a920SCyrill Gorcunov	loop	fill_noop_idt
263ed8a920SCyrill Gorcunov
273ed8a920SCyrill Gorcunovset_idt:
2819059661SAsias He	movw	$timer_isr, %es:(IRQ_OFFSET*4)
2919059661SAsias He	movw	%cs, %es:(IRQ_OFFSET*4+2)
3019059661SAsias He
3119059661SAsias Heset_pic:
3219059661SAsias He	# ICW1
3319059661SAsias He	mov	$0x11, %al
3419059661SAsias He	mov	$(IO_PIC), %dx
3519059661SAsias He	out	%al,%dx
3619059661SAsias He	# ICW2
3719059661SAsias He	mov	$(IRQ_OFFSET), %al
3819059661SAsias He	mov	$(IO_PIC+1), %dx
3919059661SAsias He	out	%al, %dx
4019059661SAsias He	# ICW3
4119059661SAsias He	mov	$0x00, %al
4219059661SAsias He	mov	$(IO_PIC+1), %dx
4319059661SAsias He	out	%al, %dx
4419059661SAsias He	# ICW4
4519059661SAsias He	mov	$0x3, %al
4619059661SAsias He	mov	$(IO_PIC+1), %dx
4719059661SAsias He	out	%al, %dx
4819059661SAsias He
4919059661SAsias Heset_pit:
5019059661SAsias He	# set 8254 mode
5119059661SAsias He	mov	$(IO_PIT+3), %dx
5219059661SAsias He	mov	$0x34, %al
5319059661SAsias He	outb	%al, %dx
54339c64c8SCyrill Gorcunov	# set 8254 freq 1KHz
5519059661SAsias He	mov	$(IO_PIT), %dx
56339c64c8SCyrill Gorcunov	movb	$(TIMER_DIV(1000) % 256), %al
5719059661SAsias He	outb	%al, %dx
58339c64c8SCyrill Gorcunov	movb	$(TIMER_DIV(1000) / 256), %al
5919059661SAsias He	outb	%al, %dx
6019059661SAsias He
6119059661SAsias Heenable_irq0:
6219059661SAsias He	mov	$0xfe, %al
6319059661SAsias He	mov	$(IO_PIC+1), %dx
6419059661SAsias He	out	%al, %dx
6519059661SAsias He	sti
6619059661SAsias Heloop:
6719059661SAsias He	1:
6819059661SAsias He	jmp	1b
6919059661SAsias He
70053b0166SAsias Hetest_ok:
71053b0166SAsias He	mov	$0x3f8,%dx
72053b0166SAsias He	cs lea	msg2, %si
73053b0166SAsias He	mov	$(msg2_end-msg2), %cx
74053b0166SAsias He	cs rep/outsb
753db4f1beSCyrill Gorcunov
76*b0822113SSasha Levin	/* Reboot by using the i8042 reboot line */
77*b0822113SSasha Levin	mov	$0xfe, %al
78*b0822113SSasha Levin	outb	%al, $0x64
79053b0166SAsias He
8019059661SAsias Hetimer_isr:
8101c07d21SCyrill Gorcunov	cli
8219059661SAsias He	pushaw
83053b0166SAsias He	pushfw
8419059661SAsias He	mov	$0x3f8,%dx
8521dd76b3SPekka Enberg	mov	$0x2e, %al	# .
8619059661SAsias He	out	%al,%dx
87053b0166SAsias He	decw	count
88053b0166SAsias He	jz	test_ok
89053b0166SAsias He	popfw
9019059661SAsias He	popaw
9119059661SAsias He	iretw
923ed8a920SCyrill Gorcunov
933ed8a920SCyrill Gorcunovnoop_handler:
943ed8a920SCyrill Gorcunov	iretw
953ed8a920SCyrill Gorcunov
96053b0166SAsias Hecount:
97053b0166SAsias He	.word	TEST_COUNT
98053b0166SAsias He
99053b0166SAsias Hemsg2:
10021dd76b3SPekka Enberg	.asciz "\nTest OK\n"
101053b0166SAsias Hemsg2_end:
102