Reorganize kernel code
This commit is contained in:
parent
1f86052a87
commit
1fc1c0150c
|
|
@ -6,7 +6,7 @@ LD = ld -m elf_x86_64
|
||||||
QEMU = qemu-system-x86_64
|
QEMU = qemu-system-x86_64
|
||||||
QEMUFLAGS = -m 1G -enable-kvm -cpu host
|
QEMUFLAGS = -m 1G -enable-kvm -cpu host
|
||||||
LDINTERNALFLAGS := -Tlinker.ld
|
LDINTERNALFLAGS := -Tlinker.ld
|
||||||
INTERNALCFLAGS := -I../ext/limine/stivale \
|
INTERNALCFLAGS := -I../ext/limine/stivale -mcmodel=kernel
|
||||||
|
|
||||||
CFILES := $(shell find src -type f -name '*.c')
|
CFILES := $(shell find src -type f -name '*.c')
|
||||||
HFILES := $(shell find src -type f -name '*.h')
|
HFILES := $(shell find src -type f -name '*.h')
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
#include <stivale2.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
static uint8_t stack[4096] = {0};
|
||||||
|
void stivale2_main(struct stivale2_struct *info);
|
||||||
|
|
||||||
|
struct stivale2_header_tag_smp smp_request = {
|
||||||
|
.tag = {
|
||||||
|
.identifier = STIVALE2_HEADER_TAG_SMP_ID,
|
||||||
|
.next = 0
|
||||||
|
},
|
||||||
|
.flags = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
__attribute__((section(".stivale2hdr"), used))
|
||||||
|
struct stivale2_header header2 = {
|
||||||
|
.entry_point = (uint64_t)stivale2_main,
|
||||||
|
.stack = (uintptr_t)stack + sizeof(stack),
|
||||||
|
.flags = 0,
|
||||||
|
.tags = (uint64_t)&smp_request
|
||||||
|
};
|
||||||
|
|
||||||
|
void stivale2_main(struct stivale2_struct *info) {
|
||||||
|
kmain();
|
||||||
|
}
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
#include <stivale2.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
#define VGA_ADDRESS 0xb8000
|
|
||||||
#define VGA_COLOR(character, color) ((uint16_t) (character) | (uint16_t) (color) << 8)
|
|
||||||
#define VGA_BLACK 0
|
|
||||||
#define VGA_BLUE 1
|
|
||||||
#define VGA_GREEN 2
|
|
||||||
#define VGA_CYAN 3
|
|
||||||
#define VGA_RED 4
|
|
||||||
#define VGA_PURPLE 5
|
|
||||||
#define VGA_BROWN 6
|
|
||||||
#define VGA_GRAY 7
|
|
||||||
#define VGA_DARK_GRAY 8
|
|
||||||
#define VGA_LIGHT_BLUE 9
|
|
||||||
#define VGA_LIGH_GREEN 10
|
|
||||||
#define VGA_LIGHT_CYAN 11
|
|
||||||
#define VGA_LIGHT_RED 12
|
|
||||||
#define VGA_LIGHT_PURPLE 13
|
|
||||||
#define VGA_YELLOW 14
|
|
||||||
#define VGA_WHITE 15
|
|
||||||
|
|
||||||
static uint8_t stack[4096] = {0};
|
|
||||||
void stivale2_main(struct stivale2_struct *info);
|
|
||||||
|
|
||||||
struct stivale2_header_tag_smp smp_request = {
|
|
||||||
.tag = {
|
|
||||||
.identifier = STIVALE2_HEADER_TAG_SMP_ID,
|
|
||||||
.next = 0
|
|
||||||
},
|
|
||||||
.flags = 0
|
|
||||||
};
|
|
||||||
|
|
||||||
__attribute__((section(".stivale2hdr"), used))
|
|
||||||
struct stivale2_header header2 = {
|
|
||||||
.entry_point = (uint64_t)stivale2_main,
|
|
||||||
.stack = (uintptr_t)stack + sizeof(stack),
|
|
||||||
.flags = 0,
|
|
||||||
.tags = (uint64_t)&smp_request
|
|
||||||
};
|
|
||||||
|
|
||||||
void stivale2_main(struct stivale2_struct *info) {
|
|
||||||
volatile uint16_t *vga_buffer = (uint16_t*)VGA_ADDRESS;
|
|
||||||
vga_buffer[0] = VGA_COLOR('h', VGA_GREEN);
|
|
||||||
vga_buffer[1] = VGA_COLOR('e', VGA_GREEN);
|
|
||||||
vga_buffer[2] = VGA_COLOR('l', VGA_GREEN);
|
|
||||||
vga_buffer[3] = VGA_COLOR('l', VGA_GREEN);
|
|
||||||
vga_buffer[4] = VGA_COLOR('o', VGA_GREEN);
|
|
||||||
asm volatile ("hlt");
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
#include "vga.h"
|
||||||
|
|
||||||
|
void kmain() {
|
||||||
|
vga_puts("hello!");
|
||||||
|
vga_putc('h');
|
||||||
|
asm volatile ("hlt");
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
void kmain();
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "vga.h"
|
||||||
|
|
||||||
|
#define VGA_ADDRESS 0xb8000
|
||||||
|
|
||||||
|
static uint8_t current_color = VGA_WHITE;
|
||||||
|
uint16_t *vga_buffer = (uint16_t*)VGA_ADDRESS;
|
||||||
|
|
||||||
|
void vga_putc(char c) {
|
||||||
|
*(vga_buffer++) = (uint16_t)c | (uint16_t)(current_color) << 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
void vga_puts(char *c) {
|
||||||
|
char cur = *(c++);
|
||||||
|
while(cur != '\0') {
|
||||||
|
vga_putc(cur);
|
||||||
|
cur = *(c++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
#define VGA_BLACK 0
|
||||||
|
#define VGA_BLUE 1
|
||||||
|
#define VGA_GREEN 2
|
||||||
|
#define VGA_CYAN 3
|
||||||
|
#define VGA_RED 4
|
||||||
|
#define VGA_PURPLE 5
|
||||||
|
#define VGA_BROWN 6
|
||||||
|
#define VGA_GRAY 7
|
||||||
|
#define VGA_DARK_GRAY 8
|
||||||
|
#define VGA_LIGHT_BLUE 9
|
||||||
|
#define VGA_LIGH_GREEN 10
|
||||||
|
#define VGA_LIGHT_CYAN 11
|
||||||
|
#define VGA_LIGHT_RED 12
|
||||||
|
#define VGA_LIGHT_PURPLE 13
|
||||||
|
#define VGA_YELLOW 14
|
||||||
|
#define VGA_WHITE 15
|
||||||
|
|
||||||
|
void vga_putc(char c);
|
||||||
|
void vga_puts(char *c);
|
||||||
Loading…
Reference in New Issue