Skip to content

Commit 548613c

Browse files
committed
Improve debugger layout and make markers get in the way less
1 parent b47828b commit 548613c

File tree

1 file changed

+60
-183
lines changed

1 file changed

+60
-183
lines changed

src/peripherals/debugger.mlog.jinja

Lines changed: 60 additions & 183 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ reset_markers:
3434
setmarker remove i
3535
jump reset_markers greaterThan i MARKER_START_ID
3636

37+
reset_loop:
3738
wait 1e-5
3839
sensor enabled {{SWITCH}} @enabled
39-
jump reset equal enabled false
40+
jump reset_loop equal enabled false
4041

4142
set i -1
4243
reset__find_lookup_start:
@@ -47,8 +48,6 @@ reset__find_lookup_start:
4748
read type_var block "_type"
4849
jump reset__find_lookup_start notEqual type_var "lookup"
4950

50-
set LOOKUP_START i
51-
5251
control enabled {{SWITCH}} true
5352

5453
draw reset
@@ -191,11 +190,6 @@ loop:
191190
read rd {{CPU}} "rd_id"
192191
read imm {{CPU}} "imm"
193192

194-
set address pc
195-
op add ret @counter 1
196-
jump load_word always
197-
set instruction result
198-
199193
read __etext {{CPU}} "__etext"
200194
read reservation_set {{CPU}} "reservation_set"
201195
read privilege_mode {{CPU}} "privilege_mode"
@@ -334,36 +328,19 @@ loop__no_mark_icache:
334328

335329
#{ print(14, 0)
336330

337-
print "pc = {0}\n"
331+
print "pc = {0}\n"
338332
set n pc
339333
op add ret @counter 1
340334
jump format_hex always
341335

342-
print "instruction = {0}\n"
343-
set n instruction
344-
op add ret @counter 1
345-
jump format_hex always
346-
347-
print "op_id = {0}\n"
348-
print "imm = {1}\n"
349-
print "rs1 = {2}\n"
350-
print "rs2 = {3}\n"
351-
print "rd = {4}\n\n"
336+
print "op_id = {0}\n"
337+
print "imm = {1}\n"
338+
print "rs1 = {2}\n"
339+
print "rs2 = {3}\n"
340+
print "rd = {4}\n\n"
352341
op add ret2 @counter 1
353342
jump format_op_id always
354343

355-
print "mtimecmp = {0}\n"
356-
format mtimecmp
357-
358-
print "mtime = {0}\n"
359-
format mtime
360-
361-
print "mcycle = {0}\n"
362-
format mcycle
363-
364-
print "minstret = {0}\n\n"
365-
format minstret
366-
367344
#{ print(0, 17)
368345

369346
print "mtvec = {0}\n"
@@ -386,7 +363,7 @@ loop__no_mark_icache:
386363
op add ret @counter 1
387364
jump format_hex always
388365

389-
print "mscratch = {0}\n"
366+
print "mscratch = {0}\n\n"
390367
set n mscratch
391368
op add ret @counter 1
392369
jump format_hex always
@@ -406,7 +383,21 @@ loop__no_mark_icache:
406383
op add ret @counter 1
407384
jump format_bin always
408385

409-
#{ print(0, 30)
386+
#{ print(0, 24)
387+
388+
print "mtimecmp = {0}\n"
389+
format mtimecmp
390+
391+
print "mtime = {0}\n"
392+
format mtime
393+
394+
print "mcycle = {0}\n"
395+
format mcycle
396+
397+
print "minstret = {0}\n"
398+
format minstret
399+
400+
#{ print(0, 34)
410401

411402
# column 2
412403

@@ -515,28 +506,7 @@ loop__no_mark_icache:
515506
op add ret @counter 1
516507
jump format_privilege_mode always
517508

