January 31st, 2010

grub2: welcome back in 1995

So I made a mistake of upgrading to grub2 on my main machine. Now I

a) have to rerun scripts to regenerate grub.cfg each time I change something -- which reminds me of 1995

b) grub menu runs in some kind of strange graphics mode, and very slowly. That's 1991 or something

c) grub still supports strange (hd0,2) syntax; unfortunately they made an off-by-one and partition number is now 1-based, not 0-based as it was in grub-1. Aaarggh.

trapping access to variables in C

I thought I'd try writing (simple!) emulator of wireless watch. Simple means -- compile it by gcc on host, then emulate registers, and do graphics by ascii art.

Unfortunately, registers are accessed in "P2DIR |= 0x1;" way, and I'd really really prefer not to have to emulate the cpu. Is there nice way to trap all accesses to variable?

I could put those variables on unmapped page, then eat all the SIGSEGVs that would generate; but that sounds complex & tricky. (But does anyone have an example I could copy from?)

I do not think it is possible to use macros.

Maybe C++ classes could be used to trap the accesses without too much difficulty? (Can they? Does anyone have examples?) I probably could do that if I was willing to implement all the different operators (+, -, |, +=, |=, ...)... or is there way to avoid that?

Oh, and today I had fun with 5kV -- physics in practice. Did you know that electric fences do not really work on snow? Apparently snow is good enough insulator. So I had great idea of repairing electric fence without turning it off.

Well, at the beggining it was ok. I could not even feel the electricity. But slowly my shoes/clothing got wet, and I got some mild shocks... snow is good insulator so nothing really bad. Then I tried to repair broken fence, grabbed one end in one hand and second end in second hand... and quickly let both go (after getting not-so-mild shock). Snow being insulator does not really help when you hold two pieces of wire...