Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

intr: avoid random trace in (init_)call_intr #81

Merged
merged 1 commit into from
Feb 4, 2024

Conversation

ecm-pushbx
Copy link
Contributor

Here's example output of what happens when setting the CheckDebugger configuration item, then loading the kernel in bootable lDebug and running it:

 -g
 FreeDOS kernel - GIT (build 2043 OEM:0xfd) [compiled Jun  4 2022]
 Kernel compatibility 7.10 - GNUC - FAT32 support
 (C) Copyright 1995-2022 Pasquale J. Villani and The FreeDOS Project.
 All Rights Reserved. This is free software and comes with ABSOLUTELY NO
 WARRANTY; you can redistribute it and/or modify it under the terms of the
 GNU General Public License as published by the Free Software Foundation;
 either version 2, or (at your option) any later version.
 Unexpected single-step interrupt
 AX=3173 BX=0030 CX=FF01 DX=C781 SP=24D0 BP=24FA SI=0C7C DI=5058
 DS=80E5 ES=013D SS=80E5 CS=7C80 IP=0204 NV DN DI PL NZ NA PO NC
 7C80:0204 1F                pop     ds
 -
 Unexpected single-step interrupt
 AX=8001 BX=3D75 CX=11F9 DX=76D0 SP=24F8 BP=2020 SI=8938 DI=B8C6
 DS=80E5 ES=305D SS=80E5 CS=7C80 IP=0204 OV UP DI NG NZ NA PO CY
 7C80:0204 1F                pop     ds
 -

The first of those two single-step interrupts happened to be caused by this code:

kernel/kernel/initoem.c

Lines 41 to 44 in 0e6d90c

