(c) ulpgc1 interrupciones software s.candela © universidad de las palmas de gran canaria

29
(c) ULPGC 1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

Upload: venceslas-quinones

Post on 23-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: (c) ULPGC1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

(c) ULPGC 1

INTERRUPCIONES SOFTWARE

S.CANDELA

© Universidad de Las Palmas de Gran Canaria

Page 2: (c) ULPGC1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

(c) ULPGC 2

Interrupción software (1)

• Una Interrupción software se produce cuando un usuario solicita un recurso del núcleo, mediante una llamada al sistema, open, write, read, mount,..

• El proceso usuario solicita la función correspondiente de la librería libc. df = open (fichero, modo);

• La función de librería coloca los parámetros de la llamada en los registros del procesador y ejecuta la instrucción INT 0x80

• Se conmuta a modo núcleo mediante las tablas IDT y GDT

• Entra a ejecutarse una función del núcleo, system_call, Interfase entre el usuario y el núcleo.

• Cuando se termina la llamada, system_call retorna al proceso que la llamo y se retorna a modo usuario.

Page 3: (c) ULPGC1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

(c) ULPGC 3

Interrupción software (2)

• Llega la interrupción software INT 80h y se busca en la IDT la entrada correspondiente a la interrupción.

• Se obtiene un puntero desplazamiento al núcleo (D)

• Y una entrada (S) a GDT

• La entrada en la GDT indica una base (B) y un limite (L) del núcleo

• Se llega al manejador de interrupción system_call.

Page 4: (c) ULPGC1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

(c) ULPGC 4

Interrupciones Software gráfico

S – SelectorD – DesplazamientoA – AtributosB – BaseL - Limite

EAX

EBX

ECX

...

CS

FLG

TSSDescriptor 1

Descriptor 2

Descriptor 3

Descriptor n

Descriptor

LDT

system_call:save_allcall sys_open

restore_all

sys_open

MEMORIANÚCLEO

Base

Limite

Desplazamiento

+S D A

S D A

S D A

S D A

S D A

S D A

S D A

S D A255

80

33

2

1

0

IDT

INT

B L

IDTR

B L A

B L A

B L A

B L A

B L A

B L A

B L A

B L A

GDT

B L

GDTR

df = open(ficheor, modo);open – libcINT 80

TR

LDTR

Page 5: (c) ULPGC1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

(c) ULPGC(c) ULPGC 55

sys_callsys_call

Se llama a una función que implementa la llamada al sistema.

Se recupera el estado de la máquina con los valores guardados en el stack para reanudar el proceso que se interrumpió.

Guardar el estado del procesador, registros Guardar el estado del procesador, registros internos, en el stack se va a asignar la CPU internos, en el stack se va a asignar la CPU a otro procesoa otro proceso..

SAVE_ALLSAVE_ALL

CALL SYS_XXXCALL SYS_XXX

RESTORE_ALLRESTORE_ALL

Page 6: (c) ULPGC1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

(c) ULPGC(c) ULPGC 66

system_call 1system_call 1 171 ENTRY(system_call)171 ENTRY(system_call)

172 pushl %eax # save orig_eax172 pushl %eax # save orig_eax

173 SAVE_ALL173 SAVE_ALL

174 GET_CURRENT(%ebx)174 GET_CURRENT(%ebx)

175 cmpl $(NR_syscalls),%eax175 cmpl $(NR_syscalls),%eax

173: SAVE_ALL hace una copia de todos los registros de la CPU en la pila. Cualquier función de C que sea llamada encontrará sus argumentos en la pila porque SAVE_ALL los pone allí.

174: Obtiene un puntero a la tarea actual en el registro EBX. La macro que lo hace es GET_CURRENT (línea 131).

175: Compara si el numero de la llamada al sistema (EAX) excede del numero máximo de llamadas al sistema.

172: el primer argumento de 172: el primer argumento de system_call system_call es el número de la llamada al sistema a es el número de la llamada al sistema a invocar; se indicará en el registro EAX.invocar; se indicará en el registro EAX. System_call permite hasta cuatro System_call permite hasta cuatro argumentos mas que serán pasados a lo argumentos mas que serán pasados a lo largo de la llamada al sistema. Uno de los largo de la llamada al sistema. Uno de los argumentos puede ser un puntero a una argumentos puede ser un puntero a una estructuraestructura

Page 7: (c) ULPGC1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

(c) ULPGC(c) ULPGC 77

system_call 2system_call 2

