From 1ce27a02d6ab0e3d00fb01335f7422014cddcd67 Mon Sep 17 00:00:00 2001 From: JozanLeClerc <> Date: Sun, 22 May 2022 14:59:51 +0000 Subject: test FossilOrigin-Name: f2736bec7cec792b6230253d86c2cb65a26c1f78 --- Makefile | 5 ++- src/c_example.S | 128 +++----------------------------------------------------- 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\n\t\n\t\tTitle\n\t\n\t\n\t\t

hey

\n\t\t

\n\t\t\tSome CPU infos:\n\t\t

\n\t\t
\n\t\t\tsysctl hw.model\n\t\t\tsysctl hw.ncpu\n\t\t\tlscpu\n\t\t
\n\t\t

\n\t\t\tGives us:\n\t\t

\n\t\t
\n\t\t\t"
+	str_begin:	.ascii "Content-type: text/html\n\n\n\t\n\t\tTitle\n\t\n\t\n\t\t

asm-cgi-example

\n\t\t

\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

\n\t\t

Some CPU infos

\n\t\t

\n\t\t\tLet's fetch some infos about this server's CPU.\n\t\t\n\t\t

\n"
 	len_begin	= . - str_begin
-	str_end:	.ascii "\t\t
\n\t\n\n" + str_end: .ascii "\t\t

\n\t\n\n" len_end = . - str_end - sysctl: .asciz "/sbin/sysctl" - lscpu: .asciz "/usr/local/bin/lscpu" - model: .asciz "hw.model" - ncpu: .asciz "hw.ncpu" -- cgit v1.2.3