Skip to contentSkip to conversation

: add leon target

PATCH In review Tristan Gingold 4 participants 10 messages Jan 7, 2009 – Jan 8, 2009 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 : add leon target

Hi,

this patch adds a new target: leon which is an open source sparc v8 variant.

The cpu itself implements the v8 architecture so there is nothing to change. However the devices are different and in particular the interrupt controller.

To handle different interrupt controllers, I added a new field in CPUSPARCState like it is done on PowerPC.

Comments are welcome,
Tristan.

Makefile.target +1 -1
Index: Makefile.target
===================================================================
@@ -694,7 +694,7 @@
 else
 OBJS+= sun4m.o tcx.o pcnet.o iommu.o m48t59.o slavio_intctl.o
 OBJS+= slavio_timer.o slavio_serial.o slavio_misc.o fdc.o sparc32_dma.o
-OBJS+= cs4231.o ptimer.o eccmemctl.o sbi.o sun4c_intctl.o
+OBJS+= cs4231.o ptimer.o eccmemctl.o sbi.o sun4c_intctl.o leon.o
 endif
 endif
 ifeq ($(TARGET_BASE_ARCH), arm)
helper.c +6 -1
Index: target-sparc/helper.c
===================================================================
@@ -731,6 +731,11 @@
 #endif
 }
 
+void cpu_sparc_set_intctl(CPUSPARCState *env, intctl_model intctl)
+{
+    env->intctl = intctl;
+}
+
 static const sparc_def_t sparc_defs[] = {
 #ifdef TARGET_SPARC64
     {
@@ -1166,7 +1171,7 @@
         .iu_version = 0xf2000000,
         .fpu_version = 4 << 17, /* FPU version 4 (Meiko) */
         .mmu_version = 0xf2000000,
-        .mmu_bm = 0x00004000,
+        .mmu_bm = 0x00000000,
         .mmu_ctpr_mask = 0x007ffff0,
         .mmu_cxr_mask = 0x0000003f,
         .mmu_sfsr_mask = 0xffffffff,
machine.c +1 -0
Index: target-sparc/machine.c
===================================================================
@@ -23,6 +23,7 @@
     qemu_register_machine(&sbook_machine);
     qemu_register_machine(&ss1000_machine);
     qemu_register_machine(&ss2000_machine);
+    qemu_register_machine(&at697_machine);
 #endif
 }
 
cpu.h +13 -0
Index: target-sparc/cpu.h
===================================================================
@@ -188,6 +188,14 @@
 #define MIN_NWINDOWS 3
 #define MAX_NWINDOWS 32
 
+typedef enum intctl_model {
+  intctl_none,
+  intctl_sun4c,
+  intctl_sun4m,
+  intctl_sun4u,
+  intctl_leon2
+} intctl_model;
+
 #if !defined(TARGET_SPARC64)
 #define NB_MMU_MODES 2
 #else
@@ -279,6 +287,7 @@
     int      psref;    /* enable fpu */
     target_ulong version;
     int interrupt_index;
+    intctl_model intctl; /* interrupt controller model */
     uint32_t nwindows;
     /* NOTE: we allow 8 more registers to handle wrapping */
     target_ulong regbase[MAX_NWINDOWS * 16 + 8];
@@ -340,6 +349,7 @@
 
 /* helper.c */
 CPUSPARCState *cpu_sparc_init(const char *cpu_model);
+void cpu_sparc_set_intctl(CPUSPARCState *env, intctl_model intctl);
 void cpu_sparc_set_id(CPUSPARCState *env, unsigned int cpu);
 void sparc_cpu_list (FILE *f, int (*cpu_fprintf)(FILE *f, const char *fmt,
                                                  ...));
@@ -500,6 +510,9 @@
 /* sum4m.c, sun4u.c */
 void cpu_check_irqs(CPUSPARCState *env);
 
+/* leon.c */
+void leon2_intctl_ack(CPUSPARCState *env, int intno);
+
 #ifdef TARGET_SPARC64
 /* sun4u.c */
 void cpu_tick_set_count(void *opaque, uint64_t count);
op_helper.c +15 -0
Index: target-sparc/op_helper.c
===================================================================
@@ -2995,6 +2995,21 @@
     env->pc = env->tbr;
     env->npc = env->pc + 4;
     env->exception_index = 0;
+
+    switch (env->intctl) {
+    case intctl_sun4c:
+    case intctl_sun4m:
+#if !defined(CONFIG_USER_ONLY)
+      cpu_check_irqs(env);
+#endif
+      break;
+    case intctl_leon2:
+      if ((intno & ~15) == TT_EXTINT)
+	leon2_intctl_ack (env, intno);
+      break;
+    default:
+      break;
+    }
 }
 #endif
 