179: Llama a la función del sistema. Sys_call_table es una tabla de punteros a funciones del núcleo que implementan las llamadas al sistema.

El segundo conjunto de paréntesis en la línea contiene tres argumentos: la dirección base del vector, el índice (EAX, el numero de la llamada al sistema), y la escala o numero de bytes en cada elemento del vector.

177: Comprueba si la llamada al 177: Comprueba si la llamada al sistema esta haciendo una traza. sistema esta haciendo una traza. Algunos programas permiten hacer Algunos programas permiten hacer trazas en las llamadas al sistema trazas en las llamadas al sistema como una herramienta para curiosos o como una herramienta para curiosos o para obtener información extra de para obtener información extra de depuración.depuración.

176176 jae badsysjae badsys

177 testb $0x20,flags(%ebx) # 177 testb $0x20,flags(%ebx) # PF_TRACESYSPF_TRACESYS

178178 jne tracesysjne tracesys

179 call *SYMBOL_NAME(sys_call_table)(,179 call *SYMBOL_NAME(sys_call_table)(,%eax,4)%eax,4)

Page 8: (c) ULPGC1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

(c) ULPGC(c) ULPGC 88

system_call 3system_call 3

182: Puntos de entrada desde otros lugares del propio system_call.

185: Chequea si "bottom half” esta activado y, de ser así, salta a la etiqueta handle_botton_half (línea 242) para manejarl el proceso de interrupción.

180: La llamada al sistema ha retornado. El 180: La llamada al sistema ha retornado. El valor devuelto que está en el registro EAX, valor devuelto que está en el registro EAX, se guarda en la posición EAX de la pila de se guarda en la posición EAX de la pila de modo que RESTORE_ALL pueda restaurar modo que RESTORE_ALL pueda restaurar el verdadero registro EAX de la pila, el verdadero registro EAX de la pila, además del resto de los registrosademás del resto de los registros..

180180movl %eax,EAX(%esp) # save movl %eax,EAX(%esp) # save the return valuethe return value

181 ALIGN181 ALIGN182 .globl ret_from_sys_call182 .globl ret_from_sys_call183 .globl ret_from_intr183 .globl ret_from_intr184 ret_from_sys_call:184 ret_from_sys_call:

185 movl SYMBOL_NAME(bh_mask),185 movl SYMBOL_NAME(bh_mask),%eax%eax

186 andl SYMBOL_NAME(bh_active),186 andl SYMBOL_NAME(bh_active),%eax%eax

187 jne handle_bottom_half187 jne handle_bottom_half

188 ret_with_reschedule:188 ret_with_reschedule:189 cmpl $0,need_resched(%ebx)189 cmpl $0,need_resched(%ebx)190 jne reschedule190 jne reschedule

Page 9: (c) ULPGC1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

(c) ULPGC(c) ULPGC 99

system_call 4system_call 4

193: La etiqueta restore_all es el punto de salida para system_call. Su contenido es simple como la macro RESTORE_ALL (línea 100), que recupera los argumentos guardados por SAVE_ALL y retorna la llamador del system_call.

191 cmpl $0,sigpending(%ebx)191 cmpl $0,sigpending(%ebx)

192 jne signal_return192 jne signal_return

193 restore_all:193 restore_all:

194 RESTORE_ALL194 RESTORE_ALL

191: Comprueba si una señal está pendiente y, de ser así, la siguiente línea salta sobre signal_return (línea 197).

Page 10: (c) ULPGC1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

(c) ULPGC(c) ULPGC 1010

signal_returnsignal_return

202: system_call esta preparado para llamar a la función de C do_signal (línea 3364) para entregar la señal. Do_signal espera dos parámetros, pasados en los registros EAX y EDX. system_call ya estableció el EDX (línea 200) al valor que quería para el primer parámetro y con un XOR de EDX con si mismo establece a 0 el segundo, así que do_signal lo interpretará como un puntero nulo.

203: Llama a do_signal para entregar la señal y entonces saltar atrás a restore_all (línea 193) para terminar.

199: Si retornamos al modo virtual 8086, 199: Si retornamos al modo virtual 8086, saltamos a saltamos a v86_signal_returnv86_signal_return (línea 207). (línea 207).

197 signal_return:197 signal_return:198 sti # we can get here from an interrupt 198 sti # we can get here from an interrupt

handlerhandler

199 testl $(VM_MASK),EFLAGS(%esp)199 testl $(VM_MASK),EFLAGS(%esp)200 movl %esp,%eax200 movl %esp,%eax201 jne v86_signal_return201 jne v86_signal_return

