kern

diff src/proc-asm.S @ 57:437360696883

I think we're done for now. two processes seem to be scheduled and switched just fine, fork seems to work (NO CoW YET!)
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 16 Aug 2011 03:26:53 +0300
parents 4eaecb14fe31
children 64a574189824
line diff
     1.1 --- a/src/proc-asm.S	Mon Aug 15 06:17:58 2011 +0300
     1.2 +++ b/src/proc-asm.S	Tue Aug 16 03:26:53 2011 +0300
     1.3 @@ -1,9 +1,51 @@
     1.4  	.text
     1.5 -	/* switch_stack(uint32_t new_stack)
     1.6 -     * switches to the new stack and returns the old stack pointer
     1.7 +	/* switch_stack(uint32_t new_stack, uint32_t *old_stack_ptr)
     1.8 +     * switches to the new stack and returns the old stack pointer, which is
     1.9 +     * also copied to the address passed as the second argument.
    1.10       */
    1.11  	.globl switch_stack
    1.12  switch_stack:
    1.13 -	movl %esp, %eax
    1.14 -	movl 4(%esp), %esp
    1.15 +	movl %esp, %eax		/* old stack in eax */
    1.16 +	movl 8(%esp), %edx
    1.17 +	cmpl $0, %edx		/* if old_stack_ptr is null, skip ahead */
    1.18 +	jz oldp_is_null
    1.19 +	movl %eax, (%edx)	/* otherwise *old_stack_ptr = eax */
    1.20 +oldp_is_null:
    1.21 +	movl 4(%esp), %esp	/* set the new stack */
    1.22  	ret
    1.23 +
    1.24 +	/* get_instr_stack_ptr(uint32_t *eip, uint32_t *esp)
    1.25 +     * returns the current instruction and stack pointers at the same
    1.26 +     * point in execution, so that a newly-forked process with these
    1.27 +     * values will just return from this function and continue on.
    1.28 +	 */
    1.29 +	.globl get_instr_stack_ptr
    1.30 +get_instr_stack_ptr:
    1.31 +	call get_instr_ptr
    1.32 +	movl %eax, 4(%esp)
    1.33 +	movl %esp, 8(%esp)
    1.34 +	ret
    1.35 +
    1.36 +	/* get_instr_ptr(void)
    1.37 +	 * returns the address of the next instruction after the call to this function
    1.38 +	 */
    1.39 +	.globl get_instr_ptr
    1.40 +get_instr_ptr:
    1.41 +	movl (%esp), %eax
    1.42 +	ret
    1.43 +
    1.44 +	/* get_caller_instr_ptr(void)
    1.45 +	 * returns the address of the next instruction after the call to the function that
    1.46 +	 * called this function.
    1.47 +     * NOTE: will only work properly when called from a function that uses ebp to point
    1.48 +     * to its stack frame, which means all of the C functions but pretty much none of
    1.49 +     * our assembly functions.
    1.50 +	 */
    1.51 +	.globl get_caller_instr_ptr
    1.52 +get_caller_instr_ptr:
    1.53 +	movl 4(%ebp), %eax
    1.54 +	ret
    1.55 +
    1.56 +	.globl just_forked
    1.57 +just_forked:
    1.58 +	call intr_ret