cpu-exec.c +2 -5
Index: cpu-exec.c
===================================================================
@@ -447,12 +447,9 @@
 			    type != TT_EXTINT) {
 			    env->interrupt_request &= ~CPU_INTERRUPT_HARD;
                             env->exception_index = env->interrupt_index;
-                            do_interrupt(env);
 			    env->interrupt_index = 0;
-#if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY)
-                            cpu_check_irqs(env);
-#endif
-                        next_tb = 0;
+                            do_interrupt(env);
+			    next_tb = 0;
 			}
 		    } else if (interrupt_request & CPU_INTERRUPT_TIMER) {
 			//do_interrupt(0, 0, 0, 0, 0);
leon.c +560 -0

560 lines not on this page · raw message

sun4m.c +3 -0
Index: hw/sun4m.c
===================================================================
@@ -451,6 +451,7 @@
             fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
             exit(1);
         }
+        cpu_sparc_set_intctl(env, intctl_sun4m);
         cpu_sparc_set_id(env, i);
         envs[i] = env;
         if (i == 0) {
@@ -1257,6 +1258,7 @@
             fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
             exit(1);
         }
+        cpu_sparc_set_intctl(env, intctl_sun4m);
         cpu_sparc_set_id(env, i);
         envs[i] = env;
         if (i == 0) {
@@ -1482,6 +1484,7 @@
         exit(1);
     }
 
+    cpu_sparc_set_intctl(env, intctl_sun4c);
     cpu_sparc_set_id(env, 0);
 
     qemu_register_reset(main_cpu_reset, env);
boards.h +3 -0
Index: hw/boards.h
===================================================================
@@ -71,6 +71,9 @@
 extern QEMUMachine sun4v_machine;
 extern QEMUMachine niagara_machine;
 
+/* leon.c */
+extern QEMUMachine at697_machine;
+
 /* integratorcp.c */
 extern QEMUMachine integratorcp_machine;
 
#1 lore raw
Quoted 10 lines · Tristan Gingold

Hi,

this patch adds a new target: leon which is an open source sparc v8 variant.

The cpu itself implements the v8 architecture so there is nothing to change. However the devices are different and in particular the interrupt controller.

To handle different interrupt controllers, I added a new field in CPUSPARCState like it is done on PowerPC.

U-Boot support it maybe you can try to use it

Gaisler LEON2 GRSIM simulator
grsim_leon2_config

Best Regards,
J.

#2 lore raw
Quoted 4 lines · Jean-Christophe PLAGNIOL-VILLARD

U-Boot support it maybe you can try to use it

Gaisler LEON2 GRSIM simulator
grsim_leon2_config

Yes, and there is even a port of linux to leon2. I will try run it if I have time to improve the leon2 support.

Tristan.

#3 lore raw
In reply to Tristan Gingold
Quoted 3 lines · Tristan Gingold

Hi,

this patch adds a new target: leon which is an open source sparc v8 variant.

Thanks for the patch. Is there any way to test the system, rom images etc? Any system level docs?

Do you think it would be useful to port OpenBIOS to the system?

Quoted 5 lines

The cpu itself implements the v8 architecture so there is nothing to change. However the devices are different and in particular the interrupt controller.

To handle different interrupt controllers, I added a new field in CPUSPARCState like it is done on PowerPC.

I have a feeling that this should be handled some other way but I don't know how yet. CPU emulation should not know about boards.

Quoted 2 lines

Comments are welcome,
Tristan.

Maybe the leon.c should be split, each device in a separate file. Though I guess the devices are so unique that they won't be used elsewhere.

Quoted 9 lines

