.include "../include/machine10-main.inc" .section .text .code64 .global _start _start: cld movq %rdi, %r14 movq %rdx, %r12 movq %r8, %r13 movabsq $M10_ABI_MAGIC, %rax movq %rax, M10_ABI_MAGIC_OFFSET(%r13) movl $M10_ABI_VERSION_MAINBOARD, M10_ABI_VERSION_OFFSET(%r13) movq %r12, M10_ABI_V3_RESPONSE_ADDRESS(%r13) movq %rcx, M10_ABI_V3_RESPONSE_CAPACITY(%r13) movq $0, M10_ABI_V3_RESPONSE_LENGTH(%r13) movl $200, M10_ABI_V3_HTTP_STATUS(%r13) movl $M10_ERROR_NONE, M10_ABI_V3_ERROR(%r13) movq $0, M10_ABI_V3_COMPLETION_SEQUENCE(%r13) movl M10_EVENT_TYPE_OFFSET(%r14), %eax movl %eax, M10_ABI_V3_EVENT_TYPE(%r13) movq M10_EVENT_OCCURRENCE_OFFSET(%r14), %rax movq %rax, M10_ABI_V3_EVENT_OCCURRENCE(%r13) movl $M10_TIMER_KEEP, M10_ABI_V3_TIMER_ACTION(%r13) movq $0, M10_ABI_V3_WAKE_AFTER_MS(%r13) movl $M10_DISPOSITION_SLEEP, M10_ABI_V3_DISPOSITION(%r13) movabsq $M10_RETAINED_COUNTER_ADDRESS, %r10 movq M10_EVENT_GENERATION_OFFSET(%r14), %rax cmpq %rax, (%r10) jne failed incq (%r10) cmpl $M10_EVENT_INIT, M10_EVENT_TYPE_OFFSET(%r14) je init movq M10_EVENT_PAYLOAD_ADDRESS(%r14), %rsi movq M10_EVENT_PAYLOAD_LENGTH(%r14), %rcx scan: cmpq $(health_needle_end-health_needle), %rcx jb not_found leaq health_needle(%rip), %rdi movq $(health_needle_end-health_needle), %r15 decq %r15 compare: movb (%rsi,%r15,1), %al cmpb (%rdi,%r15,1), %al jne advance decq %r15 jns compare leaq health_response(%rip), %rsi movq $(health_response_end-health_response), %rcx jmp respond advance: incq %rsi decq %rcx jmp scan not_found: leaq not_found_response(%rip), %rsi movq $(not_found_response_end-not_found_response), %rcx jmp respond init: leaq init_response(%rip), %rsi movq $(init_response_end-init_response), %rcx respond: movq %r12, %rdi movq %rcx, %r15 rep movsb movq %r15, M10_ABI_V3_RESPONSE_LENGTH(%r13) movl $200, M10_ABI_V3_HTTP_STATUS(%r13) movl $M10_OP_COMMIT_SLEEP, %eax jmp ring failed: movl $M10_ERROR_BAD_EVENT, M10_ABI_V3_ERROR(%r13) movl $M10_OP_EXIT, %eax ring: movw $M10_DOORBELL_PORT, %dx outl %eax, %dx cli hlt .section .rodata health_needle: .ascii "\"url\":\"/health" health_needle_end: init_response: .ascii "{\"event\":\"init\"}" init_response_end: health_response: .ascii "{\"version\":\"origin10.response.v1\",\"status\":200,\"headers\":[[\"content-type\",\"text/plain; charset=utf-8\"]],\"bodyBase64\":\"b2s=\"}" health_response_end: not_found_response: .ascii "{\"version\":\"origin10.response.v1\",\"status\":404,\"headers\":[[\"content-type\",\"text/plain; charset=utf-8\"]],\"bodyBase64\":\"bm90IGZvdW5k\"}" not_found_response_end: