|
|||||||
|
|
|
|||||
|
|
|||||||
Como buen nuevo sistema que debemos aprender, es bueno partir con el ejemplo tipico Hola Mundo, que en este caso va a consistir en crear y compilar un programa escrito en C, que realice una llamada al sistema de NACHOS que nos permita escribir un mensaje en pantalla y salir.
PASOS
1) Crear el archivo code/test/holamundo.c
#include "syscall.h"
int main( )
{
Write("Hola Mundo\n",11,ConsoleOutId);
Exit(0);
}
Tanto la función Write( ) y Exit( ), son llamadas al sistema del NACHOS y tales prototipos de encuentran en el archivo : nachos/code/userprog/debug.h. Es por eso, que debemos hacer el "include" correspondiente para enlazar dichas funcionalidades.
Para compilar el programa holamundo.c (como también todos los programas del directorio test), se debe especificar un conjunto de comandos en el archivo code/test/Makefile, que le permiten al compilador make, crear los archivos objeto y ejecutable.
El archivo code/test/Makefile en su parte inicial, muestra en forma estandar como incluir un nuevo programa a la lista de archivos compilables, pero en en el ejemplo siguiente, se resumen esos pasos para el test/holamundo.c :
:
:
# change this if you create a new test program!
#### MODIFICACION 28/07/2004 01:06 ####
PROGRAMS = halt shell matmult holamundo sort segments console_test console_error file_min file_io
exit10 join_test file_error concurrent
endif
all: $(PROGRAMS)
:
:
halt.o: halt.c ../userprog/syscall.h
$(CC) $(CFLAGS) -c halt.c
halt: halt.o start.o
$(LD) $(LDFLAGS) start.o halt.o -o halt.coff
$(COFF2NOFF) halt.coff halt
#### INICIO MODIFICACION 28/07/2004 : 00:59 AM ####
holamundo.o: holamundo.c ../userprog/syscall.h
$(CC) $(CFLAGS) -c holamundo.c
holamundo: holamundo.o start.o
$(LD) $(LDFLAGS) start.o holamundo.o -o holamundo.coff
$(COFF2NOFF) holamundo.coff holamundo
:
:
2)Guardar los cambios del archivo
3)Ejecutar el comando code/test/make
4)Ejecutar el programa holamundo.
Este comando permitirá ver el mensaje generado y después el cursor se quedará en estado
"muerto" o en otra palabras "pegado", forzando a parar la ejecución interna de NACHOS con el
comando : Ctrl + c.
linux:~/usr/local/nachos/code/test # ./nachos -x holamundo
Hola Mundo
Ya que tenemos listo el holamundo, podemos empezar a ver que es lo que pasa en NACHOS, con respecto a
las llamadas al sistema, el espacio de direcciones, las hebras, etc.
Para ello, vamos a utilizar la opciones de debug descritas en el archivo code/lib/debug.h, que se
muestran a continuación.
Opciones de debug
const char dbgAll = '+'; // todos los mensajes
const char dbgThread = 't'; // threads ( hebras )
const char dbgSynch = 's'; // locks, semaforos, variables de condicion
const char dbgInt = 'i'; // emulacion de interrupciones
const char dbgMach = 'm'; // emulacion de maquina
const char dbgDisk = 'd'; // emulacion de disco
const char dbgFile = 'f'; // sistema de archivos
const char dbgAddr = 'a'; // espacio de direcciones
const char dbgSysCall = 'c'; // llamadas al sistema
const char dbgNet = 'n'; // emulacion de red
Aplicando varias de estas opciones, se tienen los siguientes ejemplos con el programa holamundo
a) Debug en las llamadas al sistema
linux:~/usr/local/nachos/code/test # ./nachos -d c -x holamundo
System Call: Write vaddr=512 length=11 fileID=1
Output console write.
Hola Mundo
System Call: Exit status=0
b) Debug de emulación de la máquina y llamadas al sistema
linux:~/usr/local/nachos/code/test # ./nachos -d c m -x holamundo
Starting program in thread: main, at time: 590
At PC = 0 JAL 80
At PC = 4 SLL r0,r0,0
At PC = 320 ADDIU r29,r29,-24
At PC = 324 SW r31,20(r29)
At PC = 328 SW r30,16(r29)
At PC = 332 JAL 76
At PC = 336 ADDU r30,r29,r0
At PC = 304 JR r0,r31
At PC = 308 SLL r0,r0,0
At PC = 340 LUI r4,0
Executing: LUI r, 0
At PC = 344 ADDIU r4,r4,512
At PC = 348 ADDIU r5,r0,11
At PC = 352 JAL 36
At PC = 356 ADDIU r6,r0,1
At PC = 144 ADDIU r2,r0,8
At PC = 148 SYSCALL
Exception: syscall
System Call: Write vaddr=512 length=11 fileID=1
Output console write.
Hola Mundo
At PC = 152 JR r0,r31
At PC = 156 SLL r0,r0,0
At PC = 360 JAL 8
At PC = 364 ADDU r4,r0,r0
At PC = 32 ADDIU r2,r0,1
At PC = 36 SYSCALL
Exception: syscall
System Call: Exit status=0
c) Debug en el espacio de direcciones
linux:~/usr/local/nachos/code/test # ./nachos -d a -x holamundo
Initializing address space: 13 pages.
code = 400 readonly = 16 init = 0 uninit = 0
Loaded code segment page. VA: 0 bytes: 128
Loaded code segment page. VA: 128 bytes: 128
Loaded code segment page. VA: 256 bytes: 128
Loaded code segment page. VA: 384 bytes: 16
Loaded read-only data segement page. VA: 512 bytes: 16
Reading user buffer to kernel, starting virtual address: 512 ,length 11 bytes.
Hola Mundo
d) Debug en las hebras
linux:~/usr/local/nachos/code/test # ./nachos -d t -x holamundo
Entering main
Forking thread: postal worker f(a): 134622550 0x8077898
Putting thread on ready list: postal worker
Yielding thread: main
Putting thread on ready list: main
Switching from: main to: postal worker
Beginning thread: postal worker
Sleeping thread: postal worker
Switching from: postal worker to: main
Now in thread: main
Yielding thread: main
Yielding thread: main
Yielding thread: main
:
:
Yielding thread: main
Yielding thread: main
Yielding thread: main
HSleeping thread: main
Putting thread on ready list: main
Switching from: main to: main
Now in thread: main
Yielding thread: main
oSleeping thread: main
Putting thread on ready list: main
Switching from: main to: main
Now in thread: main
Yielding thread: main
lSleeping thread: main
Putting thread on ready list: main
:
:
dSleeping thread: main
Putting thread on ready list: main
Switching from: main to: main
Now in thread: main
Yielding thread: main
oSleeping thread: main
Putting thread on ready list: main
Switching from: main to: main
Now in thread: main
Yielding thread: main
Yielding thread: main
Yielding thread: main
:
:
Yielding thread: main
Yielding thread: main
Finishing thread: main
Sleeping thread: main
linux:~/usr/local/nachos/code/test # ./nachos -d i -x holamundo : : Pending interrupts: Interrupt handler timer, scheduled at 37031Interrupt handler console read, scheduled at 37031Interrupt handler network recv, scheduled at 37031 End of pending interrupts Invoking interrupt handler for the timer at time 37031 Scheduling interrupt handler the timer at time = 37051 Scheduling interrupt handler the console read at time = 37051 Scheduling interrupt handler the network recv at time = 37051 Machine idling; checking for interrupts. Time: 37031, interrupts off Pending interrupt counts: timer: 1 disk: 0 console write: 0 console read: 1 network send: 0 network recv: 1 Pending interrupts: Interrupt handler timer, scheduled at 37051Interrupt handler console read, scheduled at 37051Interrupt handler network recv, scheduled at 37051 End of pending interrupts Invoking interrupt handler for the timer at time 37051 Scheduling interrupt handler the timer at time = 37071 Scheduling interrupt handler the console read at time = 37071 Scheduling interrupt handler the network recv at time = 37071 Machine idling; checking for interrupts. Time: 37051, interrupts off Pending interrupt counts: timer: 1 disk: 0 console write: 0 console read: 1 network send: 0 network recv: 1 Pending interrupts: Interrupt handler timer, scheduled at 37071Interrupt handler console read, scheduled at 37071Interrupt handler network recv, scheduled at 37071 End of pending interrupts Invoking interrupt handler for the timer at time 37071 Scheduling interrupt handler the timer at time = 37091 Scheduling interrupt handler the console read at time = 37091 Scheduling interrupt handler the network recv at time = 37091 Machine idling; checking for interrupts. Time: 37071, interrupts off Pending interrupt counts: timer: 1 disk: 0 console write: 0 console read: 1 network send: 0 network recv: 1 : :