aboutsummaryrefslogtreecommitdiff
path: root/ia32
diff options
context:
space:
mode:
Diffstat (limited to 'ia32')
-rw-r--r--ia32/arithmetic.sts103
-rw-r--r--ia32/branch.sts19
-rw-r--r--ia32/core.sts26
-rw-r--r--ia32/elf/begin.sts127
-rw-r--r--ia32/elf/end.sts21
-rw-r--r--ia32/ia32.sts7
-rw-r--r--ia32/macro.sts50
-rw-r--r--ia32/memory.sts15
-rw-r--r--ia32/stack.sts25
-rw-r--r--ia32/syscall.sts50
10 files changed, 443 insertions, 0 deletions
diff --git a/ia32/arithmetic.sts b/ia32/arithmetic.sts
new file mode 100644
index 0000000..c9b4bf8
--- /dev/null
+++ b/ia32/arithmetic.sts
@@ -0,0 +1,103 @@
+defasm +
+; pop eax
+# 58 ?'
+; add [esp], eax
+# 01 ?' # 04 ?' # 24 ?'
+next
+
+defasm -
+; pop eax
+# 58 ?'
+; sub [esp], eax
+# 29 ?' # 04 ?' # 24 ?'
+next
+
+defasm /
+; pop ebx
+# 5b ?'
+; pop eax
+# 58 ?'
+; xor edx, edx
+# 31 ?' # d2 ?'
+; div ebx
+# f7 ?' # f3 ?'
+; push edx
+# 52 ?'
+; push eax
+# 50 ?'
+next
+
+defasm =
+; pop ebx
+# 5b ?'
+; pop eax
+# 58 ?'
+; cmp eax, ebx
+# 39 ?' # d8 ?'
+; sete al
+# 0f ?' # 94 ?' # c0 ?'
+; movzx eax, al
+# 0f ?' # b6 ?' # c0 ?'
+; push eax
+# 50 ?'
+next
+
+defasm !=
+; pop ebx
+# 5b ?'
+; pop eax
+# 58 ?'
+; cmp eax, ebx
+# 39 ?' # d8 ?'
+; sete al
+# 0f ?' # 95 ?' # c0 ?'
+; movzx eax, al
+# 0f ?' # b6 ?' # c0 ?'
+; push eax
+# 50 ?'
+next
+
+defasm !=
+; pop ebx
+# 5b ?'
+; pop eax
+# 58 ?'
+; cmp eax, ebx
+# 39 ?' # d8 ?'
+; sete al
+# 0f ?' # 95 ?' # c0 ?'
+; movzx eax, al
+# 0f ?' # b6 ?' # c0 ?'
+; push eax
+# 50 ?'
+next
+
+defasm <
+; pop ebx
+# 5b ?'
+; pop eax
+# 58 ?'
+; cmp eax, ebx
+# 39 ?' # d8 ?'
+; setb al
+# 0f ?' # 92 ?' # c0 ?'
+; movzx eax, al
+# 0f ?' # b6 ?' # c0 ?'
+; push eax
+# 50 ?'
+next
+
+defasm >
+; pop ebx
+# 5b ?'
+; pop eax
+# 58 ?'
+; cmp eax, ebx
+# 39 ?' # d8 ?'
+; seta al
+# 0f ?' # 97 ?' # c0 ?'
+; movzx eax, al
+# 0f ?' # b6 ?' # c0 ?'
+; push eax
+# 50 ?'
+next
diff --git a/ia32/branch.sts b/ia32/branch.sts
new file mode 100644
index 0000000..bedfbba
--- /dev/null
+++ b/ia32/branch.sts
@@ -0,0 +1,19 @@
+defasm branch
+; mov esi, [esi]
+# 8b ?' # 36 ?'
+; go next
+next
+
+defasm 0branch
+; pop eax
+# 58 ?'
+; add esi, 4
+# 83 ?' # c6 ?' # 4 ?'
+; cmp eax, 0
+# 83 ?' # f8 ?' # 00 ?'
+; jne +3
+# 75 ?' # 3 ?'
+; mov esi, [esi - 4]
+# 8b ?' # 76 ?' # fc ?'
+; go next
+next
diff --git a/ia32/core.sts b/ia32/core.sts
new file mode 100644
index 0000000..fd2d062
--- /dev/null
+++ b/ia32/core.sts
@@ -0,0 +1,26 @@
+defasm docol
+; sub ebp, 4
+# 83 ?' # ed ?' # 4 ?'
+; mov [ebp], esi
+# 89 ?' # 75 ?' # 0 ?'
+; add eax, 4
+# 83 ?' # c0 ?' # 4 ?'
+; mov esi, eax
+# 89 ?' # c6 ?'
+; go next
+# ad ?' # ff ?' # 20 ?'
+next
+
+defasm exit
+; mov esi, [ebp]
+# 8b ?' # 75 ?' # 0 ?'
+; add ebp, 4
+# 83 ?' # c5 ?' # 4 ?'
+next
+
+defasm lit
+; lodsd
+# ad ?'
+; push eax
+# 50 ?'
+next
diff --git a/ia32/elf/begin.sts b/ia32/elf/begin.sts
new file mode 100644
index 0000000..41c1efc
--- /dev/null
+++ b/ia32/elf/begin.sts
@@ -0,0 +1,127 @@
+?create ?? _code_segment
+_code_segment ?choose
+
+# 08048000 ?org
+# 4 ?size
+# 0 ?endianness
+
+?create ?? _data_segment
+_data_segment ?choose
+
+# 09048000 ?org
+# 4 ?size
+# 0 ?endianness
+
+_code_segment ?choose
+
+; ELF header
+; EI_MAG - ELF magic number
+# 7f ?' # 45 ?' # 4c ?' # 46 ?'
+; EI_CLASS - 32-bit format
+# 1 ?'
+; EI_DATA - little-endiann
+# 1 ?'
+; EI_VERSION - current ELF header version
+# 1 ?'
+; EI_OSABI - Linux ABI
+# 3 ?'
+; EI_ABIVERSION - none
+# 0 ?'
+; EI_PAD - padding
+# 7 ?res
+; Executable file type
+# 2 ?2.
+; IA-32 architecture
+# 3 ?2.
+; ELF version
+# 1 ?4.
+; Entry point
+?$ ?? _elf_entry
+# 0 ?4.
+; Program headers offset
+# 34 ?4.
+; Section headers offset
+# 0 ?4.
+; Extra flags
+# 0 ?4.
+; ELF header size
+# 34 ?2.
+; Program header size
+# 20 ?2.
+; Number of program headers
+# 2 ?2.
+; Section header size
+# 28 ?2.
+; Number of section headers
+# 0 ?2.
+; Section name section index
+# 0 ?2.
+
+; ELF CODE PROGRAM HEADER
+; Segment type
+# 1 ?4.
+; Segment offset
+# 0 ?4.
+; Segment virtual address
+?$$ ?4.
+; Segment physical address
+?$$ ?4.
+; Segment file size
+?$ ?? _code_segment_file_size
+# 0 ?4.
+; Segment memory size
+?$ ?? _code_segment_memory_size
+# 0 ?4.
+; Segment flags
+# 5 ?4.
+; Segment alignment
+# 1000 ?4.
+
+; ELF DATA PROGRAM HEADER
+; Segment type
+# 1 ?4.
+; Segment offset
+?$ ?? _data_segment_offset
+# 0 ?4.
+; Segment virtual address
+_data_segment ?choose
+?$$
+_code_segment ?choose
+?4.
+; Segment physical address
+_data_segment ?choose
+?$$
+_code_segment ?choose
+?4.
+; Segment file size
+?$ ?? _data_segment_file_size
+# 0 ?4.
+; Segment memory size
+?$ ?? _data_segment_memory_size
+# 0 ?4.
+; Segment flags
+# 6 ?4.
+; Segment alignment
+# 1000 ?4.
+
+; Return stack
+_data_segment ?choose
+1000 ?res
+?$ ?dup ?? _return_stack
+_code_segment ?choose
+
+; PROGRAM ENTRY CODE
+?$ _elf_entry ?!
+; mov ebp, _return_stack
+# bd ?'
+_return_stack ?.
+; mov esi, _threaded_code_entry
+# be ?'
+?$ ?? _threaded_code_entry
+# 0 ?.
+; lodsd
+# ad ?'
+; jmp dword [eax]
+# ff ?' # 20 ?'
+
+module ia32/ia32.sts
diff --git a/ia32/elf/end.sts b/ia32/elf/end.sts
new file mode 100644
index 0000000..7c80eec
--- /dev/null
+++ b/ia32/elf/end.sts
@@ -0,0 +1,21 @@
+; Code segment alignment
+# 1000 ?$ # 1000 ?mod ?- ?dup ?res
+
+; Code segment ELF sizes
+?$ ?$$ ?- _code_segment_file_size ?!
+?$ ?$$ ?- _code_segment_memory_size ?!
+
+; Data segment ELF offset
+?$ ?$$ ?-
+_code_segment ?choose
+_data_segment_offset ?!
+
+; Data segment ELF sizes
+_data_segment ?choose
+?$ ?$$ ?-
+_code_segment ?choose
+_data_segment_file_size ?!
+_data_segment ?choose
+?$ ?$$ ?-
+_code_segment ?choose
+_data_segment_memory_size ?!
diff --git a/ia32/ia32.sts b/ia32/ia32.sts
new file mode 100644
index 0000000..bedec54
--- /dev/null
+++ b/ia32/ia32.sts
@@ -0,0 +1,7 @@
+module ia32/macro.sts
+module ia32/core.sts
+module ia32/stack.sts
+module ia32/branch.sts
+module ia32/memory.sts
+module ia32/arithmetic.sts
+module ia32/syscall.sts
diff --git a/ia32/macro.sts b/ia32/macro.sts
new file mode 100644
index 0000000..befcccb
--- /dev/null
+++ b/ia32/macro.sts
@@ -0,0 +1,50 @@
+[ next 0
+ # ad ?' # ff ?' # 20 ?'
+]
+
+[ defasm 1
+ [ %1% 0
+ _%0% ?.
+ \]
+ ?$ ?? _%1%
+ ?$ # 4 ?+ ?.
+]
+
+[ defword 1
+ [ %1% 0
+ _%0% ?.
+ \]
+ ?$ ?? _%1%
+ _docol # 4 ?+ ?.
+]
+
+[ defarr 2
+ _data_segment ?choose
+ ?$ ?? _%1%_arr
+ # %2% # 4 ?* ?res
+ _code_segment ?choose
+ defasm %1%
+ ; push _%1%_arr
+ # 68 ?' _%1%_arr ?.
+ next
+]
+
+[ defvar 1
+ defarr %1% 1
+]
+
+[ literal 0
+ lit # %1% ?.
+]
+
+[ set_entry 0
+ ?$ _threaded_code_entry ?!
+]
+
+[ if 0
+ 0branch ?$ # 0 ?.
+]
+
+[ fi 0
+ ?$ ?swap ?!
+]
diff --git a/ia32/memory.sts b/ia32/memory.sts
new file mode 100644
index 0000000..f176c13
--- /dev/null
+++ b/ia32/memory.sts
@@ -0,0 +1,15 @@
+defasm @
+; pop eax
+# 58 ?'
+; push dword [eax]
+# ff ?' # 30 ?'
+next
+
+defasm !
+; pop ebx
+# 5b ?'
+; pop eax
+# 58 ?'
+; mov [ebx], eax
+# 89 ?' # 03 ?'
+next
diff --git a/ia32/stack.sts b/ia32/stack.sts
new file mode 100644
index 0000000..a8ac749
--- /dev/null
+++ b/ia32/stack.sts
@@ -0,0 +1,25 @@
+defasm drop
+; pop eax
+# 58 ?'
+next
+
+defasm dup
+; push dword [esp]
+# ff ?' # 34 ?' # 24 ?'
+next
+
+defasm over
+; push dword [esp + 4]
+# ff ?' # 74 ?' # 24 ?' # 4 ?'
+next
+
+defasm swap
+; pop eax
+# 58 ?'
+; pop ebx
+# 5b ?'
+; push eax
+# 50 ?'
+; push ebx
+# 53 ?'
+next
diff --git a/ia32/syscall.sts b/ia32/syscall.sts
new file mode 100644
index 0000000..58a6ffd
--- /dev/null
+++ b/ia32/syscall.sts
@@ -0,0 +1,50 @@
+defasm quit
+; mov eax, 1
+# b8 ?' # 1 ?.
+; xor ebx, ebx
+# 31 ?' # db ?'
+; int 0x80
+# cd ?' # 80 ?'
+
+_data_segment ?choose
+?$ ?? _io_buffer
+# 0 ?'
+_code_segment ?choose
+
+defasm key
+; mov eax, 3
+# b8 ?' # 3 ?.
+; xor ebx, ebx
+# 31 ?' # db ?'
+; mov ecx, _io_buffer
+# b9 ?' _io_buffer ?.
+; mov edx, 1
+# ba ?' # 1 ?.
+; int 0x80
+# cd ?' # 80 ?'
+; xor ebx, ebx
+# 31 ?' # db ?'
+; mov bl, [_io_buffer]
+# 8a ?' # 1d ?' _io_buffer ?.
+; push ebx
+# 53 ?'
+; push eax
+# 50 ?'
+next
+
+defasm emit
+; pop eax
+# 58 ?'
+; mov [_io_buffer], al
+# a2 ?' _io_buffer ?.
+; mov eax, 4
+# b8 ?' # 4 ?.
+; mov ebx, 1
+# bb ?' # 1 ?.
+; mov ecx, _io_buffer
+# b9 ?' _io_buffer ?.
+; mov edx, 1
+# ba ?' # 1 ?.
+; int 0x80
+# cd ?' # 80 ?'
+next