Bus error

Bus error

In computing, a bus error is generally an attempt to access memory that the CPU cannot physically address. Bus errors can also be caused by any general device fault that the computer detects. A bus error rarely means that computer hardware is physically broken - it is normally caused by a bug in a program's source code.

There are two main causes of bus errors:

; non-existent address : The CPU is instructed by software to read or write a specific physical memory address. Accordingly, the CPU sets this physical address on its address bus and requests all other hardware connected to the CPU to respond with the results, if they answer for this specific address. If no other hardware responds, the CPU raises an exception, stating that the requested physical address is unrecognised by the whole computer system. Note that this only covers "physical" memory addresses. When software tries to access an undefined "virtual" memory address, that is generally considered to be a segmentation fault rather than a bus error, though if the MMU is separate, the processor can't tell the difference.

; unaligned access : Most CPUs are "byte-addressable", where each unique memory address refers to an 8-bit byte. Most CPUs can access individual bytes from each memory address, but they generally cannot access larger units (16 bits, 32 bits, 64 bits and so on) without these units being "aligned" to a specific boundary, such as 16 bits (addresses 0, 2, 4 can be accessed, addresses from 1, 3, 5, are unaligned) or 32 bits (0, 4, 8, 12 are aligned, all addresses in-between are unaligned). Attempting to access a value larger than a byte at an unaligned address can cause a bus error.

CPUs generally access data at the full width of their data bus at all times. To address bytes, they access memory at the full width of their data bus, then mask and shift to address the individual byte. This is inefficient, but tolerated as it is an essential feature for most software, especially string-processing. Unlike bytes, larger units can span two aligned addresses and would thus require more than one fetch on the data bus. It is possible for CPUs to support this, but this functionality is rarely required directly at the machine code level, thus CPU designers normally avoid implementing it and instead issue bus errors for unaligned memory access.

Example

This is an example of un-aligned memory access, written in the C programming language.


#include int main (void) { /* iptr is a pointer to an integer, usually 32 or 64 bits in size. It is currently undefined. */ int x, *iptr;

/* cptr is a pointer to a character (the "smallest addressable unit" of the CPU, normally a byte) */ char *cptr;

/* malloc() gives us a valid, aligned memory address. put this in cptr */ cptr = (char*)malloc(33); if (!cptr) return 1;

/* increment cptr by 1. It is now unaligned */ cptr++;

/* it is OK to access individual bytes from unaligned addresses */ x = *cptr;

/* copy cptr into iptr */ iptr = (int *) cptr; /* this will cause a bus error - accessing more than 1 byte from an unaligned address */ x = *iptr;

return 0;}

See also

* Segmentation fault


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать реферат

Look at other dictionaries:

  • Bus CAN — CAN (acrónimo del inglés Controller Area Network) es un protocolo de comunicaciones desarrollado por la firma alemana Robert Bosch GmbH, basado en una topología bus para la transmisión de mensajes en entornos distribuidos. Además ofrece una… …   Wikipedia Español

  • Bus analyzer — A bus analyzer is a computer bus analysis tool, often a combination of hardware and software, used during development of hardware or device drivers for a specific bus, diagnosing bus or device failures, or reverse engineering. A bus analyzer is a …   Wikipedia

  • CAN-Bus — CAN Logo Der CAN Bus (Controller Area Network) ist ein asynchrones, serielles Bussystem und gehört zu den Feldbussen. Um die Kabelbäume (bis zu 2 km pro Fahrzeug) zu reduzieren und dadurch Gewicht zu sparen, wurde der CAN Bus 1983 von Bosch für… …   Deutsch Wikipedia

  • CAN Bus — CAN Logo Der CAN Bus (Controller Area Network) ist ein asynchrones, serielles Bussystem und gehört zu den Feldbussen. Um die Kabelbäume (bis zu 2 km pro Fahrzeug) zu reduzieren und dadurch Gewicht zu sparen, wurde der CAN Bus 1983 von Bosch für… …   Deutsch Wikipedia

  • Can-bus — CAN Logo Der CAN Bus (Controller Area Network) ist ein asynchrones, serielles Bussystem und gehört zu den Feldbussen. Um die Kabelbäume (bis zu 2 km pro Fahrzeug) zu reduzieren und dadurch Gewicht zu sparen, wurde der CAN Bus 1983 von Bosch für… …   Deutsch Wikipedia

  • Newport (Isle of Wight) bus station — For other uses, see Newport station. Newport Bus Station Location Loc …   Wikipedia

  • PCI-Bus — Ein PCI Steckplatz (32 Bit) 64 Bit PCI X Steckplätze. Peripheral Component Interconnect, meist PCI abgekürzt, ist ein Bus Standard zur Verbindung von Peripheriegeräten mit dem …   Deutsch Wikipedia

  • Front side bus — In personal computers, the Front Side Bus (FSB) is the bus that carries data between the CPU and the northbridge.Depending on the processor used, some computers may also have a back side bus which connects the CPU to the cache. This bus and the… …   Wikipedia

  • LIN-Bus — LIN Logo Das Local Interconnect Network (LIN) gehört zu den Feldbussen und wurde speziell für die kostengünstige Kommunikation von intelligenten Sensoren und Aktuatoren in Kraftfahrzeugen entwickelt. Typische Anwendungsbeispiele sind die… …   Deutsch Wikipedia

  • LIN Bus — LIN Logo Das Local Interconnect Network (LIN) gehört zu den Feldbussen und wurde speziell für die kostengünstige Kommunikation von intelligenten Sensoren und Aktuatoren in Kraftfahrzeugen entwickelt. Typische Anwendungsbeispiele sind die… …   Deutsch Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”