Skip to content

Commit

Permalink
Implemented trapv/trapcc + a few more FPU instructions.
Browse files Browse the repository at this point in the history
Implemented the divide-by-zero exception.
Made some progress toward 16/24-bit video.
  • Loading branch information
pruten committed Apr 19, 2014
1 parent ba8b9e8 commit cc2bb3c
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 104 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,3 +3,4 @@
.DS_Store
*.xcworkspace
xcuserdata
/gui/build
1 change: 1 addition & 0 deletions core/core_api.h
Expand Up @@ -46,6 +46,7 @@ typedef struct {
typedef struct {
video_ctx_color_t *direct_buf, *clut;
uint8_t *indexed_buf, *rom;
uint8_t *cur_buf;

uint32_t pixels;

Expand Down
83 changes: 77 additions & 6 deletions core/cpu.c
Expand Up @@ -69,11 +69,81 @@ global_shoebill_context_t shoe;
})

~inst(trapcc, {
assert(!"trapcc: error: not implemented\n");
~decompose(shoe.op, 0101 cccc 11111 xyz);

// (xyz) == (100) -> sz=0
// (xyz) == (010) -> sz=2
// (xyz) == (011) -> sz=4
const uint32_t sz = y << (z+1); // too clever
const uint32_t next_pc = shoe.orig_pc + 2 + sz;

const uint8_t C = sr_c();
const uint8_t Z = sr_z();
const uint8_t V = sr_v();
const uint8_t N = sr_n();

uint8_t set = 0;

switch (c) {
case 0: // trapt
set = 1; // FIXME: do-trap unconditionally?
break;
case 1: // trapf
set = 0; // FIXME: do-not-trap unconditionally?
break;
case 2:
if (!C && !Z) set = 1; // traphi
break;
case 3:
if (C || Z) set = 1; // trapls
break;
case 4:
if (!C) set = 1; // trapcc
break;
case 5:
if (C) set = 1; // trapcs
break;
case 6:
if (!Z) set = 1; // trapne
break;
case 7:
if (Z) set = 1; // trapeq
break;
case 8:
if (!V) set = 1; // trapvc
break;
case 9:
if (V) set = 1; // trapvs
break;
case 10:
if (!N) set = 1; // trappl
break;
case 11:
if (N) set = 1; // trapmi
break;
case 12:
if ( (N && V) || (!N && !V) ) set = 1; // trapge
break;
case 13:
if ( (N && !V) || (!N && V) ) set = 1; // traplt
break;
case 14:
if ( (N && V && !Z) || (!N && !V && !Z) ) set = 1; // trapgt
break;
case 15:
if ( (Z || (N && !V) || (!N && V) ) ) set = 1; // traple
break;
}

if (set)
throw_frame_two(shoe.sr, next_pc, 7, shoe.orig_pc);
else
shoe.pc = next_pc;
})

~inst(trapv, {
assert(!"trapv: error: not implemented\n");
if (sr_v())
throw_frame_two(shoe.sr, shoe.pc, 7, shoe.orig_pc);
})

