add PIT timer driver #1

Merged
brodycritchlow merged 2 commits from PIT-timer-driver into main 2026-09-01 03:54:04 +00:00
Collaborator

https://wiki.osdev.org/Programmable_Interval_Timer

some formatting stuff adds other files

I added nix dev shell, which is what .envrc is as well

I did change idle, let me know if you don't like that.

SOmething like this for debug works well:

	// Debug clock: top-right of the VGA text buffer, drawn straight into
	// the framebuffer so it never scrolls or moves the console cursor.
	volatile uint16_t *clock = (volatile uint16_t *)0xB8000;
	for (;;) {
		uint64_t ms = timer_uptime_ms();

		char buf[9];
		buf[0] = '0' + (char)((ms / 100000) % 10); // 9999.9s wraps
		buf[1] = '0' + (char)((ms / 10000) % 10);
		buf[2] = '0' + (char)((ms / 1000) % 10);
		buf[3] = '.';
		buf[4] = '0' + (char)((ms / 100) % 10);
		buf[5] = 's';
		buf[6] = '\0';

		for (int i = 0; buf[i] != '\0'; i++)
			clock[80 * 2 + 70 + i] = 0x0f00 | buf[i];

		idle();
	}
https://wiki.osdev.org/Programmable_Interval_Timer some formatting stuff adds other files I added nix dev shell, which is what .envrc is as well I did change idle, let me know if you don't like that. SOmething like this for debug works well: ```C // Debug clock: top-right of the VGA text buffer, drawn straight into // the framebuffer so it never scrolls or moves the console cursor. volatile uint16_t *clock = (volatile uint16_t *)0xB8000; for (;;) { uint64_t ms = timer_uptime_ms(); char buf[9]; buf[0] = '0' + (char)((ms / 100000) % 10); // 9999.9s wraps buf[1] = '0' + (char)((ms / 10000) % 10); buf[2] = '0' + (char)((ms / 1000) % 10); buf[3] = '.'; buf[4] = '0' + (char)((ms / 100) % 10); buf[5] = 's'; buf[6] = '\0'; for (int i = 0; buf[i] != '\0'; i++) clock[80 * 2 + 70 + i] = 0x0f00 | buf[i]; idle(); } ```
@ -0,0 +19,4 @@
outb(0x43, 0x36);
outb(0x40, (uint8_t)(div & 0xFF));
outb(0x40, (uint8_t)((div >> 8) & 0xFF));

Kinda stupid, but In other files ive been using:

#define CHANNEL_0_DATA_PORT 0x40
...

Maybe could do that here?

Kinda stupid, but In other files ive been using: ``` #define CHANNEL_0_DATA_PORT 0x40 ... ``` Maybe could do that here?
tylercritchlow marked this conversation as resolved
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
brodycritchlow/thOS!1
No description provided.