Den 21-08-2011 17:06, Geoffrey Barton skrev:
On 21 Aug 2011, at 15:33, John Clymer wrote:
As part of my table-ization of cpuinfo.pas, I am including a generic
part for each (no code published for this yet.) The caveat to this
is that FLASH size and SRAM sizes are just set to extremely large (1
MB each for now). Which means if the code size exceeds the space of
the device - the compiler/linker will not catch the overflow of the
available resource. (Running objsize on the ELF file will display
the sizes - so I just run that after every successful compile.)
As I pointed out, this will always fail because the stacktop is set
beyond the available ram. It will cause an exception I think. How do
you propose to be able to set the actual ram top for the generic part,
or am I missing something?
Also, still testing, but I have the "interrupt"reserved word working
(more or less, more testing needed.) This takes the interrupt
codeword with an integer. The integer is the offset into the vectors
table. If no interrupt is provided for the given address, it
defaults to DefaultHandler in the startup file - which is just a
continual loop - so one can breakpoint on it. (This can be enabled /
disabled via a define in the source.) This is should only be enabled
for the embedded target - but I need to double check to ensure that
is the case.
This is a useful development; ideally the integer would be backed by
an enumeration as it is a big table. One thing which I did find
missing was the interrupt enable and disable assembler codes, so I
patched them with data bytes hidden in functions. The keil C compiler
does not like these if you link to units doing this (throws a
data/code wobbly). See the file attached to bug tracker ID0017365 for
how I hacked interrupts.
The CPS* instruction with the correct operand syntax was added in #18334
SVN trunk already has experimental support for the interrupt keyword.
It's enabled with FPC_HAS_SYSTEMS_INTERRUPT_TABLE in fpcdefs.inc. I
discovered a small bug with the current implementation which is fixed
with the attached patch(which also includes some other stuff... the
bugfix is in ncgutil. It didn't search the program file for interrupt
handlers before)
Index: compiler/fpcdefs.inc
===================================================================
--- compiler/fpcdefs.inc (revision 18784)
+++ compiler/fpcdefs.inc (working copy)
@@ -33,7 +33,7 @@
$define FPC_HAS_SYSTEMS_INTERRUPT_TABLE
to fpcdefs.inc to reactivate
the corresponding code }
-{$undef FPC_HAS_SYSTEMS_INTERRUPT_TABLE}
+{$define FPC_HAS_SYSTEMS_INTERRUPT_TABLE}
{ This fake CPU is used to allow incorporation of globtype unit
into utils/ppudump without any CPU specific code PM }
Index: compiler/ncgutil.pas
===================================================================
--- compiler/ncgutil.pas (revision 18784)
+++ compiler/ncgutil.pas (working copy)
@@ -3197,7 +3197,30 @@
end;
hp:=tused_unit(hp.next);
end;
+ for i := 0 to current_module.symlist.Count-1 do
+ begin
+ sym:=tsym(current_module.symlist[i]);
+ if not assigned(sym) then
+ continue;
+ if sym.typ = procsym then
+ begin
+ for i2 := 0 to tprocsym(sym).ProcdefList.Count-1 do
+ begin
+ pd:=tprocdef(tprocsym(sym).ProcdefList[i2]);
+ if pd.interruptvector >= 0 then
+ begin
+ if pd.interruptvector > high(interruptTable) then
+ Internalerror(2011030602);
+ if interruptTable[pd.interruptvector] <> nil then
+ internalerror(2011030601);
+ interruptTable[pd.interruptvector]:=pd;
+ break;
+ end;
+ end;
+ end;
+ end;
+
new_section(current_asmdata.asmlists[al_globals],sec_init,'VECTORS',sizeof(pint));
current_asmdata.asmlists[al_globals].concat(Tai_symbol.Createname_global('VECTORS',AT_DATA,0));
{$IFDEF arm}
Index: compiler/pdecsub.pas
===================================================================
--- compiler/pdecsub.pas (revision 18784)
+++ compiler/pdecsub.pas (working copy)
@@ -2308,7 +2308,7 @@
idtok:_INTERRUPT;
pd_flags :
[pd_implemen,pd_body,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
handler : @pd_interrupt;
- pocall : pocall_oldfpccall;
+ pocall : pocall_interrupt;
pooption : [po_interrupt];
mutexclpocall :
[pocall_internproc,pocall_cdecl,pocall_cppdecl,pocall_stdcall,
pocall_pascal,pocall_far16,pocall_oldfpccall];
Index: compiler/systems.pas
===================================================================
--- compiler/systems.pas (revision 18784)
+++ compiler/systems.pas (working copy)
@@ -286,7 +286,7 @@
$define FPC_HAS_SYSTEMS_INTERRUPT_TABLE
to fpcdefs.inc to reactivate
the corresponding code }
- systems_interrupt_table = [{system_arm_embedded}];
+ systems_interrupt_table = [system_arm_embedded];
{$endif FPC_HAS_SYSTEMS_INTERRUPT_TABLE}
{ all systems for which istack must be at a 16 byte boundary
Index: rtl/embedded/arm/stm32f103.pp
===================================================================
--- rtl/embedded/arm/stm32f103.pp (revision 18784)
+++ rtl/embedded/arm/stm32f103.pp (working copy)
@@ -134,11 +134,14 @@
CNTR, res1,
ISTR, res2,
FNR, res3: Word;
- DADDR: byte; res4: word; res5: byte;
+ DADDR, res5: word;
BTABLE: Word;
end;
- TUSBMem = packed array[0..511] of byte;
+ TUSBMem = array[0..127] of record
+ Data,
+ Nothing: Word;
+ end;
TCANMailbox = record
IR,
@@ -416,7 +419,7 @@
{ USB }
USB: TUSBRegisters absolute (APB1Base+$5C00);
- USBMem: TUSBMem absolute (APB1Base+$5C00);
+ USBMem: TUSBMem absolute (APB1Base+$6000);
{ CAN }
CAN: TCANRegisters absolute (APB1Base+$6800);
@@ -472,17 +475,6 @@
{ NVIC }
NVIC: TNVICRegisters absolute (SCS_BASE+$0100);
-var
- NMI_Handler,
- HardFault_Handler,
- MemManage_Handler,
- BusFault_Handler,
- UsageFault_Handler,
- SWI_Handler,
- DebugMonitor_Handler,
- PendingSV_Handler,
- Systick_Handler: pointer;
-
implementation
var
@@ -501,143 +493,17 @@
b .Lhalt
end;
-procedure _FPC_start; assembler; nostackframe;
-label _start;
+procedure DefaultHandler; assembler; nostackframe; public name
'DefaultHandler';
asm
- .init
- .balign 16
-
- .long _stack_top // First entry in NVIC
table is the new stack pointer
- .long _start+1
- //b _start // Reset
- .long _start+1
- //b .LNMI_Addr // Non maskable
interrupt. The RCC Clock Security System (CSS) is linked to the NMI vector.
- .long _start+1
- //b .LHardFault_Addr // All class of fault
- .long _start+1
- //b .LMemManage_Addr // Memory management
- .long _start+1
- //b .LBusFault_Addr // Pre-fetch fault, memory
access fault
- .long _start+1
- //b .LUsageFault_Addr // Undefined instruction or illegal
state
- .long _start+1
- //nop // Reserved
- .long _start+1
- //nop // Reserved
- .long _start+1
- //nop // Reserved
- .long _start+1
- //nop // Reserved
- .long _start+1
- //b .LSWI_Addr // Software Interrupt
vector
- .long _start+1
- //b .LDebugMonitor_Addr // Debug Monitor
- .long _start+1
- //nop // Reserved
- .long _start+1
- //b .LPendingSV_Addr // Pendable request for
system service
- .long _start+1
- //b .LSystick_Addr // System tick timer
- //17
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- //20
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
-
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
-
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
-
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
- .long .LDefaultHandler+1
+.LDefaultLoop:
+ b .LDefaultLoop
+end;
-.LNMI_Addr:
- ldr r0,.L1
- ldr pc,[r0]
-.LHardFault_Addr:
- ldr r0,.L2
- ldr pc,[r0]
-.LMemManage_Addr:
- ldr r0,.L3
- ldr pc,[r0]
-.LBusFault_Addr:
- ldr r0,.L4
- ldr pc,[r0]
-.LUsageFault_Addr:
- ldr r0,.L5
- ldr pc,[r0]
-.LSWI_Addr:
- ldr r0,.L6
- ldr pc,[r0]
-.LDebugMonitor_Addr:
- ldr r0,.L7
- ldr pc,[r0]
-.LPendingSV_Addr:
- ldr r0,.L8
- ldr pc,[r0]
-.LSystick_Addr:
- ldr r0,.L9
- ldr pc,[r0]
-
-.L1:
- .long NMI_Handler
-.L2:
- .long HardFault_Handler
-.L3:
- .long MemManage_Handler
-.L4:
- .long BusFault_Handler
-.L5:
- .long UsageFault_Handler
-.L6:
- .long SWI_Handler
-.L7:
- .long DebugMonitor_Handler
-.L8:
- .long PendingSV_Handler
-.L9:
- .long Systick_Handler
-
- .globl _start
- .text
+procedure _FPC_start; assembler; nostackframe; interrupt 0;
+label _start;
+asm
+ .globl _start
_start:
-
// Copy initialized data to ram
ldr r1,.L_etext
ldr r2,.L_data
@@ -672,11 +538,6 @@
.long _data
.L_edata:
.long _edata
-.LDefaultHandlerAddr:
- .long .LDefaultHandler
- // default irq handler just returns
-.LDefaultHandler:
- mov pc,r14
end;
end.
_______________________________________________
fpc-devel maillist - fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel