Creating Layouts with Magic


Magic is an interactive system for creating and modifying VLSI circuit layouts. With Magic, you use a color graphics display and a mouse or graphics tablet to design basic cells and to combine them hierarchically into larger structures. Magic also has built-in knowledge of layout rules; as you are editing, it continuously checks for rule violations.

Tutorial to read first: Magic Tutorial #1: Getting Started


1. Starting Magic

Magic is started by the shell command:

You could type any file name for file, and Magic would start editing that file. If a file with this name does not exist, Magic will create it.



2. A Quick Tour of the User Interface

2.1. The Graphics Window

After starting Magic, a the Graphics Window will appear in the upper left quadrant of your screen. The window is an ordinary X window, and can be moved and resized using the window manager. This is the window where you will draw your layout. To work in this window, move the cursor to the window and click the left mouse button. This will change your focus.


2.2. The Text Window

There is also a Text Window which should be normally positioned under the Graphics Window. This is the same Shell window from which you started Magic. All commands you want to invoke should be typed in this window. You will also have all the error messages displayed in this window. Changing the Tool is also displayed there. When writing in the Text Window, you should always focus on the Graphics Window you are currently editing.


2.3. Commands and Macros

When creating or editing a layout you can use a number of commands, which are invoked by typing a colon (":") or semi-colon (";") in the Text Window, followed by a line containing a command name and zero or more parameters. One of the possible commands you can use after starting Magic is to load a cell. To do this first point to the interior of the layout window and then type:

If no name is given, a new unnamed cell is loaded. To quit Magic simply type ":quit".

You can also invoke commands in Magic by typing single keystrokes, called macros, on the keyboard. Some of the most frequently used macros are: c(copy), d (delete), u (undo), o (openwindow), v (view), z (zoom), s (select), etc.

For a full list of commands and macros in Magic see Synopsys of Magic commands


2.4. Scaleable design, Lambda and the Grid

Magic uses what is called scaleable or "lambda-based" design. In scaleable design, layout items are aligned to a grid which represents a basic unit of spacing. For a particular technology, lambda represents an actual distance (e.g., lambda = 1.6 m). However all design is done in terms of lambda. The Graphics Window contains a layout surface on which items can be placed with a resolution of one lambda.

Magic has a grid which can be set to an arbitrary multiple of lambda. The default value of this grid is one lambda by one lambda. This grid can be displayed using the ":grid" command or the "g" macro.


2.5. The Box and the Cursor

Two things, called the box and the cursor, are used to select things on the Graphics Window. As you move the mouse, the cursor moves on the screen. The shape of the cursor indicates which of the four tools is being used currently. Pressing the space bar toggles between the 4 tools available:

For the time being we will concentrate on the box tool. The purpose of the box tool is to specify a rectangular area of the layout for editing.

The left and right mouse buttons are used to position the box. If you press the left mouse button and then release it, the box will move so that its lower left corner is at the cursor position. If you press and release the right mouse button, the upper right corner of the box will move to the cursor position, but the lower left corner will not change. These two buttons are enough to position the box anywhere on the screen.

Common Pitfalls:


3. Cells, Paint and Layers

In Magic, a circuit layout is a hierarchical collection of cells. Each cell contains three things: colored shapes, called paint, that define the circuit's structure; textual labels attached to the paint; and subcells, which are instances of other cells.

3.1. The Paint and Erase commands

The two basic layout operations are painting and erasing. They can be invoked using the ":paint" and ":erase" commands, or using the mouse buttons.

In each of these commands layers is one or more names separated by commas (you can also use spaces for separators, but only if you enclose the entire list in double-quotes). In Magic there is one paint layer for each kind of conducting material (polysilicon, ndiffusion, metal1, etc.), plus one additional paint layer for each kind of transistor (n-transistor, p-transistor, etc.), and, finally, one further paint layer for each kind of contact (pcontact, ndcontact, m2contact, etc.).

The easiest way to paint and erase is with mouse buttons. To paint, position the box over the area you'd like to paint, then move the cursor over a color and click the middle mouse button. To erase everything in an area, place the box over the area, move the cursor over a blank spot, and click the middle mouse button. (While you are painting, white dots may occasionally appear and disappear. These are design rule violations and will be explained in Design Rule Checking).


