in the name of zero

July 20, 2008

magic the gathering meme

Filed under: easter eggs


Take the Magic: The Gathering ‘What Color Are You?’ Quiz.

July 13, 2008

starbucks flirting

Filed under: easter eggs

how come guys using a macbook at the local starbucks look cool? i’m running gentoo and accessing their wifi at virtual terminal two using iwconfig … but I don’t get any attention from the cute bartender “kaye”. sh* t… i must change my tactics and perhaps use vista instead.

July 12, 2008

grainne2

i know how how it feels like to have a burning hole in your heart that can only be
filled with a loved one. but sometimes, we have no choice but to accept our
fate. - kenshin himura

it’s “grainne2″!! i decided to make it available here while i’m still waiting for the mods at crackmes.de to put it up. i’ll post a solution after a week or two..

update: crackmes.de page for “grainne2″ here. enjoy you guys..

dedicated to Grainne C. Yap - the girl who broke my heart.

June 29, 2008

witch yoo hee

i’m in love!

… but she’s married (in real life). this “koreanovela” is soo addicting!

June 28, 2008

linux raw spin locks

Filed under: hermetic studies

apparently, there are some issues with linux 2.6 and pearpc.. so i still cant
get the gentoo ppc to start properly. i thought i’d do some studying in the
meantime..

typedef struct {
        volatile unsigned int slock;
} raw_spinlock_t;
static inline void __raw_spin_lock(raw_spinlock_t *lock)
{        asm volatile(\"\n1:\t\"
                     LOCK_PREFIX \" ; decb %0\n\t\"
                     \"jns 3f\n\"
                     \"2:\t\"
                     \"rep;nop\n\t\"
                     \"cmpb $0,%0\n\t\"
                     \"jle 2b\n\t\"
                     \"jmp 1b\n\"
                     \"3:\n\t\"
                     : \"+m\" (lock->slock) : : \"memory\");
}

interpretation of the extended inline asm:

1) : “+m” (locl->slock)
“+m” means that the memory operand ‘lock->slock’ is both input and output.

2) : “memory”
from gcc manual:
If your assembler instructions access memory in an unpredictable
fashion, add `memory’ to the list of clobbered registers. This will
cause GCC to not keep memory values cached in registers across the
assembler instruction and not optimize stores or loads to that memory.

3) LOCK_PREFIX is defined at /usr/src/linux/include/asm/alternative.h:

#define LOCK_PREFIX \
                \".section .smp_locks,\\"a\\"\n\"   \   ; push current section and change section to .smp_locks
                \"  .align 4\n\"                  \   ; align to 4 bytes
                \"  .long 661f\n\" /* address */  \   ; create an entry in the up/smp alternative locking table
                \".previous\n\"                   \   ; pop back the old section
                \"661:\n\tlock; \"                    ; assert processor LOCK# signal

LOCK_PREFIX is supposed to be called within the context of a procedure (executable) which finds its way to a .text section.

i haven’t digged down deep into the internals of ‘alternatives’ yet, but a quick look at kernel/alternative.c :: alternatives_smp_unlock() shows that it’s employing a self modifying code that patches the “lock” instruction with an architecture specific NOP opcode.

without all the extended asm semantics above, the asm roughly translates to:

1:      lock       ; decrement atomically
        decb    %0 ; really decrement now..
        jns     3f ; successful in acquiring lock?
2:      rep        ; nothing
        nop        ; nothing
        cmpb    $0, %0 ; someone must release the lock first.
        jle     2b     ; busy wait...
        jmp     1b     ; lock available! try acquiring lock again.
3:     ; exit __raw_spin_lock()

and then comes the trylock variant

static inline int __raw_spin_trylock(raw_spinlock_t *lock)
{
        char oldval;
        asm volatile(
                \"xchgb %b0,%1\"
                :\"=q\" (oldval), \"+m\" (lock->slock)
                :\"0\" (0) : \"memory\");
        return oldval > 0;
}

interpretation of the extended inline asm:

1) : “=q” (oldval)
output oldval in any a,b,c or d register.

2) : “+m” (locl->slock)
“+m” means that the memory operand ‘lock->slock’ is both input and output.

3) : “0″ (0)
%0 matches the output register for oldval. initialize that with the value 0.

4) : “memory”
from gcc manual:
If your assembler instructions access memory in an unpredictable
fashion, add `memory’ to the list of clobbered registers. This will
cause GCC to not keep memory values cached in registers across the
assembler instruction and not optimize stores or loads to that memory.

