1 |
2 |
jamieiles |
// Copyright Jamie Iles, 2017
|
2 |
|
|
//
|
3 |
|
|
// This file is part of s80x86.
|
4 |
|
|
//
|
5 |
|
|
// s80x86 is free software: you can redistribute it and/or modify
|
6 |
|
|
// it under the terms of the GNU General Public License as published by
|
7 |
|
|
// the Free Software Foundation, either version 3 of the License, or
|
8 |
|
|
// (at your option) any later version.
|
9 |
|
|
//
|
10 |
|
|
// s80x86 is distributed in the hope that it will be useful,
|
11 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
|
|
// GNU General Public License for more details.
|
14 |
|
|
//
|
15 |
|
|
// You should have received a copy of the GNU General Public License
|
16 |
|
|
// along with s80x86. If not, see .
|
17 |
|
|
|
18 |
|
|
// INT3
|
19 |
|
|
.at 0xcc;
|
20 |
|
|
b_sel IMMEDIATE, immediate 0xc, alu_op SELB, tmp_wr_en, jmp do_int;
|
21 |
|
|
|
22 |
|
|
// The same as above, but this time it's a 8 bit interrupt number.
|
23 |
|
|
.at 0xcd;
|
24 |
|
|
width W8, read_immed, jmp intN;
|
25 |
|
|
.auto_address;
|
26 |
|
|
intN:
|
27 |
|
|
b_sel IMMEDIATE, alu_op SELB, mar_wr_sel Q, mar_write;
|
28 |
|
|
a_sel MAR, b_sel IMMEDIATE, immediate 0xff, alu_op AND, mar_write,
|
29 |
|
|
mar_wr_sel Q;
|
30 |
|
|
a_sel MAR, b_sel IMMEDIATE, immediate 0x4, alu_op MUL, tmp_wr_en,
|
31 |
|
|
jmp do_int;
|
32 |
|
|
|
33 |
|
|
// INTO: the same as int3, but conditional on OF being set.
|
34 |
|
|
.at 0xce;
|
35 |
|
|
alu_op GETFLAGS, mdr_write, jmp into;
|
36 |
|
|
.auto_address;
|
37 |
|
|
into:
|
38 |
|
|
b_sel IMMEDIATE, immediate 0x10, alu_op SELB, tmp_wr_en,
|
39 |
|
|
jmp_if_taken into_taken, ra_sel SP;
|
40 |
|
|
next_instruction;
|
41 |
|
|
into_taken:
|
42 |
|
|
jmp do_int;
|
43 |
|
|
|
44 |
|
|
// Process an interrupt.
|
45 |
|
|
// TEMP: interrupt vector address
|
46 |
|
|
//
|
47 |
|
|
// This is a reasonably large microprocedure, but a reasonable amount of
|
48 |
|
|
// repetition. Start by storing the flags + CS:IP to the stack, clear TF+IF
|
49 |
|
|
// and then load the new CS:IP. As the vectors are stored in segment 0, this
|
50 |
|
|
// requires temporarily setting CS to 0 to read the final vector address.
|
51 |
|
|
.at 0x12d;
|
52 |
|
|
do_int:
|
53 |
|
|
alu_op GETFLAGS, mdr_write, ra_sel SP, jmp do_int_main;
|
54 |
|
|
.auto_address;
|
55 |
|
|
do_int_main:
|
56 |
|
|
a_sel RA, b_sel IMMEDIATE, immediate 0x2, alu_op SUB,
|
57 |
|
|
mar_write, mar_wr_sel Q, segment SS, segment_force;
|
58 |
|
|
segment SS, segment_force, mem_write;
|
59 |
|
|
a_sel MAR, b_sel IMMEDIATE, immediate 0x2, alu_op SUB,
|
60 |
|
|
mar_write, mar_wr_sel Q, segment_force, segment CS;
|
61 |
|
|
b_sel SR, alu_op SELB, mdr_write, segment SS, segment_force;
|
62 |
|
|
segment SS, segment_force, mem_write;
|
63 |
|
|
a_sel MAR, b_sel IMMEDIATE, immediate 0x2, alu_op SUB,
|
64 |
|
|
mar_write, mar_wr_sel Q;
|
65 |
|
|
a_sel IP, alu_op SELA, mdr_write, segment SS, segment_force;
|
66 |
|
|
segment SS, segment_force, mem_write;
|
67 |
|
|
a_sel MAR, alu_op SELA, rd_sel_source MICROCODE_RD_SEL,
|
68 |
|
|
rd_sel SP;
|
69 |
|
|
b_sel IMMEDIATE, immediate 0x0, alu_op SETFLAGSB, update_flags IF TF;
|
70 |
|
|
b_sel IMMEDIATE, immediate 0x0, alu_op SELB, segment_force,
|
71 |
|
|
segment CS, segment_wr_en;
|
72 |
|
|
b_sel TEMP, alu_op SELB, mar_wr_sel Q, mar_write, segment CS,
|
73 |
|
|
segment_force;
|
74 |
|
|
segment_force, segment CS, mem_read;
|
75 |
|
|
a_sel MDR, alu_op SELA, load_ip;
|
76 |
|
|
a_sel MAR, b_sel IMMEDIATE, immediate 0x2, alu_op ADD, mar_write,
|
77 |
|
|
mar_wr_sel Q, segment CS, segment_force;
|
78 |
|
|
segment_force, segment CS, mem_read;
|
79 |
|
|
a_sel MDR, alu_op SELA, segment_force, segment CS,
|
80 |
|
|
segment_wr_en, next_instruction;
|