Skip to content

Commit 3cd3578

Browse files
committed
x86 IDT cleanup
1 parent 49b5a55 commit 3cd3578

File tree

6 files changed

+39
-43
lines changed

6 files changed

+39
-43
lines changed

src/arch/x86/idt.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
extern void idt_flush(uint32_t);
1313
extern int init_irq();
1414

15-
#define NUM_TRAP_STRS 22 // x86 has 20 hardware traps
15+
#define NUM_TRAP_STRS 22 // x86 has 22 hardware traps
1616
#define NUM_HANDLERS 256 // Max handlers x86 allows
1717
#define MAX_HANDLERS_PER_INT 4 // Number of software handlers per interrupt
1818

@@ -135,7 +135,7 @@ static void set_idt_entry(uint8_t n, uint32_t base, uint16_t sel, uint8_t flags)
135135
static int init_idt()
136136
{
137137
uint32_t i, delta, base;
138-
138+
139139
delta = (uint32_t)isr1 - (uint32_t)isr0;
140140

141141
idt_ptr.limit = sizeof(idt_entry_t) * 256 - 1;
@@ -216,10 +216,10 @@ void interrupt_handler(x86_regs_t *regs)
216216
char buf[64];
217217

218218
// We use a small hack. Seeing int code of 0xDEADBEEF means actual int code
219-
// Is in the error code
219+
// Is in the error code
220220
if(num == 0xDEADBEEF)
221221
{
222-
num = regs->error_code;
222+
num = regs->error_code;
223223
}
224224

225225
if (num_handlers[num]) {

src/arch/x86/include/ports.h

-12
This file was deleted.

src/arch/x86/ports.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/*
2-
* (c) 2022 Apollo Project Developers
2+
* (c) 2024 Apollo Project Developers
33
* For terms, see LICENSE
44
* ports.c - x86 I/O databus commends
55
*/
66

77
#include <stdint.h>
88
#include <sys/resource.h>
99
#include <errno.h>
10-
#include "include/ports.h"
10+
#include <arch/x86/regs.h>
1111

1212
void iowait(void)
1313
{
@@ -57,7 +57,7 @@ static void io_read_32(uint16_t port, void* data)
5757
*(uint32_t*)data = ret;
5858
}
5959

60-
static int resource_io_data_op(void *src, resource_t *r, resource_type_t off,
60+
static int resource_io_data_op(void *src, resource_t *r, resource_type_t off,
6161
size_t n, int read)
6262
{
6363
int width;
@@ -129,15 +129,15 @@ static int resource_io_data_op(void *src, resource_t *r, resource_type_t off,
129129
io_op(r->start, (src + i));
130130
}
131131
break;
132-
132+
133133
case RESOURCE_IO_INDEXED: /* Write to the indexing port, then data */
134134
for(i = 0; i < n; i++)
135135
{
136-
uint8_t index = (off + i);
136+
uint8_t index = (off + i);
137137
if(r->flags & RESOURCE_IO_SLOW)
138138
{
139139
iowait();
140-
}
140+
}
141141
io_write_8(r->start, &index);
142142
io_op(r->end, (src + i));
143143
}

src/arch/x86/vmm.c

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#include <string.h>
1010
#include <arch/x86/regs.h>
1111

12-
#include "include/ports.h"
13-
1412
#ifdef DEBUG_vmm
1513
# define dbg(args...) printf("vmm: " args)
1614
#else

src/core/resource.c

+19-18
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44

55
#define weak __attribute__((__weak__))
66

7-
int resource_io_write(void *src, resource_t *r,
7+
int resource_io_write(void *src, resource_t *r,
88
resource_type_t off, size_t n) weak;
9-
int resource_io_write(void *src, resource_t *r, resource_type_t off, size_t n)
9+
int resource_io_write(void *src, resource_t *r, resource_type_t off, size_t n)
1010
{
11-
return -1;
11+
return -ENOTSUPP;
1212
}
1313

14-
int resource_io_read(void *dest, resource_t *r,
14+
int resource_io_read(void *dest, resource_t *r,
1515
resource_type_t off, size_t n) weak;
1616
int resource_io_read(void *dest, resource_t *r, resource_type_t off, size_t n)
1717
{
18-
return -1;
18+
return -ENOTSUPP;
1919
}
2020

2121
static void resource_mem_read_8(void *buf, void *reg)
@@ -74,7 +74,7 @@ static void resource_mem_write_64(void *reg, void *buf)
7474
*(dest) = *(src);
7575
}
7676

77-
static int resource_mem_write(void *buf, resource_t *r, resource_type_t off,
77+
static int resource_mem_write(void *buf, resource_t *r, resource_type_t off,
7878
size_t n)
7979
{
8080
size_t i, width = 1;
@@ -112,7 +112,8 @@ size_t n)
112112
return 0;
113113
}
114114

115-
static int resource_mem_read(void *buf, resource_t *r, resource_type_t off, size_t n)
115+
static int resource_mem_read(void *buf, resource_t *r, resource_type_t off,
116+
size_t n)
116117
{
117118
size_t i, width = 1;
118119
void(*io_op)(void *, void *);
@@ -138,7 +139,7 @@ static int resource_mem_read(void *buf, resource_t *r, resource_type_t off, size
138139
default:
139140
return -EIO;
140141
}
141-
142+
142143
off *= width;
143144
off += r->start;
144145

@@ -151,7 +152,7 @@ static int resource_mem_read(void *buf, resource_t *r, resource_type_t off, size
151152

152153
/**
153154
* @brief Perform a data write to a resource.
154-
*
155+
*
155156
* @param dest Buffer which contains data to write
156157
* @param r Resource to write to
157158
* @param off Offset from start of resource to start writing to
@@ -172,13 +173,13 @@ int resource_write(void *src, resource_t *r, resource_type_t off, size_t n)
172173
case RESOURCE_IO:
173174
return resource_io_write(src, r, off, n);
174175
}
175-
176+
176177
return -ENOTSUPP;
177178
}
178179

179180
/**
180181
* @brief Perform a data read of a resource.
181-
*
182+
*
182183
* @param dest Buffer to store read results
183184
* @param r Resource to read from
184185
* @param off Offset from start of resource to start reading from
@@ -191,7 +192,7 @@ int resource_read(void *dest, resource_t *r, resource_type_t off, size_t n)
191192
{
192193
return -EINVAL;
193194
}
194-
195+
195196
switch (r->flags & RESOURCE_TYPE)
196197
{
197198
case RESOURCE_MEM:
@@ -205,7 +206,7 @@ int resource_read(void *dest, resource_t *r, resource_type_t off, size_t n)
205206

206207
/**
207208
* @brief Register a resource with a parent node
208-
*
209+
*
209210
* @param r The resource to register
210211
* @param parent The parent resource to add this to.
211212
*/
@@ -216,7 +217,7 @@ void resource_register(resource_t *r, resource_t *parent)
216217
{
217218
return; // Not linking this resource to a parent, end early
218219
}
219-
220+
220221
r->parent = parent;
221222

222223
if(parent->child == NULL)
@@ -227,19 +228,19 @@ void resource_register(resource_t *r, resource_t *parent)
227228
next = parent->child;
228229
while(next->sibling != NULL)
229230
{
230-
next = next->sibling; // Iterate through children until the youngest
231+
next = next->sibling; // Iterate through children until the youngest
231232
}
232233
next->sibling = r; // Become new youngest sibling
233234
}
234235

235236
/**
236237
* @brief Find a resource by it's name
237-
*
238+
*
238239
* @todo Add recursive search
239-
*
240+
*
240241
* @param name The name of the resource to find
241242
* @param parent The parent node to search against
242-
* @return resource_t* NULL on failure, else the resource requested
243+
* @return resource_t* NULL on failure, else the resource requested
243244
*/
244245
resource_t *resource_find(const char *name, resource_t *parent)
245246
{

src/include/arch/x86/regs.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
/*
2-
* (c) 2018 Apollo Project Developers
2+
* (c) 2024 Apollo Project Developers
33
* <arch/x86/regs.h> - Register definitions
44
*/
55

66
#ifndef __ARCH_X86_REGS_H
77
#define __ARCH_X86_REGS_H
88

9+
#include <stdint.h>
10+
911
typedef struct regs {
1012
uint32_t ds;
1113
uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax;
1214
uint32_t interrupt_num, error_code;
1315
uint32_t eip, cs, eflags, useresp, ss;
1416
} x86_regs_t;
1517

18+
uint32_t read_cr0();
19+
uint32_t read_cr2();
20+
uint32_t read_cr3();
21+
void write_cr0(uint32_t);
22+
void write_cr2(uint32_t);
23+
void write_cr3(uint32_t);
24+
1625
#endif

0 commit comments

Comments
 (0)