3.2. Paint and Layers

Name of layer

What the layer represents

p or poly or polysilicon or red polysilicon
green or ndiff or ndiffusion n-diffusion
brown or pdiff or pdiffusion p-diffusion
blue or metal1 or m1 metal layer 1
purple or metal2 or m2 metal layer 2
pw or pwell p-tub
nw or nwell n-tub
nnc or nwcontact tub tie for n-tub
ppc or pwcontact tub tie for p-tub
ndc or ndcontact metal1 to n-diffusion contact
pdc or pdcontact metal1 to p-diffusion contact
polycontact metal1 to poly contact
m2contact metal2 to metal1 contact
nfet or ntransistor n-transistor
pfet or ptransistor p-transistor

Some layers are created by crossing two layers. For example drawing over poly and ndiff (or vice versa) will produce an n-transistor. Contacts are made by placing the box over the region of the contact (e.g. ndiff and metal1) and type ":paint ndc".

For a complete list of layers use the Magic command ":layers".

Exercise 1:

Draw a 2 lambda poly line and a 3 lambda diffusion that cross to form a transistor

Example : Schematic and a layout for a NAND gate.

Tutorials to read first: Magic Tutorial #2.2: Painting and Erasing.

Exercise 2: Draw the layout for a NOR gate using the schematic.




3.3. Working with the Selection

Once you have painted a piece of layout, there are several commands you can invoke to modify the layout. Many of them are based on the selection: you select one or more pieces of the design, and then perform operations such as copying, deletion, and rotation on the selected things. To do the selection type s, which is a macro for :select. If you type s several times without moving the cursor, each command selects a slightly larger piece of material. The macro S (short for :select more) is just like s except that it adds on to the selection, rather than replacing it.

You can also select material by area: place the box around the material you'd like to select and type a (:select area). This will select the material underneath the box. You can also use the macro A to add material to the selection by area, and you can use the command

to select only material on certain layers. If you'd like to clear the selection without modifying any of the selected material, you can use the command

or type the macro C.

Tutorials to read: Magic Tutorial #2.4:The Selection, #2.5:Operations on the Selection


3.4. Labels

Labels are pieces of text attached to the paint of a cell. They are used to provide information to other tools that will process the circuit. Most labels are node names: they provide an easy way of referring to nodes in tools such as routers, simulators, and timing analyzers. To put a label first position the cursor on the cell to label and type

Text must be supplied, but the other arguments can be defaulted. Position tells where the text should be displayed, relative to the point of the label. Layer tells which paint layer to attach the label to. All of the selection commands apply to labels as well as paint. Whenever you select paint, the labels attached to that paint will also be selected. To erase a label use the command

Tutorials to read: Magic Tutorial #2.6 and 2.7: Labels and Labeling Conventions.


3.5. Saving your design

To save the cell you are currently editing type

This command will append ".mag" to name and save the cell you are editing in that location. If you don't provide a name, Magic will use the cell's name (plus the .mag extension) as the file name, and it will prompt you for a name if the cell hasn't yet been named.

Important! Save your cells frequently during long editing sessions. Magic doesn't keep checkpoint files, i.e. if the system should crash in the middle of a session, you'll lose all the changes since the last time you wrote out cells.


3.6. Subcells

"Hierarchical structure" means that each cell can contain other cells as components. To select a subcell, place the cursor over the subcell and type f ("find cell"), which is the macro for :select cell. To create a new instance of a cell use

This command will find the file name.mag on disk, read the cell it contains, and create an instance of that cell whit its lower left corner aligned with the lower left corner of the box.

You can switch the edit cell to any cell in the hierarchy by selecting an instance of the definition you'd like to edit, and then typing the command

Tutorials to read: Magic Tutorial #4: Cell Hierarchies

Common Pitfalls:


4. Wiring

To start wiring, first you have to switch to the wiring tool. This is done by pressing the space bar. The cursor will change to arrow shape. There are three basic wiring commands: selecting the wiring material, adding a leg, and adding a contact. The first step in wiring is to pick the material and width to use for wires. This can be done in two ways. The easiest way is to find a piece of material of the right type and width, point to it with the cursor, and click the left mouse button. Magic prints out the material and width that it chose, selects a square of that material and width around the cursor and places the box around the square.