518-
set uart {{UART0}}
519-
set uart_index 0
520-
op add ret @counter 1
521-
jump format_uart always
522-
523-
set uart {{UART1}}
524-
set uart_index 1
525-
op add ret @counter 1
526-
jump format_uart always
527-
528-
set uart {{UART2}}
529-
set uart_index 2
530-
op add ret @counter 1
531-
jump format_uart always
532-
533-
set uart {{UART3}}
534-
set uart_index 3
535-
op add ret @counter 1
536-
jump format_uart always
537-
print "\n"
538-
539-
print "satp = {0}\n\n"
509+
print "satp = {0}\n"
540510
set n satp
541511
op add ret @counter 1
542512
jump format_hex always
@@ -568,6 +538,28 @@ loop__no_mark_icache:
568538

569539
#{ print(35, 17)
570540

541+
set uart {{UART0}}
542+
set uart_index 0
543+
op add ret @counter 1
544+
jump format_uart always
545+
546+
set uart {{UART1}}
547+
set uart_index 1
548+
op add ret @counter 1
549+
jump format_uart always
550+
551+
set uart {{UART2}}
552+
set uart_index 2
553+
op add ret @counter 1
554+
jump format_uart always
555+
556+
set uart {{UART3}}
557+
set uart_index 3
558+
op add ret @counter 1
559+
jump format_uart always
560+
561+
#{ print(30, 34)
562+
571563
wait 0.02
572564
jump loop always
573565

@@ -803,16 +795,19 @@ format_uart:
803795
op notEqual rx_overflow_flag rx_wptr rx_wptr_raw
804796
op land rx_overrun rx_full rx_overflow_flag
805797

806-
print "uart{0}: r={1} ({2}-{3})"
798+
print "uart{0}: rx={1}"
807799
jump format_uart__rx_fifo_size__no_overrun notEqual rx_overrun true
808-
print " !!"
800+
print "!"
801+
jump format_uart__rx_fifo_size__no_overrun__done always
809802
format_uart__rx_fifo_size__no_overrun:
803+
print " "
804+
format_uart__rx_fifo_size__no_overrun__done:
805+
print "({2}-{3}) tx={4} ({5}-{6})\n"
806+
810807
format uart_index
811808
format rx_fifo_size
812809
format rx_rptr
813810
format rx_wptr
814-
815-
print " t={0} ({1}-{2})\n"
816811
format tx_fifo_size
817812
format tx_rptr
818813
format tx_wptr
@@ -918,140 +913,22 @@ mark_memory__found:
918913

919914
setmarker remove mark_memory_id
920915
makemarker shapeText mark_memory_id x y false
916+
921917
op sub layer 120 mark_memory_id
922918
op add layer layer MARKER_START_ID
923919
setmarker drawLayer mark_memory_id layer
920+
921+
setmarker radius mark_memory_id 3
922+
setmarker textHeight mark_memory_id 0.5
923+
setmarker fontSize mark_memory_id 0.9
924+
924925
setmarker flushText mark_memory_id false
925926

926927
op add mark_memory_id mark_memory_id 1
927928
set @counter mark_memory__ret
928929