202 xorl %edx,%edx202 xorl %edx,%edx

203 call SYMBOL_NAME(do_signal)203 call SYMBOL_NAME(do_signal)204 jmp restore_all204 jmp restore_all

Page 11: (c) ULPGC1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

(c) ULPGC(c) ULPGC 1111

v86_signal_returnv86_signal_return

199: Si retornamos al modo virtual 8086, 199: Si retornamos al modo virtual 8086, saltamos a saltamos a v86_signal_returnv86_signal_return (línea 207). (línea 207).

207 v86_signal_return:207 v86_signal_return:208 call 208 call

SYMBOL_NAME(save_v86_state)SYMBOL_NAME(save_v86_state)209 movl %eax,%esp209 movl %eax,%esp210 xorl %edx,%edx210 xorl %edx,%edx211 call SYMBOL_NAME(do_signal)211 call SYMBOL_NAME(do_signal)212 jmp restore_all212 jmp restore_all

Page 12: (c) ULPGC1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

(c) ULPGC(c) ULPGC 1212

tracesystracesys

222: La llamada al sistema para traza ha retornado, el control salta hacia atrás a ret_from_sys_call (línea 184) para finalizar del mismo modo que en una llamada sin traza.

223: La etiqueta badsys se toma cuando la llamada al sistema solicitada esta fuera de rango. En este caso systeam_call debe devolver ENOSYS.

215: La etiqueta 215: La etiqueta tracesys tracesys se toma si la se toma si la llamada al sistema del proceso actual esta llamada al sistema del proceso actual esta haciendo una trazahaciendo una traza..

215 tracesys:215 tracesys:216 movl $-ENOSYS,EAX(%esp)216 movl $-ENOSYS,EAX(%esp)217 call SYMBOL_NAME(syscall_trace)217 call SYMBOL_NAME(syscall_trace)218 movl ORIG_EAX(%esp),%eax218 movl ORIG_EAX(%esp),%eax219 call *SYMBOL_NAME(sys_call_table)(,219 call *SYMBOL_NAME(sys_call_table)(,

%eax,4)%eax,4)220 movl %eax,EAX(%esp) # save 220 movl %eax,EAX(%esp) # save

the return valuethe return value221 call SYMBOL_NAME(syscall_trace)221 call SYMBOL_NAME(syscall_trace)

222 jmp ret_from_sys_call222 jmp ret_from_sys_call

223 badsys:223 badsys:224 movl $-ENOSYS,EAX(%esp)224 movl $-ENOSYS,EAX(%esp)225 jmp ret_from_sys_call225 jmp ret_from_sys_call

Page 13: (c) ULPGC1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

(c) ULPGC(c) ULPGC 1313

ret_from_exceptionret_from_exception

228: La etiqueta ret_from_exception se alcanza cuando la CPU produce una excepción como una división por cero

228 ret_from_exception:228 ret_from_exception:

229 movl SYMBOL_NAME(bh_mask),%eax229 movl SYMBOL_NAME(bh_mask),%eax

230 andl SYMBOL_NAME(bh_active),%eax230 andl SYMBOL_NAME(bh_active),%eax

231 jne handle_bottom_half231 jne handle_bottom_half

Page 14: (c) ULPGC1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

(c) ULPGC(c) ULPGC 1414

ret_from_intrret_from_intr

237: Los flags de la CPU y el registro CS han sido combinados en EAX en los 24 bits superiores. Esta línea comprueba si el proceso ha retornado al modo virtual 8086 o al modo de usuario.

238: Si cualquiera de esas condiciones es verdadera salta a la etiqueta ret_with_reschelude (línea 188) para comprobar si la CPU tiene que ser reasignada antes de que retorne system_call. En otro caso, el llamador es una tarea del núcleo, así que system_call omite el reasignar la CPU saltando a restore_all (línea 193).

233: La etiqueta ret_from_intr se toma después del manejo de bottom half

233 ret_from_intr:233 ret_from_intr:234 GET_CURRENT(%ebx)234 GET_CURRENT(%ebx)235 movl EFLAGS(%esp),%eax # mix 235 movl EFLAGS(%esp),%eax # mix

EFLAGS and CSEFLAGS and CS236 movb CS(%esp),%al236 movb CS(%esp),%al

237 testl $(VM_MASK | 3),%eax # rtn to VM86 237 testl $(VM_MASK | 3),%eax # rtn to VM86 mode|non-super?mode|non-super?