unsigned init_oem(void)
{
iregs r;
init_call_intr(0x12, &r);

As you can see it doesn't initialise the iregs structure and just expects the function to allow arbitrary values. There appear to be many cases of this in the kernel, so I decided to fix it in the call_intr function instead of hunting down all the uninitialised uses.

@tkchia
Copy link
Contributor

tkchia commented Jun 4, 2022

Hello @ecm-pushbx,

👀💭
Incidentally, in my libi86, I currently handle this by having the _intrf (...) routine load only the low byte of the flags, via sahf.

Thank you!

@ecm-pushbx
Copy link
Contributor Author

Here is a longer debugging session depicting the caller of the first unexpected single-step interrupt. The kernel used here is from my build as of today, at https://pushbx.org/ecm/download/fdkernel.zip which will be moved to https://pushbx.org/ecm/download/old/fdkernel/20220530.zip once the next build happens.

lDebug connected to serial port. Enter KEEP to confirm.
= keep
&boot protocol freedos cmdline=1 kernel.sys //
&r
AX=0000 BX=0000 CX=F000 DX=0000 SP=7AEC BP=7C00 SI=0000 DI=0000
DS=7460 ES=0060 SS=7460 CS=0060 IP=0000 NV UP DI PL ZR NA PE NC
0060:0000 EB1E              jmp     0020
&g
Unexpected breakpoint interrupt
AX=8001 BX=0000 CX=0000 DX=0BA0 SP=2596 BP=2596 SI=0017 DI=0152
DS=80E5 ES=80E5 SS=80E5 CS=7C80 IP=00DF NV UP EI PL ZR NA PE NC
7C80:00DF 7202              jb      00E3                            not jumping
&r f CY
-g
Unexpected single-step interrupt
AX=3173 BX=0030 CX=FF01 DX=C781 SP=24D0 BP=24FA SI=0C7C DI=5058
DS=80E5 ES=013D SS=80E5 CS=7C80 IP=0204 NV DN DI PL NZ NA PO NC
7C80:0204 1F                pop     ds
-dw ss:sp
header     0    2    4    6    8    A    C    E    0123456789ABCDEF
80E5:24D0  0000 0206 80E5 0000-013D 24FA 2E8F 0012 ........=..$....
80E5:24E0  24E2 3173 0030 FF01-C781 0C7C 5058 24FA .$s10.....|.XP.$
80E5:24F0  0000 013D 358B 06B6-2500 2590 0AE7 06B6 ..=..5...%.%....
80E5:2500  17B0 00D9 0007 000A-0156 3DE8 F619 0007 ........V..=....
80E5:2510  8001 3D75 11F9 76D0-8938 B8C6 2020 8DAB ..u=...v8...  ..
80E5:2520  305D F189 D9F7 F983-7610 B903 0010 1E1F ]0.......v......
80E5:2530  AC51 D7E8 B080 AA20-F7E2 1659 F71F 83D9 Q..... ...Y.....
80E5:2540  10C1 0774 20B8 AB20-E2AA C6F9 E745 892D ..t..  .....E.-.
-u
7C80:0204 1F                pop     ds
7C80:0205 CD12              int     12
7C80:0207 9C                pushf
7C80:0208 1E                push    ds
7C80:0209 53                push    bx
7C80:020A 89E3              mov     bx, sp
7C80:020C 368E5F08          mov     ds, word [ss:bx+08]
7C80:0210 368B5F14          mov     bx, [ss:bx+14]
7C80:0214 8907              mov     [bx], ax
7C80:0216 8F4702            pop     word [bx+02]
7C80:0219 894F04            mov     [bx+04], cx
7C80:021C 895706            mov     [bx+06], dx
7C80:021F 897708            mov     [bx+08], si
7C80:0222 897F0A            mov     [bx+0A], di
-
7C80:0225 896F0C            mov     [bx+0C], bp
7C80:0228 8F470E            pop     word [bx+0E]
7C80:022B 8C4710            mov     word [bx+10], es
7C80:022E 8F4716            pop     word [bx+16]
7C80:0231 9D                popf
7C80:0232 1F                pop     ds
7C80:0233 5F                pop     di
7C80:0234 5E                pop     si
7C80:0235 5D                pop     bp
7C80:0236 C20400            retn    0004
7C80:0239 5B                pop     bx
7C80:023A 59                pop     cx
7C80:023B 07                pop     es
7C80:023C 58                pop     ax
7C80:023D 5A                pop     dx
7C80:023E 0E                push    cs
7C80:023F 53                push    bx
7C80:0240 06                push    es
7C80:0241 51                push    cx
7C80:0242 CB                retf
7C80:0243 B80043            mov     ax, 4300
-g 236
AX=020D BX=24E2 CX=FF01 DX=C781 SP=24DC BP=24FA SI=013D DI=0000
DS=80E5 ES=013D SS=80E5 CS=7C80 IP=0236 NV UP EI PL NZ NA PE NC
7C80:0236 C20400            retn    0004
-u word [ss:sp] - 20
7C80:2E6F 06                push    es
7C80:2E70 E83BE0            call    0EAE
7C80:2E73 FF8668FF          inc     word [bp+FF68]
7C80:2E77 81C68200          add     si, 0082
7C80:2E7B E93FFF            jmp     2DBD
7C80:2E7E 55                push    bp
7C80:2E7F 89E5              mov     bp, sp
7C80:2E81 83EC18            sub     sp, +18
7C80:2E84 8D46E8            lea     ax, [bp-18]
7C80:2E87 50                push    ax
7C80:2E88 B81200            mov     ax, 0012
7C80:2E8B 50                push    ax
7C80:2E8C E844D3            call    01D3
-
7C80:2E8F 8B46E8            mov     ax, [bp-18]
7C80:2E92 89EC              mov     sp, bp
7C80:2E94 5D                pop     bp
7C80:2E95 C3                retn
7C80:2E96 56                push    si
7C80:2E97 57                push    di
7C80:2E98 55                push    bp
7C80:2E99 89E5              mov     bp, sp
7C80:2E9B FF7608            push    word [bp+08]
7C80:2E9E BF0E04            mov     di, 040E
7C80:2EA1 31F6              xor     si, si
7C80:2EA3 8EC6              mov     es, si
7C80:2EA5 26FF35            push    word [es:di]
7C80:2EA8 56                push    si
7C80:2EA9 FF760A            push    word [bp+0A]
7C80:2EAC 56                push    si
7C80:2EAD E8C9D4            call    0379
-

2E7Eh clearly is the init_oem function. The code not initialising its local iregs structure is visible too. The address matches that found in kernel.map:

 .text          0x0000000000002e7e       0x9f initoem.obj
                0x0000000000002e7e                _init_oem
                0x0000000000002e96                _movebda
                0x0000000000002ec7                _ebdasize

And 01D3h is the init_call_intr function:

 INIT_TEXT      0x00000000000001d3      0x106 intr.obj
                0x00000000000001d3                INIT_CALL_INTR
                0x0000000000000239                INIT_CALL_XMSCALL
                0x0000000000000243                DETECTXMSDRIVER

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants