-
Notifications
You must be signed in to change notification settings - Fork 0
/
memory.h
153 lines (132 loc) · 3.24 KB
/
memory.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#ifndef __MEMORY_H__
#define __MEMORY_H__
#include "arduino.h"
#include "cpu.h"
/*
Jump Rom Memory. dec 1048560
*/
#define JMP_START 0xffff0
#define JMP_END 0xfffff
/*
Boot Rom 0xfff8C dec 1048460
*/
#define ROM_SIZE 0x64
#define ROM_START JMP_START - ROM_SIZE
#define ROM_END JMP_START
/*
Interupt vector table RAM dec 0.
*/
#define IVT_START 0
#define IVT_END 0x3ff
/*
System Ram, could be external EEPROM, FLash etc., dec 1024.
*/
#define RAM_START 0x400
#define RAM_SIZE 0xff
#define RAM_END RAM_START + RAM_SIZE
//Ram starts at low address 0x400
byte mem_ram256[255];
//IVT and GDT ram. starts at 0x0000. ends at 0x3ff
byte mem_low1024[1023];
//Rom starts at ,
//filled with 0x64 noops for now
byte mem_rom256[] = {
0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64,
0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64,
0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64,
0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64,
0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64,
0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64,
0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64,
0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64,
0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64,
0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64,
};
/*
15bytes to make a jump,
*/
byte jmp_rom[] = {
/*
Test code for jmp rom
mov ax, ROM_START 184, 256, 256, ( 0xb8, 0xff, 0xff)
immediate to register, word,
mov cs, ax 142, 200, ( 0x8E, 0xC8 )
reg to segment
Note this jmp is never done.
jmp 0 233, 249 (0xE9, 0xF9)
reset ip.
*/
0xB8, 0xff, 0xff, 0x8E, 0xC8,
0xE9, 0xF9, 0x64, 0x00, 0x00,
0x00, 0x00, 0x64, 0x64, 0xff,
0xff
};
/*
use up about 1k of precious ram
64k segments.
16 byte
For starter's.
Rom starts at processor initalisation point, for 1/4 segment?
Ram starts at 0x0000 for IVT (and GDT?( GDT for 386 and above))
Memory map...
0x0 -> 0x3ff
IVT
0xfffff0 -> 0xfffff
Boot strap / BIOS
0x400 -> 0xfffef
RAM
*/
/*typedef struct mem_s{
int size;
byte *data;
}mem_t;
mem_t mem_ram256;
mem_t mem_rom256 = {
2,
{0x00,0x00}
}*/
/*
Return a byte of memory from the loction provided by the Code Segment and Instruction Pointers.
*/
byte get_phys_byte( unsigned int ip){
unsigned long mem = ( unsigned long )cpu86.regs.cs;
mem = (mem << 4);
mem += ip;
/*
is memory in IVT ?
*/
if( mem <= IVT_END ){
if( mem >= 0){
return mem_low1024[mem];
}
}
/*
TODO
Is the location in external eeprom memory
*/
/*
test for location mem_rom256, at location ROM_START
*/
if( mem >= ROM_START){
if( mem < ROM_END ){
if( ( mem - ROM_START ) < ROM_SIZE ){
return (byte)mem_rom256[mem - ROM_START];
}
}
}
/*
is the location in jmp rom, last address to check, at location 0xffff0 - 0xfffff
*/
if( mem >= JMP_START ){
if( mem <= JMP_END ){
if( ( mem - JMP_START ) < 16 ){
return (byte)jmp_rom[mem - JMP_START];
}
}
}
/*
Return a noop86 instruction.
*/
return 0x64;
}
#endif