title: Is it viable to write a Linux kernel-mode debugger for Intel x86-64 in Common Lisp, and with which Common Lisp implementation[s]?
body: <p>I'm interested in developing some kind of ring0 kernel-mode debugger for x86-64 in Common Lisp that would be loaded as a Linux kernel module and as I prefer Common Lisp to C in general programming, I wonder how different Common Lisp implementations would fit this kind of programming task.</p>
  
  <p>The debugger would use some external disassembling library, such as <a href="http://udis86.sourceforge.net/" rel="nofollow noreferrer">udis86</a> via some <a href="http://www.cliki.net/FFI" rel="nofollow noreferrer">FFI</a>. It seems to me that it's easiest to write kernel modules in C as they need to contain C functions <code>int init_module(void)</code> and <code>void cleanup_module(void)</code> (<a href="http://tldp.org/LDP/lkmpg/2.6/html/lkmpg.html" rel="nofollow noreferrer">The Linux Kernel Module Programming Guide</a>), so the kernel-land module code would call Common Lisp code from C by using <a href="http://common-lisp.net/project/cffi/manual/html_node/Tutorial_002dCallbacks.html" rel="nofollow noreferrer">CFFI</a>. The idea would be to create a ring0 debugger for 64-bit Linux inspired by the idea of <a href="http://rr0d.droids-corp.org/" rel="nofollow noreferrer">Rasta Ring 0 Debugger</a>, that is only available for 32-bit Linux and requires PS/2 keyboard. I think the most challenging part would be the actual debugger code with hardware and software breakpoints and low-level video, keyboard or USB input device handling. Inline assembly would help a lot in that, it seems to me that in SBCL inline assembly can be implemented by using VOPs (<a href="http://sbcl-internals.cliki.net/VOP" rel="nofollow noreferrer">SBCL Internals: VOP</a>) (<a href="http://sbcl-internals.cliki.net/Adding%20VOPs" rel="nofollow noreferrer">SBCL Internals: Adding VOPs</a>), and this <a href="http://www.bitchx.com/log/lisp-f/lisp-f-12-Jul-2010/lisp-f-12-Jul-2010-00.php" rel="nofollow noreferrer">IRC log</a> mentions that ACL (Allegro Common Lisp), <a href="http://www.clozure.com/clozurecl.html" rel="nofollow noreferrer">CCL (Clozure Common Lisp)</a> and CormanCL have LAPs (Lisp Assembly Programs). Both ACL and CormanCL are proprietary and thus discarded, but CCL (Clozure Common Lisp) could be one option. Capacity of building standalone executables is a requirement too; SBCL which I'm currently using has it, but as they are entire Lisp images, their size is quite big.</p>
  
  <p><strong>My question is:</strong> is it viable to create a ring0 kernel-mode debugger for Intel x86-64 in Common Lisp, with low-level code implemented in C and/or assembly, and if it is, which Common Lisp implementations for 64-bit Linux best suit for this kind of endeavour, and what are the pros and cons if there are more than one suitable Common Lisp implementation? Scheme can be one possible option too, if it offers some benefits over Common Lisp. I am well aware that the great majority of kernel modules are written in C, and I know C and x86 assembly well enough to be able to write the required low-level code in C and/or assembly. This is not an attempt to port Linux kernel into Lisp (see: <a href="https://stackoverflow.com/questions/1848029/why-not-port-linux-kernel-to-common-lisp">https://stackoverflow.com/questions/1848029/why-not-port-linux-kernel-to-common-lisp</a>), but a plan to write in Common Lisp a Linux kernel module that would be used as a ring0 debugger.</p>