Skip to content

Commit b67a682

Browse files
committed
Removed ACPICA, added uACPI, added LAPIC timer, added RTC
1 parent c89fb9c commit b67a682

File tree

302 files changed

+27954
-151376
lines changed

Some content is hidden

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

302 files changed

+27954
-151376
lines changed

Makefile

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
DOCKER = $(shell which docker)
2-
DOCKER_IMAGE = menios:latest
3-
1+
GIT_BRANCH = $(shell git branch --show-current)
42
IMAGE_NAME = menios
53

4+
DOCKER = $(shell which docker)
5+
DOCKER_IMAGE = $(IMAGE_NAME):$(GIT_BRANCH)
6+
67
ARCH ?= x86-64
78
GCC_DIR = /usr/bin
89
LIB_DIR = src/libc
910
CINCLUDE = \
10-
-I./include \
11-
-I../../include \
12-
-I./vendor/acpica/include \
13-
-I../../vendor/acpica/include
11+
-I./include
1412

1513
OUTPUT_DIR = bin
1614
KERNEL_DIR = src/kernel
@@ -19,19 +17,17 @@ KERNEL = $(OUTPUT_DIR)/kernel.elf
1917

2018
OBJDIR = obj
2119
LIBDIR = lib
22-
ACPICA_OBJ = $(OBJDIR)/acpica
20+
UACPI_OBJ = $(OBJDIR)/uacpi
2321
KERNEL_OBJ = $(OBJDIR)/kernel
2422

25-
LIB_ACPICA = $(LIBDIR)/libacpica.a
26-
2723
KERNEL_SRC = $(shell find -L src -type f -name '*.c')
2824
KERNEL_ASM = $(shell find -L src/kernel -type f -name '*.s')
2925
KERNEL_OBJS = $(patsubst %.c, %.o, $(KERNEL_SRC))
3026

31-
ACPICA_SRC = $(shell find -L vendor/acpica -type f -name '*.c')
32-
ACPICA_OBJS := $(patsubst %.c, %.o, $(ACPICA_SRC))
27+
UACPI_SRC = $(shell find -L vendor/uacpi -type f -name '*.c')
28+
UACPI_OBJS := $(patsubst %.c, %.o, $(UACPI_SRC))
3329

34-
OBJS = $(KERNEL_OBJS) $(ACPICA_OBJS)
30+
OBJS = $(KERNEL_OBJS) $(UACPI_OBJS)
3531

3632
override CFLAGS += \
3733
-Wall \
@@ -55,7 +51,8 @@ override CFLAGS += \
5551
-mno-sse \
5652
-mno-sse2 \
5753
-DMENIOS_KERNEL \
58-
-DACPI_DEBUG_OUTPUT
54+
-DACPI_DEBUG_OUTPUT \
55+
-DUACPI_KERNEL_INITIALIZATION
5956

6057
override CPPFLAGS := \
6158
$(CINCLUDE) \
@@ -106,12 +103,16 @@ clean:
106103

107104
.PHONY: docker
108105
docker:
109-
ifeq ($(shell docker images menios -q), )
110-
docker rmi -f menios && \
111-
docker build --platform linux/amd64 -t menios:latest .
106+
ifeq ($(OS_NAME),linux)
107+
@echo Skipping Docker
108+
else
109+
ifeq ($(shell docker images $(DOCKER_IMAGE) -q), )
110+
docker rmi -f $(DOCKER_IMAGE) && \
111+
docker build --platform linux/amd64 -t $(DOCKER_IMAGE) .
112112
else
113113
@echo "The Docker image for meniOS already exists"
114114
endif
115+
endif
115116

116117
%.o: %.c
117118
ifeq ($(OS_NAME),linux)
@@ -121,7 +122,7 @@ else
121122
endif
122123

123124
.PHONY: build
124-
build: $(OBJS)
125+
build: docker $(OBJS)
125126
ifeq ($(OS_NAME),linux)
126127
@set -eux
127128

@@ -163,7 +164,7 @@ endif
163164

164165
.PHONY: run
165166
run:
166-
qemu-system-x86_64 -smp cpus=1,maxcpus=1,sockets=1,dies=1,clusters=1,cores=1 -vga std -no-reboot --no-shutdown -M q35 -m size=2G,maxmem=2G -hda menios.hdd -serial file:com1.log -monitor stdio -d int -M hpet=on -usb -machine q35
167+
qemu-system-x86_64 -smp cpus=1,maxcpus=2,sockets=1,dies=1,clusters=1,cores=2 -vga std -no-reboot --no-shutdown -M q35 -m size=2G,maxmem=2G -hda menios.hdd -serial file:com1.log -monitor stdio -d int -M hpet=on -usb -machine q35 -rtc base=utc,clock=host
167168

168169
.PHONY: test
169170
test:
@@ -173,7 +174,7 @@ ifeq ($(OS_NAME),linux)
173174
@echo "Testing inside Linux"
174175

175176
for file in $(shell find -L test -type f -name 'test_*.c'); do \
176-
gcc -I./include $$file test/unity.c src/kernel/mem/kmalloc.c -o "$$file".bin ; \
177+
gcc -DMENIOS_NO_DEBUG -I./include $$file test/unity.c src/kernel/mem/kmalloc.c -o "$$file".bin ; \
177178
echo "Testing $(.c:.bin=$$file)" ; \
178179
"$$file".bin ; \
179180
rm "$$file".bin ; \

include/errno.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef MENIOS_INCLUDE_ERRNO_H
2+
#define MENIOS_INCLUDE_ERRNO_H
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
#include <sys/errno.h>
9+
10+
#ifdef __cplusplus
11+
}
12+
#endif
13+
14+
#endif /* MENIOS_INCLUDE_SYS_ERRNO_H */