238 jne ret_with_reschedule238 jne ret_with_reschedule239 jmp restore_all239 jmp restore_all

Page 15: (c) ULPGC1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

(c) ULPGC(c) ULPGC 1515

handle_bottom_halfhandle_bottom_half

248: El componente final de system_call esta bajo la etiqueta reschedule. Esta etiqueta se toma cuando el proceso que hace la llamada al sistema ha sido marcado para que se vuelva asignar la CPU; típicamente esto ocurre cuando la rodaja de tiempo del proceso ha expirado.

242: La etiqueta handle_bottom_half se alcanza si system_call tiene un servicio de bottom half. Simplemente llama a la función en C do_bottom_half (línea 29126).

242 handle_bottom_half:242 handle_bottom_half:

243 call 243 call SYMBOL_NAME(do_bottom_half)SYMBOL_NAME(do_bottom_half)

244 jmp ret_from_intr244 jmp ret_from_intr

247 reschedule:247 reschedule:

248 call SYMBOL_NAME(schedule) # 248 call SYMBOL_NAME(schedule) # testtest

249 jmp ret_from_sys_call249 jmp ret_from_sys_call

reschedulereschedule

Page 16: (c) ULPGC1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

(c) ULPGC(c) ULPGC 1616

posiciones de los registros en en el stackposiciones de los registros en en el stack

51 EBX = 0x0051 EBX = 0x0052 ECX = 0x0452 ECX = 0x0453 EDX = 0x0853 EDX = 0x0854 ESI = 0x0C54 ESI = 0x0C55 EDI = 0x1055 EDI = 0x1056 EBP = 0x1456 EBP = 0x1457 EAX = 0x1857 EAX = 0x1858 DS = 0x1C58 DS = 0x1C59 ES = 0x2059 ES = 0x2060 ORIG_EAX = 0x2460 ORIG_EAX = 0x2461 EIP = 0x2861 EIP = 0x2862 CS = 0x2C62 CS = 0x2C63 EFLAGS = 0x3063 EFLAGS = 0x3064 OLDESP = 0x3464 OLDESP = 0x3465 OLDSS = 0x3865 OLDSS = 0x38

66 66 67 CF_MASK = 0x0000000167 CF_MASK = 0x0000000168 IF_MASK = 0x0000020068 IF_MASK = 0x0000020069 NT_MASK = 0x0000400069 NT_MASK = 0x0000400070 VM_MASK = 0x0002000070 VM_MASK = 0x0002000071 71 72 /*72 /*73 * these are offsets into the task-struct.73 * these are offsets into the task-struct.74 */74 */75 state = 075 state = 076 flags = 476 flags = 477 sigpending = 877 sigpending = 878 addr_limit = 1278 addr_limit = 1279 exec_domain = 1679 exec_domain = 1680 need_resched = 2080 need_resched = 20

Page 17: (c) ULPGC1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

(c) ULPGC(c) ULPGC 1717

SAVE_ALLSAVE_ALL

85 #define SAVE_ALL \85 #define SAVE_ALL \86 cld; \86 cld; \87 pushl %es; \87 pushl %es; \88 pushl %ds; \88 pushl %ds; \89 pushl %eax; \89 pushl %eax; \90 pushl %ebp; \90 pushl %ebp; \91 pushl %edi; \91 pushl %edi; \92 pushl %esi; \92 pushl %esi; \93 pushl %edx; \93 pushl %edx; \94 pushl %ecx; \94 pushl %ecx; \95 pushl %ebx; \95 pushl %ebx; \96 movl $(__KERNEL_DS),%edx; \96 movl $(__KERNEL_DS),%edx; \97 movl %dx,%ds; \97 movl %dx,%ds; \98 movl %dx,%es;98 movl %dx,%es;

Page 18: (c) ULPGC1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

(c) ULPGC(c) ULPGC 1818

