Use int 0x16 for pit_sleep_and_quit_on_keypress()

This commit is contained in:
mintsuki 2020-04-23 12:56:15 +02:00
parent d314bd8401
commit 2fc3b21295
6 changed files with 40 additions and 23 deletions

Binary file not shown.

View File

@ -58,12 +58,15 @@ void pit_sleep(uint64_t pit_ticks) {
int pit_sleep_and_quit_on_keypress(uint64_t pit_ticks) {
uint64_t target = global_pit_tick + pit_ticks;
while (global_pit_tick < target && !kbd_int) {
asm volatile ("hlt");
}
if (kbd_int) {
kbd_int = 0;
return 1;
while (global_pit_tick < target) {
struct rm_regs r = {0};
r.eax = 0x0100;
rm_int(0x16, &r, &r);
if (!(r.eflags & EFLAGS_ZF)) {
r.eax = 0x0000;
rm_int(0x16, &r, &r);
return 1;
}
}
return 0;
}

View File

@ -3,8 +3,8 @@
#include <stdint.h>
#define rm_seg(x) (unsigned short)(((int)x & 0xFFFF0) >> 4)
#define rm_off(x) (unsigned short)(((int)x & 0x0000F) >> 0)
#define rm_seg(x) ((uint16_t)(((int)x & 0xffff0) >> 4))
#define rm_off(x) ((uint16_t)(((int)x & 0x0000f) >> 0))
#define rm_desegment(seg, off) (((uint32_t)(seg) << 4) + (uint32_t)(off))

View File

@ -19,6 +19,8 @@ asm (
static char cmdline[128];
static char config_entry_name[1024];
void boot_menu(void) {
text_disable_cursor();
int selected_entry = 0;
@ -31,13 +33,12 @@ refresh:
size_t max_entries;
for (max_entries = 0; ; max_entries++) {
char buf[32];
if (config_get_entry_name(buf, max_entries, 32) == -1)
if (config_get_entry_name(config_entry_name, max_entries, 1024) == -1)
break;
if (max_entries == selected_entry)
print(" -> %s\n", buf);
print(" -> %s\n", config_entry_name);
else
print(" %s\n", buf);
print(" %s\n", config_entry_name);
}
print("\nArrows to choose, enter to select, 'e' to edit command line.");

View File

@ -3,10 +3,11 @@
#include <sys/interrupt.h>
#include <lib/cio.h>
#include <lib/blib.h>
#include <lib/real.h>
__attribute__((interrupt)) static void unhandled_int(void *r) {
(void)r;
print("Warning: unhandled interrupt");
panic("Unhandled interrupt");
}
volatile uint64_t global_pit_tick = 0;
@ -17,13 +18,19 @@ __attribute__((interrupt)) static void pit_irq(void *r) {
port_out_b(0x20, 0x20);
}
volatile int kbd_int = 0;
__attribute__((interrupt)) static void keyboard_handler(void *r) {
(void)r;
kbd_int = 1;
(void)port_in_b(0x60);
port_out_b(0x20, 0x20);
__attribute__((naked)) static void ivt_timer_isr(void) {
asm (
".code16\n\t"
"pushf\n\t"
"push bx\n\t"
"mov ebx, dword ptr ds:[1f]\n\t"
"inc dword ptr ds:[ebx]\n\t"
"pop bx\n\t"
"popf\n\t"
"iret\n\t"
".code32\n\t"
"1: .long global_pit_tick\n\t"
);
}
uint8_t rm_pic0_mask = 0xff;
@ -57,7 +64,8 @@ void init_idt(void) {
}
register_interrupt_handler(0x08, pit_irq, 0x8e);
register_interrupt_handler(0x09, keyboard_handler, 0x8e);
ivt_register_handler(0x1c, ivt_timer_isr);
struct idt_ptr_t idt_ptr = {
sizeof(idt) - 1,
@ -70,7 +78,7 @@ void init_idt(void) {
: "m" (idt_ptr)
);
pm_pic0_mask = 0xfc;
pm_pic0_mask = 0xfe;
pm_pic1_mask = 0xff;
port_out_b(0x21, pm_pic0_mask);
port_out_b(0xa1, pm_pic1_mask);
@ -87,3 +95,8 @@ void register_interrupt_handler(size_t vec, void *handler, uint8_t type) {
idt[vec].type_attr = type;
idt[vec].offset_hi = (uint16_t)(p >> 16);
}
void ivt_register_handler(int vect, void *isr) {
volatile uint32_t *ivt = (volatile void *)0;
ivt[vect] = rm_seg(isr) << 16 | rm_off(isr);
}

View File

@ -5,7 +5,6 @@
#include <stddef.h>
extern volatile uint64_t global_pit_tick;
extern volatile int kbd_int;
extern uint8_t rm_pic0_mask;
extern uint8_t rm_pic1_mask;
@ -14,5 +13,6 @@ extern uint8_t pm_pic1_mask;
void init_idt(void);
void register_interrupt_handler(size_t, void *, uint8_t);
void ivt_register_handler(int vect, void *isr);
#endif