Proof of concept interrupt wrapping
PATCH 1/1 Proof of concept interrupt wrapping
Hello. We were discussing with Robert how to move BIOS interrupt routines out of kernel. There are following possibilities:
1) Have a .lowmem section in every concerned module which will always be placed in low memory. Currently in experimental.
Advantages:
a) moving functions to modules is straightforward
b) functions grow neither in size nor in complexity
Disadvantages:
c) needs lowmem allocators in core
2) Make every function needing bios interrupts setup its own trampoline. Due to complexity of trampolines it's not a real option
3) Have an universal routine grub_interrupt (int intno, struct grub_cpu_interrupt_regs *regs) which will be used by C routine to do the interrupt calls. This would move the complexity from asm to C. Advantages:
a) simplicity in core
b) complexity moved to a more readable language
c) we can also rename grub_interrupt to grub_interrupt_real and make grub_interrupt dprintf registers before and after the call. This would make debugging BIOS quirks easier.
Disadvantages:
a) Moving functions needs effort
b) C functions are probably bigger but it may be offset by possibility of inlining functions
c) repeadetly changing from/to real mode is an overhead when executing multiple interrupts in series. Fortunately this condition is rare in our codebase and is only on non performance-critical parts like halting.
d) Some functions aren't covered by this. At least grub_pxe_call is in this case. But we can use method 2 for them
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko
=== modified file 'conf/i386-pc.rmk'
i386-pc.rmk +1 -1
@@ -64,7 +64,7 @@ partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \ machine/biosdisk.h machine/boot.h machine/console.h machine/init.h \ machine/memory.h machine/loader.h machine/vga.h machine/vbe.h \ - machine/kernel.h machine/pxe.h i386/pit.h list.h handler.h command.h i18n.h + machine/kernel.h machine/pxe.h i386/pit.h list.h handler.h command.h i18n.h machine/int.h kernel_img_CFLAGS = $(COMMON_CFLAGS) $(TARGET_IMG_CFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)$(GRUB_KERNEL_MACHINE_LINK_ADDR) $(COMMON_CFLAGS)
=== modified file 'disk/i386/pc/biosdisk.c'
i386/pc/biosdisk.c +54 -0
66 lines not on this page · raw message
=== modified file 'include/grub/i386/pc/biosdisk.h'
grub/i386/pc/biosdisk.h +0 -2
@@ -106,7 +106,6 @@grub_uint64_t block; } __attribute__ ((packed)); -int EXPORT_FUNC (grub_biosdisk_rw_int13_extensions ) (int ah,int drive,void *dap);int EXPORT_FUNC (grub_biosdisk_rw_standard ) (int ah,int drive,int coff,int hoff,int soff,int nsec,int segment);int EXPORT_FUNC (grub_biosdisk_check_int13_extensions ) (int drive);
@@ -118,7 +117,6 @@unsigned long *cylinders, unsigned long *heads, unsigned long *sectors); -int EXPORT_FUNC (grub_biosdisk_get_num_floppies ) (void );void grub_biosdisk_init (void );void grub_biosdisk_fini (void );
=== added file 'include/grub/i386/pc/int.h'
grub/i386/pc/int.h +50 -0
50 lines not on this page · raw message
=== modified file 'kern/i386/pc/startup.S'
i386/pc/startup.S +71 -75
161 lines not on this page · raw message
Quoted 21 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Hello. We were discussing with Robert how to move BIOS interrupt routines out of kernel. There are following possibilities:
1) Have a .lowmem section in every concerned module which will always be placed in low memory. Currently in experimental.
Advantages:
a) moving functions to modules is straightforward
b) functions grow neither in size nor in complexity
Disadvantages:
c) needs lowmem allocators in core
2) Make every function needing bios interrupts setup its own trampoline. Due to complexity of trampolines it's not a real option
3) Have an universal routinegrub_interrupt(int intno, structgrub_cpu_interrupt_regs*regs) which will be used by C routine to do the interrupt calls. This would move the complexity from asm to C. Advantages:
a) simplicity in core
b) complexity moved to a more readable language
c) we can also renamegrub_interrupttogrub_interrupt_realand makegrub_interruptdprintf registers before and after the call. This would make debugging BIOS quirks easier.
Disadvantages:
Quoted 8 lines
a) Moving functions needs effort
b) C functions are probably bigger but it may be offset by possibility of inlining functions
c) repeadetly changing from/to real mode is an overhead when executing multiple interrupts in series. Fortunately this condition is rare in our codebase and is only on non performance-critical parts like halting.
d) Some functions aren't covered by this. At leastgrub_pxe_callis in this case. But we can use method 2 for them
We could diminish #1.c with ifdef GRUB_MACHINE_PCBIOS, but it's still ugly. I like #3 a lot more.
As for C being bigger than asm, it's argueable, taking into account that we have regparm, function alignment hacks, and gcc size optimizations :-)
In any case #3 looks a lot cleaner.
Some comments about the patch:
grub/i386/pc/int.h line 35
Quoted 12 lines
grub/i386/pc/int.h +12
-0+struct grub_cpu_int_registers +{ +grub_uint16_t bx; +grub_uint16_t es; +grub_uint16_t cx; +grub_uint16_t ax; +grub_uint16_t dx; +grub_uint16_t ds; +grub_uint16_t di; +grub_uint16_t flags; +grub_uint16_t si; +};
This structure is named in generic way, but its member names are CPU-specific. Is it useful to make this generic? In practice, it will be impossible for CPU-independant code to use it.
Besides, it's biased towards BIOS as the only i386 way. If, say, some new i386 firmware provides an interrupt-based callback interface that we're compelled to support (and YES I really hope this won't happen...), it wouldn't use i8086 mode at all.
I think it would be better to admit that this is a pure ad-hoc kludge. It's not beautiful, but it's *much* better than what we have now.
Signature · 3 lines
Robert Millan "Be the change you want to see in the world" -- Gandhi
Quoted 53 lines · Robert Millan
Quoted 21 lines · Vladimir 'φ-coder/phcoder' Serbinenko
Hello. We were discussing with Robert how to move BIOS interrupt routines out of kernel. There are following possibilities:
1) Have a .lowmem section in every concerned module which will always be placed in low memory. Currently in experimental.
Advantages:
a) moving functions to modules is straightforward
b) functions grow neither in size nor in complexity
Disadvantages:
c) needs lowmem allocators in core
2) Make every function needing bios interrupts setup its own trampoline. Due to complexity of trampolines it's not a real option
3) Have an universal routinegrub_interrupt(int intno, structgrub_cpu_interrupt_regs*regs) which will be used by C routine to do the interrupt calls. This would move the complexity from asm to C. Advantages:
a) simplicity in core
b) complexity moved to a more readable language
c) we can also renamegrub_interrupttogrub_interrupt_realand makegrub_interruptdprintf registers before and after the call. This would make debugging BIOS quirks easier.
Disadvantages:Quoted 9 lines
a) Moving functions needs effort
b) C functions are probably bigger but it may be offset by possibility of inlining functions
c) repeadetly changing from/to real mode is an overhead when executing multiple interrupts in series. Fortunately this condition is rare in our codebase and is only on non performance-critical parts like halting.
d) Some functions aren't covered by this. At leastgrub_pxe_callis in this case. But we can use method 2 for themWe could diminish #1.c with ifdef
GRUB_MACHINE_PCBIOS, but it's still ugly. I like #3 a lot more.As for C being bigger than asm, it's argueable, taking into account that we have regparm, function alignment hacks, and gcc size optimizations :-)
In any case #3 looks a lot cleaner.
Some comments about the patch:
Quoted 9 lines
(quoted diff) +9
-0+struct grub_cpu_int_registers +{ + grub_uint16_t bx; + grub_uint16_t es; + grub_uint16_t cx; + grub_uint16_t ax; + grub_uint16_t dx; + grub_uint16_t ds; + grub_uint16_t di;
Quoted 9 lines
Review
Quoted 4 lines
(quoted diff) +3
-0+ grub_uint16_t flags; + grub_uint16_t si; +};This structure is named in generic way, but its member names are CPU-specific. Is it useful to make this generic? In practice, it will be impossible for CPU-independant code to use it.
I changed it to _bios_
Quoted 4 lines
I think it would be better to admit that this is a pure ad-hoc kludge. It's not beautiful, but it's *much* better than what we have now.
I added 32-bit register support since it's needed for APM. Can wrapper be merged to mainline or is it better for it to be in a separate branch and be merged with first bunch of BIOS code going out of kernel?
Signature · 2 lines
Regards Vladimir 'φ-coder/phcoder' Serbinenko
=== modified file 'conf/i386-pc.rmk'
i386-pc.rmk +1 -1
@@ -64,7 +64,7 @@ partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \ machine/biosdisk.h machine/boot.h machine/console.h machine/init.h \ machine/memory.h machine/loader.h machine/vga.h machine/vbe.h \ - machine/kernel.h machine/pxe.h i386/pit.h list.h handler.h command.h i18n.h + machine/kernel.h machine/pxe.h i386/pit.h list.h handler.h command.h i18n.h machine/int.h kernel_img_CFLAGS = $(COMMON_CFLAGS) $(TARGET_IMG_CFLAGS) kernel_img_ASFLAGS = $(COMMON_ASFLAGS) kernel_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)$(GRUB_KERNEL_MACHINE_LINK_ADDR) $(COMMON_CFLAGS)
=== modified file 'disk/i386/pc/biosdisk.c'
i386/pc/biosdisk.c +54 -0
66 lines not on this page · raw message
=== modified file 'include/grub/i386/pc/biosdisk.h'
grub/i386/pc/biosdisk.h +0 -2
@@ -106,7 +106,6 @@grub_uint64_t block; } __attribute__ ((packed)); -int EXPORT_FUNC (grub_biosdisk_rw_int13_extensions ) (int ah,int drive,void *dap);int EXPORT_FUNC (grub_biosdisk_rw_standard ) (int ah,int drive,int coff,int hoff,int soff,int nsec,int segment);int EXPORT_FUNC (grub_biosdisk_check_int13_extensions ) (int drive);
@@ -118,7 +117,6 @@unsigned long *cylinders, unsigned long *heads, unsigned long *sectors); -int EXPORT_FUNC (grub_biosdisk_get_num_floppies ) (void );void grub_biosdisk_init (void );void grub_biosdisk_fini (void );
=== added file 'include/grub/i386/pc/int.h'
grub/i386/pc/int.h +52 -0
52 lines not on this page · raw message
=== modified file 'kern/i386/pc/startup.S'
i386/pc/startup.S +94 -75
184 lines not on this page · raw message