RESTORE_ALLRESTORE_ALL100 #define RESTORE_ALL \100 #define RESTORE_ALL \101 popl %ebx; \101 popl %ebx; \102 popl %ecx; \102 popl %ecx; \103 popl %edx; \103 popl %edx; \104 popl %esi; \104 popl %esi; \105 popl %edi; \105 popl %edi; \106 popl %ebp; \106 popl %ebp; \107 popl %eax; \107 popl %eax; \108 1: popl %ds; \108 1: popl %ds; \109 2: popl %es; \109 2: popl %es; \110 addl $4,%esp; \110 addl $4,%esp; \111 3: iret; \111 3: iret; \112 .section .fixup,"ax"; \112 .section .fixup,"ax"; \113 4: movl $0,(%esp); \113 4: movl $0,(%esp); \114 jmp 1b; \114 jmp 1b; \115 5: movl $0,(%esp); \115 5: movl $0,(%esp); \116 jmp 2b; \116 jmp 2b; \117 6: pushl %ss; \117 6: pushl %ss; \118 popl %ds; \118 popl %ds; \119 pushl %ss; \119 pushl %ss; \120 popl %es; \120 popl %es; \121 pushl $11; \121 pushl $11; \122 call do_exit; \122 call do_exit; \123 .previous; \123 .previous; \124 .section __ex_table,"a"; \124 .section __ex_table,"a"; \125 .align 4; \125 .align 4; \126 .long 1b,4b; \126 .long 1b,4b; \127 .long 2b,5b; \127 .long 2b,5b; \128 .long 3b,6b; \128 .long 3b,6b; \129 .previous129 .previous

Page 19: (c) ULPGC1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

(c) ULPGC(c) ULPGC 1919

SYS_CALL_TABLE 1SYS_CALL_TABLE 1373 ENTRY(sys_call_table)373 ENTRY(sys_call_table)374 .long SYMBOL_NAME(sys_ni_syscall) /* 0 */374 .long SYMBOL_NAME(sys_ni_syscall) /* 0 */375 .long SYMBOL_NAME(sys_exit)375 .long SYMBOL_NAME(sys_exit)376 .long SYMBOL_NAME(sys_fork)376 .long SYMBOL_NAME(sys_fork)377 .long SYMBOL_NAME(sys_read)377 .long SYMBOL_NAME(sys_read)378 .long SYMBOL_NAME(sys_write)378 .long SYMBOL_NAME(sys_write)379 .long SYMBOL_NAME(sys_open) /* 5 */379 .long SYMBOL_NAME(sys_open) /* 5 */380 .long SYMBOL_NAME(sys_close)380 .long SYMBOL_NAME(sys_close)381 .long SYMBOL_NAME(sys_waitpid)381 .long SYMBOL_NAME(sys_waitpid)382 .long SYMBOL_NAME(sys_creat)382 .long SYMBOL_NAME(sys_creat)383 .long SYMBOL_NAME(sys_link)383 .long SYMBOL_NAME(sys_link)384 .long SYMBOL_NAME(sys_unlink) /* 10 */384 .long SYMBOL_NAME(sys_unlink) /* 10 */385 .long SYMBOL_NAME(sys_execve)385 .long SYMBOL_NAME(sys_execve)386 .long SYMBOL_NAME(sys_chdir)386 .long SYMBOL_NAME(sys_chdir)387 .long SYMBOL_NAME(sys_time)387 .long SYMBOL_NAME(sys_time)388 .long SYMBOL_NAME(sys_mknod)388 .long SYMBOL_NAME(sys_mknod)389 .long SYMBOL_NAME(sys_chmod) /* 15 */389 .long SYMBOL_NAME(sys_chmod) /* 15 */390 .long SYMBOL_NAME(sys_lchown)390 .long SYMBOL_NAME(sys_lchown)391 .long SYMBOL_NAME(sys_ni_syscall) /*old break holder*/391 .long SYMBOL_NAME(sys_ni_syscall) /*old break holder*/392 .long SYMBOL_NAME(sys_stat)392 .long SYMBOL_NAME(sys_stat)393 .long SYMBOL_NAME(sys_lseek)393 .long SYMBOL_NAME(sys_lseek)394 .long SYMBOL_NAME(sys_getpid) /* 20 */394 .long SYMBOL_NAME(sys_getpid) /* 20 */395 .long SYMBOL_NAME(sys_mount)395 .long SYMBOL_NAME(sys_mount)396 .long SYMBOL_NAME(sys_oldumount)396 .long SYMBOL_NAME(sys_oldumount)397 .long SYMBOL_NAME(sys_setuid)397 .long SYMBOL_NAME(sys_setuid)398 .long SYMBOL_NAME(sys_getuid)398 .long SYMBOL_NAME(sys_getuid)......

Page 20: (c) ULPGC1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

(c) ULPGC(c) ULPGC 2020

SYS_CALL_TABLE 2SYS_CALL_TABLE 2......539 .long SYMBOL_NAME(sys_getresuid) /* 165 */539 .long SYMBOL_NAME(sys_getresuid) /* 165 */540 .long SYMBOL_NAME(sys_vm86)540 .long SYMBOL_NAME(sys_vm86)541 .long SYMBOL_NAME(sys_query_module)541 .long SYMBOL_NAME(sys_query_module)542 .long SYMBOL_NAME(sys_poll)542 .long SYMBOL_NAME(sys_poll)543 .long SYMBOL_NAME(sys_nfsservctl)543 .long SYMBOL_NAME(sys_nfsservctl)544 .long SYMBOL_NAME(sys_setresgid) /* 170 */544 .long SYMBOL_NAME(sys_setresgid) /* 170 */545 .long SYMBOL_NAME(sys_getresgid)545 .long SYMBOL_NAME(sys_getresgid)546 .long SYMBOL_NAME(sys_prctl)546 .long SYMBOL_NAME(sys_prctl)547 .long SYMBOL_NAME(sys_rt_sigreturn)547 .long SYMBOL_NAME(sys_rt_sigreturn)548 .long SYMBOL_NAME(sys_rt_sigaction)548 .long SYMBOL_NAME(sys_rt_sigaction)549 .long SYMBOL_NAME(sys_rt_sigprocmask) /* 175 */549 .long SYMBOL_NAME(sys_rt_sigprocmask) /* 175 */550 .long SYMBOL_NAME(sys_rt_sigpending)550 .long SYMBOL_NAME(sys_rt_sigpending)551 .long SYMBOL_NAME(sys_rt_sigtimedwait)551 .long SYMBOL_NAME(sys_rt_sigtimedwait)552 .long SYMBOL_NAME(sys_rt_sigqueueinfo)552 .long SYMBOL_NAME(sys_rt_sigqueueinfo)553 .long SYMBOL_NAME(sys_rt_sigsuspend)553 .long SYMBOL_NAME(sys_rt_sigsuspend)554 .long SYMBOL_NAME(sys_pread) /* 180 */554 .long SYMBOL_NAME(sys_pread) /* 180 */555 .long SYMBOL_NAME(sys_pwrite)555 .long SYMBOL_NAME(sys_pwrite)556 .long SYMBOL_NAME(sys_chown)556 .long SYMBOL_NAME(sys_chown)557 .long SYMBOL_NAME(sys_getcwd)557 .long SYMBOL_NAME(sys_getcwd)558 .long SYMBOL_NAME(sys_capget)558 .long SYMBOL_NAME(sys_capget)559 .long SYMBOL_NAME(sys_capset) /* 185 */559 .long SYMBOL_NAME(sys_capset) /* 185 */560 .long SYMBOL_NAME(sys_sigaltstack)560 .long SYMBOL_NAME(sys_sigaltstack)561 .long SYMBOL_NAME(sys_sendfile)561 .long SYMBOL_NAME(sys_sendfile)562 .long SYMBOL_NAME(sys_ni_syscall) /* streams1 */562 .long SYMBOL_NAME(sys_ni_syscall) /* streams1 */563 .long SYMBOL_NAME(sys_ni_syscall) /* streams2 */563 .long SYMBOL_NAME(sys_ni_syscall) /* streams2 */564 .long SYMBOL_NAME(sys_vfork) /* 190 */564 .long SYMBOL_NAME(sys_vfork) /* 190 */565 565

Page 21: (c) ULPGC1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

(c) ULPGC(c) ULPGC 2121

Icall7, versión para iBCS2 (1) Icall7, versión para iBCS2 (1)

145: lcall7 almacena el puntero de la tarea actual en el registro EBX, similar a system_call.

136: las primeras líneas arreglan la pila de la CPU

135 ENTRY(lcall7)135 ENTRY(lcall7)

136 pushfl # We get a different stack layout with 136 pushfl # We get a different stack layout with callcall

137 pushl %eax # gates, which has to be cleaned up 137 pushl %eax # gates, which has to be cleaned up later..later..

138 SAVE_ALL138 SAVE_ALL

139 movl EIP(%esp),%eax # this is eflags, not eip..139 movl EIP(%esp),%eax # this is eflags, not eip..140 movl CS(%esp),%edx # this is eip..140 movl CS(%esp),%edx # this is eip..141 movl EFLAGS(%esp),%ecx # and this is cs..141 movl EFLAGS(%esp),%ecx # and this is cs..142 movl %eax,EFLAGS(%esp) #142 movl %eax,EFLAGS(%esp) #143 movl %edx,EIP(%esp) # move to their "normal" 143 movl %edx,EIP(%esp) # move to their "normal"

