aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pall <mike>2009-12-10 01:24:24 +0100
committerMike Pall <mike>2009-12-10 01:24:24 +0100
commitfe36e4ac59f3408202be21fd94c4c540f23b1a6f (patch)
tree684cd08b0ee09f06a3c7f61c8c8dc95bdc9f9182
parent4523c46d10535ac6ff0716d22149e01e008dbce0 (diff)
downloadluajit-fe36e4ac59f3408202be21fd94c4c540f23b1a6f.tar.gz
luajit-fe36e4ac59f3408202be21fd94c4c540f23b1a6f.tar.bz2
luajit-fe36e4ac59f3408202be21fd94c4c540f23b1a6f.zip
Add DynASM x64 module (non-functional). Add extra x64 registers.
-rw-r--r--dynasm/dasm_x64.lua12
-rw-r--r--dynasm/dasm_x86.lua64
2 files changed, 57 insertions, 19 deletions
diff --git a/dynasm/dasm_x64.lua b/dynasm/dasm_x64.lua
new file mode 100644
index 00000000..cf31258a
--- /dev/null
+++ b/dynasm/dasm_x64.lua
@@ -0,0 +1,12 @@
1------------------------------------------------------------------------------
2-- DynASM x64 module.
3--
4-- Copyright (C) 2005-2009 Mike Pall. All rights reserved.
5-- See dynasm.lua for full copyright notice.
6------------------------------------------------------------------------------
7-- This module just sets 64 bit mode for the combined x86/x64 module.
8-- All the interesting stuff is there.
9------------------------------------------------------------------------------
10
11x64 = true -- Using a global is an ugly, but effective solution.
12return require("dasm_x86")
diff --git a/dynasm/dasm_x86.lua b/dynasm/dasm_x86.lua
index 82210806..b4eeb759 100644
--- a/dynasm/dasm_x86.lua
+++ b/dynasm/dasm_x86.lua
@@ -1,17 +1,19 @@
1------------------------------------------------------------------------------ 1------------------------------------------------------------------------------
2-- DynASM x86 module. 2-- DynASM x86/x64 module.
3-- 3--
4-- Copyright (C) 2005-2009 Mike Pall. All rights reserved. 4-- Copyright (C) 2005-2009 Mike Pall. All rights reserved.
5-- See dynasm.lua for full copyright notice. 5-- See dynasm.lua for full copyright notice.
6------------------------------------------------------------------------------ 6------------------------------------------------------------------------------
7 7
8local x64 = x64
9
8-- Module information: 10-- Module information:
9local _info = { 11local _info = {
10 arch = "x86", 12 arch = x64 and "x64" or "x86",
11 description = "DynASM x86 (i386) module", 13 description = "DynASM x86/x64 module",
12 version = "1.2.1", 14 version = "1.2.1",
13 vernum = 10201, 15 vernum = 10201,
14 release = "2009-04-16", 16 release = "2009-12-09",
15 author = "Mike Pall", 17 author = "Mike Pall",
16 license = "MIT", 18 license = "MIT",
17} 19}
@@ -261,9 +263,9 @@ local reg_list = {} -- Canonical list of int. register names.
261local map_type = {} -- Type name -> { ctype, reg } 263local map_type = {} -- Type name -> { ctype, reg }
262local ctypenum = 0 -- Type number (for _PTx macros). 264local ctypenum = 0 -- Type number (for _PTx macros).
263 265
264local addrsize = "d" -- Size for address operands. !x64 266local addrsize = x64 and "q" or "d" -- Size for address operands.
265 267
266-- Helper function to fill register maps. 268-- Helper functions to fill register maps.
267local function mkrmap(sz, cl, names) 269local function mkrmap(sz, cl, names)
268 local cname = format("@%s", sz) 270 local cname = format("@%s", sz)
269 reg_list[#reg_list+1] = cname 271 reg_list[#reg_list+1] = cname
@@ -275,33 +277,57 @@ local function mkrmap(sz, cl, names)
275 map_reg_valid_base[cname] = true 277 map_reg_valid_base[cname] = true
276 map_reg_valid_index[cname] = true 278 map_reg_valid_index[cname] = true
277 end 279 end
278 for n,name in ipairs(names) do 280 if names then
279 local iname = format("@%s%x", sz, n-1) 281 for n,name in ipairs(names) do
280 reg_list[#reg_list+1] = iname 282 local iname = format("@%s%x", sz, n-1)
283 reg_list[#reg_list+1] = iname
284 map_archdef[name] = iname
285 map_reg_rev[iname] = name
286 map_reg_num[iname] = n-1
287 map_reg_opsize[iname] = sz
288 if sz == addrsize then
289 map_reg_valid_base[iname] = true
290 map_reg_valid_index[iname] = true
291 end
292 end
293 end
294 for i=0,(x64 and sz ~= "f") and 15 or 7 do
295 local iname = format("@%s%x", sz, i)
296 local name
297 if sz == "o" then name = format("xmm%d", i)
298 elseif sz == "f" then name = format("st%d", i)
299 else name = format("r%d%s", i, sz == addrsize and "" or sz) end
281 map_archdef[name] = iname 300 map_archdef[name] = iname
282 map_reg_rev[iname] = name 301 if not map_reg_rev[iname] then
283 map_reg_num[iname] = n-1 302 reg_list[#reg_list+1] = iname
284 map_reg_opsize[iname] = sz 303 map_reg_rev[iname] = name
285 if sz == addrsize then 304 map_reg_num[iname] = i
286 map_reg_valid_base[iname] = true 305 map_reg_opsize[iname] = sz
287 map_reg_valid_index[iname] = true 306 if sz == addrsize then
307 map_reg_valid_base[iname] = true
308 map_reg_valid_index[iname] = true
309 end
288 end 310 end
289 end 311 end
290 reg_list[#reg_list+1] = "" 312 reg_list[#reg_list+1] = ""
291end 313end
292 314
293-- Integer registers (dword, word and byte sized). 315-- Integer registers (qword, dword, word and byte sized).
316if x64 then
317 mkrmap("q", "Rq", {"rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi"})
318end
294mkrmap("d", "Rd", {"eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi"}) 319mkrmap("d", "Rd", {"eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi"})
295map_reg_valid_index[map_archdef.esp] = false
296mkrmap("w", "Rw", {"ax", "cx", "dx", "bx", "sp", "bp", "si", "di"}) 320mkrmap("w", "Rw", {"ax", "cx", "dx", "bx", "sp", "bp", "si", "di"})
297mkrmap("b", "Rb", {"al", "cl", "dl", "bl", "ah", "ch", "dh", "bh"}) 321mkrmap("b", "Rb", {"al", "cl", "dl", "bl", "ah", "ch", "dh", "bh"})
322-- !x64: ah, ch, dh, bh not valid with REX, r4b-r15b require REX
323map_reg_valid_index[map_archdef[x64 and "rsp" or "esp"]] = false
298map_archdef["Ra"] = "@"..addrsize 324map_archdef["Ra"] = "@"..addrsize
299 325
300-- FP registers (internally tword sized, but use "f" as operand size). 326-- FP registers (internally tword sized, but use "f" as operand size).
301mkrmap("f", "Rf", {"st0", "st1", "st2", "st3", "st4", "st5", "st6", "st7"}) 327mkrmap("f", "Rf")
302 328
303-- SSE registers (oword sized, but qword and dword accessible). 329-- SSE registers (oword sized, but qword and dword accessible).
304mkrmap("o", "xmm", {"xmm0","xmm1","xmm2","xmm3","xmm4","xmm5","xmm6","xmm7"}) 330mkrmap("o", "xmm")
305 331
306-- Operand size prefixes to codes. 332-- Operand size prefixes to codes.
307local map_opsize = { 333local map_opsize = {