Something went wrong. Try again.
🌱 A minimal programming language and compiler. git.urbach.dev/cli/q
high-performance programming-language compiler
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129package x86_test
import ( "testing"
"git.urbach.dev/cli/q/src/cpu" "git.urbach.dev/cli/q/src/x86" "git.urbach.dev/go/assert")
func TestReadFS(t *testing.T) { usagePatterns := []struct { Register cpu.Register Code []byte }{ {x86.R0, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xC0}}, {x86.R1, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xC1}}, {x86.R2, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xC2}}, {x86.R3, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xC3}}, {x86.SP, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xC4}}, {x86.R5, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xC5}}, {x86.R6, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xC6}}, {x86.R7, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xC7}}, {x86.R8, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xC0}}, {x86.R9, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xC1}}, {x86.R10, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xC2}}, {x86.R11, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xC3}}, {x86.R12, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xC4}}, {x86.R13, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xC5}}, {x86.R14, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xC6}}, {x86.R15, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xC7}}, }
for _, pattern := range usagePatterns { t.Logf("rdfsbase %s", pattern.Register) code := x86.ReadFS(nil, pattern.Register) assert.DeepEqual(t, code, pattern.Code) }}
func TestReadGS(t *testing.T) { usagePatterns := []struct { Register cpu.Register Code []byte }{ {x86.R0, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xC8}}, {x86.R1, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xC9}}, {x86.R2, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xCA}}, {x86.R3, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xCB}}, {x86.SP, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xCC}}, {x86.R5, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xCD}}, {x86.R6, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xCE}}, {x86.R7, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xCF}}, {x86.R8, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xC8}}, {x86.R9, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xC9}}, {x86.R10, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xCA}}, {x86.R11, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xCB}}, {x86.R12, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xCC}}, {x86.R13, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xCD}}, {x86.R14, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xCE}}, {x86.R15, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xCF}}, }
for _, pattern := range usagePatterns { t.Logf("rdgsbase %s", pattern.Register) code := x86.ReadGS(nil, pattern.Register) assert.DeepEqual(t, code, pattern.Code) }}
func TestWriteFS(t *testing.T) { usagePatterns := []struct { Register cpu.Register Code []byte }{ {x86.R0, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xD0}}, {x86.R1, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xD1}}, {x86.R2, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xD2}}, {x86.R3, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xD3}}, {x86.SP, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xD4}}, {x86.R5, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xD5}}, {x86.R6, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xD6}}, {x86.R7, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xD7}}, {x86.R8, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xD0}}, {x86.R9, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xD1}}, {x86.R10, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xD2}}, {x86.R11, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xD3}}, {x86.R12, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xD4}}, {x86.R13, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xD5}}, {x86.R14, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xD6}}, {x86.R15, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xD7}}, }
for _, pattern := range usagePatterns { t.Logf("wrfsbase %s", pattern.Register) code := x86.WriteFS(nil, pattern.Register) assert.DeepEqual(t, code, pattern.Code) }}
func TestWriteGS(t *testing.T) { usagePatterns := []struct { Register cpu.Register Code []byte }{ {x86.R0, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xD8}}, {x86.R1, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xD9}}, {x86.R2, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xDA}}, {x86.R3, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xDB}}, {x86.SP, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xDC}}, {x86.R5, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xDD}}, {x86.R6, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xDE}}, {x86.R7, []byte{0xF3, 0x48, 0x0F, 0xAE, 0xDF}}, {x86.R8, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xD8}}, {x86.R9, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xD9}}, {x86.R10, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xDA}}, {x86.R11, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xDB}}, {x86.R12, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xDC}}, {x86.R13, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xDD}}, {x86.R14, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xDE}}, {x86.R15, []byte{0xF3, 0x49, 0x0F, 0xAE, 0xDF}}, }
for _, pattern := range usagePatterns { t.Logf("wrgsbase %s", pattern.Register) code := x86.WriteGS(nil, pattern.Register) assert.DeepEqual(t, code, pattern.Code) }}