Skip to content

Commit 49f2d57

Browse files
committed
FIIXED
1 parent 2b04380 commit 49f2d57

59 files changed

Lines changed: 1901 additions & 1981 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.ps1

Lines changed: 0 additions & 122 deletions
This file was deleted.

include/arch/x86/cpu.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef ARCH_X86_CPU_H
2+
#define ARCH_X86_CPU_H
3+
4+
#include "types.h"
5+
6+
struct registers {
7+
uint32_t gs, fs, es, ds;
8+
uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax;
9+
uint32_t int_no, err_code;
10+
uint32_t eip, cs, eflags, useresp, ss;
11+
};
12+
13+
#define LAPIC_BASE 0xFEE00000
14+
#define LAPIC_ID 0x0020
15+
#define LAPIC_EOI 0x00B0
16+
#define LAPIC_SVR 0x00F0
17+
#define LAPIC_ICR_LOW 0x0300
18+
#define LAPIC_ICR_HIGH 0x0310
19+
#define LAPIC_LVT_TMR 0x0320
20+
#define LAPIC_TMRINIT 0x0380
21+
#define LAPIC_TMRCURR 0x0390
22+
#define LAPIC_TMRDIV 0x03E0
23+
24+
#endif
File renamed without changes.

include/idt.h renamed to include/arch/x86/idt.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define IDT_H
33

44
#include "types.h"
5+
#include "cpu.h"
56

67
typedef struct {
78
uint16_t offset_low;
@@ -16,17 +17,11 @@ typedef struct {
1617
uint32_t base;
1718
} __attribute__((packed)) idt_ptr_t;
1819

19-
typedef struct {
20-
uint32_t gs, fs, es, ds;
21-
uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax;
22-
uint32_t int_no, err_code;
23-
uint32_t eip, cs, eflags, useresp, ss;
24-
} registers_t;
25-
2620
typedef registers_t* (*isr_t)(registers_t* regs);
2721

2822
void idt_set_gate(uint8_t num, uint32_t base, uint16_t selector, uint8_t type, uint8_t dpl, uint8_t present);
2923
void idt_init(void);
24+
void idt_load_current(void);
3025
void idt_load(uint32_t idt_ptr_addr);
3126
void register_interrupt_handler(uint8_t n, isr_t handler);
3227
void isr_init(void);

include/arch/x86/interrupts.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef INTERRUPTS_H
2+
#define INTERRUPTS_H
3+
4+
#include "types.h"
5+
#include "cpu.h"
6+
7+
#if defined(__i386__)
8+
#include "arch/x86/cpu.h"
9+
#endif
10+
11+
typedef registers_t* (*isr_t)(registers_t* regs);
12+
13+
void register_interrupt_handler(uint8_t n, isr_t handler);
14+
void idt_init(void);
15+
16+
#endif

include/arch/x86/smp_rally.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef SMP_RALLY_H
2+
#define SMP_RALLY_H
3+
4+
#include "types.h"
5+
6+
#define LAPIC_BASE 0xFEE00000
7+
#define LAPIC_ID 0x0020
8+
#define LAPIC_VER 0x0030
9+
#define LAPIC_TPR 0x0080
10+
#define LAPIC_EOI 0x00B0
11+
#define LAPIC_SVR 0x00F0
12+
#define LAPIC_ICR_LOW 0x0300
13+
#define LAPIC_ICR_HIGH 0x0310
14+
#define LAPIC_LVT_TMR 0x0320
15+
#define LAPIC_TMRINIT 0x0380
16+
#define LAPIC_TMRCURR 0x0390
17+
#define LAPIC_TMRDIV 0x03E0
18+
19+
void smp_rally_init(void);
20+
uint32_t smp_rally_cpu_count(void);
21+
int smp_rally_boot(uint32_t cpu_id);
22+
uint32_t smp_rally_online_mask(void);
23+
int smp_rally_add_cpu(uint32_t cpu_id);
24+
int smp_rally_remove_cpu(uint32_t cpu_id);
25+
26+
#endif

include/cpu.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#ifndef CPU_H
2+
#define CPU_H
3+
4+
#include "types.h"
5+
#include "arch/x86/cpu.h"
6+
7+
// Generic register state structure
8+
// This will be defined by each architecture
9+
typedef struct registers registers_t;
10+
11+
// CPU features
12+
int cpu_has_feature(uint32_t feature);
13+
#define CPU_FEATURE_SSE 1
14+
#define CPU_FEATURE_SSE41 2
15+
#define CPU_FEATURE_FPU 3
16+
17+
// Feature enablement
18+
void cpu_enable_feature(uint32_t feature);
19+
20+
// CPU information
21+
void cpu_get_vendor(char* out, uint32_t max);
22+
23+
// System control
24+
void cpu_reboot(void);
25+
26+
// Architecture-specific initialization
27+
void arch_init(void);
28+
29+
// Interrupt control
30+
void interrupts_enable(void);
31+
void interrupts_disable(void);
32+
int interrupts_enabled(void);
33+
34+
// CPU identification
35+
uint32_t cpu_get_id(void);
36+
uint32_t cpu_get_count(void);
37+
38+
#include "mmu.h"
39+
40+
// TLB management
41+
static inline void tlb_flush(uintptr_t addr) { mmu_tlb_flush(addr); }
42+
static inline void tlb_flush_all(void) { mmu_tlb_flush_all(); }
43+
44+
// Paging control
45+
static inline void paging_switch_directory(uintptr_t dir_phys) { mmu_switch_space(dir_phys); }
46+
47+
// Halt the CPU
48+
void cpu_halt(void);
49+
void cpu_pause(void);
50+
51+
// Port I/O (x86 specific, but can be stubs elsewhere)
52+
uint8_t inb(uint16_t port);
53+
void outb(uint16_t port, uint8_t val);
54+
uint16_t inw(uint16_t port);
55+
void outw(uint16_t port, uint16_t val);
56+
uint32_t inl(uint16_t port);
57+
void outl(uint16_t port, uint32_t val);
58+
59+
#endif

include/heap.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
#include "types.h"
55

66
void heap_init(void);
7-
void* kmalloc(uint32_t size);
7+
void* kmalloc(size_t size);
88
void kfree(void* ptr);
9-
uint32_t heap_total_bytes(void);
10-
uint32_t heap_free_bytes(void);
11-
void* aligned_alloc(uint32_t size, uint32_t align);
12-
void kheap_stats(uint32_t* total_bytes, uint32_t* free_bytes);
9+
size_t heap_total_bytes(void);
10+
size_t heap_free_bytes(void);
11+
void* aligned_alloc(size_t size, size_t align);
12+
void kheap_stats(size_t* total_bytes, size_t* free_bytes);
1313

1414
#endif

0 commit comments

Comments
 (0)