From 2fc3b212959d84e1f4cca8a70c4151319d9ce875 Mon Sep 17 00:00:00 2001 From: mintsuki Date: Thu, 23 Apr 2020 12:56:15 +0200 Subject: [PATCH] Use int 0x16 for pit_sleep_and_quit_on_keypress() --- qloader2.bin | Bin 32768 -> 32768 bytes src/lib/blib.c | 15 +++++++++------ src/lib/real.h | 4 ++-- src/main.c | 9 +++++---- src/sys/interrupt.c | 33 +++++++++++++++++++++++---------- src/sys/interrupt.h | 2 +- 6 files changed, 40 insertions(+), 23 deletions(-) diff --git a/qloader2.bin b/qloader2.bin index a35ee83353e57ba38bb7f739aa988455be9fac8f..f961043563f2f5bc35580ed74534e414f394d0b9 100644 GIT binary patch delta 6972 zcmbVQ3s_XuzTbN@1E|ByC}1NG9dJZM6i`tJNf1;l%@O471I@-QifMvnX5bkp$2sGn zR-WvbDbhLD(wlaMJmjN51k@l=yEja4k#%Y#~IRcWNLuc?dWsD}?QU@$j5J>Ofp#Wt%0!%P^< z(ZnKGnMyg1OB1V4ah$YoD91IbX$l!nqZ*T(QHOZ!3*xv+*m76B!u@mNyUPmPjncNQ& zc!K@4-v}Y0i#7ENG^|Fb8cO(*0o>|3$2x9{ZvtGZSgm1v|Db3h(o>NPWLZt2(BZ7J zlsBqrNR*DZT(H7J%p}e-`;Qn%91pO8z&iRrSxhWZ=YGC%_KH2(q_XL&o12=NejY*S z+AAKwdD`@K<<#4K6?I-@&E_p+oBJo`RRujO4+g$(Tk2p;1k5dK%SB??aKG#-KH- z=}q)T^@RJ-N)0@FY4r$#lA$o}>(L8u^~%4&3FWdgJWlK(U*&$*KG zl`?7Uh}MlBl|-}EjcVh(v_KrBf3{D+u=2gIF5P+ zyEriMKM*jxm%@+(UV>(axs~9THjsjnfF_PZNxC#yFYEZ0J(R-s1)!GiM%E*Ap-SF39k3^Xwcehi z+v=_C7v#(ws60%sc3H^~O-IFZgkJ3hs179rQK#BB{EGg8LXZ0u?n4Fl31nP>>Cxi{ zMcF|18hKqP4}sa6X`Noz{Y^-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t% z_MLsnEY`+B(&Jb`|EX(&{)Vg(BmV{G>p=bfpx^8$RItDEZ!QU$I>PH;hLtPF2faIb<9Z{XGH*v1A>3x6_ESQ}DY4zo458E!ekn`v_VZd({_Vzh`X+QvV z)ueFFYk}+F(_#}m74SR{&uh+MhL6Q6(~|W?tBO`m(3BLhONy4SS+QKRs;GFy`t>F2 zib;4uDADBkiO1~cc?r3_GL%fq`wP8~G~`XB>zu#j>1eu%WEKROxp#P8N_l^9{7_l& zd1wvAj`Qgd&VDxnE`qMLX83b8o;yyW&&7Ml6mGw z#Cw6$MxHe526qAVJ;<&L!Trra#l@-%6M*7keF-W`5QtS z8dt5Nvq)m04dm|@E~Bf7dUb(V0=xBo61h5Cwn^04S}VF>U`24H3g182*!rpmIX$YxHJ z>9b`G8<)*%odqnrrVo#H2Ltz-}9 z(Ou5WC->9zRp+3GnTg1}PpcP6uil6nH2JdOD3s=pcW7+9=k405@P^ z@~3S`B;8Ms7q4g|LLtiuVU&gw1aNX%1Dua- LJnc&~gB -#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)) diff --git a/src/main.c b/src/main.c index 837dd587..fd00bad7 100644 --- a/src/main.c +++ b/src/main.c @@ -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."); diff --git a/src/sys/interrupt.c b/src/sys/interrupt.c index 2362c9a7..3bfffaeb 100644 --- a/src/sys/interrupt.c +++ b/src/sys/interrupt.c @@ -3,10 +3,11 @@ #include #include #include +#include __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); +} diff --git a/src/sys/interrupt.h b/src/sys/interrupt.h index d22e5bd7..4f33e7d1 100644 --- a/src/sys/interrupt.h +++ b/src/sys/interrupt.h @@ -5,7 +5,6 @@ #include 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