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

The HandleException macro in interruptstubs.s assumes all exceptions have an error code #45

Open
mpetch opened this issue Aug 29, 2024 · 0 comments

Comments

@mpetch
Copy link

mpetch commented Aug 29, 2024

The HandleException macro assumes that all exceptions have an error code pushed on the stack. The list of exceptions that the CPU pushes an error code/doesn't push can be found here: https://wiki.osdev.org/Exceptions . One option is to split the HandleException macro into two macros. One that handles exceptions with an error code and one that doesn't. When an error code isn't pushed a dummy value of 0 can be used in its place.

Remove the current HandleException macro in interruptstubs.s and replace with:

.macro HandleExceptionErrCode num
.global _ZN16InterruptManager19HandleException\num\()Ev
_ZN16InterruptManager19HandleException\num\()Ev:
    movb $\num, (interruptnumber)
    jmp int_bottom
.endm

.macro HandleExceptionNoErrCode num
.global _ZN16InterruptManager19HandleException\num\()Ev
_ZN16InterruptManager19HandleException\num\()Ev:
    movb $\num, (interruptnumber)
    push $0x00                    # Push Dummy Error Code
    jmp int_bottom
.endm

Then generate stubs for all 32 exceptions like this:

HandleExceptionNoErrCode 0x00
HandleExceptionNoErrCode 0x01
HandleExceptionNoErrCode 0x02
HandleExceptionNoErrCode 0x03
HandleExceptionNoErrCode 0x04
HandleExceptionNoErrCode 0x05
HandleExceptionNoErrCode 0x06
HandleExceptionNoErrCode 0x07
HandleExceptionErrCode   0x08
HandleExceptionNoErrCode 0x09
HandleExceptionErrCode   0x0A
HandleExceptionErrCode   0x0B
HandleExceptionErrCode   0x0C
HandleExceptionErrCode   0x0D
HandleExceptionErrCode   0x0E
HandleExceptionNoErrCode 0x0F
HandleExceptionNoErrCode 0x10
HandleExceptionErrCode   0x11
HandleExceptionNoErrCode 0x12
HandleExceptionNoErrCode 0x13
HandleExceptionNoErrCode 0x14
HandleExceptionErrCode   0x15
HandleExceptionNoErrCode 0x16
HandleExceptionNoErrCode 0x17
HandleExceptionNoErrCode 0x18
HandleExceptionNoErrCode 0x19
HandleExceptionNoErrCode 0x1A
HandleExceptionNoErrCode 0x1B
HandleExceptionNoErrCode 0x1C
HandleExceptionErrCode   0x1D
HandleExceptionErrCode   0x1E
HandleExceptionNoErrCode 0x1F

In interrupts.cpp and interrupts.h you can then add all the exception handlers that are missing. The InterruptManager only supplies default exception handlers for HandleException0x00 to HandleException0x13, and that can now be up to HandleException0x1f

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

No branches or pull requests

1 participant