Operating System-Class 9-Feb. 23rd

 

Remote gdb needs two windows: do gdb commands in gdb window, program input in Tutor window:

See $cs644/mon-worker-debug.txt.

 

 

 

 

 

 

 

 

 

 


HW2 – portable lock service

·         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

 

Ex. “getline.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 Service

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

 

Finishing topic 1, user level issues

{syscall}: defines much of the OS capabilities

+             idea of virtual machine, time-sharing

 

Process executing over time:

 

 

 

 

 

 


ex. pid = getpid();

syscall that does i/o often has to wait(block)

 

 

 

 

 

 

 

 


Another way to go UàK: an interrupt happens

 

 

 


I/O hardware generates int: serial port/kerboard/network + timer.

Device Interrupts

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

First considering I/O programming without interrupts

 

 

 

 

 

 

 

 

 

 

 

 


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

 

What is a register?

 

 

 

 


                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

 

 

 

 

 

 


See Notes on using C to access hardware registers.