?

Log in

iris, and darwin tweaks - Benjamin C. Wiley Sittler [entries|archive|friends|userinfo]
Benjamin C. Wiley Sittler

[ website | bsittler ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

iris, and darwin tweaks [Jan. 12th, 2008|11:43 am]
Benjamin C. Wiley Sittler
[Tags|, , , , ]

i think iris might be starting to talk. the words are few, and the pronunciation odd enough that i'm never really sure, but i think i've been hearing "fish", "kitty", "guido" (one of the cats), and "no" used in more-or-less appropriate situations. rebbyribs is a bit more skeptical, but i'm sure iris will talk clearly and distinctly soon enough.

note: what follows is a discussion of scripts that modify your mac os x kernel. this is potentially very risky, as the kernel is what allows everything else to run. although i have made every attempt to ensure they are safe (and believe they are), i can't guarantee it or be held liable if things go wrong. in particular:

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR OR ANY OTHER CONTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

also, this morning's project was to get the mac os x/darwin console vt100 alternate character set support to work and (closely related) to customize the mac os x/darwin console color palette. the end result is a pair of shell scripts that seem to work, and a lot of scratching my head — why didn't they
ⓐ ship with the VT100 positions filled in their font, or
ⓑ provide a simpler interface for switching the font and color palette at runtime (using, say, escape sequences or a sysctl.) oh and
ⓒ why does their console strip the eighth bit off of all output (despite the font [based on a design by zestyping] supporting the first 256 unicode/ucs code points), and finally
ⓓ why don't the function keys work?

update: it's probably worth explaining a bit more here:

On Intel and PowerPC platforms, Apple's Darwin operating system and Mac OS X use a full-screen system console derived from a NetBSD framebuffer console. It is an ANSI-style terminal, and is not really VT100 compatible.

Under Mac OS X (both PowerPC and Intel), this is the system console driver used while in single-user mode [reachable by holding down Command-S during the boot process] and when logged in using console mode [reachable by typing ">console" at the graphical login prompt.]

Under Mac OS X version 10.4, you'll need to enable the password dialog inside the System Preferences | Accounts | Login Options panel by disabling the "Automatically log in as" option and setting the "Display login window as" option to "Name and password"

The scripts require access to kernel memory. By default they enable the built-in /dev/kmem by adding the kmem=1 option to the nvram boot-args — however, it may be possible to use them with Amit Singh's alternate implementation (not tested, though.)

The scripts need the nm utility; get it from Xcode or odcctools


update: it looks like joey hagedorn made a truetype version of the darwin console font!
linkReply

Comments:
[User Picture]From: two_pi_r
2008-01-12 08:14 pm (UTC)
dd of=/dev/kmem bs=1 seek=$(( 0x$(nm /mach_kernel | fgrep _iso_font | awk '{print $1}') + 128 * 16 ))

Yow. How many kernel panics did you have to go through when figuring this out?!
(Reply) (Thread)
[User Picture]From: bsittler
2008-01-12 08:24 pm (UTC)
zero. the font is a publicly exported symbol (_iso_font) with known contents (256 8x16-bit bitmaps), the font layout is well known (ISO 8859-1 with VT100 alternate character set [blank in the distributed kernel] in the C1 range [corresponding to characters 0x80-0x9f]), the script is carefully modifying only the correct region of the font, and it has a precondition check to make sure the previous data was the expected blank cells.

the one for the palette is on slightly shakier ground, as there's no exported symbol for the palette, but the distance between the font and the palette is easy to calculate and the precondition check is a lot more robust since the old palette data is very distinctive (vga palette entry × 4, RGB-5/5/5 entry × 2, and RGB-8/8/8 entry padded to 32 bits.) the palette hack is unlikely to work on a 64-bit machine, and may not even work on a powerpc, but because of the precondition it should at least not crash.

although a third-party kext does panic the machine from time to time (at least, it only seems to happen while starting or stopping parallels. the trickiest part was figuring out that the font is stored reverse-bit-endian (at least compared to a VGA font), but that was not too tricky.
(Reply) (Parent) (Thread)
[User Picture]From: two_pi_r
2008-01-12 08:44 pm (UTC)
touch&eeacute;. I just see "dd of=/dev/kmem" and think "panic city". Of course, the only thing I've done with dd of=/dev/kmem is with an if=/dev/urandom just to see what happens, so hey.
(Reply) (Parent) (Thread)
[User Picture]From: bsittler
2008-01-12 08:47 pm (UTC)
yeah, that sounds fun. how well did it stand up to the fuzzing?
(Reply) (Parent) (Thread)
[User Picture]From: two_pi_r
2008-01-13 01:14 am (UTC)
Not very. The screen barfed colors and blinks, and of course the machine locked.
(Reply) (Parent) (Thread)
[User Picture]From: bsittler
2008-01-13 03:28 pm (UTC)
yeah, most software (kernels included) is not written with "major random memory corruption" as a design constraint. i guess interplanetary probes and some satellites are exceptions here.
(Reply) (Parent) (Thread)
[User Picture]From: bsittler
2008-01-12 08:39 pm (UTC)
that said, i did go ahead and add a warning and disclaimer. Bad Things Might Happen, but you run this stuff entirely at your own risk and if your computer turns into a smoking brick that's your problem, not mine ☺.
(Reply) (Parent) (Thread)
[User Picture]From: bsittler
2008-01-12 08:41 pm (UTC)
also the earlier project of examining the darwin/mac os x console font in c (which is a read-only operation) made me fairly confident about what was where.
(Reply) (Parent) (Thread)
[User Picture]From: two_pi_r
2008-01-12 08:45 pm (UTC)
Also touch&eeacute;
(Reply) (Parent) (Thread)
[User Picture]From: jilflirt
2008-01-12 10:14 pm (UTC)
Isn't it cool how the first words kids learn (after mama and dada -- or in our case, before mama) are almost always the pets? I love how much they love animals.
(Reply) (Thread)
[User Picture]From: bsittler
2008-01-13 03:21 pm (UTC)
yes, and guido is much more willing than to play with iris than the other cat is, so he has a name :)
(Reply) (Parent) (Thread)