Skip to content

Commit

Permalink
ARC: entry: Add more common chores to EXCEPTION_PROLOGUE
Browse files Browse the repository at this point in the history
THe high level structure of most ARC exception handlers is
 1. save regfile with EXCEPTION_PROLOGUE
 2. setup r0: EFA (not part of pt_regs)
 3. setup r1: pointer to pt_regs (SP)
 4. drop down to pure kernel mode (from exception)
 5. call the Linux "C" handler

Remove the boiler plate code by moving #2, #3, #4 into #1.

The exceptions to most exceptions are syscall Trap and Machine check
which don't do some of above for various reasons, so call a newly
introduced variant EXCEPTION_PROLOGUE_KEEP_AE (same as original
EXCEPTION_PROLOGUE)

Tested-by: Pavel Kozlov <Pavel.Kozlov@synopsys.com>
Signed-off-by: Vineet Gupta <vgupta@kernel.org>
  • Loading branch information
Vineet Gupta committed Aug 18, 2023
1 parent 0e93eca commit 13347c1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 47 deletions.
12 changes: 11 additions & 1 deletion arch/arc/include/asm/entry-arcv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
.endm

/*------------------------------------------------------------------------*/
.macro EXCEPTION_PROLOGUE
.macro EXCEPTION_PROLOGUE_KEEP_AE

; Before jumping to Exception Vector, hardware micro-ops did following:
; 1. SP auto-switched to kernel mode stack
Expand Down Expand Up @@ -104,6 +104,16 @@
; OUTPUT: r10 has ECR expected by EV_Trap
.endm

.macro EXCEPTION_PROLOGUE

EXCEPTION_PROLOGUE_KEEP_AE ; return ECR in r10

lr r0, [efa]
mov r1, sp

FAKE_RET_FROM_EXCPN ; clobbers r9
.endm

/*------------------------------------------------------------------------
* This macro saves the registers manually which would normally be autosaved
* by hardware on taken interrupts. It is used by
Expand Down
12 changes: 11 additions & 1 deletion arch/arc/include/asm/entry-compact.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
*
* After this it is safe to call the "C" handlers
*-------------------------------------------------------------*/
.macro EXCEPTION_PROLOGUE
.macro EXCEPTION_PROLOGUE_KEEP_AE

/* Need at least 1 reg to code the early exception prologue */
PROLOG_FREEUP_REG r9, @ex_saved_reg1
Expand Down Expand Up @@ -179,6 +179,16 @@
; OUTPUT: r10 has ECR expected by EV_Trap
.endm

.macro EXCEPTION_PROLOGUE

EXCEPTION_PROLOGUE_KEEP_AE ; return ECR in r10

lr r0, [efa]
mov r1, sp

FAKE_RET_FROM_EXCPN ; clobbers r9
.endm

/*--------------------------------------------------------------
* Restore all registers used by system call or Exceptions
* SP should always be pointing to the next free stack element
Expand Down
15 changes: 0 additions & 15 deletions arch/arc/kernel/entry-arcv2.S
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,6 @@ ENTRY(mem_service)

EXCEPTION_PROLOGUE

lr r0, [efa]
mov r1, sp

FAKE_RET_FROM_EXCPN

bl do_memory_error
b ret_from_exception
END(mem_service)
Expand All @@ -138,11 +133,6 @@ ENTRY(EV_Misaligned)

EXCEPTION_PROLOGUE

lr r0, [efa] ; Faulting Data address
mov r1, sp

FAKE_RET_FROM_EXCPN

SAVE_CALLEE_SAVED_USER
mov r2, sp ; callee_regs

Expand All @@ -163,11 +153,6 @@ ENTRY(EV_TLBProtV)

EXCEPTION_PROLOGUE

lr r0, [efa] ; Faulting Data address
mov r1, sp ; pt_regs

FAKE_RET_FROM_EXCPN

mov blink, ret_from_exception
b do_page_fault

Expand Down
13 changes: 0 additions & 13 deletions arch/arc/kernel/entry-compact.S
Original file line number Diff line number Diff line change
Expand Up @@ -256,16 +256,6 @@ ENTRY(EV_TLBProtV)

EXCEPTION_PROLOGUE ; ECR returned in r10

lr r0, [efa] ; Faulting Data address (not part of pt_regs saved above)

; Exception auto-disables further Intr/exceptions.
; Re-enable them by pretending to return from exception
; (so rest of handler executes in pure K mode)

FAKE_RET_FROM_EXCPN

mov r1, sp ; Handle to pt_regs

;------ (5) Type of Protection Violation? ----------
;
; ProtV Hardware Exception is triggered for Access Faults of 2 types
Expand Down Expand Up @@ -301,9 +291,6 @@ END(EV_TLBProtV)
ENTRY(call_do_page_fault)

EXCEPTION_PROLOGUE
lr r0, [efa] ; Faulting Data address
mov r1, sp
FAKE_RET_FROM_EXCPN

mov blink, ret_from_exception
b do_page_fault
Expand Down
19 changes: 2 additions & 17 deletions arch/arc/kernel/entry.S
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ ENTRY(instr_service)

EXCEPTION_PROLOGUE

lr r0, [efa]
mov r1, sp

FAKE_RET_FROM_EXCPN

bl do_insterror_or_kprobe
b ret_from_exception
END(instr_service)
Expand All @@ -95,7 +90,7 @@ END(instr_service)

ENTRY(EV_MachineCheck)

EXCEPTION_PROLOGUE ; ECR returned in r10
EXCEPTION_PROLOGUE_KEEP_AE ; ECR returned in r10

lr r0, [efa]
mov r1, sp
Expand Down Expand Up @@ -128,11 +123,6 @@ ENTRY(EV_PrivilegeV)

EXCEPTION_PROLOGUE

lr r0, [efa]
mov r1, sp

FAKE_RET_FROM_EXCPN

bl do_privilege_fault
b ret_from_exception
END(EV_PrivilegeV)
Expand All @@ -144,11 +134,6 @@ ENTRY(EV_Extension)

EXCEPTION_PROLOGUE

lr r0, [efa]
mov r1, sp

FAKE_RET_FROM_EXCPN

bl do_extension_fault
b ret_from_exception
END(EV_Extension)
Expand Down Expand Up @@ -229,7 +214,7 @@ trap_with_param:

ENTRY(EV_Trap)

EXCEPTION_PROLOGUE
EXCEPTION_PROLOGUE_KEEP_AE

lr r12, [efa]

Expand Down

0 comments on commit 13347c1

Please sign in to comment.