PERFORCE change 164785 for review
Arnar Mar Sig
antab at FreeBSD.org
Sun Jun 21 03:12:29 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=164785
Change 164785 by antab at antab_farm on 2009/06/21 03:12:09
* Implement *setjmp/*longjmp
* Implement pmap_change_wiring
* Use vm_paddr_t for physical address
* Disable usart1 PDC before entering debugger
* Change SYSCALL() to use r0 instead of r8, needed for vararg syscalls
some other small hacks
Affected files ...
.. //depot/projects/avr32/src/lib/libc/avr32/gen/_setjmp.S#2 edit
.. //depot/projects/avr32/src/lib/libc/avr32/gen/setjmp.S#2 edit
.. //depot/projects/avr32/src/lib/libc/avr32/gen/sigsetjmp.S#2 edit
.. //depot/projects/avr32/src/lib/libc/avr32/sys/pipe.S#3 edit
.. //depot/projects/avr32/src/sys/avr32/avr32/pmap.c#20 edit
.. //depot/projects/avr32/src/sys/avr32/avr32/trap.c#11 edit
.. //depot/projects/avr32/src/sys/avr32/conf/NGW100.hints#3 edit
.. //depot/projects/avr32/src/sys/avr32/include/asm.h#7 edit
.. //depot/projects/avr32/src/sys/avr32/include/setjmp.h#2 edit
.. //depot/projects/avr32/src/sys/dev/uart/uart_dev_atmel.c#7 edit
Differences ...
==== //depot/projects/avr32/src/lib/libc/avr32/gen/_setjmp.S#2 (text+ko) ====
@@ -1,7 +1,10 @@
/*-
- * Copyright (c) 2009 Arnar Mar Sig
+ * Copyright (c) 2009 The FreeBSD Foundation
* All rights reserved.
*
+ * This software was developed by Arnar Mar Sig under sponsorship from the
+ * FreeBSD Foundation.
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -11,10 +14,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
@@ -30,20 +33,33 @@
/*
* C library -- _setjmp, _longjmp
*
- * _longjmp(a,v)
- * will generate a "return(v)" from the last call to
- * _setjmp(a)
- * by restoring registers from the environment 'a'.
+ * _longjmp(env, val)
+ * will generate a "return(val)" from the last call to
+ * _setjmp(env)
+ * by restoring registers from the stack.
* The previous signal state is NOT restored.
+ *
+ * Note: r8-r12 are scratch registers and not stored
*/
-/* XXX: AVR32 Implement this */
+/**
+ * r12: env
+ */
ENTRY(_setjmp)
- breakpoint
- retal sp
+ mov r11, _JB_MAGIC__SETJMP /* Magic number for _setjmp */
+ st.w r12++, r11 /* Store magic */
+ stm r12, r0-r7,sp,lr /* Store registers */
+ retal sp /* return 0 */
END(_setjmp)
+/**
+ * r12: env
+ * r11: val
+ */
ENTRY(_longjmp)
breakpoint
- retal sp
+ sub r12, -4 /* Skip magic */
+ ldm r12, r0-r7,sp,lr /* Restore registes */
+ mov r12, r11
+ retal r12 /* Return val */
END(_longjmp)
==== //depot/projects/avr32/src/lib/libc/avr32/gen/setjmp.S#2 (text+ko) ====
@@ -1,7 +1,10 @@
/*-
- * Copyright (c) 2009 Arnar Mar Sig
+ * Copyright (c) 2009 The FreeBSD Foundation
* All rights reserved.
*
+ * This software was developed by Arnar Mar Sig under sponsorship from the
+ * FreeBSD Foundation.
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -11,10 +14,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
@@ -28,22 +31,54 @@
__FBSDID("$FreeBSD: $");
/*
- * C library -- _setjmp, _longjmp
+ * C library -- setjmp, longjmp
+ *
+ * longjmp(env, val)
+ * will generate a "return(val)" from the last call to
+ * setjmp(env)
+ * by restoring registers from the stack.
*
- * longjmp(a,v)
- * will generate a "return(v)" from the last call to
- * setjmp(a)
- * by restoring registers from the environment 'a'.
- * The previous signal state is restored.
+ * Note: r8-r12 are scratch registers and not stored
*/
-/* XXX: AVR32 Implement this */
+/**
+ * r12: env
+ */
ENTRY(setjmp)
- breakpoint
- retal sp
+ /* Store signal mask */
+ pushm r12,lr
+ mov r10, r12 /* oset */
+ sub r10, -(10 << 2) /* index to sigmask */
+ mov r11, 0 /* set */
+ mov r12, 1 /* SIG_BLOCK */
+ call PIC_PLT(_C_LABEL(sigprocmask))
+ popm r12,lr
+
+ mov r11, _JB_MAGIC_SETJMP /* Magic number for setjmp */
+ st.w r12++, r11 /* and store in buffer */
+ stm r12, r0-r7,sp,lr /* Store registers */
+
+ retal sp /* return 0 */
END(setjmp)
+/**
+ * r12: env
+ * r11: val
+ */
ENTRY(longjmp)
breakpoint
- retal sp
+ /* Restore signal mask */
+ pushm r11,r12
+ mov r10, 0 /* oset */
+ mov r11, r12 /* set */
+ sub r11, -(10 << 2) /* index to sigmask */
+ mov r12, 3 /* SIG_SETMASK */
+ call PIC_PLT(_C_LABEL(sigprocmask))
+ popm r11,r12
+
+ sub r12, -4 /* Skip magic */
+ ldm r12, r0-r7,sp,lr /* Restore registes */
+ mov r12, r11
+ retal r12 /* Return val */
END(longjmp)
+
==== //depot/projects/avr32/src/lib/libc/avr32/gen/sigsetjmp.S#2 (text+ko) ====
@@ -1,7 +1,10 @@
/*-
- * Copyright (c) 2009 Arnar Mar Sig
+ * Copyright (c) 2009 The FreeBSD Foundation
* All rights reserved.
*
+ * This software was developed by Arnar Mar Sig under sponsorship from the
+ * FreeBSD Foundation.
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -11,10 +14,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
@@ -27,26 +30,39 @@
#include <machine/asm.h>
__FBSDID("$FreeBSD: $");
-
/*
* C library -- sigsetjmp, siglongjmp
*
- * siglongjmp(a,v)
- * will generate a "return(v)" from
- * the last call to
- * sigsetjmp(a, savemask)
- * by restoring registers from the stack,
- * and dependent on savemask restores the
- * signal mask.
+ * siglongjmp(env, val)
+ * will generate a "return(val)" from the last call to
+ * sigsetjmp(env, savemask)
+ * by restoring registers from the stack.
+ * The previous signal state is restored if savemask is not zero
+ *
+ * Note: r8-r12 are scratch registers and not stored
*/
-/* XXX: AVR32 Implement this */
+/**
+ * r12: env
+ * r11: savemask
+ */
ENTRY(sigsetjmp)
- breakpoint
- retal sp
+ /* Store signal mask */
+ cp.w r11, 0 /* Check if zero */
+ breq PIC_PLT(_C_LABEL(_setjmp))
+ bral PIC_PLT(_C_LABEL(setjmp))
END(sigsetjmp)
+/**
+ * r12: env
+ * r11: val
+ */
ENTRY(siglongjmp)
- breakpoint
- retal sp
+ /* Store signal mask */
+ mov r9, _JB_MAGIC__SETJMP /* Magic number for _setjmp */
+ ld.w r10, r12 /* Load magic from buf */
+ cp.w r9, r10 /* Compare them */
+ breq PIC_PLT(_C_LABEL(_setjmp))
+ bral PIC_PLT(_C_LABEL(setjmp))
END(siglongjmp)
+
==== //depot/projects/avr32/src/lib/libc/avr32/sys/pipe.S#3 (text+ko) ====
@@ -29,8 +29,16 @@
#include "SYS.h"
.text
+/**
+ * r12: int fildes[2]
+ */
ENTRY(pipe)
- breakpoint
+ mov r10, r12 /* Save r12 for later use */
SCALL(pipe)
+ brcs _C_LABEL(cerror)
+
+ st.w r10[0], r12 /* read part of pipe */
+ st.w r10[4], r11 /* write part of pipe */
+
retal sp
END(pipe)
==== //depot/projects/avr32/src/sys/avr32/avr32/pmap.c#20 (text+ko) ====
@@ -315,7 +315,24 @@
void
pmap_change_wiring(pmap_t pmap, vm_offset_t va, boolean_t wired)
{
- avr32_impl();
+ pt_entry_t *pte;
+
+ PMAP_LOCK(pmap);
+
+ if (wired && ((*pte & PTE_WIRED) == 0)) {
+ pmap->pm_stats.wired_count++;
+ }
+ else if (!wired && (*pte & PTE_WIRED)) {
+ pmap->pm_stats.wired_count--;
+ }
+
+ if (wired) {
+ *pte |= PTE_WIRED;
+ } else {
+ *pte &= ~PTE_WIRED;
+ }
+
+ PMAP_UNLOCK(pmap);
}
/*
@@ -430,7 +447,7 @@
void
pmap_zero_page_area(vm_page_t m, int off, int size)
{
- vm_offset_t phys = VM_PAGE_TO_PHYS(m);
+ vm_paddr_t phys = VM_PAGE_TO_PHYS(m);
bzero((caddr_t)AVR32_PHYS_TO_P2(phys) + off, size);
}
==== //depot/projects/avr32/src/sys/avr32/avr32/trap.c#11 (text+ko) ====
@@ -80,8 +80,10 @@
#include <machine/debug.h>
#include <machine/reg.h>
#include <machine/reg_sys.h>
+#include <machine/reg_pdc.h>
static char *trap_name(uint32_t type);
+static int trap_breakpoint(uint32_t type, struct trapframe *frame);
extern char *syscallnames[];
/*
@@ -145,7 +147,7 @@
#ifdef KDB
if (kdb_on_nmi) {
printf("NMI ... going to debugger\n");
- kdb_trap(type, 0, frame);
+ trap_breakpoint(type, frame);
}
#endif /* KDB */
if (panic_on_nmi) {
@@ -200,7 +202,7 @@
/*
* XXX: Break into kdb until we have userspace and working gdb
*/
- kdb_trap(type, 0, frame);
+ trap_breakpoint(type, frame);
return;
#if 0
signo = SIGTRAP;
@@ -270,7 +272,7 @@
case T_BREAKPOINT:
#ifdef KDB
- if (kdb_trap(type, 0, frame)) {
+ if (trap_breakpoint(type, frame)) {
return;
}
#endif /* KDB */
@@ -385,10 +387,11 @@
struct sysent *callp;
int code, error, nargs, nsaved;
register_t args[8];
+ caddr_t params;
PCPU_INC(cnt.v_syscall);
- code = frame->regs.r8;
+ code = frame->regs.r0;
switch (code) {
case SYS_syscall:
code = frame->regs.r12;
@@ -405,12 +408,25 @@
nsaved = 2;
break;
+ /*
+ * XXX: syscalls prototyped with varargs, on avr32 all varargs get
+ * pushed on stack so we must handled thous:/ I'm not sure this is
+ * the right way but it seems to work for now.
+ */
+ case SYS_fcntl:
+ case SYS_ioctl:
+ args[0] = frame->regs.r12;
+ args[1] = frame->regs.r11;
+ nsaved = 2;
+ break;
+
default:
args[0] = frame->regs.r12;
args[1] = frame->regs.r11;
args[2] = frame->regs.r10;
args[3] = frame->regs.r9;
- nsaved = 4;
+ args[4] = frame->regs.r8;
+ nsaved = 5;
break;
}
@@ -426,10 +442,12 @@
error = 0;
if (nargs > nsaved) {
- error = copyin((caddr_t)frame->regs.sp, (caddr_t)&args[nsaved],
+ params = (caddr_t)frame->regs.sp + sizeof(register_t);
+ error = copyin(params, (caddr_t)&args[nsaved],
(u_int)(nargs - nsaved) * sizeof(register_t));
}
+
printf("--- syscall: %d (%s) at pc: 0x%x, lr: 0x%x, args: %d\n",
code, syscallnames[code], frame->regs.pc, frame->regs.lr, nargs);
// for (int i = 0; i < nargs; i++) {
@@ -572,7 +590,7 @@
#ifdef KDB
if (debugger_on_panic || kdb_active) {
- if (kdb_trap(type, 0, frame)) {
+ if (trap_breakpoint(type, frame)) {
return;
}
}
@@ -596,3 +614,17 @@
}
return "UNKNOWN";
}
+
+/**
+ * XXX: Turn PDC for uart1 off before entering debugger.
+ */
+static int
+trap_breakpoint(uint32_t type, struct trapframe *frame)
+{
+ int ret;
+
+ bus_space_write_4(NULL, 0xFFE01000, PDC_PTCR, PDC_PTCR_RXTDIS);
+ ret = kdb_trap(type, 0, frame);
+ bus_space_write_4(NULL, 0xFFE01000, PDC_PTCR, PDC_PTCR_RXTEN);
+ return (ret);
+}
==== //depot/projects/avr32/src/sys/avr32/conf/NGW100.hints#3 (text+ko) ====
@@ -31,3 +31,7 @@
hint.geom_hints.2.at="cfid0"
hint.geom_hints.2.maddr="0x007f0000"
hint.geom_hints.2.msize="0x00010000"
+
+# Serial console
+hint.uart.1.flags=0x10
+
==== //depot/projects/avr32/src/sys/avr32/include/asm.h#7 (text+ko) ====
@@ -62,14 +62,15 @@
#define _C_LABEL(x) x
/**
- * Do syscall and pass the syscall number in thru r8. All registers
- * are preserved except r12 and r11. thous hold return values.
+ * Do syscall and pass the syscall number in thru r0. Old value of r0
+ * is pushed to stack. All registers are preserved except r12 and r11,
+ * thous hold return values.
*/
#define SCALL(name) \
- stm --sp, r8 ;\
- mov r8, SYS_ ## name ;\
+ stm --sp, r0 ;\
+ mov r0, SYS_ ## name ;\
scall ;\
- ldm sp++, r8
+ ldm sp++, r0
/**
* Save trapfrome to stack
@@ -156,4 +157,18 @@
#define FRAMEPOINTER_RESTORE
#endif
+#ifndef _JB_MAGIC__SETJMP
+#define _JB_MAGIC__SETJMP 0xFE
+#define _JB_MAGIC_SETJMP 0xED
+#endif
+
+#ifdef PIC
+#define PIC_PLT(x) x
+#define PIC_GOT(x) x
+#else
+#define PIC_PLT(x) x
+#define PIC_GOT(x) x
+#endif
+
+
#endif /* !_MACHINE_ASM_H_ */
==== //depot/projects/avr32/src/sys/avr32/include/setjmp.h#2 (text+ko) ====
@@ -30,7 +30,32 @@
#ifndef _MACHINE_SETJMP_H_
#define _MACHINE_SETJMP_H_
-#define _JBLEN 64 /* size, in longs, of a jmp_buf */
+#define _JBLEN 13 /* size, in longs, of a jmp_buf */
+
+/**
+ * NOTE: The internal structure of a jmp_buf is *PRIVATE*
+ *
+ * Description of the setjmp buffer
+ *
+ * word 0 magic number (dependant on creator)
+ * 1 lr link register
+ * 2 r7 register 7
+ * 3 r6 register 6
+ * 4 r5 register 5
+ * 5 r4 register 4
+ * 6 r3 register 3
+ * 7 r2 register 2
+ * 8 r1 register 1
+ * 9 r0 register 0
+ * 10 signal mask (dependant on magic)
+ * 11 (con't)
+ * 12 (con't)
+ * 13 (con't)
+ *
+ * The magic number number identifies the jmp_buf and
+ * how the buffer was created as well as providing
+ * a sanity check
+ */
#if __BSD_VISIBLE || __POSIX_VISIBLE || __XSI_VISIBLE
typedef struct _sigjmp_buf { int _sjb[_JBLEN + 1]; } sigjmp_buf[1];
==== //depot/projects/avr32/src/sys/dev/uart/uart_dev_atmel.c#7 (text+ko) ====
@@ -300,6 +300,7 @@
uart_atmel_getc(struct uart_bas *bas, struct mtx *mtx)
{
int c;
+
while (!(RD4(bas, USART_CSR) & USART_CSR_RXRDY))
continue;
c = RD4(bas, USART_RHR);
@@ -347,12 +348,12 @@
* XXX: Enableing interrupts and PDC creates races between sysdev pools
* and the dma
*/
- if (sc->sc_sysdev != NULL) {
+/* if (sc->sc_sysdev != NULL) {
di = sc->sc_sysdev;
uart_atmel_init(&sc->sc_bas, di->baudrate, di->databits, di->stopbits,
di->parity);
return(0);
- }
+ } */
/*
* See if we have a TIMEOUT bit. We disable all interrupts as
@@ -680,8 +681,6 @@
struct uart_atmel_softc *atsc;
atsc = (struct uart_atmel_softc *)sc;
-
-
#ifndef SKYEYE_WORKAROUNDS
if (sc->sc_sysdev == NULL) {
if (bus_dmamap_load(atsc->dmatag, atsc->tx_map, sc->sc_txbuf,
@@ -701,6 +700,7 @@
for (int i = 0; i < sc->sc_txdatasz; i++) {
uart_atmel_putc(&sc->sc_bas, sc->sc_txbuf[i]);
}
+ WR4(&sc->sc_bas, USART_IER, USART_CSR_TXRDY);
} else {
/*
* Setup the PDC to transfer the data and interrupt us when it
More information about the p4-projects
mailing list