Skip to content

Commit 33c3488

Browse files
committed
Add MP Config
Added MP configuration tables setup.
1 parent a07a85e commit 33c3488

File tree

13 files changed

+618
-51
lines changed

13 files changed

+618
-51
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ OBJS = \
1515
interrupt.o\
1616
kbd.o\
1717
disk.o\
18+
mp.o\
1819
instructions_00.o\
1920
instructions_10.o\
2021
instructions_20.o\
@@ -33,6 +34,7 @@ OBJS = \
3334
instructions_F0.o\
3435
instructions_0F00.o\
3536
instructions_0F20.o\
37+
instructions_0F80.o\
3638
instructions_0FB0.o
3739

3840
CC = /usr/bin/gcc

emulator.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
(byte & 0x02 ? '1' : '0'), \
1919
(byte & 0x01 ? '1' : '0')
2020

21-
Emulator *create_emu(uint32_t eip, uint32_t esp)
21+
Emulator *create_emu(uint8_t *memory, uint32_t eip, uint32_t esp)
2222
{
2323
Emulator *emu = malloc(sizeof(Emulator));
2424

@@ -32,7 +32,7 @@ Emulator *create_emu(uint32_t eip, uint32_t esp)
3232

3333
/* Devices */
3434
emu->lapic = create_lapic(emu);
35-
emu->memory = malloc(MEMORY_SIZE);
35+
emu->memory = memory;
3636
emu->disk = NULL;
3737

3838
/* Utility */
@@ -91,20 +91,18 @@ void dump_registers(Emulator *emu)
9191
printf("GDTR: %04x %08x\n", emu->gdtr.limit, emu->gdtr.base);
9292
}
9393

94-
/*
95-
void dump_input(Emulator *emu)
96-
{
97-
printf("Input:\n");
98-
int i;
99-
for (i = 0; i < MEMORY_SIZE; i++)
100-
{
101-
if (emu->memory[i])
102-
{
103-
printf("%08x\n", emu->memory[i]);
104-
}
105-
}
106-
}
107-
*/
94+
// void dump_input(Emulator *emu)
95+
// {
96+
// printf("Input:\n");
97+
// int i;
98+
// for (i = 0; i < MEMORY_SIZE; i++)
99+
// {
100+
// if (emu->memory[i])
101+
// {
102+
// printf("%08x\n", emu->memory[i]);
103+
// }
104+
// }
105+
// }
108106

109107
void dump_memory(Emulator *emu)
110108
{

emulator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ struct LAPIC
162162
pthread_t *timer_thread;
163163
};
164164

165-
Emulator *create_emu(uint32_t eip, uint32_t esp);
165+
Emulator *create_emu(uint8_t *memory, uint32_t eip, uint32_t esp);
166166
void destroy_emu(Emulator *emu);
167167

168168
void attach_disk(Emulator *emu, Disk *disk);

io.c

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,48 @@
55
#include "kbd.h"
66

77
/*
8-
* 0x60
98
* PS/2 (keyboard) Controller
10-
* in/out: Data Register
11-
*
12-
* 0x64
13-
* PS/2 (keyboard) Controller
14-
* in: Status Register
15-
* out: Command Register
16-
*
17-
* 0x3f8
18-
* Serial COM1 port: Convenience Implementation
19-
* Actual IO checks 0x03fd (status port) and read
20-
* from 0x3f8 (data port) if data is there.
21-
* Also while loop below clears buffer if needed.
22-
* while ((ch = getchar()) != '\n' && ch != EOF) continue;
9+
* 0x60: in|out: Data Register
10+
* 0x64: in: Status Register | out: Command Register
11+
*/
12+
#define PS2DATA 0x60
13+
#define PS2STACMD 0x64
14+
15+
/*
16+
* Serial (COM1)
17+
* 0x3f8: in|out: Data port
18+
* 0x3fd: in: Status port
19+
*/
20+
#define SERIALSTA 0x3fd
21+
#define SERIALDATA 0x3f8
22+
23+
/*
24+
* Disk
25+
* 0x1F0: Data Register
26+
* 0x1F2: in|out: Sector Count Register
27+
* 0x1F3: in|out: LBA Low
28+
* 0x1F4: in|out: LBA Mid
29+
* 0x1F5: in|out: LBA High
30+
* 0x1F6: in|out: Drive/Head Register
31+
* 0x1F7: in: Status Register | out: Command Register
2332
*/
33+
#define DISKDATA 0x1f0
34+
#define DISKSECCOUNT 0x1f2
35+
#define DISKLBALOW 0x1f3
36+
#define DISKLBAMID 0x1f4
37+
#define DISKLBAHIGH 0x1f5
38+
#define DISKDRVHEAD 0x1f6
39+
#define DISKSTACMD 0x1f7
2440

2541
uint8_t io_in8(Emulator *emu, uint16_t address)
2642
{
2743
switch (address)
2844
{
29-
case 0x64:
45+
case PS2STACMD:
3046
return get_kbd_status();
31-
case 0x1f7:
47+
case DISKSTACMD:
3248
return get_disk_status(emu->disk);
33-
case 0x3f8:
49+
case SERIALDATA:
3450
return getchar();
3551
default:
3652
printf("IN8 on port %x not implemented.\n", address);
@@ -44,7 +60,7 @@ uint32_t io_in32(Emulator *emu, uint16_t address)
4460
{
4561
case 0x1F0:
4662
return read_disk_data32(emu->disk);
47-
case 0x3f8:
63+
case SERIALDATA:
4864
return getchar();
4965
default:
5066
printf("IN32 on port %x not implemented.\n", address);
@@ -56,31 +72,31 @@ void io_out8(Emulator *emu, uint16_t address, uint8_t value)
5672
{
5773
switch (address)
5874
{
59-
case 0x60:
75+
case PS2DATA:
6076
write_ps2_config_byte(value);
6177
break;
62-
case 0x64:
78+
case PS2STACMD:
6379
write_ps2_output_port(value);
6480
break;
65-
case 0x1f2:
81+
case DISKSECCOUNT:
6682
set_sec_count(emu->disk, value);
6783
break;
68-
case 0x1f3:
84+
case DISKLBALOW:
6985
set_lba_low(emu->disk, value);
7086
break;
71-
case 0x1f4:
87+
case DISKLBAMID:
7288
set_lba_mid(emu->disk, value);
7389
break;
74-
case 0x1f5:
90+
case DISKLBAHIGH:
7591
set_lba_high(emu->disk, value);
7692
break;
77-
case 0x1f6:
93+
case DISKDRVHEAD:
7894
set_drive_head(emu->disk, value);
7995
break;
80-
case 0x1f7:
96+
case DISKSTACMD:
8197
set_disk_command(emu->disk, value);
8298
break;
83-
case 0x3f8:
99+
case SERIALDATA:
84100
putchar(value);
85101
break;
86102
default:
@@ -93,7 +109,7 @@ void io_out32(Emulator *emu, uint16_t address, uint32_t value)
93109
{
94110
switch (address)
95111
{
96-
case 0x3f8:
112+
case SERIALDATA:
97113
putchar(value);
98114
break;
99115
default:

kbd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static void *kbd_loop()
5656
{
5757
kbd->buf_index += 1;
5858
}
59-
ioapic_int_to_lapic(kbd->ioapic, T_IRQ0 + IRQ_KBD);
59+
ioapic_int_to_lapic(T_IRQ0 + IRQ_KBD);
6060
}
6161
return NULL;
6262
}

main.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "ioapic.h"
1010
#include "disk.h"
1111
#include "kbd.h"
12+
#include "mp.h"
1213

1314
int remove_arg_at(int argc, char *argv[], int index)
1415
{
@@ -56,11 +57,17 @@ int main(int argc, char *argv[])
5657
return 1;
5758
}
5859

60+
/* Main memory */
61+
uint8_t *memory = malloc(MEMORY_SIZE);
62+
5963
/*
6064
* Initial setup: EIP: 0x7c00, ESP: 0x7c00
6165
* BIOS places instructions at 0x7c00.
6266
*/
63-
emu = create_emu(0x7c00, 0x7c00);
67+
emu = create_emu(memory, 0x7c00, 0x7c00);
68+
69+
/* BIOS configures MP settings */
70+
set_mp_config(emu);
6471

6572
/* Binary file loading */
6673
binary = fopen(argv[1], "rb"); // rb: read-binary (r: translated mode for "\n")

0 commit comments

Comments
 (0)