placesplaces144 movl %ecx,CS(%esp) #144 movl %ecx,CS(%esp) #

145 movl %esp,%ebx145 movl %esp,%ebx

Page 22: (c) ULPGC1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

(c) ULPGC(c) ULPGC 2222

Icall7 (2)Icall7 (2)

152: Salta a la etiqueta ret_from_syscall (línea 184) dentro de sys_call para retornar

148: Obtiene el puntero a la tarea actual exec_domain, usa ese campo para encontrar un puntero al propio manejador lcall7 y luego llamar al manejador.

146 pushl %ebx146 pushl %ebx

147 andl $-8192,%ebx # GET_CURRENT147 andl $-8192,%ebx # GET_CURRENT

148 movl exec_domain(%ebx),%edx # Get 148 movl exec_domain(%ebx),%edx # Get the execution domainthe execution domain

149 movl 4(%edx),%edx # Get lcall7 149 movl 4(%edx),%edx # Get lcall7 handler for domainhandler for domain

150 call *%edx150 call *%edx151 popl %eax151 popl %eax

152 jmp ret_from_sys_call152 jmp ret_from_sys_call

Page 23: (c) ULPGC1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

(c) ULPGC(c) ULPGC 2323

Excepciones (1)Excepciones (1)251 ENTRY(divide_error)251 ENTRY(divide_error)252 pushl $0 # no error code252 pushl $0 # no error code253 pushl $ 253 pushl $

SYMBOL_NAME(do_divide_error)SYMBOL_NAME(do_divide_error)254 ALIGN254 ALIGN255 error_code:255 error_code:256 pushl %ds256 pushl %ds257 pushl %eax257 pushl %eax258 xorl %eax,%eax258 xorl %eax,%eax259 pushl %ebp259 pushl %ebp260 pushl %edi260 pushl %edi261 pushl %esi261 pushl %esi262 pushl %edx262 pushl %edx263 decl %eax # eax = -1263 decl %eax # eax = -1264 pushl %ecx264 pushl %ecx265 pushl %ebx265 pushl %ebx266 cld266 cld

Page 24: (c) ULPGC1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

(c) ULPGC(c) ULPGC 2424

Excepciones (2)Excepciones (2)267 movl %es,%cx267 movl %es,%cx

268 xchgl %eax, ORIG_EAX(%esp) # orig_eax (get error code.)268 xchgl %eax, ORIG_EAX(%esp) # orig_eax (get error code.)

269 movl %esp,%edx269 movl %esp,%edx

270 xchgl %ecx, ES(%esp) # get the addr and save es.270 xchgl %ecx, ES(%esp) # get the addr and save es.

271 pushl %eax # push the error code271 pushl %eax # push the error code

272 pushl %edx272 pushl %edx

273 movl $(__KERNEL_DS),%edx273 movl $(__KERNEL_DS),%edx

274 movl %dx,%ds274 movl %dx,%ds

275 movl %dx,%es275 movl %dx,%es

276 GET_CURRENT(%ebx)276 GET_CURRENT(%ebx)

277 call *%ecx277 call *%ecx

278 addl $8,%esp278 addl $8,%esp

279 jmp ret_from_exception279 jmp ret_from_exception

Page 25: (c) ULPGC1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

(c) ULPGC(c) ULPGC 2525

Excepciones (3)Excepciones (3)

281 ENTRY(coprocessor_error)281 ENTRY(coprocessor_error)282 pushl $0282 pushl $0283 pushl $ SYMBOL_NAME(do_coprocessor_error)283 pushl $ SYMBOL_NAME(do_coprocessor_error)284 jmp error_code284 jmp error_code285 285 286 ENTRY(device_not_available)286 ENTRY(device_not_available)287 pushl $-1 # mark this as an int287 pushl $-1 # mark this as an int288 SAVE_ALL288 SAVE_ALL289 GET_CURRENT(%ebx)289 GET_CURRENT(%ebx)290 pushl $ret_from_exception290 pushl $ret_from_exception291 movl %cr0,%eax291 movl %cr0,%eax292 testl $0x4,%eax # EM (math emulation bit)292 testl $0x4,%eax # EM (math emulation bit)293 je SYMBOL_NAME(math_state_restore)293 je SYMBOL_NAME(math_state_restore)294 pushl $0 # temp storage for ORIG_EIP294 pushl $0 # temp storage for ORIG_EIP295 call SYMBOL_NAME(math_emulate)295 call SYMBOL_NAME(math_emulate)296 addl $4,%esp296 addl $4,%esp297 ret297 ret

