# Linux Kernel Module Cheat

##### 24.22.6.1. gem5 `ThreadContext`

As we delve into more details below, we will reach the following conclusion: a `ThreadContext` represents on thread of a CPU with multiple Hardware threads.

We therefore we can have multiple `ThreadContext` for each `BaseCPU`.

`ThreadContext` is what gets passed in syscalls, e.g.:

src/sim/syscall_emul.hh

    template <class OS>
    SyscallReturn
    readFunc(SyscallDesc *desc, ThreadContext *tc,
            int tgt_fd, Addr buf_ptr, int nbytes)

The class hierarchy for `ThreadContext` looks like:

    ThreadContext
      O3ThreadContext
      SimpleThread

where the gem5 MinorCPU also uses `SimpleThread`:

    /** Minor will use the SimpleThread state for now */
    typedef SimpleThread MinorThread;

It is a bit confusing, things would be much clearer if `SimpleThread` was called instead `SimpleThreadContext`!

`readIntReg` and other register access methods are some notable methods implemented in descendants, e.g. `SimpleThread::readIntReg`.

Essentially all methods of the base `ThreadContext` are pure virtual.

- gem5 <code>SimpleThread</code>

- gem5 <code>O3ThreadContext</code>