:: commit 8e7ce7a105a87da9b30cdb3e018640d3617eede6

mintsuki <mintsuki@protonmail.com> — 2020-04-29 15:16

parents: f8c0b317aa

Dehook int 0x08 when unused

diff --git a/qloader2.bin b/qloader2.bin
index 28b58c07..5269c3fe 100644
Binary files a/qloader2.bin and b/qloader2.bin differ
diff --git a/src/lib/blib.c b/src/lib/blib.c
index 0e25df2a..6774787b 100644
--- a/src/lib/blib.c
+++ b/src/lib/blib.c
@@ -63,14 +63,21 @@ __attribute__((naked)) static void int_08_isr(void) {
 uint32_t *ivt = 0; // this variable is not static else gcc will optimise the
                    // 0 ptr to a ud2
 
-static void hook_int_08(void) {
+__attribute__((used)) static void hook_int_08(void) {
     ivt[0x40] = ivt[0x08];  // int 0x40 is callback interrupt
     ivt[0x08] = rm_seg(int_08_isr) << 16 | rm_off(int_08_isr);
 }
 
+__attribute__((used)) static void dehook_int_08(void) {
+    ivt[0x08] = ivt[0x40];
+}
+
 // This is a dirty hack but we need to execute this full function in real mode
-__attribute__((naked)) int _pit_sleep_and_quit_on_keypress(uint32_t ticks) {
+__attribute__((naked))
+int pit_sleep_and_quit_on_keypress(uint32_t ticks) {
     asm (
+        "call hook_int_08\n\t"
+
         // pit_ticks in edx
         "mov edx, dword ptr ss:[esp+4]\n\t"
 
@@ -151,22 +158,12 @@ __attribute__((naked)) int _pit_sleep_and_quit_on_keypress(uint32_t ticks) {
         "pop ebx\n\t"
 
         // Exit
+        "call dehook_int_08\n\t"
         "ret\n\t"
     );
     (void)ticks;
 }
 
-static bool int_08_hooked = false;
-
-int pit_sleep_and_quit_on_keypress(uint32_t ticks) {
-    if (!int_08_hooked) {
-        hook_int_08();
-        int_08_hooked = true;
-    }
-
-    return _pit_sleep_and_quit_on_keypress(ticks);
-}
-
 uint64_t strtoui(const char *s) {
     uint64_t n = 0;
     while (*s)
tab: 248 wrap: offon