Page 26: (c) ULPGC1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

(c) ULPGC(c) ULPGC 2626

Excepciones (4)Excepciones (4)

299 ENTRY(debug)299 ENTRY(debug)300 pushl $0300 pushl $0301 pushl $ SYMBOL_NAME(do_debug)301 pushl $ SYMBOL_NAME(do_debug)302 jmp error_code302 jmp error_code303 303 304 ENTRY(nmi)304 ENTRY(nmi)305 pushl $0305 pushl $0306 pushl $ SYMBOL_NAME(do_nmi)306 pushl $ SYMBOL_NAME(do_nmi)307 jmp error_code307 jmp error_code308 308 309 ENTRY(int3)309 ENTRY(int3)310 pushl $0310 pushl $0311 pushl $ SYMBOL_NAME(do_int3)311 pushl $ SYMBOL_NAME(do_int3)312 jmp error_code312 jmp error_code

Page 27: (c) ULPGC1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

(c) ULPGC(c) ULPGC 2727

Excepciones (5)Excepciones (5)314 ENTRY(overflow)314 ENTRY(overflow)315 pushl $0315 pushl $0316 pushl $ SYMBOL_NAME(do_overflow)316 pushl $ SYMBOL_NAME(do_overflow)317 jmp error_code317 jmp error_code318 318 319 ENTRY(bounds)319 ENTRY(bounds)320 pushl $0320 pushl $0321 pushl $ SYMBOL_NAME(do_bounds)321 pushl $ SYMBOL_NAME(do_bounds)322 jmp error_code322 jmp error_code323 323 324 ENTRY(invalid_op)324 ENTRY(invalid_op)325 pushl $0325 pushl $0326 pushl $ SYMBOL_NAME(do_invalid_op)326 pushl $ SYMBOL_NAME(do_invalid_op)327 jmp error_code327 jmp error_code328 328 329 ENTRY(coprocessor_segment_overrun)329 ENTRY(coprocessor_segment_overrun)330 pushl $0330 pushl $0331 pushl $ SYMBOL_NAME(do_coprocessor_segment_overrun)331 pushl $ SYMBOL_NAME(do_coprocessor_segment_overrun)332 jmp error_code332 jmp error_code

Page 28: (c) ULPGC1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

(c) ULPGC(c) ULPGC 2828

Excepciones (6)Excepciones (6)334 ENTRY(reserved)334 ENTRY(reserved)335 pushl $0335 pushl $0336 pushl $ SYMBOL_NAME(do_reserved)336 pushl $ SYMBOL_NAME(do_reserved)337 jmp error_code337 jmp error_code338 338 339 ENTRY(double_fault)339 ENTRY(double_fault)340 pushl $ SYMBOL_NAME(do_double_fault)340 pushl $ SYMBOL_NAME(do_double_fault)341 jmp error_code341 jmp error_code342 342 343 ENTRY(invalid_TSS)343 ENTRY(invalid_TSS)344 pushl $ SYMBOL_NAME(do_invalid_TSS)344 pushl $ SYMBOL_NAME(do_invalid_TSS)345 jmp error_code345 jmp error_code346 346 347 ENTRY(segment_not_present)347 ENTRY(segment_not_present)348 pushl $ SYMBOL_NAME(do_segment_not_present)348 pushl $ SYMBOL_NAME(do_segment_not_present)349 jmp error_code349 jmp error_code

Page 29: (c) ULPGC1 INTERRUPCIONES SOFTWARE S.CANDELA © Universidad de Las Palmas de Gran Canaria

(c) ULPGC(c) ULPGC 2929

Excepciones (7)Excepciones (7)

351 ENTRY(stack_segment)351 ENTRY(stack_segment)

352 pushl $ SYMBOL_NAME(do_stack_segment)352 pushl $ SYMBOL_NAME(do_stack_segment)

353 jmp error_code353 jmp error_code

354 354

355 ENTRY(general_protection)355 ENTRY(general_protection)

356 pushl $ SYMBOL_NAME(do_general_protection)356 pushl $ SYMBOL_NAME(do_general_protection)

357 jmp error_code357 jmp error_code

358 358

359 ENTRY(page_fault)359 ENTRY(page_fault)

360 pushl $ SYMBOL_NAME(do_page_fault)360 pushl $ SYMBOL_NAME(do_page_fault)

361 jmp error_code361 jmp error_code