include/kernel/acpi.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#ifndef MENIOS_INCLUDE_KERNEL_ACPI_H
22
#define MENIOS_INCLUDE_KERNEL_ACPI_H
33

4-
#include <acpi.h>
5-
#include <acpixf.h>
4+
#include <types.h>
65

76
#ifdef __cplusplus
87
extern "C" {
@@ -40,8 +39,6 @@ typedef struct {
4039
uint32_t creator_revision;
4140
} acpi_sdt_header_t;
4241

43-
#define ACPI_SDT_HEADER_SIZE 36
44-
4542
typedef struct {
4643
acpi_sdt_header_t header;
4744
uint32_t* sdt;
@@ -53,7 +50,7 @@ typedef struct {
5350
} acpi_xsdt_t;
5451

5552
int acpi_init();
56-
void acpi_shutdown();
53+
int acpi_shutdown();
5754

5855
#ifdef __cplusplus
5956
}

include/kernel/apic.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@
1212
#define PIC2_COMMAND_PORT 0xa0
1313
#define PIC2_DATA_PORT 0xa1
1414

15+
#define IOAPIC_REG_ENTRYCOUNT 1
16+
17+
#define LAPIC_SVR 0x0f0
18+
#define LAPIC_EOI 0x0b0
19+
#define LAPIC_TIMER_DIV 0x3e0
20+
#define LAPIC_TIMER_INIT 0x380
21+
#define LAPIC_TIMER_CURR 0x390
22+
#define LAPIC_TIMER_LVT 0x320
23+
1524
void apic_init();
25+
void write_lapic(uintptr_t reg, uint32_t value);
26+
uint32_t read_lapic(uintptr_t reg);
1627

1728
#endif

include/kernel/console.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,16 @@
1010
#define FLAG_TYPE 0x08 // The '#' flag
1111
#define FLAG_ZERO 0x10 // The '0' flag
1212

13+
typedef struct screen_pos_t {
14+
uint8_t x;
15+
uint8_t y;
16+
} screen_pos_t;
17+
1318
void set_cursor_position(uint16_t pos);
1419

1520
uint16_t get_cursor_position();
1621

22+
void gotoxy(uint32_t x, uint32_t y);
23+
void get_cursor_pos(screen_pos_t* pos);
24+
1725
#endif

include/kernel/heap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ void* kmalloc(size_t size);
4343
void kfree(void* ptr);
4444
// void* kmem_align(uint64_t size);
4545

46+
void dump_heap(heap_node_p heap, size_t size);
47+
4648
#ifdef __cplusplus
4749
}
4850
#endif

include/kernel/idt.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define ISR_FLOAT_POINT_EXCEPTION 0x10
2121
#define ISR_ALIGNMENT_CHECK 0x11
2222
#define ISR_MACHINE_CHECK 0x12
23+
#define ISR_PERIODIC_TIMER 0x20
2324

2425
typedef struct {
2526
uint16_t base_low; // Lower 16 bits of ISR address
@@ -66,7 +67,9 @@ extern void idt_generic_isr_asm_handler();
6667
extern void idt_gpf_isr_asm_handler();
6768
extern void idt_load(idt_pointer_t *idt_ptr);
6869
extern void idt_pf_isr_asm_handler();
70+
extern void idt_period_timer_isr_asm_handler();
6971

72+
void idt_add_isr(int interruption, void* handler);
7073
void idt_init();
7174

7275
#endif

include/kernel/kernel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
uint8_t inb(uint16_t port);
77
uint16_t inw(uint16_t port);
8+
uint32_t inl(uint16_t port);
89

910
void cli();
1011
void hcf() __attribute__((noreturn));
1112
void outb(uint16_t port, uint8_t value);
1213
void outw(uint16_t port, uint16_t value);
14+
void outl(uint16_t port, uint32_t value);
1315
void sti();
1416

1517
#endif
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef MENIOS_INCLUDE_SYS_MMAN_H
2-
#define MENIOS_INCLUDE_SYS_MMAN_H
1+
#ifndef MENIOS_INCLUDE_KERNEL_MMAN_H
2+
#define MENIOS_INCLUDE_KERNEL_MMAN_H
33

44
#ifdef __cplusplus
55
extern "C" {
@@ -20,10 +20,10 @@ extern "C" {
2020

2121
#define MAP_FAILED ((void *) -1) // mapping failed
2222

23-
void* mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
24-
int munmap(void *addr, size_t len);
23+
void* kmmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
24+
int kmunmap(void *addr, size_t len);
2525

2626
#ifdef __cplusplus
2727
}
2828
#endif
29-
#endif //MENIOS_INCLUDE_SYS_MMAN_H
29+
#endif //MENIOS_INCLUDE_KERNEL_MMAN_H

include/kernel/rtc.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef MENIOS_INCLUDE_KERNEL_RTC_H
2+
#define MENIOS_INCLUDE_KERNEL_RTC_H
3+
4+
#include <types.h>
5+
6+
#ifdef __cplusplus
7+
extern "C" {
8+
#endif
9+
10+
#define RTC_INDEX_PORT 0x70
11+
#define RTC_DATA_PORT 0x71
12+
13+
typedef struct rtc_time_t {
14+
uint8_t seconds;
15+
uint8_t minutes;
16+
uint8_t hours;
17+
uint8_t day;
18+
uint8_t month;
19+
uint8_t year;
20+
uint16_t full_year;
21+
uint8_t weekday;
22+
uint8_t century;
23+
uint8_t register_b;
24+
} rtc_time_t;
25+
26+
void rtc_time(rtc_time_t* time);
27+
28+
#ifdef __cplusplus
29+
}
30+
#endif
31+
32+
33+
#endif // MENIOS_INCLUDE_KERNEL_RTC_H

0 commit comments

Comments
 (0)