Once you've selected the wiring material, the right button paints legs of a wire. Each leg of a wire must be either horizontal or vertical. You can also force Magic to paint the next leg in a particular direction with the commands

When the wiring tool is active, the middle mouse button places contacts.

Tutorials to read: Magic Tutorial #3: Advanced Painting (Wiring and Plowing).


5. DRC

When you are editing a layout with Magic, the system automatically checks design rules on your behalf. This function is called Design-Rule Checker. Every time you paint or erase, and every time you move a cell or change an array structure, Magic rechecks the area you've changed to make sure you haven't violated any of the layout rules. If you do violate rules, Magic will display little white dots in the vicinity of the violation.

Some of the rules determine the minimum width of the layers: poly should be no less then 2 lambda wide, metal1 - no less than 3 lambda, etc. Other rules specify the minimum separation between layers. For a full list of Magic's design rules see: MOSIS Scalable CMOS Design Rules.

However, Magic provides several commands for you to use to find violations and figure what's wrong in case it isn't obvious.

This is the most often used command. It will print a message in the Text Window specifying the violated rules. (You can also use the macro "y").

Common Pitfalls:

Tutorials to read: Magic Tutorial #6: Design-Rule Checking.


6. Printing the Layout

You can get a printout of a layout using the flea command in the UNIX shell:

This command will submit a print job directly to the printer. You can also get a postscript file for the layout:

generates the file magicfile.ps which you can then send to the printer using the lpr command.


7. Circuit Extraction and creating a Netlist

7.1. How to use the Extractor?

The extractor computes from the layout the information needed to run simulation tools such as IRSIM and Crystal. The information includes the sizes and shapes of transistors, and the connectivity, resistance, and parasitic capacitance of nodes. Both capacitance to subtrate and several kind of internodal coupling capacitances are extracted.

To extract all the edited subcells, from Magic, use the command

Or to extract just the selected (current) cell try

The output will be placed in the file name.

Magic's extractor is both incremental and hierarchical: only part of entire layout must be re-extracted after each change, and the structure of the extracted circuit parallels the structure of the layout being extracted. The extractor produces a separate .ext file for each .mag file in a hierarchical design.

To extract only those cells that have changed since they were extracted, use

The extractor looks for a .ext file for every cell in the tree that descends from the cell root. The .ext file is searched for in the same directory that contains the cell's .mag file. Any cells that have been modified since they were last extracted, and all of their parents are re-extracted. Cells having no .ext files are also re-extracted.


7.2. Creating a Netlist

To use the files produced by Magic's extractor for simulation or timing analysis, you will most likely need to convert them to a flattened format, such as sim (5). One of the programs for flattening is ext2sim. To run it you should exit magic and type

where name is the name of the root.ext file produced by the Magic's extractor. The file root.ext and all the files it references are recursively flattened. The result is a single, flat representation of the circuit that is written to the file root.sim, a list of node aliases written to the file root.al, and a list of locations of all nodenames in CIF format, suitable for plotting, to the file root.nodes. By using the switches -R -C the extracted resistances and capacitances are suppressed during flattening.

For a full list of options see ext2sim manual page.


7.3. The SIM file syntax

The SIM file syntax is MOS-specific. SIM files have no hierarchy; they are simply a list of devices, capacitors and connections. Here are the file entities, recognized by Gemini (used for LVS):

Scale is an integer scale factor that is used with the -w option of Gemini. Transistor lengths and widths in this file are multiplied by this factor and the result is in centimicrons. Tech is ignored. Fmt selects a format type from the set {MIT, UCB, LBL}. The format type is required if the -w option is selected. If no format type is specified, no property information is assumed on the transistor lines. If the entire line is absent then MIT format is assumed.

The arguments gate, source and drain are required. The argument substrate is required only if the LBL format type was selected. The other arguments are all integers denoting distance in centimicrons and are scaled by the unit scale factor.

For further information on the SIM file format, see the man page entry for SIM (section 5, file formats).