1 ; SMP Test Program (v1.0, July 6 2010)
2 ; Written by Ian Seyler
5 ; nasm smptest.asm -o smptest.app
9 [ORG 0x0000000000200000]
13 start: ; Start of program label
15 mov rax
, ap_print_id
; Our code to run on all CPUs
16 xor rbx
, rbx
; Clear RBX as there is no argument
17 mov rcx
, 64 ; Number of instances to spawn
26 call b_smp_dequeue
; Try to dequeue a workload
27 jc emptyqueue
; If carry is set then the queue is empty
28 call b_smp_run
; Otherwise run the workload
29 jne bsp
; If it is not empty try to do another workload
32 call b_smp_wait
; Wait for all other processors to finish
38 ; This procedure will be executed by each of the processors
39 ; It requires mutually exclusive access while it creates the string and prints to the screen
40 ; We must insure that only one CPU at a time can execute this code, so we employ a 'spinlock'.
49 bt word [mutex
], 0 ; Check if the mutex is free
50 jnc grablock
; If not check it again
52 lock ; The mutex was free, lock the bus
53 btr word [mutex
], 0 ; Try to grab the mutex
54 jnc grablock
; Jump if we were unsuccessful
56 call b_smp_get_id
; Get the local APIC ID
57 call b_debug_dump_al
; Print the APIC ID
61 bts word [mutex
], 0 ; Release the mutex
64 mutex
dw 1 ; The MUTual-EXclustion flag