AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
trap.c File Reference

aarch64: turning exceptions into the kernel's events (see docs/kernel/interrupts.md). More...

#include <core/system.h>
#include <core/arch.h>
#include <core/panic.h>
#include <cpu/cpu.h>
#include <mm/mm.h>
#include <sys/lock.h>
#include <sys/sched.h>
#include <sys/signal.h>
#include <platform/virt.h>

Go to the source code of this file.

Macros

#define EC(esr)
#define EC_UNKNOWN   0x00
#define EC_FP   0x07
#define EC_SVC64   0x15
#define EC_IABT_LOW   0x20
#define EC_IABT_CUR   0x21
#define EC_PC_ALIGN   0x22
#define EC_DABT_LOW   0x24
#define EC_DABT_CUR   0x25
#define EC_SP_ALIGN   0x26
#define EC_BRK   0x3C
#define ISS_WNR   (1 << 6)
#define ISS_FSC(esr)
#define FSC_PERMISSION   0x0C

Functions

static void dump (struct aarch64_regs *r)
 Prints the saved registers, for a panic.
static int uaccess_fixup (struct aarch64_regs *r)
 Handles a fault in a copy from or to user memory (cpu/uaccess.S): the copy goes on at its fixup, which returns how much wasn't copied.
static void abort (struct aarch64_regs *r, int ec)
 Handles an instruction or data abort: a page fault in the process's memory, or else a SIGSEGV, a failed copy, or a panic.
static void sync_dispatch (struct aarch64_regs *r)
 Handles a synchronous exception, by its class.
void aarch64_sync (struct aarch64_regs *r)
 Handles a synchronous exception (a system call, a fault), which cpu/vectors.S calls.
void aarch64_preempt (void)
 Switches away from this CPU's running thread, which stays ready, to the next ready thread.
void aarch64_irq (struct aarch64_regs *r)
 Handles an interrupt, which cpu/vectors.S calls.
void aarch64_bad (struct aarch64_regs *r)
 Panics on an exception that the vectors don't handle (an FIQ, an SError, or one from aarch32).

Variables

struct aarch64_regs * aarch64_irq_regs

Detailed Description

aarch64: turning exceptions into the kernel's events (see docs/kernel/interrupts.md).

A synchronous exception is a system call, a page fault (mm_page_fault()), or another fault (a signal, or a panic in the kernel). An interrupt runs its handlers, and the tick may switch threads.

References: [1] - Arm Architecture Reference Manual for A-profile, D1.10 (Exception entry) and ESR_EL1's exception classes (D19.2)

Definition in file trap.c.

Macro Definition Documentation

◆ EC

#define EC ( esr)
Value:
(((esr) >> 26) & 0x3F)

Definition at line 24 of file trap.c.

Referenced by sync_dispatch().

◆ EC_BRK

#define EC_BRK   0x3C

Definition at line 34 of file trap.c.

Referenced by sync_dispatch().

◆ EC_DABT_CUR

#define EC_DABT_CUR   0x25

Definition at line 32 of file trap.c.

Referenced by sync_dispatch().

◆ EC_DABT_LOW

#define EC_DABT_LOW   0x24

Definition at line 31 of file trap.c.

Referenced by sync_dispatch().

◆ EC_FP

#define EC_FP   0x07

Definition at line 26 of file trap.c.

Referenced by sync_dispatch().

◆ EC_IABT_CUR

#define EC_IABT_CUR   0x21

Definition at line 29 of file trap.c.

Referenced by abort(), and sync_dispatch().

◆ EC_IABT_LOW

#define EC_IABT_LOW   0x20

Definition at line 28 of file trap.c.

Referenced by abort(), and sync_dispatch().

◆ EC_PC_ALIGN

#define EC_PC_ALIGN   0x22

Definition at line 30 of file trap.c.

Referenced by sync_dispatch().

◆ EC_SP_ALIGN

#define EC_SP_ALIGN   0x26

Definition at line 33 of file trap.c.

Referenced by sync_dispatch().

◆ EC_SVC64

#define EC_SVC64   0x15

Definition at line 27 of file trap.c.

Referenced by sync_dispatch().

◆ EC_UNKNOWN

#define EC_UNKNOWN   0x00

Definition at line 25 of file trap.c.

◆ FSC_PERMISSION

