Remote gdb needs two windows: do gdb commands in gdb window, program input in Tutor window:
See $cs644/mon-worker-debug.txt.
![]() |
· API itself the same for: Xinu / Linux / UNIX(Solaris)
· implementation of the function must vary 2 ways: Xinu(semaphore) vs. Linux/Solaris(POSIX sem)
o
![]() |
o proper way to do platform-dependent code in C
Platform-independent getline function based on:
fgets(buf,
maxbuf, CONSOLE) ---- XINU
fgets(buf, maxbuf, stdio) ---- UNIX*
void getline(char *buf, int maxbuf)
{
#ifdef XINU
fgets(buf, maxbuf, CONSOLE);
#else
…..
}
getline.h: C prototype for getline
void getline(char *buf, int maxbuf); à API for the service(platform-independent)
C lib: many platform independent for Xinu/UNIX*
eg. putchar(int c), printf(……), sleep(int nsec)
lock.c: contains platform dependent code
lock.h: portable, no “ifdef”
test program: test1.c, test2.c ==> create processes: platform dependent
worker(platform independent) for: executed by worker processor
-- use lock service
-- sleep
-- printf
{syscall}: defines much of the OS capabilities
+ idea of virtual machine, time-sharing
ex. pid = getpid();
I/O hardware generates int: serial port/kerboard/network + timer.
1. Serial port: SAPC CONSOLE(via mtip) is the PC COM2 serial port
The device is a serial interface or UART, capable of generating interrupt signals:
-- data ready interrupt: serial port has a byte ready for reading
-- transmit ready interrupt: serial port can accept another byte for output
CPU: has an interrupt input pin and can be programmed to divert its execution to a level interrupt handling when an interrupt comes in
![]() |
CPU can read/write the device register using a bus cycle, much like it reads/writes memory.
-- i.e. there is an instruction that can do it(maybe same for reading memory, but not on x86)
-- x86 has I/O instructions for this: inb and outb
![]() |
consider as object: actions on register
o load a register: put certain bit values into it
o read a register: determine bit values in register
ð memory = bunch of registers with addresses
Device registers: serial port ---- DATA reg, LSR reg(status), 8 ports in all.
x86 I/O instruction in gnu assembly:
inb %dx, %al ---- get byte from this port into AL register (low 8 bits of EAX)
outb %al, %dx ---- send byte from AL to this port
In both cases, the port number is in DX (low 16 bits of EDX)
16-bit port number means a hard limit of 64K ports on x86. The PC uses only a small fraction of them, at least for the old devices like serial ports, parallel ports, timer, etc.
32 bit Intel registers: EAX, EBX, ECX, EDX, ..., ESP, EIP, EFLAGS
![]() |