Bus Error Article Index for
Bus
Website Links For
Bus
 

Information About

Bus Error




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.

; 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. ---/

  • iptr;


  • cptr is a pointer to a character (the "smallest addressable unit" of the CPU, normally a byte) ---/

  • cptr;


  • malloc() gives us a valid, aligned memory address. put this in cptr ---/

  • )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 ---/

  • cptr;


  • copy cptr into iptr ---/

  • ) cptr;

  • this will cause a bus error - accessing more than 1 byte from an unaligned address ---/

  • iptr;


return 0;
}



HUMOR


The term bus error is also sometimes used
{Link without Title}
to refer to some critical member of a team becoming unavailable
because of catastrophe, as in being "hit by a bus".

From FreeBSD 's Fortune :
'Bus error -- driver executed.'


SEE ALSO