#define FSC_PERMISSION   0x0C

Definition at line 40 of file trap.c.

Referenced by abort().

◆ ISS_FSC

#define ISS_FSC ( esr)
Value:
((esr) & 0x3F)

Definition at line 39 of file trap.c.

Referenced by abort().

◆ ISS_WNR

#define ISS_WNR   (1 << 6)

Definition at line 38 of file trap.c.

Referenced by abort().

Function Documentation

◆ aarch64_bad()

void aarch64_bad ( struct aarch64_regs * r)

Panics on an exception that the vectors don't handle (an FIQ, an SError, or one from aarch32).

Parameters
rthe registers saved on the kernel stack

Definition at line 243 of file trap.c.

References aarch64_bad(), dump(), panic, and printk().

Referenced by aarch64_bad().

◆ aarch64_irq()

void aarch64_irq ( struct aarch64_regs * r)

Handles an interrupt, which cpu/vectors.S calls.

It runs with the kernel lock, taken if the interrupt came from user mode or the idle loop, and let go of on the way back there.

Parameters
rthe registers saved on the kernel stack

Definition at line 203 of file trap.c.

References aarch64_irq(), aarch64_irq_regs, aarch64_preempt(), aarch64_return_to_user(), curthread, irq_handle(), kernel_enter(), kernel_leave(), REGS_USER, sched_idle_wakeup(), sched_thread_killed(), sched_urgent, and schedule().

Referenced by aarch64_irq().

◆ aarch64_preempt()

void aarch64_preempt ( void )

Switches away from this CPU's running thread, which stays ready, to the next ready thread.

When the thread is chosen again, it goes on from here.

Definition at line 188 of file trap.c.

References aarch64_ctx_save(), aarch64_preempt(), aarch64_thread::ctx, curthread, and schedule().

Referenced by aarch64_irq(), aarch64_preempt(), arch_syscall(), and arch_yield().

◆ aarch64_sync()

void aarch64_sync ( struct aarch64_regs * r)

Handles a synchronous exception (a system call, a fault), which cpu/vectors.S calls.

It runs with the kernel lock, taken if the exception came from user mode.

Parameters
rthe registers saved on the kernel stack

Definition at line 168 of file trap.c.

References aarch64_sync(), curthread, kernel_enter(), kernel_leave(), sched_thread_killed(), and sync_dispatch().

Referenced by aarch64_sync().

◆ abort()

void abort ( struct aarch64_regs * r,
int ec )
static

Handles an instruction or data abort: a page fault in the process's memory, or else a SIGSEGV, a failed copy, or a panic.

Definition at line 71 of file trap.c.

References aarch64_return_to_user(), abort(), curproc, curthread, dump(), EC_IABT_CUR, EC_IABT_LOW, aarch64_regs::esr, FSC_PERMISSION, ISS_FSC, ISS_WNR, mm_page_fault(), panic, PF_EXEC, PF_PRESENT, PF_READ, PF_USER, PF_WRITE, printk(), read_sysreg, REGS_USER, signal_force(), uaccess_fixup(), and USER_STACK.

Referenced by abort(), and sync_dispatch().

◆ dump()

void dump ( struct aarch64_regs * r)
static

Prints the saved registers, for a panic.

Definition at line 43 of file trap.c.

References dump(), aarch64_regs::esr, NULL, aarch64_regs::pc, printk(), aarch64_regs::pstate, read_sysreg, aarch64_regs::sp, and aarch64_regs::x.

Referenced by aarch64_bad(), abort(), dump(), and sync_dispatch().

◆ sync_dispatch()

◆ uaccess_fixup()

int uaccess_fixup ( struct aarch64_regs * r)
static

Handles a fault in a copy from or to user memory (cpu/uaccess.S): the copy goes on at its fixup, which returns how much wasn't copied.

Returns 1 if the fault was such a copy's, 0 if not.

Definition at line 55 of file trap.c.

References aarch64_regs::pc, and uaccess_fixup().

Referenced by abort(), isr_dispatch(), uaccess_fixup(), and uaccess_fixup().

Variable Documentation

◆ aarch64_irq_regs

struct aarch64_regs* aarch64_irq_regs

Definition at line 183 of file trap.c.

Referenced by aarch64_irq(), and sched_tick().