summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <>2022-05-22 14:59:51 +0000
committerJozanLeClerc <>2022-05-22 14:59:51 +0000
commit1ce27a02d6ab0e3d00fb01335f7422014cddcd67 (patch)
tree4a2c804463f90643bb6cfb7965125e1bab305d90
parentDate update (diff)
downloadasm-cgi-example-1ce27a02d6ab0e3d00fb01335f7422014cddcd67.tar.gz
asm-cgi-example-1ce27a02d6ab0e3d00fb01335f7422014cddcd67.tar.bz2
asm-cgi-example-1ce27a02d6ab0e3d00fb01335f7422014cddcd67.tar.xz
asm-cgi-example-1ce27a02d6ab0e3d00fb01335f7422014cddcd67.tar.zst
asm-cgi-example-1ce27a02d6ab0e3d00fb01335f7422014cddcd67.zip
test
FossilOrigin-Name: f2736bec7cec792b6230253d86c2cb65a26c1f78
-rw-r--r--Makefile5
-rw-r--r--src/c_example.S128
2 files changed, 8 insertions, 125 deletions
diff --git a/Makefile b/Makefile
index 30fa5af..06b253b 100644
--- a/Makefile
+++ b/Makefile
@@ -11,7 +11,7 @@
# ========================
#
# asm-cgi-example: Makefile
-# Sun May 22 16:40:45 CEST 2022
+# Sun May 22 16:55:43 CEST 2022
# Joe
#
# BSD Makefile
@@ -21,7 +21,8 @@ default: run
SRCS_DIR := src
INSTALL_DIR := /usr/local/www/jozan
-SRCS := ${SRCS_DIR}/c_example.S
+SRCS := ${SRCS_DIR}/c_cpu.S
+SRCS += ${SRCS_DIR}/c_example.S
OBJS := ${SRCS:.S=.S.o}
diff --git a/src/c_example.S b/src/c_example.S
index 76b9362..3de431b 100644
--- a/src/c_example.S
+++ b/src/c_example.S
@@ -39,11 +39,12 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* asm-cgi-example: src/c_example.S
- * Sun May 22 16:35:27 CEST 2022
+ * Sun May 22 16:51:38 CEST 2022
* Joe
*/
.text
+.extern c_cpu
.globl main
main:
@@ -57,122 +58,7 @@ write_begin:
movq $len_begin, %rdx
movb $0x4, %al /* SYS_write */
syscall
-
-fork_model:
- xorq %rdi, %rdi
- xorq %rsi, %rsi
- xorq %rax, %rax
- movb $0x2, %al /* SYS_fork */
- syscall
- cmp $0x0, %rax
- jl err
- je exec_model
- jg wait_model
-
-fork_ncpu:
- xorq %rdi, %rdi
- xorq %rsi, %rsi
- xorq %rax, %rax
- movb $0x2, %al /* SYS_fork */
- syscall
- cmp $0x0, %rax
- jl err
- je exec_ncpu
- jg wait_ncpu
-
-fork_lscpu:
- xorq %rdi, %rdi
- xorq %rsi, %rsi
- xorq %rax, %rax
- movb $0x2, %al /* SYS_fork */
- syscall
- cmp $0x0, %rax
- jl err
- je exec_lscpu
- jg wait_lscpu
-
-exec_model:
- xorq %rax, %rax
- pushq %rbp
- movq %rsp, %rbp
- movq $sysctl, -32(%rbp)
- movq $model, -24(%rbp)
- movq $0x0, -16(%rbp)
- movq -32(%rbp), %rdi
- leaq -32(%rbp), %rsi
- xorq %rdx, %rdx
- movq $0x3b, %rax /* SYS_execve */
- syscall
- popq %rbp
- retq
-
-exec_ncpu:
- xorq %rdi, %rdi
- xorq %rsi, %rsi
- xorq %rax, %rax
- pushq %rbp
- movq %rsp, %rbp
- movq $sysctl, -32(%rbp)
- movq $ncpu, -24(%rbp)
- movq $0x0, -16(%rbp)
- movq -32(%rbp), %rdi
- leaq -32(%rbp), %rsi
- xorq %rdx, %rdx
- movq $0x3b, %rax /* SYS_execve */
- syscall
- popq %rbp
-
-exec_lscpu:
- xorq %rdi, %rdi
- xorq %rsi, %rsi
- xorq %rax, %rax
- pushq %rbp
- movq %rsp, %rbp
- movq $lscpu, -24(%rbp)
- movq $0x0, -16(%rbp)
- movq -24(%rbp), %rdi
- leaq -24(%rbp), %rsi
- xorq %rdx, %rdx
- movq $0x3b, %rax /* SYS_execve */
- syscall
- popq %rbp
-
-wait_model:
- movq %rax, %rdi
- xorq %rsi, %rsi
- xorq %rdx, %rdx
- xorq %rcx, %rcx
- xorq %rax, %rax
- movb $0x7, %al /* sys_wait4 */
- syscall
- jmp fork_ncpu
-
-wait_ncpu:
- movq %rax, %rdi
- xorq %rsi, %rsi
- xorq %rdx, %rdx
- xorq %rcx, %rcx
- xorq %rax, %rax
- movb $0x7, %al /* sys_wait4 */
- syscall
- jmp fork_lscpu
-
-wait_lscpu:
- movq %rax, %rdi
- xorq %rsi, %rsi
- xorq %rdx, %rdx
- xorq %rcx, %rcx
- xorq %rax, %rax
- movb $0x7, %al /* sys_wait4 */
- syscall
- jmp write_end
-
-err:
- xorq %rdi, %rdi
- xorq %rax, %rax
- movb $0x1, %dil
- movb $0x1, %al
- syscall
+ callq c_cpu
write_end:
xorq %rdi, %rdi
@@ -189,11 +75,7 @@ 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>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"
+ 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\n\t\t<pre>\n"
len_begin = . - str_begin
- str_end: .ascii "\t\t</pre>\n\t</body>\n</html>\n"
+ str_end: .ascii "\t\t</pre></p>\n\t</body>\n</html>\n"
len_end = . - str_end
- sysctl: .asciz "/sbin/sysctl"
- lscpu: .asciz "/usr/local/bin/lscpu"
- model: .asciz "hw.model"
- ncpu: .asciz "hw.ncpu"