Setting Up Interrupts - Amateur OS Dev (in C)

Channel:
Subscribers:
5,840
Published on ● Video Link: https://www.youtube.com/watch?v=NqSE_aVCJXg



Category:
Tutorial
Duration: 2:16:31
3,744 views
72


Adding basic interrupt support including: the IDT, default ISRs for exceptions and software interrupts,
a system call handler for software interrupt 0x80, and PIC setup & remapping for hardware interrupts.

OS Dev playlist:
https://www.youtube.com/playlist?list=PLT7NbkyNWaqajsw8Xh7SP9KJwjfpP8TNX

Source code as of the end of this video:
https://git.sr.ht/~queso_fuego/amateur_os_video_sources/tree/master/item/38_setting_up_interrupts

Repos for this OS:
Sourcehut: https://git.sr.ht/~queso_fuego/quesos
Github mirror: https://github.com/queso-fuego/amateuros

OS Dev Wiki pages for interrupts:
https://wiki.osdev.org/Interrupts_tutorial
https://wiki.osdev.org/Interrupt_Descriptor_Table
https://wiki.osdev.org/Interrupt_Service_Routines
https://wiki.osdev.org/System_Calls
https://wiki.osdev.org/PIC

More in-depth tutorial over the PIC:
http://www.brokenthorn.com/Resources/OSDevPic.html

Other links:
https://gcc.gnu.org/onlinedocs/gcc-11.1.0/gcc/x86-Function-Attributes.html
https://www.felixcloutier.com/x86/sti

Notes:
- The intel x86 manuals say exceptions 22-31 are reserved and not to use them. So the code for initializing the IDT should change to only set exception ISRs 0-21, just in case. Also, since the PIC is remapped to use interrupts 0x20-0x2F, setting the regular interrupts could probably be done with entry number starting at 0x30 (48).
- I thought that sizeof wasn't working before, but I probably misread error messages or didn't understand what it does. It could lead to easy refactors now at least, for less hardcoding in parts.
- OBS recording firefox and scrolling on pdfs and some webpages has a lot of artifacting, sorry about that. Probably due to monitor 1 being 144fps and the other monitor with obs and video recording at 60fps. Maybe, idk. Only happens when recording these. Do not adjust your set! That is normal on the video.
- div/idiv instructions, in 32bit mode, can only ever be 2 bytes: F6 /6 & F7 /6 for div, and F6 /7 & F7 /7 for idiv. So in the divide by 0 handler, it could be eip += 2 to skip the whole div/idiv instruction. That works, at least for the calculator, and is probably a better way to handle it.
- The PIT is the programmable _Interval_ timer, not _Interrupt_ timer, my bad. PIC and PIT names are easy to confuse.
- My voice was a bit shot for the later parts, for the PIC and after, sorry about that. I need to stock up on some werther's originals or something.

Next video ideas:
It'll probably be over automating the build process (no more manually updating file sizes! ...until the filetable/system changes later e.g. directory support), and a couple PIC interrupt handlers for timer ticks, keyboard, or Real Time Clock/RTC. But I might research virtual memory management & paging
(for 32bit protected mode), a malloc() or other syscall, or other things.

- Let me know if there's anything specific you'd like to see

Outline:
0:00 - intro/overview
5:18 - idt.h; set up IDT and default ISRs
46:01 - exceptions.h; divide by 0 exception handler
59:37 - explaining sizeof and address of array
1:02:46 - syscalls.h; system call interrupt, syscall table, example syscalls
1:29:49 - pic.h & io.h; remap the PIC for hardware interrupts, small C asm io functions
2:14:46 - Coming up and Outro

Software used:
VMware Workstation Player - https://www.vmware.com/products/workstation-player/workstation-player-evaluation.html
openBSD - https://www.openbsd.org/
qemu - https://www.qemu.org/
vim - https://www.vim.org/
clang - https://clang.llvm.org/
davinci resolve - https://www.blackmagicdesign.com/products/davinciresolve/
OBS Studio - https://obsproject.com/

Peripherals:
Camera: Sony ZV-1, Elgato Camlink 4k
Microphone: Shure SM7B, Cloudlifter CL-1, Focusrite Scarlett Solo
Keyboard: HHKB Pro Hybrid Type S, white/blank keycaps
Mouse: Logitech M590

Contact:
email - fuegoqueso@gmail.com
twitter - @Queso_Fuego
twitch - https://www.twitch.tv/queso_fuego

Thoughts/Notes/Suggestions/Other - Drop a message in the video comments, twitter, or email

Updates for these videos and other things will be on twitter or the YouTube channel community tab or mailing lists, if I remember.

Credits:
Music from https://incompetech.com:
"Your Call" Kevin MacLeod (incompetech.com)
Licensed under Creative Commons: By Attribution 4.0 License
http://creativecommons.org/licenses/by/4.0/

#osdev #programming #interrupts







Tags:
osdev
os dev
programming
interrupts
queso fuego
low level
PIC
operating systems
system calls
exceptions
x86
c programming