From e0d20b2e2de069c6714f48eb36eec1ad02845f4c Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Wed, 4 Aug 2010 17:04:24 -0700 Subject: [xcc,pk,sim] Added first part of FP support In particular, FP loads, stores, and moves now work. --- Makefile | 4 +- boot.S | 4 +- entry.S | 36 ++- handlers.c | 58 ++++ mcf.out | 915 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ pcr.h | 12 + pk.c | 21 +- pk.h | 1 + 8 files changed, 1024 insertions(+), 27 deletions(-) create mode 100644 handlers.c create mode 100644 mcf.out diff --git a/Makefile b/Makefile index b73bf20..6a1accd 100644 --- a/Makefile +++ b/Makefile @@ -5,8 +5,8 @@ TARGETS := pk all: $(TARGETS) -pk: boot.o entry.o pk.o syscall.o file.o frontend.o pk.ld - $(CC) -o pk entry.o pk.o syscall.o file.o frontend.o -T pk.ld +pk: boot.o entry.o pk.o syscall.o file.o frontend.o handlers.o pk.ld + $(CC) -o pk entry.o pk.o syscall.o file.o frontend.o handlers.o -T pk.ld %.o: %.c *.h $(CC) -c $< diff --git a/boot.S b/boot.S index c74327a..4318a40 100644 --- a/boot.S +++ b/boot.S @@ -1,10 +1,12 @@ +#include "pcr.h" + .text .global __start .ent __start __start: # set up SR - li $t0, 0xFF + li $t0, SR_S | SR_PS | SR_ET | SR_UX | SR_KX mtpcr $t0, $0 # set up trap table diff --git a/entry.S b/entry.S index ae76962..db49a98 100644 --- a/entry.S +++ b/entry.S @@ -1,5 +1,6 @@ .text - .set noat + .set noat + .ent save_tf save_tf: # write the trap frame onto the stack # save gprs sd $1,8($k1) @@ -39,11 +40,15 @@ save_tf: # write the trap frame onto the stack mfpcr $t0,$2 # badvaddr sd $t0,272($k1) jr $ra + .end save_tf - .global pop_tf + .globl pop_tf + .ent pop_tf pop_tf: # write the trap frame onto the stack # restore gprs - di + ld $t0,256($a0) # restore sr, which should disable interrupts + mtpcr $t0,$0 + move $k0,$a0 ld $1,8($k0) ld $2,16($k0) @@ -79,6 +84,7 @@ pop_tf: # write the trap frame onto the stack ld $k0,264($k0) mtpcr $k0,$1 eret + .end pop_tf @@ -95,16 +101,26 @@ pop_tf: # write the trap frame onto the stack .align 12 .global trap_table + .ent trap_table trap_table: - TRAP_TABLE_ENTRY(unhandled_trap) - TRAP_TABLE_ENTRY(unhandled_trap) - TRAP_TABLE_ENTRY(unhandled_trap) - TRAP_TABLE_ENTRY(unhandled_trap) - TRAP_TABLE_ENTRY(unhandled_trap) - TRAP_TABLE_ENTRY(unhandled_trap) + TRAP_TABLE_ENTRY(handle_illegal_instruction) + TRAP_TABLE_ENTRY(handle_privileged_instruction) + TRAP_TABLE_ENTRY(handle_fp_disabled) + TRAP_TABLE_ENTRY(handle_badtrap) + TRAP_TABLE_ENTRY(handle_misaligned_fetch) + TRAP_TABLE_ENTRY(handle_misaligned_ldst) + TRAP_TABLE_ENTRY(handle_fault_fetch) + TRAP_TABLE_ENTRY(handle_fault_ldst) TRAP_TABLE_ENTRY(handle_syscall) TRAP_TABLE_ENTRY(handle_breakpoint) - .align 12 + TRAP_TABLE_ENTRY(handle_badtrap) + TRAP_TABLE_ENTRY(handle_badtrap) + TRAP_TABLE_ENTRY(handle_badtrap) + TRAP_TABLE_ENTRY(handle_badtrap) + TRAP_TABLE_ENTRY(handle_badtrap) + TRAP_TABLE_ENTRY(handle_badtrap) + .align 12 + .end trap_table .bss .global stack_bot diff --git a/handlers.c b/handlers.c new file mode 100644 index 0000000..6cc5958 --- /dev/null +++ b/handlers.c @@ -0,0 +1,58 @@ +#include "pcr.h" +#include "pk.h" + +void handle_breakpoint(trapframe_t* tf) +{ + printk("Breakpoint\n"); + dump_tf(tf); + tf->epc += 4; + pop_tf(tf); +} + +void handle_fp_disabled(trapframe_t* tf) +{ + tf->sr |= SR_EF; + pop_tf(tf); +} + +void handle_badtrap(trapframe_t* tf) +{ + dump_tf(tf); + panic("Bad trap vector!"); +} + +void handle_privileged_instruction(trapframe_t* tf) +{ + dump_tf(tf); + panic("A privileged instruction was executed!"); +} + +void handle_illegal_instruction(trapframe_t* tf) +{ + dump_tf(tf); + panic("An illegal instruction was executed!"); +} + +void handle_misaligned_fetch(trapframe_t* tf) +{ + dump_tf(tf); + panic("Misaligned instruction access!"); +} + +void handle_misaligned_ldst(trapframe_t* tf) +{ + dump_tf(tf); + panic("Misaligned data access!"); +} + +void handle_fault_fetch(trapframe_t* tf) +{ + dump_tf(tf); + panic("Faulting instruction access!"); +} + +void handle_fault_ldst(trapframe_t* tf) +{ + dump_tf(tf); + panic("Faulting data access!"); +} diff --git a/mcf.out b/mcf.out new file mode 100644 index 0000000..959caba --- /dev/null +++ b/mcf.out @@ -0,0 +1,915 @@ +() +552 +*** +557 +583 +*** +595 +*** +608 +() +95 +111 +139 +169 +185 +198 +215 +228 +245 +258 +270 +291 +312 +*** +364 +389 +*** +446 +482 +() +84 +*** +222 +251 +292 +304 +316 +*** +354 +*** +397 +444 +461 +494 +526 +556 +599 +620 +643 +() +81 +135 +173 +*** +232 +261 +294 +*** +332 +355 +*** +395 +409 +() +69 +85 +115 +149 +165 +188 +205 +218 +*** +313 +*** +390 +448 +*** +488 +534 +*** +543 +*** +562 +588 +() +67 +123 +*** +187 +234 +*** +339 +386 +() +66 +117 +*** +199 +220 +*** +264 +*** +340 +387 +440 +*** +493 +512 +536 +549 +564 +582 +*** +627 +() +64 +*** +145 +168 +*** +247 +284 +*** +361 +415 +460 +519 +546 +573 +597 +618 +634 +() +61 +*** +97 +*** +253 +300 +347 +*** +436 +*** +505 +() +57 +106 +157 +*** +214 +*** +283 +*** +351 +380 +410 +431 +*** +501 +533 +*** +593 +621 +644 +() +56 +72 +*** +120 +167 +203 +*** +315 +*** +366 +*** +447 +467 +487 +511 +527 +539 +554 +592 +607 +() +55 +*** +132 +176 +224 +*** +307 +345 +() +54 +*** +131 +*** +239 +*** +276 +337 +392 +449 +500 +() +53 +*** +119 +166 +204 +246 +*** +309 +346 +*** +420 +*** +481 +502 +518 +*** +544 +581 +*** +591 +632 +() +52 +*** +113 +134 +158 +170 +*** +230 +*** +281 +303 +*** +356 +370 +383 +*** +411 +456 +469 +*** +495 +525 +569 +596 +616 +*** +637 +() +50 +*** +100 +*** +141 +*** +213 +256 +298 +*** +378 +*** +412 +*** +450 +*** +489 +529 +563 +606 +*** +636 +() +48 +68 +122 +*** +193 +*** +320 +*** +357 +381 +405 +430 +452 +478 +498 +521 +*** +565 +*** +568 +*** +584 +601 +615 +() +46 +109 +153 +197 +233 +277 +*** +368 +398 +*** +454 +*** +484 +515 +548 +*** +572 +598 +*** +609 +638 +() +45 +*** +118 +161 +192 +221 +252 +*** +318 +333 +*** +375 +*** +419 +441 +466 +*** +503 +523 +547 +560 +574 +*** +587 +() +42 +90 +*** +206 +254 +301 +362 +417 +473 +520 +575 +*** +579 +605 +*** +635 +() +41 +60 +82 +98 +128 +159 +175 +*** +376 +423 +457 +*** +486 +540 +585 +624 +() +39 +77 +*** +240 +*** +293 +317 +*** +365 +*** +468 +480 +492 +516 +545 +*** +617 +642 +() +36 +43 +*** +92 +130 +162 +191 +*** +242 +271 +308 +*** +350 +() +33 +*** +79 +*** +219 +235 +248 +260 +*** +352 +400 +453 +496 +() +31 +65 +105 +151 +*** +229 +255 +268 +286 +*** +341 +*** +384 +407 +429 +*** +458 +479 +508 +530 +*** +541 +558 +570 +*** +577 +602 +628 +641 +() +29 +*** +88 +*** +156 +194 +*** +259 +275 +290 +305 +330 +*** +379 +*** +439 +() +28 +71 +133 +177 +223 +267 +324 +*** +399 +451 +517 +553 +*** +561 +604 +630 +() +26 +*** +73 +*** +125 +155 +178 +190 +*** +237 +274 +327 +*** +433 +*** +485 +532 +*** +571 +619 +() +24 +40 +*** +101 +138 +*** +210 +*** +288 +336 +*** +404 +462 +528 +*** +590 +603 +*** +614 +631 +() +23 +51 +89 +*** +146 +184 +226 +263 +314 +*** +388 +435 +472 +504 +() +22 +*** +76 +*** +116 +*** +172 +201 +*** +289 +306 +*** +359 +401 +*** +506 +535 +559 +586 +623 +639 +() +20 +*** +75 +99 +121 +148 +160 +189 +*** +231 +262 +295 +335 +385 +421 +() +19 +*** +62 +86 +108 +137 +*** +182 +*** +266 +325 +377 +424 +476 +() +18 +44 +*** +124 +150 +179 +195 +208 +*** +257 +297 +353 +*** +406 +*** +442 +470 +491 +524 +551 +*** +625 +640 +646 +() +17 +*** +63 +*** +114 +127 +142 +*** +211 +*** +321 +*** +408 +426 +471 +*** +510 +555 +600 +626 +() +16 +34 +*** +112 +126 +*** +217 +*** +326 +*** +373 +394 +416 +() +14 +37 +94 +*** +163 +207 +244 +*** +310 +360 +413 +*** +465 +513 +550 +*** +580 +594 +610 +622 +() +13 +30 +*** +96 +154 +*** +249 +265 +278 +*** +322 +*** +367 +*** +418 +434 +455 +475 +*** +499 +() +12 +47 +103 +*** +180 +*** +250 +*** +329 +*** +372 +*** +428 +*** +463 +507 +542 +567 +611 +*** +633 +() +11 +*** +78 +129 +*** +171 +202 +*** +285 +*** +363 +*** +437 +() +10 +*** +59 +*** +107 +*** +196 +243 +*** +311 +*** +391 +*** +425 +477 +522 +*** +612 +*** +645 +() +9 +35 +83 +*** +152 +181 +212 +*** +279 +*** +331 +349 +*** +414 +459 +*** +483 +538 +566 +589 +613 +629 +() +8 +25 +*** +93 +*** +200 +*** +280 +296 +334 +371 +*** +403 +*** +432 +445 +*** +509 +537 +*** +576 +() +7 +*** +70 +*** +144 +186 +*** +269 +299 +*** +343 +358 +() +6 +*** +49 +*** +104 +140 +*** +174 +216 +*** +302 +319 +342 +*** +393 +422 +443 +464 +490 +514 +531 +*** +578 +() +5 +*** +74 +87 +102 +*** +143 +*** +282 +323 +*** +402 +() +4 +32 +80 +136 +*** +209 +225 +238 +*** +287 +348 +() +3 +15 +38 +*** +110 +164 +*** +241 +272 +*** +344 +369 +*** +438 +() +2 +27 +*** +91 +147 +183 +227 +*** +338 +*** +382 +396 +() +1 +21 +58 +*** +236 +273 +328 +374 +*** +427 +474 +*** +497 diff --git a/pcr.h b/pcr.h index 22650a3..23e6185 100644 --- a/pcr.h +++ b/pcr.h @@ -1,6 +1,16 @@ #ifndef _RISCV_COP0_H #define _RISCV_COP0_H +#define SR_ET 0x0000000000000001 +#define SR_PS 0x0000000000000004 +#define SR_S 0x0000000000000008 +#define SR_EF 0x0000000000000010 +#define SR_UX 0x0000000000000020 +#define SR_KX 0x0000000000000040 +#define SR_IM 0x000000000000FF00 + +#ifndef __ASSEMBLER__ + #define mtpcr(val,reg) ({ long __tmp = (long)(val); \ asm volatile ("mtpcr %0,$%1"::"r"(__tmp),"i"(reg)); }) @@ -9,3 +19,5 @@ __tmp; }) #endif + +#endif diff --git a/pk.c b/pk.c index bfc4dad..2f0ba17 100644 --- a/pk.c +++ b/pk.c @@ -1,3 +1,4 @@ +#include "pcr.h" #include "pk.h" #include "file.h" #include "frontend.h" @@ -119,18 +120,12 @@ void dump_tf(trapframe_t* tf) printk("sr %lx pc %lx va %lx\n",tf->sr,tf->epc,tf->badvaddr); } -void unhandled_trap(trapframe_t* tf) +void init_tf(trapframe_t* tf, long pc, long sp) { - dump_tf(tf); - panic("unhandled trap!"); -} - -void handle_breakpoint(trapframe_t* tf) -{ - printk("Breakpoint\n"); - dump_tf(tf); - tf->epc += 4; - pop_tf(tf); + memset(tf,0,sizeof(*tf)); + tf->sr = SR_S | SR_KX | SR_UX; // SR_PS=0 (usermode); SR_ET=0 + tf->gpr[29] = USER_MEM_SIZE-USER_MAINVARS_SIZE; + tf->epc = USER_START; } void bss_init() @@ -150,9 +145,7 @@ void mainvars_init() void jump_usrstart() { trapframe_t tf; - memset(&tf,0,sizeof(tf)); - tf.gpr[29] = USER_MEM_SIZE-USER_MAINVARS_SIZE; - tf.epc = USER_START; + init_tf(&tf, USER_START, USER_MEM_SIZE-USER_MAINVARS_SIZE); pop_tf(&tf); } diff --git a/pk.h b/pk.h index eab43fd..dfe68f7 100644 --- a/pk.h +++ b/pk.h @@ -21,6 +21,7 @@ extern "C" { #endif void printk(const char* s, ...); +void init_tf(trapframe_t*, long pc, long sp); void pop_tf(trapframe_t*); void dump_tf(trapframe_t*); -- cgit v1.1