1515// TODO: needs to be changed
1616:imagesoutdir: images
1717
18+ <% arch_def = crd.arch_def # Set local Ruby variables -%>
19+
1820= <%= crd.name %> Certification Requirements Document
1921
2022[Preface]
@@ -35,6 +37,27 @@ a| <% rev.changes.each do |change| %>
3537<% end -%>
3638|===
3739
40+ [Preface]
41+ == Typographic Conventions
42+
43+ CSR field colors::
44+
45+ * Grey fields are reserved (WPRI)
46+ * Green fields are present
47+ * Red fields are defined by the RISC-V ISA but not present
48+
49+ CSR field types::
50+
51+ [%autowidth]
52+ |===
53+ | Abbreviation | Description
54+
55+ <% CsrField::TYPE_DESC_MAP.each do |abbreviation, description| -%>
56+ | <%= abbreviation %>
57+ | <%= description %>
58+ <% end -%>
59+ |===
60+
3861== Introduction
3962
4063<%= crd.family.introduction %>
@@ -298,7 +321,7 @@ Requirement <%= req.name %> only apply when <%= req.when_pretty %>.
298321<% end -%>
299322
300323// TODO: GitHub issue 92: Use version specified by each profile.
301- <% insts = crd. arch_def.instructions.select { |i| i.defined_by?(ext_db.name,ext_db.min_version) } -%>
324+ <% insts = arch_def.instructions.select { |i| i.defined_by?(ext_db.name,ext_db.min_version) } -%>
302325<% unless insts.empty? -%>
303326==== Instructions
304327
@@ -451,13 +474,13 @@ RV64::
451474<% if inst . key? ( "operation()" ) -%>
452475[source,idl,subs="specialchars,macros"]
453476----
454- <%= inst . operation_ast ( crd . arch_def . symtab ) . gen_adoc %>
477+ <%= inst . operation_ast ( arch_def . symtab ) . gen_adoc %>
455478----
456479<% end -%>
457480
458481==== Exceptions
459482
460- <%- exception_list = inst . reachable_exceptions_str ( crd . arch_def . symtab ) -%>
483+ <%- exception_list = inst . reachable_exceptions_str ( arch_def . symtab ) -%>
461484<%- if exception_list . empty? -%>
462485This instruction does not generate synchronous exceptions.
463486<%- else -%>
@@ -504,26 +527,22 @@ h| CSR Address | <%= "0x#{csr.address.to_s(16)}" %>
504527h| Virtual CSR Address | <%= "0x#{ csr . virtual_address . to_s ( 16 ) } " %>
505528<% end -%>
506529h| Defining extension a| <%= csr . defined_by . to_asciidoc %>
507- <% if csr . dynamic_length? ( crd . arch_def ) -%>
508- h| Length | <%= csr . length_pretty ( crd . arch_def ) %>
530+ <% if csr . dynamic_length? ( arch_def ) -%>
531+ h| Length | <%= csr . length_pretty ( arch_def ) %>
509532<% else -%>
510- h| Length | <%= csr . length_pretty ( crd . arch_def ) %>
533+ h| Length | <%= csr . length_pretty ( arch_def ) %>
511534<% end -%>
512535h| Privilege Mode | <%= csr . priv_mode %>
513536|===
514537
515538
516- ==== Format
517-
518- Green fields are present in <%= crd . name %> .
519- Red fields are defined by the RISC-V ISA but not present in <%= crd . name %> .
520-
521- <% unless csr . dynamic_length? ( crd . arch_def ) || csr . fields . any? { |f | f . dynamic_location? ( crd . arch_def ) } -%>
539+ ==== <%= crd . name %> Format
540+ <% unless csr . dynamic_length? ( crd . arch_def ) || csr . implemented_fields ( arch_def ) . any? { |f | f . dynamic_location? ( crd . arch_def ) } -%>
522541<%# CSR has a known static length, so there is only one format to display -%>
523542.<%= csr . name %> format
524543[wavedrom, ,svg,subs='attributes',width="100%"]
525544....
526- <%= JSON . dump csr . wavedrom_desc ( crd . arch_def , csr . base . nil? ? 32 : csr . base , optional_type : 3 ) %>
545+ <%= JSON . dump csr . wavedrom_desc ( arch_def , csr . base . nil? ? 32 : csr . base , optional_type : 3 ) %>
527546....
528547<% else -%>
529548<%# CSR has a dynamic length, or a field has a dynamic location,
@@ -533,16 +552,119 @@ This CSR format changes dynamically with XLEN.
533552.<%= csr . name %> Format when <%= csr . length_cond32 %>
534553[wavedrom, ,svg,subs='attributes',width="100%"]
535554....
536- <%= JSON . dump csr . wavedrom_desc ( crd . arch_def , 32 , optional_type : 3 ) %>
555+ <%= JSON . dump csr . wavedrom_desc ( arch_def , 32 , optional_type : 3 ) %>
537556....
538557
539558.<%= csr . name %> Format when <%= csr . length_cond64 %>
540559[wavedrom, ,svg,subs='attributes',width="100%"]
541560....
542- <%= JSON . dump csr . wavedrom_desc ( crd . arch_def , 64 , optional_type : 3 ) %>
561+ <%= JSON . dump csr . wavedrom_desc ( arch_def , 64 , optional_type : 3 ) %>
543562....
544563
545564
546565<% end # unless dynamic length -%>
547566
567+ ==== <%= crd.name %> Field Summary
568+
569+ // use @ as a separator since IDL code can contain |
570+ [%autowidth,separator=@,float="center",align="center",cols="^,< ,< ,< ",options="header",role="stretch"]
571+ |===
572+ @ Name @ Location @ Type @ Reset Value
573+
574+ <%- csr.implemented_fields(arch_def).each do |field| -%>
575+ @ xref:<%= csr.name%> -<%= field.name%> -def[`<%= field.name %> `]
576+ a@
577+ <%- if field.dynamic_location?(arch_def) -%>
578+
579+ [when,"<%= field.location_cond32 %> "]
580+ --
581+ <%= field.location_pretty(arch_def, 32) %>
582+ --
583+
584+ [when,"<%= field.location_cond64 %> "]
585+ --
586+ <%= field.location_pretty(arch_def, 64) %>
587+ --
588+
589+ <%- else -%>
590+ <%= field.location_pretty(arch_def) %>
591+ <%- end -%>
592+ a@
593+
594+ --
595+ <%= field.type_pretty(arch_def.symtab) %>
596+ --
597+
598+ a@
599+
600+ --
601+ <%= field.reset_value_pretty(arch_def) %>
602+ --
603+
604+ <%- end -%>
605+ |===
606+
607+ ==== <%= crd.name %> Fields
608+
609+ <%- if csr.implemented_fields(arch_def).empty? -%>
610+ This CSR has no fields. However, it must still exist (not cause an `Illegal Instruction` trap) and always return zero on a read.
611+ <%- else -%>
612+
613+ <%- csr.implemented_fields(arch_def).each do |field| -%>
614+ [[<%= csr.name%> -<%= field.name%> -def]]
615+ ===== `<%= field.name %> `
616+
617+ <%- if !field.defined_in_all_bases? -%>
618+ IMPORTANT: <%= field.name %> is only defined in <%= field.base32_only? ? "RV32" : "RV64" %> (`<%= field.base32_only? ? field.location_cond32 : field.location_cond64 %> `)
619+ <%- end -%>
620+
621+ ****
622+ Location::
623+ <%= field.location_pretty(arch_def) %>
624+
625+ Description::
626+ <%= field.description.gsub("\n", " +\n") %>
627+
628+ Type::
629+ <%= field.type_pretty(arch_def.symtab) %>
630+
631+ Reset value::
632+ <%= field.reset_value_pretty(arch_def) %>
633+
634+ ****
635+
636+ <%- end -%>
637+ <%- end -%>
638+
639+ <%- if csr.implemented_fields(arch_def).map(&:has_custom_sw_write?).any? -%>
640+ ==== Software write
641+
642+ This CSR may store a value that is different from what software attempts to write.
643+
644+ When a software write occurs (_e.g._, through `csrrw`), the following determines the
645+ written value:
646+
647+ [idl]
648+ ----
649+ <%- csr.implemented_fields(arch_def).each do |field| -%>
650+ <%- if field.has_custom_sw_write? -%>
651+ <%= field.name %> = <%= field["sw_write(csr_value)"] %>
652+ <%- else -%>
653+ <%= field.name %> = csr_value.<%= field.name %>
654+ <%- end -%>
655+ <%- end -%>
656+ ----
657+ <%- end -%>
658+
659+ <%- if csr.has_custom_sw_read? -%>
660+ ==== Software read
661+
662+ This CSR may return a value that is different from what is stored in hardware.
663+
664+ [source,idl,subs="specialchars,macros"]
665+ ----
666+ <%= csr.sw_read_ast(arch_def.symtab).gen_adoc %>
667+ ----
668+ <%- end -%>
669+
548670<% end # do csrs -%>
0 commit comments