Skip to content
This repository
Browse code

Add new BIOS commands to play with MMU

  • Loading branch information...
commit 2f35de4d8270d964de7565a72d49cf1267b44703 1 parent 2bcd496
Yann Sionneau authored June 06, 2012
4  software/bios/dtlb_exception_handling_tests.c
@@ -51,7 +51,7 @@ void dtlb_exception_handling_tests() {
51 51
 	printf("\n<= Reading %d from virtual address 0x%08X\n\n", data, addr);
52 52
 
53 53
 	printf("=> Invalidating the mapping of virtual address 0x%08X in the TLB\n", addr);
54  
-	mmu_dtlb_invalidate(addr);
  54
+	mmu_dtlb_invalidate_line(addr);
55 55
 
56 56
 	data = 43;
57 57
 	printf("=> Writing %d to physical address 0x%08X\n", data, addr);
@@ -67,7 +67,7 @@ void dtlb_exception_handling_tests() {
67 67
 	check_for_error(ret);
68 68
 
69 69
 	printf("=> Invalidating the mapping of virtual address 0x%08X in the TLB\n", addr);
70  
-	mmu_dtlb_invalidate(addr); // AND invalidate the mapping
  70
+	mmu_dtlb_invalidate_line(addr); // AND invalidate the mapping
71 71
 
72 72
 	data = 44;
73 73
 	printf("=> Writting %d to physical address 0x%08X\n", data, addr+0x1000);
86  software/bios/main.c
@@ -422,6 +422,14 @@ static void help()
422 422
 	puts("version    - display version");
423 423
 	puts("reboot     - system reset");
424 424
 	puts("reconf     - reload FPGA configuration");
  425
+	puts("dmap       - adds a MMU DTLB mapping");
  426
+	puts("dunmap     - removes a MMU DTLB mapping");
  427
+	puts("dtlbi      - invalidates the whole DTLB");
  428
+	puts("dmapi      - invalidates a DTLB mapping");
  429
+	puts("mmu        - activates MMU");
  430
+	puts("nommu      - disactivates MMU");
  431
+	puts("mmuread    - reads from memory with MMU enabled");
  432
+	puts("mmuwrite   - writes to memory with MMU enabled");
425 433
 	puts("dtlbtest   - runs DTLB MMU load store tests");
426 434
 	puts("detest     - runs DTLB MMU exception handling tests");
427 435
 }
@@ -506,6 +514,75 @@ static void dtlbtest(void)
506 514
 
507 515
 }
508 516
 
  517
+void mmuread(char *vaddr_str)
  518
+{
  519
+	unsigned int vaddr, data;
  520
+	char *c;
  521
+
  522
+	vaddr = strtoul(vaddr_str, &c, 0);
  523
+
  524
+	data = read_word_with_mmu_enabled(vaddr);
  525
+
  526
+	printf("0x%08X contains 0x%08X\n", vaddr, data);
  527
+}
  528
+
  529
+void mmuwrite(char *vaddr_str, char * data_str)
  530
+{
  531
+	unsigned int vaddr, data;
  532
+	char *c;
  533
+
  534
+	vaddr = strtoul(vaddr_str, &c, 0);
  535
+	data = strtoul(data_str, &c, 0);
  536
+
  537
+	write_word_with_mmu_enabled(vaddr, data);
  538
+}
  539
+
  540
+void dmap(char *vaddr_str, char *paddr_str)
  541
+{
  542
+	unsigned int vaddr, paddr;
  543
+	char *c;
  544
+
  545
+	vaddr = strtoul(vaddr_str, &c, 0);
  546
+	paddr = strtoul(paddr_str, &c, 0);
  547
+
  548
+	mmu_map(vaddr, paddr);
  549
+}
  550
+
  551
+void dunmap(char *vaddr_str)
  552
+{
  553
+	unsigned int vaddr;
  554
+	char *c;
  555
+
  556
+	vaddr = strtoul(vaddr_str, &c, 0);
  557
+
  558
+	remove_mmu_mapping_for(vaddr);
  559
+}
  560
+
  561
+void dtlbi(void)
  562
+{
  563
+	mmu_dtlb_invalidate();
  564
+}
  565
+
  566
+void dmapi(char *vaddr_str)
  567
+{
  568
+	unsigned int vaddr;
  569
+	char *c;
  570
+
  571
+	vaddr = strtoul(vaddr_str, &c, 0);
  572
+
  573
+	mmu_dtlb_invalidate_line(vaddr);
  574
+}
  575
+
  576
+void activate_mmu(void)
  577
+{
  578
+	enable_dtlb();
  579
+}
  580
+
  581
+void disactivate_mmu(void)
  582
+{
  583
+	disable_dtlb();
  584
+}
  585
+
509 586
 static void do_command(char *c)
510 587
 {
511 588
 	char *token;
@@ -540,7 +617,14 @@ static void do_command(char *c)
540 617
 	else if(strcmp(token, "wcsr") == 0) wcsr(get_token(&c), get_token(&c));
541 618
 	else if(strcmp(token, "dtlbtest") == 0) dtlbtest();
542 619
 	else if(strcmp(token, "detest") == 0) dtlb_exception_handling_tests();
543  
-
  620
+	else if(strcmp(token, "dmap") == 0) dmap(get_token(&c), get_token(&c));
  621
+	else if(strcmp(token, "dunmap") == 0) dunmap(get_token(&c));
  622
+	else if(strcmp(token, "dtlbi") == 0) dtlbi();
  623
+	else if(strcmp(token, "mmu") == 0) activate_mmu();
  624
+	else if(strcmp(token, "nommu") == 0) disactivate_mmu();
  625
+	else if(strcmp(token, "mmuread") == 0) mmuread(get_token(&c));
  626
+	else if(strcmp(token, "mmuwrite") == 0) mmuwrite(get_token(&c), get_token(&c));
  627
+	else if(strcmp(token, "dmapi") == 0) dmapi(get_token(&c));
544 628
 	else if(strcmp(token, "") != 0)
545 629
 		printf("Command not found\n");
546 630
 }
