kern

annotate src/proc-asm.S @ 73:b4b7198986a6

fixed a potential null dereference when deleting a bug in the redblack tree
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 15 Oct 2011 08:06:10 +0300
parents 437360696883
children
rev   line source
nuclear@54 1 .text
nuclear@57 2 /* switch_stack(uint32_t new_stack, uint32_t *old_stack_ptr)
nuclear@57 3 * switches to the new stack and returns the old stack pointer, which is
nuclear@57 4 * also copied to the address passed as the second argument.
nuclear@54 5 */
nuclear@54 6 .globl switch_stack
nuclear@54 7 switch_stack:
nuclear@57 8 movl %esp, %eax /* old stack in eax */
nuclear@57 9 movl 8(%esp), %edx
nuclear@57 10 cmpl $0, %edx /* if old_stack_ptr is null, skip ahead */
nuclear@57 11 jz oldp_is_null
nuclear@57 12 movl %eax, (%edx) /* otherwise *old_stack_ptr = eax */
nuclear@57 13 oldp_is_null:
nuclear@57 14 movl 4(%esp), %esp /* set the new stack */
nuclear@54 15 ret
nuclear@57 16
nuclear@57 17 /* get_instr_stack_ptr(uint32_t *eip, uint32_t *esp)
nuclear@57 18 * returns the current instruction and stack pointers at the same
nuclear@57 19 * point in execution, so that a newly-forked process with these
nuclear@57 20 * values will just return from this function and continue on.
nuclear@57 21 */
nuclear@57 22 .globl get_instr_stack_ptr
nuclear@57 23 get_instr_stack_ptr:
nuclear@57 24 call get_instr_ptr
nuclear@57 25 movl %eax, 4(%esp)
nuclear@57 26 movl %esp, 8(%esp)
nuclear@57 27 ret
nuclear@57 28
nuclear@57 29 /* get_instr_ptr(void)
nuclear@57 30 * returns the address of the next instruction after the call to this function
nuclear@57 31 */
nuclear@57 32 .globl get_instr_ptr
nuclear@57 33 get_instr_ptr:
nuclear@57 34 movl (%esp), %eax
nuclear@57 35 ret
nuclear@57 36
nuclear@57 37 /* get_caller_instr_ptr(void)
nuclear@57 38 * returns the address of the next instruction after the call to the function that
nuclear@57 39 * called this function.
nuclear@57 40 * NOTE: will only work properly when called from a function that uses ebp to point
nuclear@57 41 * to its stack frame, which means all of the C functions but pretty much none of
nuclear@57 42 * our assembly functions.
nuclear@57 43 */
nuclear@57 44 .globl get_caller_instr_ptr
nuclear@57 45 get_caller_instr_ptr:
nuclear@57 46 movl 4(%ebp), %eax
nuclear@57 47 ret
nuclear@57 48
nuclear@58 49 /* this is where we end up when we first context_switch to a newly forked
nuclear@58 50 * process. The interrupt frame is already there, so we just call intr_ret
nuclear@58 51 * to return to user space
nuclear@58 52 */
nuclear@57 53 .globl just_forked
nuclear@57 54 just_forked:
nuclear@57 55 call intr_ret