~inst(asx_reg, {
Expand Down Expand Up @@ -344,7 +414,7 @@ global_shoebill_context_t shoe;
const uint16_t divisor = (uint16_t)shoe.dat;

if (divisor == 0) {
throw_divide_by_zero();
throw_frame_two(shoe.orig_sr, shoe.uncommitted_ea_read_pc, 5, shoe.orig_pc);
return ;
}

Expand All @@ -371,7 +441,7 @@ global_shoebill_context_t shoe;
const int16_t s_divisor = (int16_t)shoe.dat;

if (s_divisor == 0) {
throw_divide_by_zero();
throw_frame_two(shoe.orig_sr, shoe.uncommitted_ea_read_pc, 5, shoe.orig_pc);
return ;
}

Expand Down Expand Up @@ -976,14 +1046,15 @@ global_shoebill_context_t shoe;
~decompose(shoe.op, 0100 1100 01 MMMMMM);
~decompose(ext, 0 qqq u s 0000000 rrr);
call_ea_read(M, 4);
call_ea_read_commit(M, 4);

const uint32_t divisor = shoe.dat;
if (divisor == 0) {
throw_divide_by_zero();
throw_frame_two(shoe.orig_sr, shoe.uncommitted_ea_read_pc, 5, shoe.orig_pc);
return ;
}

call_ea_read_commit(M, 4);

uint64_t dividend;
if (s)
dividend = (((uint64_t)shoe.d[r])<<32) | shoe.d[q];
Expand Down
9 changes: 1 addition & 8 deletions core/exception.c
Expand Up @@ -239,13 +239,6 @@ void throw_privilege_violation()
//printf("throw_privilege_violation(): I'm throwing a privilege violation exception! (shoe.orig_pc = 0x%08x op=0x%04x\n", shoe.orig_pc, shoe.op);

throw_frame_zero(shoe.orig_sr, shoe.orig_pc, 8);
shoe.abort = 1;
// shoe.abort = 1;

}

void throw_divide_by_zero()
{
printf("throw_divide_by_zero(): I'm throwing a divide-by-zero exception!\n");
assert(0);
shoe.abort = 1;
}
2 changes: 1 addition & 1 deletion core/filesystem.c
Expand Up @@ -1374,7 +1374,7 @@ uint8_t* shoebill_extract_kernel(const char *disk_path, const char *kernel_path,
uint32_t size;
char error_str[1024];
buf = extract_kernel(argv[1], argv[2], error_str, &size);
buf = shoebill_extract_kernel(argv[1], argv[2], error_str, &size);
if (!buf)
return 0;
Expand Down
28 changes: 23 additions & 5 deletions core/fpu.c
Expand Up @@ -1304,10 +1304,17 @@ void inst_fmath(uint16_t op, uint16_t ext)
break;
case ~b(0001000): assert(!"fpu_inst_fetoxm1;");
case ~b(0001001): assert(!"fpu_inst_ftanh;");
case ~b(0001010): assert(!"fpu_inst_fatan;");
case ~b(0001010): // fatan
printf("inst_fatan dest = %Lf source = %Lf\n", dest, source);
result = atanl(source);
break;

case ~b(0001100): assert(!"fpu_inst_fasin;");
case ~b(0001101): assert(!"fpu_inst_fatanh;");
case ~b(0001110): assert(!"fpu_inst_fsin;");
case ~b(0001110): // fsin
printf("inst_fsin dest = %Lf source = %Lf\n", dest, source);
result = sinl(source);
break;
case ~b(0001111): assert(!"fpu_inst_ftan;");
case ~b(0010000): // fetox
printf("inst_fetox dest = %Lf source = %Lf\n", dest, source);
Expand All @@ -1320,7 +1327,11 @@ void inst_fmath(uint16_t op, uint16_t ext)
case ~b(0010110): assert(!"fpu_inst_flog2;");
case ~b(0011001): assert(!"fpu_inst_fcosh;");
case ~b(0011100): assert(!"fpu_inst_facos;");
case ~b(0011101): assert(!"fpu_inst_fcos;");
case ~b(0011101): // fcos
printf("fpu_inst_fcos dest = %Lf source = %Lf\n", dest, source);
result = cosl(source);
break;

case ~b(0011110): assert(!"fpu_inst_fgetexp;");
case ~b(0011111): assert(!"fpu_inst_fgetman;");
case ~b(0100001):
Expand Down Expand Up @@ -1380,10 +1391,13 @@ void inst_fmath(uint16_t op, uint16_t ext)
break;
}

case ~b(0011010):
case ~b(1011010):
case ~b(1011110):
assert(!"fpu_inst_fneg;");
assert(!"fneg: can't handle");
case ~b(0011010): // fneg
printf("inst_fneg dest = %Lf source = %Lf\n", dest, source);
result = -source;
break;

case ~b(1000001):
case ~b(1000101):
Expand Down Expand Up @@ -1458,6 +1472,10 @@ void fpu_setup_jump_table()
fpu_inst_fsqrt,
fpu_inst_flognp1,
fpu_inst_fetox,
fpu_inst_fsin,
fpu_inst_fcos,
fpu_inst_fneg,
fpu_inst_fatan,
};

const fpu_inst_name_t dyadic[] = {
Expand Down

0 comments on commit cc2bb3c

Please sign in to comment.