Posts

GNU Emacs as a lightweight IDE - Assembly

Image
CEDET support for Assembly language Auto-completion using company and speedbar outline view Jump to label Jump to include file Auto-completion using company Speedbar outline view     ASM file extensions supported - .s, .S and .asm   Grammar file: https://gitlab.com/atamariya/emacs/-/blob/dev/admin/grammars/asm.wy

Molly Kernel

Image
Molly kernel is a bare kernel (32kB size) for x86 based on JamesM's kernel development tutorials for learning purpose. It also adds keyboard support from Bran's kernel development tutorials .   Build The original version of the code is in master branch . The modifications (bug fixes + enhancements) are in dev branch .   ;; Pre-requisites sudo apt install nasm gcc make kvm bochs   git clone https://gitlab.com/atamariya/molly.git make -C src ./update_image.sh ./run.sh     ;; Optional ;; Run floppy image kvm -fda floppy.img     ;; Run kernel binary kvm -kernel src/kernel -initrd initrd.img     Debugging You can use GDB to debug the kernel while executing it under qemu. Start qemu with "-s -S" flags and attach GDB remote session using "target remote localhost:1234". Make sure you match the architecture (i386 in this case) for qemu command and the kernel.   qemu-system- i386 -kernel src/kernel -initrd initrd.img -s -S     References Debugging 16-bit in QEMU

Meta git (mgit)

Image
  Meta git (mgit) is a wrapper around magit , which is a wrapper around git . If the output looks familiar, it's because it's the output from command git status -v. For the discerning eye, it uses the font-lock defaults from diff mode (notice the highlight on ;;). diff-mode uses repeated diff commands to highlight the refinements. Use diff-mode or diff-refine-hunk if you must have the eye-candy. Motivation Magit is a handy tool for working with git repository in GNU Emacs. However, if you work with a large enough repository, you'll hit a performance road-block. Here's an attempt to deconstruct the problem and find a solution. Magit provides an information rich dashboard for git status. However, this comes with multiple calls to git command. If you run M-x magit-toggle-verbose-refresh and then run magit-status, you'll see the following output: Refreshing buffer ‘magit: src<anand>’...   magit-insert-error-header                          2.031e-06   magit-inser

Git graph in GNU Emacs

Image
  Get a decent view of git tree in GNU Emacs (M-x magit-pg-repo ). By default, it draws the graph with last 100 commits. If you want a different behaviour, edit the following constant. (defconst magit-pg-command   (concat "git --no-pager log --branches --decorate=full "           "--pretty=format:\"%H%x00%P%x00%an%x00%ar%x00%s%x00%d\" "           " -n 100 ")   "The command used to fill the raw output buffer.")     If you want to use the script in terminal ( temacs -batch -l $PWD/magit-pretty-graph.el -f magit-pg-repo ), add the following path (adjust for versions) to the top of the script and uncomment line 238. (setq path '("~/.emacs.d/elpa/magit-20220603.1738/"          "~/.emacs.d/elpa/compat-28.1.1.1/"          "~/.emacs.d/elpa/dash-20220602.2113/"          "~/.emacs.d/elpa/magit-section-20220513.1429/"          "~/.emacs.d/elpa/with-editor-20220506.420/"          "~/.emac

GNU Emacs as a LISP interpreter

Image
  After applying the following patch, you can run GNU Emacs as a standalone LISP interpreter for batch usage. It basically disables the command loop and non-essential symbols in batch mode.   temacs is Emacs sans any bootstrap elisp code. It is the first artifact generated during the Emacs build process. So you might not find it in your package installation. You can use the emacs binary too for the same effect - just understand that underneath they are not the same.   modified   src/keyboard.c @@ -1067,6 +1067,7 @@ command_loop (void)      while (1)        {      internal_catch (Qtop_level, top_level_1, Qnil); +    if (!noninteractive)      internal_catch (Qtop_level, command_loop_2, Qnil);      executing_kbd_macro = Qnil;   @@ -2631,9 +2632,9 @@ read_char (int commandflag, Lisp_Object map,    if (minibuf_level == 0        && !end_time        && !current_kboard->immediate_echo +      && ! noninteractive        && (this_command_key_count > 0       

Towards GNU/MINIX - libstdc++

Image
Cross-compiled C++ program running on Minix   To compile a C++ program, we need C++ standard library. While Clang libc++.so comes with Minix distribution, GCC version of libstdc++.so has to be cross-compiled . Interestingly, while GNU C library Glibc is a separate project, libstdc++ is part of the GCC project. In other words, you can use a different C library (like musl or ulibc) with GCC if you want. Lessons Learnt Clang uses inline namespaces by default whereas GCC does not. anand@PureBook:~/work/minix/usr/lib$ nm -s libstdc++.so | c++filt | grep cout 00328a20 b __gnu_internal::buf_cout_sync 00329080 b __gnu_internal::buf_wcout_sync 00328ae0 b __gnu_internal::buf_cout 00329140 b __gnu_internal::buf_wcout 003285c0 B std::cout 00328840 B std::wcout anand@PureBook:~/work/minix/usr/lib$ nm -s libc++.so | c++filt | grep cout 000c2b00 B std::__1::cout 000c2c54 B std::__1::wcout   You can use objcopy to alter symbol name in an object file or library. mthread.h has provisions for supporti

Micro Emacs on GNU/Minix

Image
Following the filesystem creation on GNU/Minix, the next step is to port an application. Here's a basic port of Micro Emacs (v3.5) running on GNU/Minix (v3.3.0). ./configure --without-curses     Since configure doesn't support Minix, we need to manually edit the CC and LIBOBJS (for reallocarray() function) variable in generated Makefile. LIBOBJS =  ${LIBOBJDIR}fparseln$U.o ${LIBOBJDIR}strlcpy$U.o ${LIBOBJDIR}strlcat$U.o ${LIBOBJDIR}strtonum$U.o ${LIBOBJDIR}reallocarray$U.o   Also we need following patches. modified   src/def.h @@ -12,7 +12,8 @@    #include    "config.h"   -#if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) +#if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) \ +  || defined(__minix)  # include    <sys/queue.h>  # include    <sys/tree.h>  # ifdef __FreeBSD__ @@ -23,15 +24,14 @@  #else /* __NotBSD__, DragonFly BSD, or macOS */  # include    "queue.h"  # include    "tree.h" +#ifd