+++ target-sparc/op_helper.c (working copy)
@@ -2995,6 +2995,21 @@

     env->pc = env->tbr;
     env->npc = env->pc + 4;
     env->exception_index = 0;
 +
 +    switch (env->intctl) {
 +    case intctl_sun4c:
 +    case intctl_sun4m:
Quoted 7 lines

+#if !defined(CONFIG_USER_ONLY)
+ cpu_check_irqs(env);
+#endif
+ break;
+ case intctl_leon2:
+ if ((intno & ~15) == TT_EXTINT)
+ leon2_intctl_ack (env, intno);

This breaks linux-user compilation, the whole switch should be enclosed in #if !defined(CONFIG_USER_ONLY)
#endif

For extra bonus, you could implement the following:
- register device reset methods
- savevm/loadvm support
- pic_info, irq_info support

#4 lore raw
Quoted 7 lines · Blue Swirl
Quoted 3 lines · Tristan Gingold

Hi,

this patch adds a new target: leon which is an open source sparc v8 variant.

Thanks for the patch. Is there any way to test the system, rom images etc? Any system level docs?

I can send an image if you need one. I can also send the sources but I suppose it would be useless to you as this is Ada code.

For docs, see:
http://www.atmel.com/dyn/products/product_card.asp?part_id=3178

or www.gaisler.com

(Don't forget leon is open-source. You can get VHDL files if you need).

Quoted 1 line

Do you think it would be useful to port OpenBIOS to the system?

Usually this chip is used in space engine: no disk and no ethernet. I doubt OpenBIOS would be useful. Gaisler Research provides a monitor but I didn't test it on qemu (and I am not sure it is freely available). Also there is a port of Linux. I once made it running on qemu (maybe 4 years ago). It should be the easiest way to test the system.

Quoted 8 lines
Quoted 5 lines

The cpu itself implements the v8 architecture so there is nothing to change. However the devices are different and in particular the interrupt controller.

To handle different interrupt controllers, I added a new field in CPUSPARCState like it is done on PowerPC.

I have a feeling that this should be handled some other way but I don't know how yet. CPU emulation should not know about boards.

I have the same feeling too. I am ready to improve the code but I need a few advices. As currently implemented CPU emulation know about interrupt controller. Wether interrupt controller belongs to CPU or to the board is an open question :-)
Do you simply prefer to have hooks in CPUSPARCState ?

The same question applies to the MMU. Most of early SPARC models do not have an integrated MMU. Leon2 MMU is optional too.

Quoted 6 lines
Quoted 2 lines

Comments are welcome,
Tristan.

Maybe the leon.c should be split, each device in a separate file. Though I guess the devices are so unique that they won't be used elsewhere.

Yes, they are so unique that it would create a lot of small files. I am not sure we want to go that way.

Quoted 7 lines
Quoted 7 lines
op_helper.c +7 -0
+
+    switch (env->intctl) {
+    case intctl_sun4c:
+    case intctl_sun4m:
+#if !defined(CONFIG_USER_ONLY)
+      cpu_check_irqs(env);
+#endif
Quoted 8 lines

op_helper.c line 3008

Quoted 4 lines
op_helper.c +4 -0
+      break;
+    case intctl_leon2:
+      if ((intno & ~15) == TT_EXTINT)
+       leon2_intctl_ack (env, intno);

This breaks linux-user compilation, the whole switch should be enclosed in #if !defined(CONFIG_USER_ONLY)
#endif

Oops, sorry. I will fix that.

Quoted 4 lines

For extra bonus, you could implement the following:
- register device reset methods
- savevm/loadvm support
- pic_info, irq_info support

Ok.

Tristan.

#5 lore raw
Quoted 5 lines · Tristan Gingold
Quoted 2 lines · Blue Swirl
Quoted 1 line · Tristan Gingold

Hi,

Thanks for the patch Tristian,

I've got a couple of comments:

Quoted 39 lines
Quoted 6 lines
Quoted 3 lines

this patch adds a new target: leon which is an open source sparc v8 variant.

Thanks for the patch. Is there any way to test the system, rom images etc? Any system level docs?

I can send an image if you need one. I can also send the sources but I suppose it would be useless to you
as this is Ada code.

For docs, see:
http://www.atmel.com/dyn/products/product_card.asp?part_id=3178

or www.gaisler.com

(Don't forget leon is open-source. You can get VHDL files if you need).

Quoted 1 line

Do you think it would be useful to port OpenBIOS to the system?

Usually this chip is used in space engine: no disk and no ethernet. I doubt OpenBIOS would be useful.
Gaisler Research provides a monitor but I didn't test it on qemu (and I am not sure it is freely available).
Also there is a port of Linux. I once made it running on qemu (maybe 4 years ago). It should be the
easiest way to test the system.

Quoted 10 lines
Quoted 7 lines

The cpu itself implements the v8 architecture so there is nothing to change.
However the devices are different and in particular the interrupt controller.

To handle different interrupt controllers, I added a new field in CPUSPARCState like it is done on PowerPC.

I have a feeling that this should be handled some other way but I don't know how yet. CPU emulation should not know about boards.

Quoted 8 lines

I have the same feeling too. I am ready to improve the code but I need a few advices.
As currently implemented CPU emulation know about interrupt controller. Wether interrupt controller
belongs to CPU or to the board is an open question :-)
Do you simply prefer to have hooks in CPUSPARCState ?

From my experience, interrupt controllers are usually not considered to

be part of the CPU.

Regarding the leon interrupt controller, I had a quick look at the vhdl and AFAICT there is no need for any special tricks in the sparc cpu model. What you need is to handle accesses to the interrupt clear register, in your code you seem to call it ITC and your io_writel does not handle it. This is the place to hook in calls to mask off bits from the pending interrupt reg.

Your leon software should be writing to this register when acking interrupts.

What you are doing know is providing a magic automatic ACK from the core as soon as the interrupt is taken, IIUC this is not what leon does.

Quoted 8 lines

The same question applies to the MMU. Most of early SPARC models do not have an integrated MMU.
Leon2 MMU is optional too.

Quoted 3 lines
Quoted 2 lines

Comments are welcome,
Tristan.

Quoted 6 lines
Quoted 3 lines

Maybe the leon.c should be split, each device in a separate file. Though I guess the devices are so unique that they won't be used elsewhere.

Yes, they are so unique that it would create a lot of small files. I am not sure we want to go that way.

IMO you should be splitting the different blocks into separate files as already suggested. You should also register separate IO regions for every block. This is important in order to be able to reuse the blocks for different leon based socs/boards that may have different memory maps.

Cheers

#6 lore raw
Quoted 1 line
Quoted 1 line

Hi,

Quoted 9 lines
Quoted 6 lines

I have the same feeling too. I am ready to improve the code but I need a few advices.
As currently implemented CPU emulation know about interrupt controller. Wether interrupt controller
belongs to CPU or to the board is an open question :-)
Do you simply prefer to have hooks in CPUSPARCState ?

From my experience, interrupt controllers are usually not considered to be part of the CPU.

(What about LAPIC/LSAPIC ?)

Quoted 9 lines

Regarding the leon interrupt controller, I had a quick look at the vhdl and AFAICT there is no need for any special tricks in the sparc cpu model. What you need is to handle accesses to the interrupt clear register, in your code you seem to call it ITC and your io_writel does not handle it. This is the place to hook in calls to mask off bits from the pending interrupt reg.

Your leon software should be writing to this register when acking interrupts.

No. You have missed (p19):

When the IU acknowledges the interrupt, the corresponding pending bit will automatically be cleared.

This is the only reason why the CPU must inform the interrupt controller.

Quoted 2 lines

What you are doing know is providing a magic automatic ACK from the core as soon as the interrupt is taken, IIUC this is not what leon does.

It is ;-)