3  software/include/hal/mmu.h
@@ -50,6 +50,7 @@ struct mmu_mapping {
50 50
 
51 51
 void mmu_dtlb_map(unsigned int vpfn, unsigned int pfn);
52 52
 unsigned int read_word_with_mmu_enabled(unsigned int vaddr);
53  
-void mmu_dtlb_invalidate(unsigned int vaddr);
  53
+void mmu_dtlb_invalidate_line(unsigned int vaddr);
  54
+void mmu_dtlb_invalidate(void);
54 55
 
55 56
 #endif
45  software/libhal/mmu.c
@@ -18,6 +18,10 @@
18 18
 #include <hal/mmu.h>
19 19
 #include <base/mmu.h>
20 20
 
  21
+#define DTLB_CTRL_FLUSH_CMD	(0x3)
  22
+#define DTLB_CTRL_DISABLE_CMD	(0x5)
  23
+#define DTLB_CTRL_ENABLE_CMD	(0x9)
  24
+
21 25
 /* @vpfn : virtual page frame number
22 26
  * @pfn  : physical page frame number
23 27
  */
@@ -25,25 +29,32 @@ inline void mmu_dtlb_map(unsigned int vpfn, unsigned int pfn)
25 29
 {
26 30
 
27 31
 	asm volatile	("ori %0, %0, 1\n\t"
28  
- 			 "wcsr tlbvaddr, %0"::"r"(vpfn):);
  32
+ 			 "wcsr tlbvaddr, %0" :: "r"(vpfn) : );
29 33
 
30 34
 	asm volatile	("ori %0, %0, 1\n\t"
31 35
 			 "wcsr tlbpaddr, %0"::"r"(pfn):);
32 36
 
33 37
 	asm volatile	("xor r11, r11, r11\n\t"
34 38
 			 "ori r11, r11, 0x5\n\t"
35  
-			 "wcsr tlbctrl, r11":::"r11");
  39
+			 "wcsr tlbctrl, r11" ::: "r11");
36 40
 
37 41
 }
38 42
 
39  
-inline void mmu_dtlb_invalidate(unsigned int vaddr)
  43
+inline void mmu_dtlb_invalidate_line(unsigned int vaddr)
40 44
 {
41 45
 	asm volatile ("ori %0, %0, 1\n\t"
42 46
 		      "wcsr tlbvaddr, %0"::"r"(vaddr):);
43 47
 
44 48
 	asm volatile ("xor r11, r11, r11\n\t"
45 49
 		      "ori r11, r11, 0x21\n\t"
46  
-		      "wcsr tlbctrl, r11":::"r11");
  50
+		      "wcsr tlbctrl, r11" ::: "r11");
  51
+}
  52
+
  53
+inline void mmu_dtlb_invalidate(void)
  54
+{
  55
+	register unsigned int cmd = DTLB_CTRL_FLUSH_CMD;
  56
+	asm volatile("wcsr tlbctrl, %0" :: "r"(cmd) : );
  57
+
47 58
 }
48 59
 
49 60
 /* This function activates the MMU
@@ -55,20 +66,32 @@ inline void mmu_dtlb_invalidate(unsigned int vaddr)
55 66
 
56 67
 unsigned int read_word_with_mmu_enabled(unsigned int vaddr)
57 68
 {
58  
-	register unsigned int data;
  69
+	register unsigned int data, cmd1, cmd2;
  70
+
  71
+	cmd1  = DTLB_CTRL_ENABLE_CMD;
  72
+	cmd2 = DTLB_CTRL_DISABLE_CMD;
  73
+
  74
+	asm volatile("wcsr tlbctrl, %2\n\t" // Activates the MMU
  75
+		     "xor r0, r0, r0\n\t"
  76
+		     "lw  %0, (%1+0)\n\t" // Reads from virtual address "addr"
  77
+		     "wcsr tlbctrl, %3\n\t" // Disactivates the MMU
  78
+		     "xor r0, r0, r0\n\t" : "=&r"(data) : "r"(vaddr), "r"(cmd1), "r"(cmd2) : 
  79
+	);
  80
+
  81
+	return data;
  82
+}
  83
+
  84
+unsigned int write_word_with_mmu_enabled(register unsigned int vaddr, register unsigned int data)
  85
+{
59 86
 	asm volatile(
60 87
 		"xor r11, r11, r11\n\t"
61 88
 		"ori r11, r11, 0x11\n\t"
62 89
 		"wcsr tlbctrl, r11\n\t" // Activates the MMU
63 90
 		"xor r0, r0, r0\n\t"
64  
-		"xor r11, r11, r11\n\t"
65  
-		"or r11, r11, %1\n\t"
66  
-		"lw  %0, (r11+0)\n\t" // Reads from virtual address "addr"
  91
+		"sw  (%0 + 0), %1\n\t" // Reads from virtual address "addr"
67 92
 		"xor r11, r11, r11\n\t"
68 93
 		"ori r11, r11, 0x9\n\t"
69 94
 		"wcsr tlbctrl, r11\n\t" // Disactivates the MMU
70  
-		"xor r0, r0, r0\n\t" : "=&r"(data) : "r"(vaddr) : "r11"
  95
+		"xor r0, r0, r0\n\t" :: "r"(vaddr), "r"(data) : "r11"
71 96
 	);
72  
-
73  
-	return data;
74 97
 }

0 notes on commit 2f35de4

Please sign in to comment.
Something went wrong with that request. Please try again.