Skip to content
This repository was archived by the owner on Feb 10, 2021. It is now read-only.

Commit e947339

Browse files
committed
build .so file
1 parent fc1c62e commit e947339

File tree

4 files changed

+105
-111
lines changed

4 files changed

+105
-111
lines changed

software/src/e2/address_space.h

Lines changed: 0 additions & 31 deletions
This file was deleted.

software/src/e2/lib53k.so.do

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
redo-ifchange processor.c processor.h
4+
5+
gcc -MD -MF processor.d -shared -fPIC -o $3 processor.c
6+
read DEPS <processor.d
7+
redo-ifchange ${DEPS#*:}
8+

software/src/e2/processor.c

Lines changed: 35 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,21 @@
1616

1717
#include <stdlib.h>
1818
#include <string.h>
19-
#include <stdio.h>
19+
// #include <stdio.h>
20+
#include <stdint.h>
2021

21-
#include "address_space.h"
22-
#include "timeline.h"
2322
#include "processor.h"
2423

2524

2625
#define UNDEFINED (0xCCCCCCCCCCCCCCCC)
2726

2827

2928
static void
30-
trap(Processor *p, Uint64_t cause) {
29+
trap(Processor *p, uint64_t cause) {
3130
/* KCP53000 only supports M-mode, so we can hardwire the
3231
* MPP bits of mstatus.
3332
*/
34-
Uint64_t newstat = p->mstatus & 0xFFFFFFFFFFFFE777;
33+
uint64_t newstat = p->mstatus & 0xFFFFFFFFFFFFE777;
3534
newstat |= (p->mstatus & 0x8) << 4;
3635

3736
p->mcause = cause;
@@ -130,7 +129,7 @@ ecall(Processor *p) {
130129

131130
static void
132131
mret(Processor *p) {
133-
Uint64_t new_mie = (p->mstatus & 0x80) >> 4;
132+
uint64_t new_mie = (p->mstatus & 0x80) >> 4;
134133
p->mstatus = (p->mstatus & 0xFFFFFFFFFFFE0F77) | new_mie | 0x1880;
135134
p->pc = p->mepc;
136135
}
@@ -161,11 +160,13 @@ new_processor(AddressSpace *as) {
161160

162161

163162
void
164-
step(Processor *p, Timeline *t) {
163+
step(Processor *p) {
165164
int32_t ir;
166165
int opc, rd, fn3, rs1, rs2, imm12, imm12s, disp12;
167166
int64_t imm20, disp20, ia;
168-
Uint64_t mask, v;
167+
uint64_t mask, v;
168+
AddressSpace *as = p->as;
169+
IAddressSpace *asi = as->i;
169170

170171
/* If service from the virtual machine monitor is required,
171172
* return to the VMM until it has been properly serviced.
@@ -186,18 +187,17 @@ step(Processor *p, Timeline *t) {
186187
mask = (p->mstatus & MSTATUSF_MIE) ?
187188
p->mip & p->mie : 0;
188189
if(mask & MIEF_MEIE) {
189-
trap(p, MCAUSEF_IRQ | MEIB_MEIE);
190+
trap(p, MCAUSEF_IRQ | MIEB_MEIE);
190191
}
191192
else if(mask & MIEF_MSIE) {
192-
trap(p, MCAUSEF_IRQ | MEIB_MSIE);
193+
trap(p, MCAUSEF_IRQ | MIEB_MSIE);
193194
}
194195
else if(mask & MIEF_MTIE) {
195-
trap(p, MCAUSEF_IRQ | MEIB_MTIE);
196+
trap(p, MCAUSEF_IRQ | MIEB_MTIE);
196197
}
197198

198-
ir = as->fetch_word(p->as, ia);
199+
ir = asi->fetch_word(p->as, ia);
199200
p->pc = ia + 4;
200-
tt->step(t, 2); /* 32-bit fetches take 2 cycles over 16-bit bus. */
201201

202202
/* This takes a bunch of time. */
203203
opc = ir & 0x7F;
@@ -280,16 +280,16 @@ step(Processor *p, Timeline *t) {
280280

281281
case 6: /* BLTU */
282282
if(
283-
(Uint64_t)(p->x[rs1]) <
284-
(Uint64_t)(p->x[rs2])
283+
(uint64_t)(p->x[rs1]) <
284+
(uint64_t)(p->x[rs2])
285285
)
286286
p->pc = ia + disp12;
287287
break;
288288

289289
case 7: /* BGEU */
290290
if(
291-
(Uint64_t)(p->x[rs1]) >=
292-
(Uint64_t)(p->x[rs2])
291+
(uint64_t)(p->x[rs1]) >=
292+
(uint64_t)(p->x[rs2])
293293
)
294294
p->pc = ia + disp12;
295295
break;
@@ -300,102 +300,90 @@ step(Processor *p, Timeline *t) {
300300
case 0x03:
301301
switch(fn3) {
302302
case 0: /* LB */
303-
p->x[rd] = as->fetch_byte(
303+
p->x[rd] = asi->fetch_byte(
304304
p->as, p->x[rs1] + imm12
305305
);
306306
p->x[rd] |= -(p->x[rd] & 0x80);
307-
tt->step(t, 1);
308307
break;
309308

310309
case 1: /* LH */
311-
p->x[rd] = as->fetch_hword(
310+
p->x[rd] = asi->fetch_hword(
312311
p->as, p->x[rs1] + imm12
313312
);
314313
p->x[rd] |= -(p->x[rd] & 0x8000);
315-
tt->step(t, 1);
316314
break;
317315

318316
case 2: /* LW */
319-
p->x[rd] = as->fetch_word(
317+
p->x[rd] = asi->fetch_word(
320318
p->as, p->x[rs1] + imm12
321319
);
322320
p->x[rd] |= -(p->x[rd] & 0x80000000);
323-
tt->step(t, 2);
324321
break;
325322

326323
case 3: /* LD */
327-
p->x[rd] = as->fetch_dword(
324+
p->x[rd] = asi->fetch_dword(
328325
p->as, p->x[rs1] + imm12
329326
);
330-
tt->step(t, 4);
331327
break;
332328

333329
case 4: /* LBU */
334-
p->x[rd] = as->fetch_byte(
330+
p->x[rd] = asi->fetch_byte(
335331
p->as, p->x[rs1] + imm12
336332
);
337-
tt->step(t, 1);
338333
break;
339334

340335
case 5: /* LHU */
341-
p->x[rd] = as->fetch_hword(
336+
p->x[rd] = asi->fetch_hword(
342337
p->as, p->x[rs1] + imm12
343338
);
344-
tt->step(t, 1);
345339
break;
346340

347341
case 6: /* LWU */
348-
p->x[rd] = as->fetch_word(
342+
p->x[rd] = asi->fetch_word(
349343
p->as, p->x[rs1] + imm12
350344
);
351-
tt->step(t, 2);
352345
break;
353346

354347
case 7: /* LDU */
355-
p->x[rd] = as->fetch_dword(
356-
p->as, p->x[rs1] + imm12'
348+
p->x[rd] = asi->fetch_dword(
349+
p->as, p->x[rs1] + imm12
357350
);
358-
tt->step(t, 4);
359351
break;
360352
}
361353
break;
362354
/* Sx */
363355
case 0x23:
364356
switch(fn3) {
365357
case 0: /* SB */
366-
as->store_byte(
358+
asi->store_byte(
367359
p->as,
368360
p->x[rs1]+imm12s,
369361
p->x[rs2]
370362
);
371-
tt->step(t, 1);
372363
break;
373364

374365
case 1: /* SH */
375-
as->store_hword(
366+
asi->store_hword(
376367
p->as,
377368
p->x[rs1]+imm12s,
378369
p->x[rs2]
379370
);
380-
tt->step(t, 1);
381371
break;
382372

383373
case 2: /* SW */
384-
as->store_word(
374+
asi->store_word(
385375
p->as,
386376
p->x[rs1]+imm12s,
387377
p->x[rs2]
388378
);
389-
tt->step(t, 2);
390379
break;
391380

392381
case 3: /* SD */
393-
as->store_dword(
382+
asi->store_dword(
394383
p->as,
395384
p->x[rs1]+imm12s,
396385
p->x[rs2]
397386
);
398-
tt->step(t, 4);
399387
break;
400388

401389
default:
@@ -421,7 +409,7 @@ step(Processor *p, Timeline *t) {
421409

422410
case 3: /* SLTIU */
423411
p->x[rd] =
424-
(Uint64_t)p->x[rs1] < (Uint64_t)imm12;
412+
(uint64_t)p->x[rs1] < (uint64_t)imm12;
425413
break;
426414

427415
case 4: /* XORI */
@@ -435,7 +423,7 @@ step(Processor *p, Timeline *t) {
435423
}
436424
else {
437425
p->x[rd] =
438-
(Uint64_t)p->x[rs1] >> (Uint64_t)imm12;
426+
(uint64_t)p->x[rs1] >> (uint64_t)imm12;
439427
}
440428
break;
441429

@@ -548,7 +536,7 @@ step(Processor *p, Timeline *t) {
548536

549537
case 3: /* SLTU */
550538
p->x[rd] =
551-
(Uint64_t)p->x[rs1] < (Uint64_t)p->x[rs2];
539+
(uint64_t)p->x[rs1] < (uint64_t)p->x[rs2];
552540
break;
553541

554542
case 4: /* XOR */
@@ -562,8 +550,8 @@ step(Processor *p, Timeline *t) {
562550
}
563551
else {
564552
p->x[rd] =
565-
(Uint64_t)p->x[rs1] >>
566-
(Uint64_t)p->x[rs2];
553+
(uint64_t)p->x[rs1] >>
554+
(uint64_t)p->x[rs2];
567555
}
568556
break;
569557

0 commit comments

Comments
 (0)