Quoted 4 lines

IMO you should be splitting the different blocks into separate files as already suggested. You should also register separate IO regions for every block. This is important in order to be able to reuse the blocks for different leon based socs/boards that may have different memory maps.

Ok.

Tristan.

#7 lore raw
Quoted 12 lines · Tristan Gingold
Quoted 1 line
Quoted 1 line

Hi,

Quoted 7 lines
Quoted 6 lines

I have the same feeling too. I am ready to improve the code but I need a few advices.
As currently implemented CPU emulation know about interrupt controller. Wether interrupt controller
belongs to CPU or to the board is an open question :-)
Do you simply prefer to have hooks in CPUSPARCState ?

Quoted 4 lines
Quoted 2 lines

From my experience, interrupt controllers are usually not considered to be part of the CPU.

(What about LAPIC/LSAPIC ?)

There are ofcourse exceptions :)

Quoted 13 lines
Quoted 10 lines

Regarding the leon interrupt controller, I had a quick look at the vhdl and
AFAICT there is no need for any special tricks in the sparc cpu model. What you need is to handle accesses to the interrupt clear register, in your
code you seem to call it ITC and your io_writel does not handle it. This is the place to hook in calls to mask off bits from the pending interrupt reg.

Quoted 2 lines

Your leon software should be writing to this register when acking interrupts.

Quoted 7 lines

No. You have missed (p19):

When the IU acknowledges the interrupt, the corresponding pending bit will automatically be cleared.

This is the only reason why the CPU must inform the interrupt controller.

Not sure what docs you are refering to, but I had a second look at the vhd and you seem to be correct. Odd...

Best regards

#8 lore raw
Quoted 2 lines

Not sure what docs you are refering to, but I had a second look at the

Sorry I was referring to the AT697E manual.

Quoted 1 line

vhd and you seem to be correct. Odd...

Yes, boring for our case...

Tristan.

#9 lore raw
Quoted 8 lines · Tristan Gingold
Quoted 2 lines

Not sure what docs you are refering to, but I had a second look at the

Sorry I was referring to the AT697E manual.

Quoted 1 line

vhd and you seem to be correct. Odd...

Yes, boring for our case...

Hi again,

You might want to handle writes to the ITC reg anyway.

It is increasingly common for drivers (software) to mix interrupt drivenness with polling modes. These drivers sometimes need to be able to poll for and ack interrupts without necessarily having the core take them.

Best regards