diff options
Diffstat (limited to 'src/c_example.S')
-rw-r--r-- | src/c_example.S | 123 |
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" |