|
|
1.1 root 1: ////////
2: /
3: / Clocked Functions - schedule function 'f' to be periodically invoked.
4: / - invocation is at clock interrupt level
5: / - only one function can be clocked
6: /
7: / clocked( f, hz )
8: / void (*f)();
9: / int hz;
10: /
11: ////////
12:
13: .globl clocked_
14:
15: ////////
16: /
17: / Hardware Dependant Constants
18: /
19: ////////
20:
21: EOI = 0x20 / Non-specific End of Interrupt command
22: PIC = 0x20 / 8259 pic base address
23: PIT = 0x40 / 8253 timer base address
24:
25: ////////
26: /
27: / Private Data Declarations
28: /
29: ////////
30:
31: .bssd
32: stack: .blkb 256 / Run time stack for the clocked function.
33: stktop:
34:
35: .shri / CODE SPACE!
36: uss: .word 0 / User stack segment
37: usp: .word 0 / User stack pointer
38: kds: .word 0 / Kernel data segment
39: oldclk: .word 0 / Previous clock interrupt entry point.
40: reload: .word 0 / Number of polls per logical clock tick.
41: resid: .word 0 / Number of polls left in logical clock tick.
42: cfunc: .word 0 / Clocked function
43: .shri
44:
45: ////////
46: /
47: / clocked( f, hz )
48: / void (*f)();
49: / int hz;
50: /
51: / Input: f = function to be clocked.
52: / hz = desired clock rate in invocations/second.
53: /
54: / Action: Calculate the number of polls per logical clock tick.
55: / Seize the clock hardware interrupt.
56: / Preserve the previous clock interrupt handler.
57: / Reprogram the hardware clock to the desired rate.
58: /
59: / Return: 0 = clock interrupt seized.
60: / -1 = clock interrupt previously seized.
61: /
62: / Notes: The logical clock rate to the OS will be unchanged.
63: /
64: ////////
65:
66: clocked_:
67: pop ax / Convert IP into PSW,CS,IP so can use iret.
68: pushf
69: push cs
70: push ax
71:
72: mov cs:kds, ds / Remember the kernel data segment
73:
74: cli / Disable interrupts
75:
76: push es / Seize clock interrupt vector
77: sub ax, ax
78: mov es, ax
79: mov ax, es:0x0020
80: cmp ax, $clocker
81: jne 0f
82: mov ax, $-1
83: pop es
84: iret
85:
86: 0: mov cs:oldclk, ax
87: mov es:0x0020, $clocker
88: pop es
89:
90: mov bx, sp / Remember the function to be clocked.
91: mov ax, ss:6(bx)
92: mov cs:cfunc, ax
93:
94: mov ax, ss:8(bx) / Compute polling rate relative to 20 hz.
95: sub dx, dx
96: mov cx, $20
97: div cx
98: mov cs:reload, ax
99: mov cs:resid, ax
100:
101: movb al, $0x36 / Timer 0, LSB, MSB, mode 3
102: outb PIT+3, al
103: mov ax, $59659
104: sub dx, dx
105: div cs:reload
106: outb PIT, al / LSB of 59659/reload
107: jmp 0f
108: 0: movb al, ah
109: outb PIT, al / MSB of 59659/reload
110:
111: sub ax, ax
112: iret
113:
114: ////////
115: /
116: / clocker() - initiate clocked function.
117: /
118: / Action: Every hardware clock tick, invoke the clocked function.
119: / Every 'reload' hardware clock ticks,
120: / simulate a logical clock interrupt to the OS.
121: /
122: ////////
123:
124: clocker:
125: push ax / Save registers.
126: push bx
127: push cx
128: push dx
129: push ds
130: push es
131:
132: mov cs:uss, ss / Save current stack.
133: mov cs:usp, sp
134:
135: mov ax, cs:kds / Remap Data/Extra/Stack Segments into Kernel.
136: mov ds, ax
137: mov es, ax
138: mov ss, ax
139: mov sp, $stktop / Remap stack pointer onto private intr stack.
140:
141: icall cs:cfunc / Call the clocked function.
142:
143: mov ss, cs:uss / Restore previous stack.
144: mov sp, cs:usp
145:
146: pop es / Restore registers.
147: pop ds
148: pop dx
149: pop cx
150: pop bx
151:
152: dec cs:resid
153: je 0f
154: movb al, $EOI
155: outb PIC, al
156: pop ax
157: iret
158:
159: 0: mov ax, cs:reload
160: mov cs:resid, ax
161: pop ax
162: ijmp cs:oldclk
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.