summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJozanLeClerc <>2022-05-22 14:39:57 +0000
committerJozanLeClerc <>2022-05-22 14:39:57 +0000
commit27542bbc4a58f46b1fbd8037f9df85d11fdce44b (patch)
treed045099d28033b00a70fea90d5b98a05b2007176 /src
parentGood progress, now wait(2) (diff)
downloadasm-cgi-example-27542bbc4a58f46b1fbd8037f9df85d11fdce44b.tar.gz
asm-cgi-example-27542bbc4a58f46b1fbd8037f9df85d11fdce44b.tar.bz2
asm-cgi-example-27542bbc4a58f46b1fbd8037f9df85d11fdce44b.tar.xz
asm-cgi-example-27542bbc4a58f46b1fbd8037f9df85d11fdce44b.tar.zst
asm-cgi-example-27542bbc4a58f46b1fbd8037f9df85d11fdce44b.zip
Its cool
FossilOrigin-Name: 25af2cffe75e6654fb19ea2df8cdcbc22e1e1b80
Diffstat (limited to 'src')
-rw-r--r--src/c_example.S123
1 files changed, 102 insertions, 21 deletions
diff --git a/src/c_example.S b/src/c_example.S
index f410c17..76b9362 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
- * Wed May 4 22:06:59 CEST 2022
+ * Sun May 22 16:35:27 CEST 2022
* Joe
*/
@@ -47,24 +47,51 @@
.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
+write_begin:
+ 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
+
+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
- jne next
+ 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
@@ -79,7 +106,7 @@ main:
popq %rbp
retq
-next:
+exec_ncpu:
xorq %rdi, %rdi
xorq %rsi, %rsi
xorq %rax, %rax
@@ -95,22 +122,76 @@ next:
syscall
popq %rbp
- # 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
+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
+
+write_end:
+ 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
+end:
xorq %rax, %rax
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"
len_begin = . - str_begin
- str_end: .ascii "\t\t</pre>\n\t</body>\n</html>"
+ str_end: .ascii "\t\t</pre>\n\t</body>\n</html>\n"
len_end = . - str_end
sysctl: .asciz "/sbin/sysctl"
lscpu: .asciz "/usr/local/bin/lscpu"