* remove "\r" nonsense
[mascara-docs.git] / amd64 / bareMetalOS-0.5.2 / baremetal0.5.2 / programs / smptest.asm
blob2678dd3811e8323475fdee06de59711ecbb29bdd
1 ; SMP Test Program (v1.0, July 6 2010)
2 ; Written by Ian Seyler
4 ; BareMetal compile:
5 ; nasm smptest.asm -o smptest.app
8 [BITS 64]
9 [ORG 0x0000000000200000]
11 %INCLUDE "bmdev.asm"
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
19 spawn:
20 call b_smp_enqueue
21 sub rcx, 1
22 cmp rcx, 0
23 jne spawn
25 bsp:
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
31 emptyqueue:
32 call b_smp_wait ; Wait for all other processors to finish
33 call b_print_newline
35 ret ; Return to OS
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'.
41 ap_print_id:
42 mov rcx, 0x1FFFFF
43 delay:
44 dec rcx
45 cmp rcx, 0
46 jne delay
48 grablock:
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
58 mov al, ' '
59 call b_print_char
61 bts word [mutex], 0 ; Release the mutex
62 ret
64 mutex dw 1 ; The MUTual-EXclustion flag