6
21.1.02 - 1 37-023 Systemprogrammierung ©Alonso/Stricker Programming in Systems (37-023) Programming in Assembler Basics of Operating Systems Models of Computer Architecture Lecturer today: Prof. Thomas M. Stricker Text-/Reference-Books: R.P.Paul: SPARC Architecture... and C Sun SPARC V8 Manual and K&R C Reference Topics of Today: The I/O System and Networks Serial Ports / The 8530 SCC Programming an I/O driver (Interrupts vs. Polling) Eidgenössische Technische Hochschule Zürich 21.1.02 - 2 37-023 Systemprogrammierung ©Alonso/Stricker The I/O System (path from a program to a printer) 21.1.02 - 3 37-023 Systemprogrammierung ©Alonso/Stricker Problem 1 10 print “hello world” 2 printf(“hello world\n”)l 3 writeln(‘hello world’); 4 102 FORMAT(15X,’Hello World’) WRITE(3,102) 5 (print “hello world”) 6 cout << “hello world” << nl; ... 21.1.02 - 4 37-023 Systemprogrammierung ©Alonso/Stricker 20 years ago - 1978 System: Apple II+Dot Matrix Printer 8bit processor - 1MHz Printer in dot matrix technology z.B. Wenger Datentechnik Print Swiss Effort for a driver: 16 Lines of assembly code Restriction: only 96 char US ASCII, 80 char/line one user per printer

The I/O System (path from a program to a printer) · Modern System 2000 System: Sparc Workstation with VPP • 300 MHz Ultra Sparc Prozessor • VPP Spooler with 100 MHz 80586 •

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: The I/O System (path from a program to a printer) · Modern System 2000 System: Sparc Workstation with VPP • 300 MHz Ultra Sparc Prozessor • VPP Spooler with 100 MHz 80586 •

21.1.02 - 1 37-023 Systemprogrammierung ©Alonso/Stricker

Programming in Systems(37-023)

Programming in AssemblerBasics of Operating Systems

Models of Computer Architecture

Lecturer today:

Prof. Thomas M. Stricker

Text-/Reference-Books:

R.P.Paul: SPARC Architecture... and CSun SPARC V8 Manual and K&R C Reference

Topics of Today:

• The I/O System and Networks

• Serial Ports / The 8530 SCC

• Programming an I/O driver(Interrupts vs. Polling)

EidgenössischeTechnische Hochschule

Zürich

21.1.02 - 2 37-023 Systemprogrammierung ©Alonso/Stricker

The I/O System

(path from a program to a printer)

21.1.02 - 3 37-023 Systemprogrammierung ©Alonso/Stricker

Problem

1

10 print “hello world”

2

printf(“hello world\n”)l

3

writeln(‘hello world’);

4

102 FORMAT(15X,’Hello World’)WRITE(3,102)

5

(print “hello world”)

6

cout << “hello world” << nl;

...

21.1.02 - 4 37-023 Systemprogrammierung ©Alonso/Stricker

20 years ago - 1978

System: Apple II+Dot Matrix Printer

• 8bit processor - 1MHz

• Printer in dot matrix technologyz.B. Wenger Datentechnik Print Swiss

Effort for a driver:

• 16 Lines of assembly code

Restriction:

• only 96 char US ASCII, 80 char/line

• one user per printer

Page 2: The I/O System (path from a program to a printer) · Modern System 2000 System: Sparc Workstation with VPP • 300 MHz Ultra Sparc Prozessor • VPP Spooler with 100 MHz 80586 •

21.1.02 - 5 37-023 Systemprogrammierung ©Alonso/Stricker

a printer serial port (9600bit/s)

IO Card in Expansion Slot 2

IO Regs: Contol (0xC0A0), Data (0xC0A1)

1

0400: 48 65 6f DATA .ASCII “Hello “

2

.... .ASCII “World”

3

0D 00 .BYTE 0D 00

4

0420: A4 00 STRT: LDY #00

5

0422: B9 00 04 NXTC: LDA 0400,Y

6

0425: C9 00 CMP #00

7

0427: FO 15 BEQ END

8

0429: 48 PHA

9

0430: AD A0 C0 WAIT: LDA C0A0

10

0433: 20 02 AND #02

11

0435: F0 F9 BEQ WAIT

12

0437: 68 PLA

13

0438: 8D A1 C0 STA C0A1

14

043B: E4 INY

15

043C: D0 E8 BNE NXTC

16

043E: 60 END RTS

21.1.02 - 6 37-023 Systemprogrammierung ©Alonso/Stricker

Modern System 2000

System: Sparc Workstation with VPP

• 300 MHz Ultra Sparc Prozessor

• VPP Spooler with 100 MHz 80586

• Laserprinter HP 8100with 200 MHz AMD 29000 processor

• 10/100 MBit/s Ethernet

Effort required:

• ca 500’000 lines of assembly code

Enhanced functionality:

• multiple users (spooling)

• printer control (duplex, white etc...)

• prints in cyrillic, chinese and graphicsnot just “hello world” in dot matrix.

• standardized page description language (Postscript)

21.1.02 - 7 37-023 Systemprogrammierung ©Alonso/Stricker

The Software System

Text

proc

esso

r

Pos

tscr

ipt D

rvr

Libr

arie

s “s

tdio

File

syst

em

VP

P P

rogr

amm

File

syst

em

TC

P/IP

le0(

) E

ther

net

Ultr

a S

PAR

C

File

syst

em

TC

P/IP

le0(

) E

ther

net

VP

P S

pool

er

Pos

tscr

ipt E

ng.

TC

P/IP

le0(

) E

ther

net

Ras

ter

Imag

e P.

Dru

ckw

erk

21.1.02 - 8 37-023 Systemprogrammierung ©Alonso/Stricker

Role of Postscript

hello world\n will look like:

%%Creator: nenscript v1.13++ 24-November-1992%%For: tomstr%%CreationDate: Sun Jan 4 19:06:54 1998%%DocumentFonts: Courier Courier-Bold%%Pages: (atend)/newcodes % foreign character encodings[160/space 161/exclamdown 162/cent 163/sterling 164/currency165/yen 166/brokenbar 167/section 168/dieresis 169/copyright170/ordfeminine 171/guillemotleft 172/logicalnot 173/hyphen 174/registered175/macron 176/degree....../EndPage {showpage SavedPage restore } def%%EndProlog%%Page: 1 1(1) (stdin) StartPage(hello world) 78700 2500 TEndPage%%Trailer%%Pages: 1

Nicht von Interesse in dieser Vorlesung!

Page 3: The I/O System (path from a program to a printer) · Modern System 2000 System: Sparc Workstation with VPP • 300 MHz Ultra Sparc Prozessor • VPP Spooler with 100 MHz 80586 •

21.1.02 - 9 37-023 Systemprogrammierung ©Alonso/Stricker

VPP - Spooler

• Much too complex for a single printer...

• We rather use the queuing system of the unix workstation:

% a.out | lpr

Ethernet

• Was far too expesive for printer in the past - today cheap $50 for 100 MBit/s.

• Very popular for high-end printers, other periferials (Scanner, NASDs) - maybe!.

Standard on old systems:

• Serial ports• Point to point links• Up to 64 kbit/s• 3 or 5 wires

• People in the WinTel world love 12 wires and use parallel port.

21.1.02 - 10 37-023 Systemprogrammierung ©Alonso/Stricker

Simplified System

UN

IX P

rogr

am

File

syst

em

/dev

/ttya

Ser

ial d

river

Ultr

a S

PAR

C

Line

Prin

ter

Ras

ter

Imag

e P.

Dru

ckw

erk

Ser

ial d

river

Dru

cker

Ben

utze

rA

dres

srau

mS

yste

mA

dres

srau

m

Em

ulat

or

21.1.02 - 11 37-023 Systemprogrammierung ©Alonso/Stricker

Der 8530 SCC

21.1.02 - 12 37-023 Systemprogrammierung ©Alonso/Stricker

[A]Synchronous Serial Links(twisted pair V24, RS232, RS485)

Page 4: The I/O System (path from a program to a printer) · Modern System 2000 System: Sparc Workstation with VPP • 300 MHz Ultra Sparc Prozessor • VPP Spooler with 100 MHz 80586 •

21.1.02 - 13 37-023 Systemprogrammierung ©Alonso/Stricker

Networks

Asynchron Characters

HDLC Frame

21.1.02 - 14 37-023 Systemprogrammierung ©Alonso/Stricker

LocalTalk

21.1.02 - 15 37-023 Systemprogrammierung ©Alonso/Stricker

Network Media

21.1.02 - 16 37-023 Systemprogrammierung ©Alonso/Stricker

AppleTalk Low Level Protocol

Page 5: The I/O System (path from a program to a printer) · Modern System 2000 System: Sparc Workstation with VPP • 300 MHz Ultra Sparc Prozessor • VPP Spooler with 100 MHz 80586 •

21.1.02 - 17 37-023 Systemprogrammierung ©Alonso/Stricker

Memory Mapped I/O

• I/O Devices are all mapped into the phy-sical address space of the processor.

• Video RAM (Bitmaps)

• Keyboard/mouse ports

• Control, status + data FIFO queuesof the serial lines

• Control, status + data FIFO queuesof the SCSI and IDE interfaces

• Control, status + data buffer RAMof the ethernet interfaces

• Can be mapped into the addressspace of a user program:

• protection? / sharing? / access control?

RAM

I/O

.text.data

.stack

i/o

21.1.02 - 18 37-023 Systemprogrammierung ©Alonso/Stricker

Memory Management

Same principle like files in unix:

%ls -l

rwxr.x..x 345532 programma

/dev/kmem file

21.1.02 - 19 37-023 Systemprogrammierung ©Alonso/Stricker

Programmed I/O (polling)

• Map of device status to a storage loca-tion.

• Continous polling of statusbits

• Deposit and fetch of the data at a parti-cular memory address

• Concept of a FIFO memory cell

Example: simple console terminal

Two I/O registers with read/write

• Poll status on read - command on write

• Input of keyboard data on readOutput to console data on write

Netload, store

r w rstirqenerrrdy

r d6d7 d4d5 d2d3 d0d1 w d6d7 d4d5 d2d3 d0d1

21.1.02 - 20 37-023 Systemprogrammierung ©Alonso/Stricker

Driver Code (Common Defs)

! crt device locationcrt = 0xffff0000 ! fictitious crt device

! crt registers data = 0 ! data registerstatus = 4 ! status register

! status register bitscrt_ready = 0x80 ! readycrt_error = 0x40 ! errorcrt_intr = 0x20 ! interruptcrt_reset = 0xl ! reset device

! registers assignments in programcrt_r = 12 !%12 crt base registerptr_r = 13 !%13 pointer to stringptr_adr_r = 14 !%14 address of pointerdata_r = 15 !%15 datastatus_r = 16 !%16 status

.dataouttxt:

.asciz "the quick brown fox jumps...\n"ptr_m:

.word outtxt

Page 6: The I/O System (path from a program to a printer) · Modern System 2000 System: Sparc Workstation with VPP • 300 MHz Ultra Sparc Prozessor • VPP Spooler with 100 MHz 80586 •

21.1.02 - 21 37-023 Systemprogrammierung ©Alonso/Stricker

Driver Code (with polling)

.text

main:

set ptr_m,%ptr_adr_r

!addr of str pointer

ld [%ptr_adr_r], %ptr_r

!pointer to str

set crt, %crt_r

!addr crt dev struct

mov crt_reset,%status_r

!clr error and int status

stb %status_r,[ %crt_r +status ]

!and thus set ready bit

ldub [ %ptr_r ], %data_r

!output first character

stb %data_r ,[ %crt_r +data ]

next:

inc %ptr_r

!increment pointer

ldub [ %ptr_r ], %data_r

!load byte of data

tst %data_r

!check to see if end string

be done

ldub [ %crt_r +status ],%status_r

!load status

wait:

btst crt_ready,%status_r

!device ready?

be wait

!no loop

ldub [ %crt_r +status ],%status_r

ba next

stb %data_r ,[ %crt_r +data ]

!output next char

done:

mov crt_reset,%status_r

!and reset device

stb %status_r,[ %crt_r +status ]

!clr error/intret

21.1.02 - 22 37-023 Systemprogrammierung ©Alonso/Stricker

Driver Code (with Interrupts)

• Automatic “subroutine call” (trap) when the device status changes.

• Interrupt after the next machine instruc-tion and call to the trap handler.

• Save the entire CPU state and process with handler.

• User spare set of registers (window) for trap handlers.

• Fast reaction / cheap processing.

21.1.02 - 23 37-023 Systemprogrammierung ©Alonso/Stricker

Program with interrupt handler

start: !code to start transmissionset ptr_m,%ptr_adr_r !address of string pointerld [%ptr_adr_r], %ptr_r !pointer to stringset crt, %crt_r !addr. crt device structmov crt_reset,%status_r !clear error and int statusstb %status_r,[ %crt_r +status ] !... set ready bitmov crt_intr, %status_r !enable interrupts stb %status_r,[ %crt_r +status ]ldub [ %ptr_r ], %data_r !output first characterstb %data_r ,[ %crt_r +data ]inc %ptr_r !increment pointerst %ptr_r ,[%ptr_adr_r]ret !and return

next: !interrupt codeset ptr_m,%ptr_adr_r ! pointer addressld [%ptr_adr_r], %ptr_r !pointer to stringldub [ %ptr_r ], %data_r !load byte of datatst %data_r !check to see if end stringbe doneset crt, %crt_r !addr. crt device structstb %data_r ,[ %crt_r +data ] !output next characterinc %ptr_r ! increment pointerst %ptr_r ,[%ptr_adr_r] !return from interrupt

done:clr %ptr_r !just clear pointerst %ptr_r ,[%ptr_adr_r]mov crt_reset, %status_r ! and reset devicestb %status_r,[ %crt_r +status ] !clear error and intreti !return from interrupt

21.1.02 - 24 37-023 Systemprogrammierung ©Alonso/Stricker

Prinziple of a ring buffer

interrupthandler

traphandler

Spe

iche

rber

eich

syscall