__raw_spin_trylock() basically exchanges the current value in raw_spinlock_t->slock with zero and returns true if locking was successful and false if acquiring of lock didn’t succeed.

lastly, we have the raw unlock procedure:

static inline void __raw_spin_unlock(raw_spinlock_t *lock)
{
        char oldval = 1;
	
        asm volatile(\"xchgb %b0, %1\"
                     : \"=q\" (oldval), \"+m\" (lock->slock)
                     : \"0\" (oldval) : \"memory\");
}

i haven’t been able to understand the significance of the “%b” in the assembler template but looking at the asm listing of the template with and without the %b yielded the same intructions, so could anyone shed some light on this one?

basically looks like __raw_spin_trylock(), but the difference is that oldval is now initialized to 1 instead of 0.

there are many variants stemming from the idea of this implementation. raw reader/writer locks which allows multiple readers but only one writer (with no concurrent readers). and then there’s the spinlock layer above the raw spinlock implementation.. but those are for another post.

’til then.

June 14, 2008

on my own and moving on

i’ve been puting off a lot of things lately. at the top of my list is to give some just attention to this little web space of mine. its not because i don’t have time anymore. its just that, i felt the need to explore some de-stressing activities other than writing my thoughts and rants down. i always found writing rather emotionally helpful, but during those carefree college days, i rarely
did anything to the point of exhaustion.

but im bringing my hiatus onto a peaceful end. good day! gentoo powerpc land!

June 9, 2008

happy anniversary

today… june 10, marks the first anniversary of my emancipation. it has been a challenging past year…

here’s hoping i can last another…

May 18, 2008

one lone marine

Filed under: easter eggs

just sharing a classic from starcraft.org

In the wastelands of Antiga
On a battlefield grown still
Only one Marine is standing
By a bunker on a hill.
His armour’s scored with claw marks
And a shoulder wound still bleeds
A single solitary soldier-
The one last lone Marine

The battle’s noise is silenced now.
The bodies lie in heaps.
He leans upon his rifle,
Bows his head, and softly weeps.
Only moments span the distance
When the comlink rang with screams
Now he stands forlorn, forsaken-
The one last lone Marine.

He remembers it so clearly
When he lost all that he loved
The Zerg descended like a plague
Rained Hell from heav’n above.
As they scoured across his homeworld
The Zerg shattered all his dreams
But he lived to wreak his vengeance-
A Confederate Marine.

The battle’s moved away now
Nothing stirs across the plain.
The wind unfurls the Blood Hawk’s flag
As the sky begins to rain.
The bodies of his comrades
Fallen brothers on his team
Lying shattered all around him
The one last lone Marine.

He locks and loads another clip
And thinks of all he’s lost
He wonders if the victory
Is truly worth the cost.
The silence now is broken
By a horde of Zergling screams
All thoughts of home are banished
By the one last lone Marine.

He grips his rifle tightly
And waits for them to near
His stimpack gives a final shot
And drives away his fear.
His rifle chatters loudly
Tracers strafing in a stream
He fires down at the charging Zerg
The one last lone Marine

The aliens charge heedlessly
Into the hail of fire
But many run behind them
With legs that never tire.
Like a wall that pushes back the tide
Or a dike restrains the sea
He stands and holds his ground alone
The one last lone Marine.

The comlink crackles static
And no one hears him scream
As the Zerglings close around him
The one last lone Marine.

April 19, 2008

and ever!

Filed under: Uncategorized

liu yi fei forever

April 7, 2008

still…

something i wish i have lots of right now… free time.

Get free blog up and running in minutes with Blogsome | Theme designs available here