PATCH: flush_icache_page() and flush_icache_range()
Hi,
gdb has a problem in that it often doesn't stop the target program
when you do a 'step' or 'next'. This is because it plants breakpoints, but those breakpoints sit in the data cache and don't get flushed through to be visible as code in time. We need a flush_icache_page() implementation to fix this; the following adds that and flush_icache_range() also. It does fix gdb for me on my a500.
Posted here for comments, before commiting. I modelled the new flush_kernel_icache_page on flush_kernel_dcache_page, just changing the stride and fdc to fic.
Richard
Index: include/asm-parisc/pgalloc.h
===================================================================
RCS file: /var/cvs/linux/include/asm-parisc/pgalloc.h,v retrieving revision 1.34
asm-parisc/pgalloc.h +2 -2
@@ -121,9 +121,9 @@ } } -#define flush_icache_page (vma,page) +#define flush_icache_page (vma,page) do { flush_kernel_dcache_page(page_address(page)); flush_kernel_icache_page(page_address(page)); } while (0) -#define flush_icache_range flush_kernel_icache_range_asm +#define flush_icache_range (s,e) do { flush_kernel_dcache_range_asm(s,e); flush_kernel_icache_range_asm(s,e); } while (0)/* TLB flushing routines.... */
Index: arch/parisc/kernel/pacache.S
===================================================================
RCS file: /var/cvs/linux/arch/parisc/kernel/pacache.S,v retrieving revision 1.10
parisc/kernel/pacache.S +44 -0
50 lines not on this page · raw message
Quoted 7 lines
Hi,
gdb has a problem in that it often doesn't stop the target program
when you do a 'step' or 'next'. This is because it plants breakpoints, but those breakpoints sit in the data cache and don't get flushed through to be visible as code in time. We need aflush_icache_page()implementation to fix this; the following adds that andflush_icache_range()also. It does fix gdb for me on my a500.
Good find! I'll give it a try. Can you now print function results?
Dave
Signature · 2 lines
J. David Anglin [email protected] National Research Council of Canada (613) 990-0752 (FAX: 952-6605)
Quoted 9 lines · John David Anglin
Quoted 7 lines
Hi,
gdb has a problem in that it often doesn't stop the target program
when you do a 'step' or 'next'. This is because it plants breakpoints, but those breakpoints sit in the data cache and don't get flushed through to be visible as code in time. We need aflush_icache_page()implementation to fix this; the following adds that andflush_icache_range()also. It does fix gdb for me on my a500.Good find! I'll give it a try. Can you now print function results?
You mean like
Breakpoint 1, main (argc=1, argv=0xbff00148) at ../simple.c:16
16 a = thing(1);
(gdb) print thing(7)
Program terminated with signal SIGSEGV, Segmentation fault. The program no longer exists.
The program being debugged stopped while in a function called from GDB. When the function (thing) is done executing, GDB will silently stop (instead of continuing to evaluate the expression containing the function call).
(gdb)
thing(x) just returns x*2 in this case. As you see it didn't work, and gave a protection id trap for the target program. I'll investigate further.
Richard
Quoted 3 lines · Richard Hirst
This is because it plants breakpoints,
but those breakpoints sit in the data cache and don't get flushed through to be visible as code in time.
Richard,
Someone put code in arch/parisc/mm/init.c as per Alan Cox's suggestion to trap excessive __init's. But it didn't flush dcache or icache. Can you glob/rework the following patch with yours?
(I'm very guilty of being tired and not checking for compile errors or warnings...way past my bedtime again...the code does compile and link though)
thanks,
grant
Index: arch/parisc/mm/init.c
===================================================================
RCS file: /var/cvs/linux/arch/parisc/mm/init.c,v
retrieving revision 1.48
parisc/mm/init.c +16 -3
@@ -381,10 +381,23 @@ void free_initmem(void)printk (KERN_INFO "Freeing unused kernel memory: " );#if 1 -cli ();/* disable all interrupts */ -memset (&__init_begin,0xff , +/* Attempt to catch anyone trying to execute code here +* by filling the page with BRK insns. +* +* If we disable interrupts for all CPUs, then IPI stops working. +* Kinda breaks the global cache flushing. +*/ +local_irq_disable (); + +memset (&__init_begin,0x00 , (unsigned long )&__init_end - (unsigned long )&__init_begin); -sti ();/* re-enable all interrupts */ + +flush_data_cache (); + asmvolatile ("sync" : : ); +flush_icache_range (&__init_begin, &__init_end); + asmvolatile ("sync" : : ); + +local_irq_enable ();#endif addr = (unsigned long )(&__init_begin);
Quoted 5 lines
You mean like
Breakpoint 1, main (argc=1, argv=0xbff00148) at
../simple.c:16
16 a = thing(1);
(gdb) print thing(7)
Yes. I find this an extremely useful feature in debugging gcc. It has various hooks to print rtl and tree structs that I miss not being able to use.
Quoted 3 lines
thing(x) just returns x*2 in this case. As you see it didn't work, and gave a protection id trap for the target program. I'll investigate further.
Great.
Dave
Signature · 2 lines
J. David Anglin [email protected] National Research Council of Canada (613) 990-0752 (FAX: 952-6605)
Quoted 9 lines · John David Anglin
Quoted 5 lines
You mean like
Breakpoint 1, main (argc=1, argv=0xbff00148) at
../simple.c:16
16 a = thing(1);
(gdb) print thing(7)Yes. I find this an extremely useful feature in debugging gcc. It has various hooks to print rtl and tree structs that I miss not being able to use.
I've got this semi-working now. Simple cases like the example above now work (thing(n) returns n*2). Other cases, such as print strlen("abc") crash the target program. I'll keep working on it and post a diff once it works for a few more cases.
Richard