929-
# helper function to find the ram proc and variable for a given address
930-
# address -> ram, variable
931-
access_ram:
932-
op sub _address address {{RAM_START}}
933-
934-
# we store 4 bytes in each value
935-
op idiv _address _address 4
936-
937-
# get the ram proc containing this address
938-
op idiv _ram_index _address {{RAM_PROC_VARS}}
939-
op add _ram_index _ram_index RAM_START_PROC
940-
941-
op mod _ram_x _ram_index MEMORY_WIDTH
942-
op add _ram_x _ram_x MEMORY_X
943-
944-
op idiv _ram_y _ram_index MEMORY_WIDTH
945-
op add _ram_y _ram_y MEMORY_Y
946-
947-
getblock building ram _ram_x _ram_y
948-
949-
# get the variable within the ram proc containing this address
950-
op mod _address _address {{RAM_PROC_VARS}}
951-
set lookup_variable__ret access_ram__ret
952-
953-
# given a value 0 <= _address < RAM_PROC_VARS, resolve that variable in the lookup table
954-
# this must stay directly after access_ram
955-
# _address -> variable
956-
op idiv _lookup _address {{LOOKUP_PROC_SIZE}}
957-
op add _lookup _lookup LOOKUP_START
958-
getlink _lookup _lookup
959-
960-
op mod variable _address {{LOOKUP_PROC_SIZE}}
961-
lookup block variable variable
962-
sensor variable variable @name
963-
read variable _lookup variable
964-
965-
set @counter lookup_variable__ret
966-
967-
# loads the word from memory that contains the specified address
968-
# mcause is required in order to raise the correct exception in case of access fault
969-
# address, mcause -> result
970-
load_word:
971-
jump load_rom_word_unchecked lessThan address ROM_SIZE
972-
973-
jump inaccessible_load lessThan address {{RAM_START}}
974-
jump inaccessible_load greaterThanEq address RAM_END
975-
976-
# locate and read value from ram
977-
op add access_ram__ret @counter 1
978-
jump access_ram always
979-
read value ram variable
980-
# null is coerced to 0 by swap_endianness
981-
982-
# tail call, swap_endianness will jump to the ret value of load_word's caller
983-
984-
# converts a little endian 32-bit number to big endian, or vice versa
985-
# https://stackoverflow.com/a/2182184
986-
# this MUST stay directly after load_word
987-
# value -> result
988-
# swap_endianness:
989-
# byte 3 -> byte 0
990-
op shr result value 24
991-
op and result result 0xff
992-
993-
# byte 1 -> byte 2
994-
op shl _tmp value 8
995-
op and _tmp _tmp 0xff0000
996-
op or result result _tmp
997-
998-
# byte 2 -> byte 1
999-
op shr _tmp value 8
1000-
op and _tmp _tmp 0xff00
1001-
op or result result _tmp
1002-
1003-
# byte 0 -> byte 3
1004-
op shl _tmp value 24
1005-
op and _tmp _tmp 0xff000000
1006-
op or result result _tmp
1007-
1008-
set @counter ret
1009-
1010-
# loads a word from ROM
1011-
# address -> result
1012-
load_rom_word_unchecked:
1013-
# align to 4 bytes
1014-
op and _address address 0xfffffffc
1015-
1016-
# get rom proc data
1017-
op idiv _rom_index _address {{ROM_PROC_BYTES}}
1018-
1019-
op mod _rom_x _rom_index MEMORY_WIDTH
1020-
op add _rom_x _rom_x MEMORY_X
1021-
1022-
op idiv _rom_y _rom_index MEMORY_WIDTH
1023-
op add _rom_y _rom_y MEMORY_Y
1024-
1025-
getblock building _rom _rom_x _rom_y
1026-
read _rom _rom "v"
1027-
1028-
# read word and convert to big endian
1029-
set result 0
1030-
1031-
op mod _str_index _address {{ROM_PROC_BYTES}}
1032-
set _shift 0 # leftmost byte in memory becomes rightmost byte in word
1033-
load_rom_word__loop:
1034-
read _byte _rom _str_index
1035-
op sub _byte _byte {{ROM_BYTE_OFFSET}}
1036-
op max _byte _byte 0 # if we're reading out of bounds, default to 0
1037-
op shl _byte _byte _shift
1038-
op add result result _byte
1039-
1040-
op add _str_index _str_index 1
1041-
op add _shift _shift 8
1042-
jump load_rom_word__loop lessThan _shift 32 # stop when we've read 4 bytes
1043-
1044-
set _rom null # avoid issues with the vars menu and block data size
1045-
set @counter ret
1046-
1047-
inaccessible_load:
1048-
set result null
1049-
set @counter ret
1050-
1051930
#% if false
1052931
# {% raw %}
1053-
set {{LOOKUP_PROC_SIZE}} null
1054-
set {{ROM_BYTE_OFFSET}} null
1055932
set {{ROM_PROC_BYTES}} null
1056933
set {{RAM_PROC_VARS}} null
1057934
set {{ROM_START}} null

0 commit comments

Comments
 (0)