1#define SEG_KCODE 1 // kernel code 2#define SEG_KDATA 2 // kernel data+stack 3#define SEG_KCPU 3 // kernel per-cpu data 4 5 # vectors.S sends all traps here. 6.globl alltraps 7alltraps: 8 # Build trap frame. 9 pushl %ds 10 pushl %es 11 pushl %fs 12 pushl %gs 13 pushal 14 15 # Set up data and per-cpu segments. 16 movw $(SEG_KDATA<<3), %ax 17 movw %ax, %ds 18 movw %ax, %es 19 movw $(SEG_KCPU<<3), %ax 20 movw %ax, %fs 21 movw %ax, %gs 22 23 # Call trap(tf), where tf=%esp 24 pushl %esp 25 call trap 26 addl $4, %esp 27 28 # Return falls through to trapret... 29.globl trapret 30trapret: 31 popal 32 popl %gs 33 popl %fs 34 popl %es 35 popl %ds 36 addl $0x8, %esp # trapno and errcode 37 iret 38 39 # A forked process switches to user mode by calling 40 # forkret1(tf), where tf is the trap frame to use. 41.globl forkret1 42forkret1: 43 movl 4(%esp), %esp 44 jmp trapret 45 46