# Copyright (C) 2026 Sebastian G. Kirmayer # # This file is part of sysf-i386. # # sysf-i386 is free software: you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) # any later version. # # sysf-i386 is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along # with sysf-i386. If not, see . # rodata align L s long s^ long $VAL_FIX long s^ long $VAL_ABS label term_fix L s long s^ long $VAL_READ long s^ long $VAL_ABS long s^ long $VAL_ABS long s^ long $VAL_ABS label term_read L s long s^ long $VAL_WRITE0 long s^ long $VAL_ABS label term_write0 L s long s^ long $VAL_WRITE1 long s^ long $VAL_ABS label term_write1 L s long s^ long $VAL_EXIT label term_exit bss align label alloc_next long 0 data align label context_root long 0 long 0 long 0 long 0x10 # Context elements: # 0: parent # 4: context # 8: term # 12: refcount text label execute pushl 0 pushl term_exit pushl context_root pushl 0 pushl term_write1 pushl context_root pushl 0 pushl term_write0 pushl context_root pushl 0 pushl term_read pushl context_root pushl 0 pushl term_fix pushl context_root pushl 0 pushl %eax pushl context_root L exec_loop movl @%esp+4 %eax movl @%eax+-4 %ebx testl %ebx %ebx js special. L var movl @%esp %esi L loop decl %ebx %ebx js done. movl @%esi %esi jmp loop^ L done # %esi -- variable context movl @%esi+8 %edi # %edi -- new term cmpl $VAL_ABS @%edi+-4 je no_writeback. movl @%esp+8 %ebx # %ebx -- old writeback testl %ebx %ebx jz no_old_writeback. # write current value back movl @%ebx+4 %eax call unref movl @%esp %ecx incl @%ecx+12 movl %ecx @%ebx+4 movl @%esp+4 %ecx movl %ecx @%ebx+8 movl %ebx %eax call unref L no_old_writeback incl @%esi+12 movl %esi @%esp+8 L no_writeback movl %edi @%esp+4 movl @%esi+4 %eax incl @%eax+12 xchgl %eax @%esp call unref jmp exec_loop^ L special cmpl $VAL_APP %ebx je app. cmpl $VAL_ABS %ebx je abs. cmpl $VAL_FIX %ebx je fix. cmpl $VAL_READ %ebx je read. cmpl $VAL_WRITE0 %ebx je write0. cmpl $VAL_WRITE1 %ebx je write1. cmpl $VAL_EXIT %ebx je exit ud2 L app pushl 0 subl 8 %eax movl %eax @%esp+8 pushl @%eax+-8 movl @%esp+8 %eax incl @%eax+12 pushl %eax jmp exec_loop^ L abs popl %ebx popl %ebp popl %edi # %ebx -- context # %ebp -- term # %edi -- writeback testl %edi %edi jz no_writeback. movl @%edi+4 %eax call unref incl @%ebx+12 movl %ebx @%edi+4 movl %ebp @%edi+8 movl %edi %eax call unref L no_writeback movl @alloc_next %eax testl %eax %eax jz no_next. movl @%eax %ecx movl %ecx @alloc_next L have_ctx movl %ebx @%eax movl @%esp %ecx movl %ecx @%eax+4 movl @%esp+4 %ecx movl %ecx @%eax+8 movl 1 @%eax+12 movl %eax @%esp subl 8 %ebp movl %ebp @%esp+4 jmp exec_loop^ L no_next movl @heap_ptr %esi movl %esi %eax addl 16 %esi movl %esi @heap_ptr cmpl @heap_end %esi ja realloc. jmp have_ctx^ L realloc movl %eax %esi call alloc movl %esi %eax jmp have_ctx^ L fix movl @%esp %eax incl @%eax+12 pushl %eax pushl @%eax+8 movl @%eax+4 %eax incl @%eax+12 pushl %eax jmp exec_loop^ L read call read movl 1 %ebx subl %eax %ebx jmp var^ L write0 call write0 xorl %ebx %ebx jmp var^ L write1 call write1 xorl %ebx %ebx jmp var^ label unref decl @%eax+12 jz free. ret L free pushl %eax movl @%eax %eax call unref movl @%esp %eax movl @%eax+4 %eax call unref popl %eax movl @alloc_next %ecx movl %eax @alloc_next movl %ecx @%eax ret