diff options
author | JozanLeClerc <> | 2022-05-22 16:30:43 +0000 |
---|---|---|
committer | JozanLeClerc <> | 2022-05-22 16:30:43 +0000 |
commit | 6c0655e7dfd83b726eeec71ecb72e29f5ef0a8d4 (patch) | |
tree | b5b6815fba5abfb0cfab8c9c25c1d297f048e8d2 | |
parent | Update (diff) | |
download | asm-cgi-example-6c0655e7dfd83b726eeec71ecb72e29f5ef0a8d4.tar.gz asm-cgi-example-6c0655e7dfd83b726eeec71ecb72e29f5ef0a8d4.tar.bz2 asm-cgi-example-6c0655e7dfd83b726eeec71ecb72e29f5ef0a8d4.tar.xz asm-cgi-example-6c0655e7dfd83b726eeec71ecb72e29f5ef0a8d4.tar.zst asm-cgi-example-6c0655e7dfd83b726eeec71ecb72e29f5ef0a8d4.zip |
WIP
FossilOrigin-Name: 50c6fcb1c1758fb6252c48df702f81c626389bcc
-rw-r--r-- | Makefile | 13 | ||||
-rw-r--r-- | src/c_cpu.S | 16 | ||||
-rw-r--r-- | src/c_example.S | 20 | ||||
-rw-r--r-- | src/c_infos.S | 78 | ||||
-rw-r--r-- | src/u_utils.S | 58 |
5 files changed, 163 insertions, 22 deletions
@@ -11,7 +11,7 @@ # ======================== # # asm-cgi-example: Makefile -# Sun May 22 16:55:43 CEST 2022 +# Sun May 22 18:12:41 CEST 2022 # Joe # # BSD Makefile @@ -23,11 +23,11 @@ INSTALL_DIR := /usr/local/www/jozan SRCS := ${SRCS_DIR}/c_cpu.S SRCS += ${SRCS_DIR}/c_example.S +SRCS += ${SRCS_DIR}/c_infos.S +SRCS += ${SRCS_DIR}/u_utils.S OBJS := ${SRCS:.S=.S.o} -LDFLAGS := -lc - TARGET := asm-example.cgi SHELL := /bin/sh @@ -44,23 +44,22 @@ INSTALL := install ${AS} -g -o ${.TARGET} ${.IMPSRC} ${TARGET}: ${OBJS} - ${CC} ${CFLAGS} -o ${.TARGET} ${OBJS} ${LDFLAGS} + ${CC} ${CFLAGS} -o ${.TARGET} ${OBJS} all: ${TARGET} clean: ${RM} ${OBJS} ${OBJS} ${TARGET}.core ${TARGET} -re: clean all - install: ${CP} ${TARGET} ${INSTALL_DIR} run: ${TARGET} ./${TARGET} -.PHONY: all clean re install run +.PHONY: all clean install run # Files prefixes # -------------- # c: core +# u: utils diff --git a/src/c_cpu.S b/src/c_cpu.S index 395b176..fedcebb 100644 --- a/src/c_cpu.S +++ b/src/c_cpu.S @@ -39,7 +39,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * asm-cgi-example: src/c_cpu.S - * Sun May 22 16:51:35 CEST 2022 + * Sun May 22 17:22:17 CEST 2022 * Joe */ @@ -49,8 +49,6 @@ c_cpu: fork_model: xorq %rdi, %rdi - xorq %rsi, %rsi - xorq %rdx, %rdx xorq %rax, %rax movb $0x1, %dil movq $str_model, %rsi @@ -69,8 +67,6 @@ fork_model: fork_ncpu: xorq %rdi, %rdi - xorq %rsi, %rsi - xorq %rdx, %rdx xorq %rax, %rax movb $0x1, %dil movq $str_ncpu, %rsi @@ -89,8 +85,6 @@ fork_ncpu: fork_lscpu: xorq %rdi, %rdi - xorq %rsi, %rsi - xorq %rdx, %rdx xorq %rax, %rax movb $0x1, %dil movq $str_lscpu, %rsi @@ -202,13 +196,13 @@ err: syscall .data - str_model: .asciz "\t\t<p>\n\t\t\t<code>sysctl hw.model</code>:\n\t\t</p>\n\t\t<pre>\n" + str_model: .ascii "\t\t<p>\n\t\t\t<code>sysctl hw.model</code>:\n\t\t</p>\n\t\t<pre>\n" len_model = . - str_model - str_ncpu: .asciz "\t\t</pre>\n\t\t<p>\n\t\t\t<code>sysctl hw.ncpu</code>:\n\t\t</p>\n\t\t<pre>\n" + str_ncpu: .ascii "\t\t</pre>\n\t\t<p>\n\t\t\t<code>sysctl hw.ncpu</code>:\n\t\t</p>\n\t\t<pre>\n" len_ncpu = . - str_ncpu - str_lscpu: .asciz "\t\t</pre>\n\t\t<p>\n\t\t\t<code>lscpu</code>:\n\t\t</p>\n\t\t<pre>\n" + str_lscpu: .ascii "\t\t</pre>\n\t\t<p>\n\t\t\t<code>lscpu</code>:\n\t\t</p>\n\t\t<pre>\n" len_lscpu = . - str_lscpu - str_end: .asciz "\t\t</pre>\n" + str_end: .ascii "\t\t</pre>\n" len_end = . - str_end sysctl: .asciz "/sbin/sysctl" lscpu: .asciz "/usr/local/bin/lscpu" diff --git a/src/c_example.S b/src/c_example.S index 17b2f34..652f688 100644 --- a/src/c_example.S +++ b/src/c_example.S @@ -39,12 +39,13 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * asm-cgi-example: src/c_example.S - * Sun May 22 16:51:38 CEST 2022 + * Sun May 22 17:17:07 CEST 2022 * Joe */ .text .extern c_cpu +.extern c_infos .globl main main: @@ -59,12 +60,21 @@ write_begin: movb $0x4, %al /* SYS_write */ syscall +infos: + callq c_infos + cpu: - callq c_cpu + xorq %rdi, %rdi + xorq %rax, %rax + movb $0x1, %dil + movq $str_h2cpu, %rsi + movq $len_h2cpu, %rdx + movb $0x4, %al /* SYS_write */ + syscall + # callq c_cpu write_end: xorq %rdi, %rdi - xorq %rsi, %rsi xorq %rax, %rax movb $0x1, %dil movq $str_end, %rsi @@ -77,7 +87,9 @@ end: retq .data - 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>asm-cgi-example</h1>\n\t\t<p>\n\t\t\tThis page was generated by a small assembly program. It will run some shell commands for you. It's pointless in essence but I am trying to prove a point.\n\t\t</p>\n\t\t<h2>Some CPU infos</h2>\n\t\t<p>\n\t\t\tLet's fetch some infos about this server's CPU.\n\t\t</p>\n" + 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>asm-cgi-example</h1>\n\t\t<p>\n\t\t\tThis page was generated by a small assembly program. It will run some shell commands for you. It's pointless in essence but I am trying to prove a point.\n\t\t</p>\n\t\t<h2>General infos</h2>\n\t\t<p>\n\t\t\tLet's fetch some general informations first.\n\t\t</p>\n" len_begin = . - str_begin + str_h2cpu: .ascii "\t\t<h2>Some CPU infos</h2>\n\t\t<p>\n\t\t\tNow let's fetch some infos about this server's CPU.\n\t\t</p>\n" + len_h2cpu = . - str_h2cpu str_end: .ascii "\t</body>\n</html>\n" len_end = . - str_end diff --git a/src/c_infos.S b/src/c_infos.S new file mode 100644 index 0000000..1698298 --- /dev/null +++ b/src/c_infos.S @@ -0,0 +1,78 @@ +/* + * ======================== + * ===== =============== + * ====== ================ + * ====== ================ + * ====== ==== ==== == + * ====== === == = = + * ====== === = == = + * = === === = == ==== + * = === === = == = = + * == ===== ==== == + * ======================== + * + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2022 Joe + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the organization nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * asm-cgi-example: src/c_infos.S + * Sun May 22 18:13:05 CEST 2022 + * Joe + */ + +.text +.extern getcwd +.extern u_strlen +.globl c_infos + +c_infos: + xorq %rax, %rax + xorq $buff, %rdi + xorq $0x80, %rsi + movw $0x146, %ax /* SYS_getcwd */ + callq getcwd + cmp $0x0, %rax + je err + movq %rax, %rdi + callq u_strlen + movq %rax, %rdx + movq %rdi, %rsi + xorq %rdi, %rdi + xorq %rax, %rax + movb $0x1, %dil + movb $0x4, %al /* SYS_write */ + syscall + retq + +err: + xorq %rax, %rax + xorq %rdi, %rdi + movb $0x1, %dil + movb $0x1, %al + syscall + +.bss + buff: .zero 0x80 diff --git a/src/u_utils.S b/src/u_utils.S new file mode 100644 index 0000000..a460701 --- /dev/null +++ b/src/u_utils.S @@ -0,0 +1,58 @@ +/* + * ======================== + * ===== =============== + * ====== ================ + * ====== ================ + * ====== ==== ==== == + * ====== === == = = + * ====== === = == = + * = === === = == ==== + * = === === = == = = + * == ===== ==== == + * ======================== + * + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2022 Joe + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the organization nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * asm-cgi-example: src/u_utils.S + * Sun May 22 18:12:26 CEST 2022 + * Joe + */ + +.text +.globl u_strlen + +u_strlen: + movq $-1, %rax + pushq %rdi +loop: + addq $0x1, %rax + cmpb $0x0, (%rdi) + leaq 1(%rdi), %rdi + jne loop + popq %rdi + retq |