.global _hw_exception_handler
.section .text
.align4
.ent _hw_exception_handler
_hw_exception_handler:
swi r1, r0, TOPHYS(pt_pool_space + PT_R1); /* GET_SP */ /* Save date to kernel memory. Here is the problem
* when you came from user space */
ori r1, r0, TOPHYS(pt_pool_space);
swi r3, r1, PT_R3
swi r4, r1, PT_R4
swi r5, r1, PT_R5
swi r6, r1, PT_R6
swi r11, r1, PT_R11
swi r31, r1, PT_R31
lwi r31, r0, TOPHYS(PER_CPU(CURRENT_SAVE)) /* get saved current */
/* 0x01 - Unaligned data access exception *Thisoccurswhenawordaccessisnotalignedonawordboundary, *orwhena16-bitaccessisnotalignedona16-bitboundary. *Thishandlerperformtheaccess,andreturns,exceptforMMUwhen *theunalignedaddressislastona4kpageorthephysicaladdressis *notfoundinthepagetable,inwhichcaseunaligned_data_trapiscalled.
*/
handle_unaligned_ex: /* Working registers already saved: R3, R4, R5, R6 *R4=ESR *R3=EAR
*/
andi r6, r4, 0x1000 /* Check ESR[DS] */
beqi r6, _no_delayslot /* Branch if ESR[DS] not set */
mfs r17, rbtr; /* ESR[DS] set - return address in BTR */
nop
_no_delayslot: /* jump to high level unaligned handler */
RESTORE_STATE;
bri unaligned_data_trap
andi r6, r4, 0x3E0; /* Mask and extract the register operand */ srl r6, r6; /* r6 >> 5 */ srl r6, r6; srl r6, r6; srl r6, r6; srl r6, r6; /* Store the register operand in a temporary location */
sbi r6, r0, TOPHYS(ex_reg_op);
andi r6, r4, 0x400; /* Extract ESR[S] */
bnei r6, ex_sw;
ex_lw:
andi r6, r4, 0x800; /* Extract ESR[W] */
beqi r6, ex_lhw;
lbui r5, r3, 0; /* Exception address in r3 */ /* Load a word, byte-by-byte from destination address
and save it in tmp space */
sbi r5, r0, TOPHYS(ex_tmp_data_loc_0);
lbui r5, r3, 1;
sbi r5, r0, TOPHYS(ex_tmp_data_loc_1);
lbui r5, r3, 2;
sbi r5, r0, TOPHYS(ex_tmp_data_loc_2);
lbui r5, r3, 3;
sbi r5, r0, TOPHYS(ex_tmp_data_loc_3); /* Get the destination register value into r4 */
lwi r4, r0, TOPHYS(ex_tmp_data_loc_0);
bri ex_lw_tail;
ex_lhw:
lbui r5, r3, 0; /* Exception address in r3 */ /* Load a half-word, byte-by-byte from destination
address and save it in tmp space */
sbi r5, r0, TOPHYS(ex_tmp_data_loc_0);
lbui r5, r3, 1;
sbi r5, r0, TOPHYS(ex_tmp_data_loc_1); /* Get the destination register value into r4 */
lhui r4, r0, TOPHYS(ex_tmp_data_loc_0);
ex_lw_tail: /* Get the destination register number into r5 */
lbui r5, r0, TOPHYS(ex_reg_op); /* Form load_word jump table offset (lw_table + (8 * regnum)) */
addik r6, r0, TOPHYS(lw_table);
addk r5, r5, r5;
addk r5, r5, r5;
addk r5, r5, r5;
addk r5, r5, r6;
bra r5;
ex_lw_end: /* Exception handling of load word, ends */
ex_sw: /* Get the destination register number into r5 */
lbui r5, r0, TOPHYS(ex_reg_op); /* Form store_word jump table offset (sw_table + (8 * regnum)) */
addik r6, r0, TOPHYS(sw_table);
add r5, r5, r5;
add r5, r5, r5;
add r5, r5, r5;
add r5, r5, r6;
bra r5;
ex_sw_tail:
mfs r6, resr;
nop
andi r6, r6, 0x800; /* Extract ESR[W] */
beqi r6, ex_shw; /* Get the word - delay slot */
swi r4, r0, TOPHYS(ex_tmp_data_loc_0); /* Store the word, byte-by-byte into destination address */
lbui r4, r0, TOPHYS(ex_tmp_data_loc_0);
sbi r4, r3, 0;
lbui r4, r0, TOPHYS(ex_tmp_data_loc_1);
sbi r4, r3, 1;
lbui r4, r0, TOPHYS(ex_tmp_data_loc_2);
sbi r4, r3, 2;
lbui r4, r0, TOPHYS(ex_tmp_data_loc_3);
sbi r4, r3, 3;
bri ex_handler_done;
ex_shw: /* Store the lower half-word, byte-by-byte into destination address */
swi r4, r0, TOPHYS(ex_tmp_data_loc_0);
lbui r4, r0, TOPHYS(ex_tmp_data_loc_2);
sbi r4, r3, 0;
lbui r4, r0, TOPHYS(ex_tmp_data_loc_3);
sbi r4, r3, 1;
ex_sw_end: /* Exception handling of store word, ends. */
ex_handler_done:
RESTORE_STATE;
rted r17, 0
nop
/* Exception vector entry code. This code runs with address translation
* turned off (i.e. using physical addresses). */
/* Exception vectors. */
/* 0x10 - Data Storage Exception *Thishappensforjustafewreasons.U0set(butwedon'tdothat), *orzoneprotectionfault(userviolation,writetoprotectedpage). *Ifthisisjustanupdateofmodifiedstatus,wedothatquickly *andexit.Otherwise,wecallheavyweightfunctionstodothework.
*/
handle_data_storage_exception: /* Working registers already saved: R3, R4, R5, R6 *R3=ESR
*/
mfs r11, rpid
nop /* If we are faulting a kernel address, we have to use the *kernelpagetables.
*/
ori r5, r0, CONFIG_KERNEL_START
cmpu r5, r3, r5
bgti r5, ex3 /* First, check if it was a zone fault (which means a user *triedtoaccessakernelorread-protectedpage-always *aSEGV).Allotherfaultsheremustbestores,sono
* need to check ESR_S as well. */
andi r4, r4, ESR_DIZ /* ESR_Z - zone protection */
bnei r4, ex2
ori r4, r0, swapper_pg_dir
mts rpid, r0 /* TLB will have 0 TID */
nop
bri ex4
/* Get the PGD for the current thread. */
ex3: /* First, check if it was a zone fault (which means a user *triedtoaccessakernelorread-protectedpage-always *aSEGV).Allotherfaultsheremustbestores,sono
* need to check ESR_S as well. */
andi r4, r4, ESR_DIZ /* ESR_Z */
bnei r4, ex2 /* get current task address */
addi r4 ,CURRENT_TASK, TOPHYS(0);
lwi r4, r4, TASK_THREAD+PGDIR
ex4:
tophys(r4,r4) /* Create L1 (pgdir/pmd) address */
bsrli r5, r3, PGDIR_SHIFT - 2
andi r5, r5, PAGE_SIZE - 4 /* Assume pgdir aligned on 4K boundary, no need for "andi r4,r4,0xfffff003" */
or r4, r4, r5
lwi r4, r4, 0/* Get L1 entry */
andi r5, r4, PAGE_MASK /* Extract L2 (pte) base address */
beqi r5, ex2 /* Bail if no table */
tophys(r5,r5)
bsrli r6, r3, PTE_SHIFT /* Compute PTE address */
andi r6, r6, PAGE_SIZE - 4
or r5, r5, r6
lwi r4, r5, 0/* Get Linux PTE */
andi r6, r4, _PAGE_RW /* Is it writeable? */
beqi r6, ex2 /* Bail if not */
/* Update 'changed' */
ori r4, r4, _PAGE_DIRTY|_PAGE_ACCESSED|_PAGE_HWWRITE
swi r4, r5, 0/* Update Linux page table */
/* Most of the Linux PTE is ready to load into the TLB LO. *WesetZSEL,whereonlytheLS-bitdeterminesuseraccess. *Wesetexecute,becausewedon'thavethegranularityto *properlysetthisatthepagelevel(Linuxproblem). *Ifsharedisset,wecauseazeroPID->TIDload. *Manyofthesebitsaresoftwareonly.Bitswedon'tset *herewe(properlyshould)assumehavetheappropriatevalue.
*/ /* Ignore memory coherent, just LSB on ZSEL is used + EX/WR */
andi r4, r4, PAGE_MASK | TLB_EX | TLB_WR | \
TLB_ZSEL(1) | TLB_ATTR_MASK
ori r4, r4, _PAGE_HWEXEC /* make it executable */
/* find the TLB index that caused the fault. It has to be here*/
mts rtlbsx, r3
nop
mfs r5, rtlbx /* DEBUG: TBD */
nop
mts rtlblo, r4 /* Load TLB LO */
nop /* Will sync shadow TLBs */
/* Done...restore registers and get out of here. */
mts rpid, r11
nop
bri 4
RESTORE_STATE;
rted r17, 0
nop
ex2: /* The bailout. Restore registers to pre-exception conditions
* and call the heavyweights to help us out. */
mts rpid, r11
nop
bri 4
RESTORE_STATE;
bri page_fault_data_trap
/* 0x11 - Instruction Storage Exception
* This is caused by a fetch from non-execute or guarded pages. */
handle_instruction_storage_exception: /* Working registers already saved: R3, R4, R5, R6 *R3=ESR
*/
RESTORE_STATE;
bri page_fault_instr_trap
/* 0x12 - Data TLB Miss Exception *Asthenameimplies,translationisnotintheMMU,sosearchthe *pagetablesandfixit.Theonlypurposeofthisfunctionisto *loadTLBentriesfromthepagetableiftheyexist.
*/
handle_data_tlb_miss_exception: /* Working registers already saved: R3, R4, R5, R6 *R3=EAR,R4=ESR
*/
mfs r11, rpid
nop
/* If we are faulting a kernel address, we have to use the
* kernel page tables. */
ori r6, r0, CONFIG_KERNEL_START
cmpu r4, r3, r6
bgti r4, ex5
ori r4, r0, swapper_pg_dir
mts rpid, r0 /* TLB will have 0 TID */
nop
bri ex6
/* Get the PGD for the current thread. */
ex5: /* get current task address */
addi r4 ,CURRENT_TASK, TOPHYS(0);
lwi r4, r4, TASK_THREAD+PGDIR
ex6:
tophys(r4,r4) /* Create L1 (pgdir/pmd) address */
bsrli r5, r3, PGDIR_SHIFT - 2
andi r5, r5, PAGE_SIZE - 4 /* Assume pgdir aligned on 4K boundary, no need for "andi r4,r4,0xfffff003" */
or r4, r4, r5
lwi r4, r4, 0/* Get L1 entry */
andi r5, r4, PAGE_MASK /* Extract L2 (pte) base address */
beqi r5, ex7 /* Bail if no table */
tophys(r5,r5)
bsrli r6, r3, PTE_SHIFT /* Compute PTE address */
andi r6, r6, PAGE_SIZE - 4
or r5, r5, r6
lwi r4, r5, 0/* Get Linux PTE */
andi r6, r4, _PAGE_PRESENT
beqi r6, ex7
ori r4, r4, _PAGE_ACCESSED
swi r4, r5, 0
/* Most of the Linux PTE is ready to load into the TLB LO. *WesetZSEL,whereonlytheLS-bitdeterminesuseraccess. *Wesetexecute,becausewedon'thavethegranularityto *properlysetthisatthepagelevel(Linuxproblem). *Ifsharedisset,wecauseazeroPID->TIDload. *Manyofthesebitsaresoftwareonly.Bitswedon'tset *herewe(properlyshould)assumehavetheappropriatevalue.
*/
brid finish_tlb_load
andi r4, r4, PAGE_MASK | TLB_EX | TLB_WR | \
TLB_ZSEL(1) | TLB_ATTR_MASK
ex7: /* The bailout. Restore registers to pre-exception conditions *andcalltheheavyweightstohelpusout.
*/
mts rpid, r11
nop
bri 4
RESTORE_STATE;
bri page_fault_data_trap
/* If we are faulting a kernel address, we have to use the *kernelpagetables.
*/
ori r4, r0, CONFIG_KERNEL_START
cmpu r4, r3, r4
bgti r4, ex8
ori r4, r0, swapper_pg_dir
mts rpid, r0 /* TLB will have 0 TID */
nop
bri ex9
/* Get the PGD for the current thread. */
ex8: /* get current task address */
addi r4 ,CURRENT_TASK, TOPHYS(0);
lwi r4, r4, TASK_THREAD+PGDIR
ex9:
tophys(r4,r4) /* Create L1 (pgdir/pmd) address */
bsrli r5, r3, PGDIR_SHIFT - 2
andi r5, r5, PAGE_SIZE - 4 /* Assume pgdir aligned on 4K boundary, no need for "andi r4,r4,0xfffff003" */
or r4, r4, r5
lwi r4, r4, 0/* Get L1 entry */
andi r5, r4, PAGE_MASK /* Extract L2 (pte) base address */
beqi r5, ex10 /* Bail if no table */
tophys(r5,r5)
bsrli r6, r3, PTE_SHIFT /* Compute PTE address */
andi r6, r6, PAGE_SIZE - 4
or r5, r5, r6
lwi r4, r5, 0/* Get Linux PTE */
andi r6, r4, _PAGE_PRESENT
beqi r6, ex10
ori r4, r4, _PAGE_ACCESSED
swi r4, r5, 0
/* Most of the Linux PTE is ready to load into the TLB LO. *WesetZSEL,whereonlytheLS-bitdeterminesuseraccess. *Wesetexecute,becausewedon'thavethegranularityto *properlysetthisatthepagelevel(Linuxproblem). *Ifsharedisset,wecauseazeroPID->TIDload. *Manyofthesebitsaresoftwareonly.Bitswedon'tset *herewe(properlyshould)assumehavetheappropriatevalue.
*/
brid finish_tlb_load
andi r4, r4, PAGE_MASK | TLB_EX | TLB_WR | \
TLB_ZSEL(1) | TLB_ATTR_MASK
ex10: /* The bailout. Restore registers to pre-exception conditions *andcalltheheavyweightstohelpusout.
*/
mts rpid, r11
nop
bri 4
RESTORE_STATE;
bri page_fault_instr_trap
/* Both the instruction and data TLB miss get to this point to load the TLB. *r3-EAoffault *r4-TLBLO(infofromLinuxPTE) *r5,r6-availabletouse *PID-loadedwithpropervaluewhenwegethere *Uponexit,wereloadeverythingandRFI. *AcommonplacetoloadtheTLB.
*/
.section .data
.align4
.global tlb_skip
tlb_skip:
.long MICROBLAZE_TLB_SKIP
tlb_index: /* MS: storing last used tlb index */
.long MICROBLAZE_TLB_SIZE/2
.previous
finish_tlb_load: /* MS: load the last used TLB index. */
lwi r5, r0, TOPHYS(tlb_index)
addik r5, r5, 1/* MS: inc tlb_index -> use next one */
/* MS: FIXME this is potential fault, because this is mask not count */
andi r5, r5, MICROBLAZE_TLB_SIZE - 1
ori r6, r0, 1
cmp r31, r5, r6
blti r31, ex12
lwi r5, r0, TOPHYS(tlb_skip)
ex12: /* MS: save back current TLB index */
swi r5, r0, TOPHYS(tlb_index)
ori r4, r4, _PAGE_HWEXEC /* make it executable */
mts rtlbx, r5 /* MS: save current TLB */
nop
mts rtlblo, r4 /* MS: save to TLB LO */
nop
/* Create EPN. This is the faulting address plus a static *setofbits.Thesearesize,valid,E,U0,andensure *bits20and21arezero.
*/
andi r3, r3, PAGE_MASK
ori r3, r3, TLB_VALID | TLB_PAGESZ(PAGESZ_4K)
mts rtlbhi, r3 /* Load TLB HI */
nop
/* Done...restore registers and get out of here. */
mts rpid, r11
nop
bri 4
RESTORE_STATE;
rted r17, 0
nop
/* Unaligned data access exception last on a 4k page for MMU. *Whenthisiscalled,weareinvirtualmodewithexceptionsenabled *andregisters1-13,15,17,18saved. * *R3=ESR *R4=EAR *R7=pointertosavedregisters(structpt_regs*regs) * *Thishandlerperformtheaccess,andreturnsviaret_from_exc.
*/
.global _unaligned_data_exception
.ent _unaligned_data_exception
_unaligned_data_exception:
andi r8, r3, 0x3E0; /* Mask and extract the register operand */
bsrli r8, r8, 2; /* r8 >> 2 = register operand * 8 */
andi r6, r3, 0x400; /* Extract ESR[S] */
bneid r6, ex_sw_vm;
andi r6, r3, 0x800; /* Extract ESR[W] - delay slot */
ex_lw_vm:
beqid r6, ex_lhw_vm;
load1: lbui r5, r4, 0; /* Exception address in r4 - delay slot */ /* Load a word, byte-by-byte from destination address and save it in tmp space*/
addik r6, r0, ex_tmp_data_loc_0;
sbi r5, r6, 0;
load2: lbui r5, r4, 1;
sbi r5, r6, 1;
load3: lbui r5, r4, 2;
sbi r5, r6, 2;
load4: lbui r5, r4, 3;
sbi r5, r6, 3;
brid ex_lw_tail_vm; /* Get the destination register value into r3 - delay slot */
lwi r3, r6, 0;
ex_lhw_vm: /* Load a half-word, byte-by-byte from destination address and
* save it in tmp space */
addik r6, r0, ex_tmp_data_loc_0;
sbi r5, r6, 0;
load5: lbui r5, r4, 1;
sbi r5, r6, 1;
lhui r3, r6, 0; /* Get the destination register value into r3 */
ex_lw_tail_vm: /* Form load_word jump table offset (lw_table_vm + (8 * regnum)) */
addik r5, r8, lw_table_vm;
bra r5;
ex_lw_end_vm: /* Exception handling of load word, ends */
brai ret_from_exc;
ex_sw_vm: /* Form store_word jump table offset (sw_table_vm + (8 * regnum)) */
addik r5, r8, sw_table_vm;
bra r5;
ex_sw_tail_vm:
addik r5, r0, ex_tmp_data_loc_0;
beqid r6, ex_shw_vm;
swi r3, r5, 0; /* Get the word - delay slot */ /* Store the word, byte-by-byte into destination address */
lbui r3, r5, 0;
store1: sbi r3, r4, 0;
lbui r3, r5, 1;
store2: sbi r3, r4, 1;
lbui r3, r5, 2;
store3: sbi r3, r4, 2;
lbui r3, r5, 3;
brid ret_from_exc;
store4: sbi r3, r4, 3; /* Delay slot */
ex_shw_vm: /* Store the lower half-word, byte-by-byte into destination address */
#ifdef __MICROBLAZEEL__
lbui r3, r5, 0;
store5: sbi r3, r4, 0;
lbui r3, r5, 1;
brid ret_from_exc;
store6: sbi r3, r4, 1; /* Delay slot */
#else
lbui r3, r5, 2;
store5: sbi r3, r4, 0;
lbui r3, r5, 3;
brid ret_from_exc;
store6: sbi r3, r4, 1; /* Delay slot */
#endif
ex_sw_end_vm: /* Exception handling of store word, ends. */
/* We have to prevent cases that get/put_user macros get unaligned pointer *tobadpagearea.Wehavetofindoutwhichorigininstructioncausedit *andcalledfixupforthatorigininstructionnotinstructioninunaligned
* handler */
ex_unaligned_fixup:
ori r5, r7, 0/* setup pointer to pt_regs */
lwi r6, r7, PT_PC; /* faulting address is one instruction above */
addik r6, r6, -4/* for finding proper fixup */
swi r6, r7, PT_PC; /* a save back it to PT_PC */
addik r7, r0, SIGSEGV /* call bad_page_fault for finding aligned fixup, fixup address is saved
* in PT_PC which is used as return address from exception */
addik r15, r0, ret_from_exc-8/* setup return address */
brid bad_page_fault
nop
/* We prevent all load/store because it could failed any attempt to access */
.section __ex_table,"a";
.word load1,ex_unaligned_fixup;
.word load2,ex_unaligned_fixup;
.word load3,ex_unaligned_fixup;
.word load4,ex_unaligned_fixup;
.word load5,ex_unaligned_fixup;
.word store1,ex_unaligned_fixup;
.word store2,ex_unaligned_fixup;
.word store3,ex_unaligned_fixup;
.word store4,ex_unaligned_fixup;
.word store5,ex_unaligned_fixup;
.word store6,ex_unaligned_fixup;
.previous;
.end _unaligned_data_exception
.global ex_handler_unhandled
ex_handler_unhandled: /* FIXME add handle function for unhandled exception - dump register */
bri 0
/* Temporary data structures used in the handler */
.section .data
.align4
ex_tmp_data_loc_0:
.byte 0
ex_tmp_data_loc_1:
.byte 0
ex_tmp_data_loc_2:
.byte 0
ex_tmp_data_loc_3:
.byte 0
ex_reg_op:
.byte 0
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.140Bemerkung:
(vorverarbeitet am 2026-09-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.