summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile9
-rw-r--r--src/c_example.S60
2 files changed, 57 insertions, 12 deletions
diff --git a/Makefile b/Makefile
index baaebf5..ab1a625 100644
--- a/Makefile
+++ b/Makefile
@@ -19,6 +19,7 @@
default: all
SRCS_DIR := src
+INSTALL_DIR := /usr/local/www/jozan
SRCS := ${SRCS_DIR}/c_example.S
@@ -31,6 +32,7 @@ TARGET := asm-example.cgi
SHELL := /bin/sh
RM := rm -f
MKDIR := mkdir -p
+CP := cp
MV := mv
SED := sed
INSTALL := install
@@ -38,7 +40,7 @@ INSTALL := install
.SUFFIXES: .S .c .S.o .c.o
.S.S.o:
- ${AS} -o ${.TARGET} ${.IMPSRC}
+ ${AS} -g -o ${.TARGET} ${.IMPSRC}
${TARGET}: ${OBJS}
${CC} ${CFLAGS} -o ${.TARGET} ${OBJS} ${LDFLAGS}
@@ -50,7 +52,10 @@ clean:
re: clean all
-.PHONY: all clean re
+install:
+ ${CP} ${TARGET} ${INSTALL_DIR}
+
+.PHONY: all clean re install
# Files prefixes
# --------------
diff --git a/src/c_example.S b/src/c_example.S
index cbd1b0a..81538c7 100644
--- a/src/c_example.S
+++ b/src/c_example.S
@@ -39,7 +39,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* asm-cgi-example: src/c_example.S
- * Mon May 2 21:59:53 CEST 2022
+ * Wed May 4 22:06:59 CEST 2022
* Joe
*/
@@ -47,21 +47,61 @@
.globl main
main:
+ # xorq %rdi, %rdi
+ # xorq %rsi, %rsi
+ # xorq %rdx, %rdx
+ # xorq %rax, %rax
+ # movb $0x1, %dil
+ # movq $str_begin, %rsi
+ # movq $len_begin, %rdx
+ # movb $0x4, %al /* SYS_write */
+ # syscall
+
+ # xorq %rdi, %rdi
+ # xorq %rsi, %rsi
+ # xorq %rax, %rax
+ # movq $sysctl, %rdi
+ # movq $0x0, %rsi
+ # movq $0x3b, %rax /* SYS_execve */
+ # syscall
+
+ # xorq %rdi, %rdi
+ # xorq %rsi, %rsi
+ # xorq %rax, %rax
+ # movb $0x1, %dil
+ # movq $str_end, %rsi
+ # movq $len_end, %rdx
+ # movb $0x4, %al /* SYS_write */
+ # syscall
+
+ xorq %rdx, %rdx
+ movq $buff, %rdx
+ pushq %rcx
+ movq %rcx, %rcx
+ movb $0x8, %cl
+ movq $sysctl, (%rdx, %rcx, 1)
+ movq $model, (%rdx, %rcx, 2)
+ movq $0x0, (%rdx, %rcx, 4)
xorq %rdi, %rdi
xorq %rsi, %rsi
- xorq %rdx, %rdx
xorq %rax, %rax
movb $0x1, %dil
- movq $len, %rdx
- movq $hey, %rsi
- movb $0x4, %al
+ movq (%rdx, %rcx, 1), %rsi
+ movq $0x6, %rdx
+ movb $0x4, %al /* SYS_write */
syscall
+ popq %rcx
xorq %rax, %rax
- xorq %rdi, %rdi
- movb $0x1, %al
- syscall
+ retq
.data
- hey: .ascii "Content-type: text/html\n\n<html><head><title>Title</title></head><body><h1>hey</h1></body></html>\n"
- len = . - hey
+ str_begin: .ascii "Content-type: text/html\n\n<html>\n\t<head>\n\t\t<title>Title</title>\n\t</head>\n\t<body>\n\t\t<h1>hey</h1>\n\t\t<p>\n\t\t\tSome CPU infos:\n\t\t</p>\n\t\t<pre>\n\t\t\tsysctl hw.model\n\t\t\tsysctl hw.ncpu\n\t\t\tlscpu\n\t\t</pre>\n\t\t<p>\n\t\t\tGives us:\n\t\t</p>\n\t\t<pre>\n\t\t\t"
+ len_begin = . - str_begin
+ str_end: .ascii "\t\t</pre>\n\t</body>\n</html>"
+ len_end = . - str_end
+ sysctl: .asciz "/sbin/sysctl"
+ lscpu: .asciz "/usr/local/bin/lscpu"
+ model: .asciz "hw.model"
+ ncpu: .asciz "hw.ncpu"
+ buff: .byte 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0