x86_64 icon indicating copy to clipboard operation
x86_64 copied to clipboard

Allow passing index as :ident in set_general_handler macro

Open asoderman opened this issue 3 years ago • 1 comments

Hello, please consider this small QOL change to the set_general_handler macro.

This would allow the index to be specified by a const or variable e.g.

const PAGEFAULT: u8 = 0xe;

set_general_handler(idt, page_fault, PAGEFAULT);

instead of being forced to convert it to a range

set_general_handler(idt, page_fault, PAGEFAULT..PAGEFAULT)

I'm not sure if there's any way to make this change less repetitive by having $idx be either literal or ident. It might also be worth considering refactoring out the setting individual handler functionality (the $idx variants) into its own macro and allow users to pass a $range:ident to the current macro to avoid ambiguity.

asoderman avatar Jun 09 '22 19:06 asoderman

Perhaps we could approach this from another angle: The SliceIndex trait is used in the standard library to allow indexing with multiple different types. This was already considered in https://github.com/rust-osdev/x86_64/pull/95#issuecomment-557496537 and later ruled out in https://github.com/rust-osdev/x86_64/pull/319 because SliceIndex is based on usize and not u8. Instead, perhaps we could implement our own trait InterruptDescriptorTableIndex that would be implemented on u8 as well as all the range types and use that type for the bounds checks in the macro. The same trait could probably be used for InterruptDescriptorTable::slice as well as InterruptDescriptorTable::index.

Freax13 avatar Jun 14 '22 12:06 Freax13