mirror of
https://github.com/kenshineto/kern.git
synced 2025-04-21 04:42:25 +00:00
fmt
This commit is contained in:
parent
876970bcfd
commit
d0854aa095
13 changed files with 161 additions and 148 deletions
|
@ -60,7 +60,7 @@ extern void *memset(void *restrict dest, int c, size_t n);
|
||||||
* @returns a pointer to dest
|
* @returns a pointer to dest
|
||||||
*/
|
*/
|
||||||
extern volatile void *memcpyv(volatile void *restrict dest,
|
extern volatile void *memcpyv(volatile void *restrict dest,
|
||||||
const volatile void *restrict src, size_t n);
|
const volatile void *restrict src, size_t n);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy the first n bytes from memory area src to memory area dest. The memory
|
* Copy the first n bytes from memory area src to memory area dest. The memory
|
||||||
|
@ -72,7 +72,7 @@ extern volatile void *memcpyv(volatile void *restrict dest,
|
||||||
* @returns a pointer to dest
|
* @returns a pointer to dest
|
||||||
*/
|
*/
|
||||||
extern volatile void *memmovev(volatile void *restrict dest,
|
extern volatile void *memmovev(volatile void *restrict dest,
|
||||||
const volatile void *restrict src, size_t n);
|
const volatile void *restrict src, size_t n);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fill the first n bytes of the memory region dest with the constant byte c.
|
* Fill the first n bytes of the memory region dest with the constant byte c.
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
#include "pic.h"
|
#include "pic.h"
|
||||||
#include "idt.h"
|
#include "idt.h"
|
||||||
|
|
||||||
void cpu_init(void) {
|
void cpu_init(void)
|
||||||
|
{
|
||||||
pic_remap();
|
pic_remap();
|
||||||
idt_init();
|
idt_init();
|
||||||
fpu_init();
|
fpu_init();
|
||||||
|
|
|
@ -2,11 +2,12 @@
|
||||||
|
|
||||||
#include "fpu.h"
|
#include "fpu.h"
|
||||||
|
|
||||||
void fpu_init(void) {
|
void fpu_init(void)
|
||||||
|
{
|
||||||
size_t cr4;
|
size_t cr4;
|
||||||
uint16_t cw = 0x37F;
|
uint16_t cw = 0x37F;
|
||||||
__asm__ volatile ("mov %%cr4, %0" : "=r"(cr4));
|
__asm__ volatile("mov %%cr4, %0" : "=r"(cr4));
|
||||||
cr4 |= 0x200;
|
cr4 |= 0x200;
|
||||||
__asm__ volatile ("mov %0, %%cr4" :: "r"(cr4));
|
__asm__ volatile("mov %0, %%cr4" ::"r"(cr4));
|
||||||
__asm__ volatile("fldcw %0" :: "m"(cw));
|
__asm__ volatile("fldcw %0" ::"m"(cw));
|
||||||
}
|
}
|
||||||
|
|
109
kernel/cpu/idt.c
109
kernel/cpu/idt.c
|
@ -9,12 +9,12 @@
|
||||||
#define IDT_SIZE 256
|
#define IDT_SIZE 256
|
||||||
|
|
||||||
struct idt_entry {
|
struct idt_entry {
|
||||||
uint16_t isr_low; // low 16 bits of isr
|
uint16_t isr_low; // low 16 bits of isr
|
||||||
uint16_t kernel_cs; // kernel segment selector
|
uint16_t kernel_cs; // kernel segment selector
|
||||||
uint8_t ist; // interrupt stack table
|
uint8_t ist; // interrupt stack table
|
||||||
uint8_t flags; // gate type, privilege level, present bit
|
uint8_t flags; // gate type, privilege level, present bit
|
||||||
uint16_t isr_mid; // middle 16 bits of isr
|
uint16_t isr_mid; // middle 16 bits of isr
|
||||||
uint32_t isr_high; // high 32 bits of isr
|
uint32_t isr_high; // high 32 bits of isr
|
||||||
uint32_t reserved;
|
uint32_t reserved;
|
||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ struct idtr {
|
||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
|
|
||||||
// interrupt gate
|
// interrupt gate
|
||||||
#define GATE_64BIT_INT 0x0E
|
#define GATE_64BIT_INT 0x0E
|
||||||
// trap gate
|
// trap gate
|
||||||
#define GATE_64BIT_TRAP 0x0F
|
#define GATE_64BIT_TRAP 0x0F
|
||||||
|
|
||||||
|
@ -37,15 +37,15 @@ struct idtr {
|
||||||
// interrupt is present in IDT
|
// interrupt is present in IDT
|
||||||
#define PRESENT 0x80
|
#define PRESENT 0x80
|
||||||
|
|
||||||
__attribute__((aligned(0x10)))
|
__attribute__((aligned(0x10))) static struct idt_entry idt[256];
|
||||||
static struct idt_entry idt[256];
|
|
||||||
|
|
||||||
static struct idtr idtr;
|
static struct idtr idtr;
|
||||||
// from idt.S
|
// from idt.S
|
||||||
extern void *isr_stub_table[];
|
extern void *isr_stub_table[];
|
||||||
|
|
||||||
// initialize and load the IDT
|
// initialize and load the IDT
|
||||||
void idt_init(void) {
|
void idt_init(void)
|
||||||
|
{
|
||||||
// initialize idtr
|
// initialize idtr
|
||||||
idtr.address = (uint64_t)&idt;
|
idtr.address = (uint64_t)&idt;
|
||||||
idtr.size = (uint16_t)sizeof(struct idt_entry) * IDT_SIZE - 1;
|
idtr.size = (uint16_t)sizeof(struct idt_entry) * IDT_SIZE - 1;
|
||||||
|
@ -67,10 +67,11 @@ void idt_init(void) {
|
||||||
entry->reserved = 0;
|
entry->reserved = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
__asm__ volatile ("lidt %0" : : "m"(idtr));
|
__asm__ volatile("lidt %0" : : "m"(idtr));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void isr_print_regs(struct isr_regs *regs) {
|
static void isr_print_regs(struct isr_regs *regs)
|
||||||
|
{
|
||||||
printf("rax: %#016lx (%lu)\n", regs->rax, regs->rax);
|
printf("rax: %#016lx (%lu)\n", regs->rax, regs->rax);
|
||||||
printf("rbx: %#016lx (%lu)\n", regs->rbx, regs->rbx);
|
printf("rbx: %#016lx (%lu)\n", regs->rbx, regs->rbx);
|
||||||
printf("rcx: %#016lx (%lu)\n", regs->rcx, regs->rcx);
|
printf("rcx: %#016lx (%lu)\n", regs->rcx, regs->rcx);
|
||||||
|
@ -79,8 +80,8 @@ static void isr_print_regs(struct isr_regs *regs) {
|
||||||
printf("rdi: %#016lx (%lu)\n", regs->rdi, regs->rdi);
|
printf("rdi: %#016lx (%lu)\n", regs->rdi, regs->rdi);
|
||||||
printf("rsp: %#016lx (%lu)\n", regs->rsp, regs->rsp);
|
printf("rsp: %#016lx (%lu)\n", regs->rsp, regs->rsp);
|
||||||
printf("rbp: %#016lx (%lu)\n", regs->rbp, regs->rbp);
|
printf("rbp: %#016lx (%lu)\n", regs->rbp, regs->rbp);
|
||||||
printf("r8 : %#016lx (%lu)\n", regs->r8 , regs->r8 );
|
printf("r8 : %#016lx (%lu)\n", regs->r8, regs->r8);
|
||||||
printf("r9 : %#016lx (%lu)\n", regs->r9 , regs->r9 );
|
printf("r9 : %#016lx (%lu)\n", regs->r9, regs->r9);
|
||||||
printf("r10: %#016lx (%lu)\n", regs->r10, regs->r10);
|
printf("r10: %#016lx (%lu)\n", regs->r10, regs->r10);
|
||||||
printf("r11: %#016lx (%lu)\n", regs->r11, regs->r11);
|
printf("r11: %#016lx (%lu)\n", regs->r11, regs->r11);
|
||||||
printf("r12: %#016lx (%lu)\n", regs->r12, regs->r12);
|
printf("r12: %#016lx (%lu)\n", regs->r12, regs->r12);
|
||||||
|
@ -91,30 +92,48 @@ static void isr_print_regs(struct isr_regs *regs) {
|
||||||
printf("rflags: %#016lx (%lu)\n", regs->rflags, regs->rflags);
|
printf("rflags: %#016lx (%lu)\n", regs->rflags, regs->rflags);
|
||||||
struct rflags *rflags = (struct rflags *)regs->rflags;
|
struct rflags *rflags = (struct rflags *)regs->rflags;
|
||||||
puts("rflags: ");
|
puts("rflags: ");
|
||||||
if (rflags->cf) puts("CF ");
|
if (rflags->cf)
|
||||||
if (rflags->pf) puts("PF ");
|
puts("CF ");
|
||||||
if (rflags->af) puts("AF ");
|
if (rflags->pf)
|
||||||
if (rflags->zf) puts("ZF ");
|
puts("PF ");
|
||||||
if (rflags->sf) puts("SF ");
|
if (rflags->af)
|
||||||
if (rflags->tf) puts("TF ");
|
puts("AF ");
|
||||||
if (rflags->if_) puts("IF ");
|
if (rflags->zf)
|
||||||
if (rflags->df) puts("DF ");
|
puts("ZF ");
|
||||||
if (rflags->of) puts("OF ");
|
if (rflags->sf)
|
||||||
if (rflags->iopl) puts("IOPL ");
|
puts("SF ");
|
||||||
if (rflags->nt) puts("NT ");
|
if (rflags->tf)
|
||||||
if (rflags->md) puts("MD ");
|
puts("TF ");
|
||||||
if (rflags->rf) puts("RF ");
|
if (rflags->if_)
|
||||||
if (rflags->vm) puts("VM ");
|
puts("IF ");
|
||||||
if (rflags->ac) puts("AC ");
|
if (rflags->df)
|
||||||
if (rflags->vif) puts("VIF ");
|
puts("DF ");
|
||||||
if (rflags->vip) puts("VIP ");
|
if (rflags->of)
|
||||||
if (rflags->id) puts("ID ");
|
puts("OF ");
|
||||||
|
if (rflags->iopl)
|
||||||
|
puts("IOPL ");
|
||||||
|
if (rflags->nt)
|
||||||
|
puts("NT ");
|
||||||
|
if (rflags->md)
|
||||||
|
puts("MD ");
|
||||||
|
if (rflags->rf)
|
||||||
|
puts("RF ");
|
||||||
|
if (rflags->vm)
|
||||||
|
puts("VM ");
|
||||||
|
if (rflags->ac)
|
||||||
|
puts("AC ");
|
||||||
|
if (rflags->vif)
|
||||||
|
puts("VIF ");
|
||||||
|
if (rflags->vip)
|
||||||
|
puts("VIP ");
|
||||||
|
if (rflags->id)
|
||||||
|
puts("ID ");
|
||||||
puts("\n");
|
puts("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#define EX_DEBUG 0x01
|
#define EX_DEBUG 0x01
|
||||||
#define EX_BREAKPOINT 0x03
|
#define EX_BREAKPOINT 0x03
|
||||||
#define EX_PAGE_FAULT 0x0e
|
#define EX_PAGE_FAULT 0x0e
|
||||||
|
|
||||||
// Intel manual vol 3 ch 6.3.1
|
// Intel manual vol 3 ch 6.3.1
|
||||||
char *EXCEPTIONS[] = {
|
char *EXCEPTIONS[] = {
|
||||||
|
@ -152,13 +171,15 @@ char *EXCEPTIONS[] = {
|
||||||
"Reserved",
|
"Reserved",
|
||||||
};
|
};
|
||||||
|
|
||||||
void idt_exception_handler(uint64_t exception, uint64_t code, struct isr_regs *state) {
|
void idt_exception_handler(uint64_t exception, uint64_t code,
|
||||||
|
struct isr_regs *state)
|
||||||
|
{
|
||||||
uint64_t cr2;
|
uint64_t cr2;
|
||||||
|
|
||||||
switch (exception) {
|
switch (exception) {
|
||||||
case EX_PAGE_FAULT:
|
case EX_PAGE_FAULT:
|
||||||
// page faults store the offending address in cr2
|
// page faults store the offending address in cr2
|
||||||
__asm__ volatile ("mov %%cr2, %0" : "=r"(cr2));
|
__asm__ volatile("mov %%cr2, %0" : "=r"(cr2));
|
||||||
if (!load_page((void *)cr2))
|
if (!load_page((void *)cr2))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -182,13 +203,15 @@ void idt_exception_handler(uint64_t exception, uint64_t code, struct isr_regs *s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void idt_pic_eoi(uint8_t exception) {
|
void idt_pic_eoi(uint8_t exception)
|
||||||
|
{
|
||||||
pic_eoi(exception - PIC_REMAP_OFFSET);
|
pic_eoi(exception - PIC_REMAP_OFFSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
|
||||||
void idt_pic_timer(void) {
|
void idt_pic_timer(void)
|
||||||
|
{
|
||||||
// print a message once we know the timer works
|
// print a message once we know the timer works
|
||||||
// but avoid spamming the logs
|
// but avoid spamming the logs
|
||||||
if (counter == 3) {
|
if (counter == 3) {
|
||||||
|
@ -199,6 +222,10 @@ void idt_pic_timer(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void idt_pic_keyboard(void) {}
|
void idt_pic_keyboard(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void idt_pic_mouse(void) {}
|
void idt_pic_mouse(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
|
@ -36,33 +36,13 @@ struct isr_regs {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct rflags {
|
struct rflags {
|
||||||
uint64_t cf : 1,
|
uint64_t cf : 1, : 1, pf : 1, : 1, af : 1, : 1, zf : 1, sf : 1,
|
||||||
: 1,
|
|
||||||
pf : 1,
|
|
||||||
: 1,
|
|
||||||
af : 1,
|
|
||||||
: 1,
|
|
||||||
zf : 1,
|
|
||||||
sf : 1,
|
|
||||||
|
|
||||||
tf : 1,
|
tf : 1, if_ : 1, df : 1, of : 1, iopl : 2, nt : 1, md : 1,
|
||||||
if_ : 1,
|
|
||||||
df : 1,
|
|
||||||
of : 1,
|
|
||||||
iopl : 2,
|
|
||||||
nt : 1,
|
|
||||||
md : 1,
|
|
||||||
|
|
||||||
rf : 1,
|
rf : 1, vm : 1, ac : 1, vif : 1, vip : 1, id : 1, : 42;
|
||||||
vm : 1,
|
|
||||||
ac : 1,
|
|
||||||
vif : 1,
|
|
||||||
vip : 1,
|
|
||||||
id : 1,
|
|
||||||
: 42;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void idt_init(void);
|
void idt_init(void);
|
||||||
|
|
||||||
#endif /* idt.h */
|
#endif /* idt.h */
|
||||||
|
|
||||||
|
|
|
@ -2,56 +2,63 @@
|
||||||
|
|
||||||
#include "pic.h"
|
#include "pic.h"
|
||||||
|
|
||||||
#define PIC1 0x20 /* IO base address for master PIC */
|
#define PIC1 0x20 /* IO base address for master PIC */
|
||||||
#define PIC2 0xA0 /* IO base address for slave PIC */
|
#define PIC2 0xA0 /* IO base address for slave PIC */
|
||||||
#define PIC1_COMMAND PIC1
|
#define PIC1_COMMAND PIC1
|
||||||
#define PIC1_DATA (PIC1+1)
|
#define PIC1_DATA (PIC1 + 1)
|
||||||
#define PIC2_COMMAND PIC2
|
#define PIC2_COMMAND PIC2
|
||||||
#define PIC2_DATA (PIC2+1)
|
#define PIC2_DATA (PIC2 + 1)
|
||||||
|
|
||||||
#define PIC_EOI 0x20 /* End-of-interrupt command code */
|
#define PIC_EOI 0x20 /* End-of-interrupt command code */
|
||||||
|
|
||||||
#define ICW1_ICW4 0x01 /* Indicates that ICW4 will be present */
|
#define ICW1_ICW4 0x01 /* Indicates that ICW4 will be present */
|
||||||
#define ICW1_SINGLE 0x02 /* Single (cascade) mode */
|
#define ICW1_SINGLE 0x02 /* Single (cascade) mode */
|
||||||
#define ICW1_INTERVAL4 0x04 /* Call address interval 4 (8) */
|
#define ICW1_INTERVAL4 0x04 /* Call address interval 4 (8) */
|
||||||
#define ICW1_LEVEL 0x08 /* Level triggered (edge) mode */
|
#define ICW1_LEVEL 0x08 /* Level triggered (edge) mode */
|
||||||
#define ICW1_INIT 0x10 /* Initialization - required! */
|
#define ICW1_INIT 0x10 /* Initialization - required! */
|
||||||
|
|
||||||
#define ICW4_8086 0x01 /* 8086/88 (MCS-80/85) mode */
|
#define ICW4_8086 0x01 /* 8086/88 (MCS-80/85) mode */
|
||||||
#define ICW4_AUTO 0x02 /* Auto (normal) EOI */
|
#define ICW4_AUTO 0x02 /* Auto (normal) EOI */
|
||||||
#define ICW4_BUF_SLAVE 0x08 /* Buffered mode/slave */
|
#define ICW4_BUF_SLAVE 0x08 /* Buffered mode/slave */
|
||||||
#define ICW4_BUF_MASTER 0x0C /* Buffered mode/master */
|
#define ICW4_BUF_MASTER 0x0C /* Buffered mode/master */
|
||||||
#define ICW4_SFNM 0x10 /* Special fully nested (not) */
|
#define ICW4_SFNM 0x10 /* Special fully nested (not) */
|
||||||
|
|
||||||
void pic_remap(void) {
|
void pic_remap(void)
|
||||||
|
{
|
||||||
uint8_t a1, a2;
|
uint8_t a1, a2;
|
||||||
|
|
||||||
a1 = inb(PIC1_DATA); // save masks
|
a1 = inb(PIC1_DATA); // save masks
|
||||||
a2 = inb(PIC2_DATA);
|
a2 = inb(PIC2_DATA);
|
||||||
|
|
||||||
outb(PIC1_COMMAND, ICW1_INIT | ICW1_ICW4); // starts the initialization sequence (in cascade mode)
|
outb(PIC1_COMMAND,
|
||||||
|
ICW1_INIT |
|
||||||
|
ICW1_ICW4); // starts the initialization sequence (in cascade mode)
|
||||||
io_wait();
|
io_wait();
|
||||||
outb(PIC2_COMMAND, ICW1_INIT | ICW1_ICW4);
|
outb(PIC2_COMMAND, ICW1_INIT | ICW1_ICW4);
|
||||||
io_wait();
|
io_wait();
|
||||||
outb(PIC1_DATA, PIC_REMAP_OFFSET); // ICW2: Master PIC vector offset
|
outb(PIC1_DATA, PIC_REMAP_OFFSET); // ICW2: Master PIC vector offset
|
||||||
io_wait();
|
io_wait();
|
||||||
outb(PIC2_DATA, PIC_REMAP_OFFSET + 8); // ICW2: Slave PIC vector offset
|
outb(PIC2_DATA, PIC_REMAP_OFFSET + 8); // ICW2: Slave PIC vector offset
|
||||||
io_wait();
|
io_wait();
|
||||||
outb(PIC1_DATA, 4); // ICW3: tell Master PIC that there is a slave PIC at IRQ2 (0000 0100)
|
outb(
|
||||||
|
PIC1_DATA,
|
||||||
|
4); // ICW3: tell Master PIC that there is a slave PIC at IRQ2 (0000 0100)
|
||||||
io_wait();
|
io_wait();
|
||||||
outb(PIC2_DATA, 2); // ICW3: tell Slave PIC its cascade identity (0000 0010)
|
outb(PIC2_DATA, 2); // ICW3: tell Slave PIC its cascade identity (0000 0010)
|
||||||
io_wait();
|
io_wait();
|
||||||
|
|
||||||
outb(PIC1_DATA, ICW4_8086); // ICW4: have the PICs use 8086 mode (and not 8080 mode)
|
outb(PIC1_DATA,
|
||||||
|
ICW4_8086); // ICW4: have the PICs use 8086 mode (and not 8080 mode)
|
||||||
io_wait();
|
io_wait();
|
||||||
outb(PIC2_DATA, ICW4_8086);
|
outb(PIC2_DATA, ICW4_8086);
|
||||||
io_wait();
|
io_wait();
|
||||||
|
|
||||||
outb(PIC1_DATA, a1); // restore saved masks.
|
outb(PIC1_DATA, a1); // restore saved masks.
|
||||||
outb(PIC2_DATA, a2);
|
outb(PIC2_DATA, a2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pic_mask(int irq) {
|
void pic_mask(int irq)
|
||||||
|
{
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
uint8_t mask;
|
uint8_t mask;
|
||||||
if (irq < 8) {
|
if (irq < 8) {
|
||||||
|
@ -64,7 +71,8 @@ void pic_mask(int irq) {
|
||||||
outb(port, mask);
|
outb(port, mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pic_unmask(int irq) {
|
void pic_unmask(int irq)
|
||||||
|
{
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
uint8_t mask;
|
uint8_t mask;
|
||||||
if (irq < 8) {
|
if (irq < 8) {
|
||||||
|
@ -77,12 +85,14 @@ void pic_unmask(int irq) {
|
||||||
outb(port, mask);
|
outb(port, mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pic_disable(void) {
|
void pic_disable(void)
|
||||||
|
{
|
||||||
outb(PIC1_DATA, 0xff);
|
outb(PIC1_DATA, 0xff);
|
||||||
outb(PIC2_DATA, 0xff);
|
outb(PIC2_DATA, 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pic_eoi(int irq) {
|
void pic_eoi(int irq)
|
||||||
|
{
|
||||||
if (irq >= 8) {
|
if (irq >= 8) {
|
||||||
outb(PIC2_COMMAND, PIC_EOI);
|
outb(PIC2_COMMAND, PIC_EOI);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,14 +3,17 @@
|
||||||
#include <comus/asm.h>
|
#include <comus/asm.h>
|
||||||
|
|
||||||
#define PORT 0x3F8
|
#define PORT 0x3F8
|
||||||
static void serial_out(uint8_t ch) {
|
static void serial_out(uint8_t ch)
|
||||||
|
{
|
||||||
// wait for output to be free
|
// wait for output to be free
|
||||||
while ((inb(PORT + 5) & 0x20) == 0);
|
while ((inb(PORT + 5) & 0x20) == 0)
|
||||||
|
;
|
||||||
outb(PORT, ch);
|
outb(PORT, ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fputc(FILE *stream, char c) {
|
void fputc(FILE *stream, char c)
|
||||||
(void) stream;
|
{
|
||||||
|
(void)stream;
|
||||||
|
|
||||||
serial_out(c);
|
serial_out(c);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <comus/asm.h>
|
#include <comus/asm.h>
|
||||||
|
|
||||||
__attribute__((noreturn))
|
__attribute__((noreturn)) void panic(const char *format, ...)
|
||||||
void panic(const char *format, ...) {
|
{
|
||||||
cli();
|
cli();
|
||||||
va_list list;
|
va_list list;
|
||||||
va_start(list, format);
|
va_start(list, format);
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
|
|
||||||
void *locate_mboot_table(volatile void *mboot, uint32_t type)
|
void *locate_mboot_table(volatile void *mboot, uint32_t type)
|
||||||
{
|
{
|
||||||
struct mboot_info *info = (struct mboot_info *) mboot;
|
struct mboot_info *info = (struct mboot_info *)mboot;
|
||||||
const char *mboot_end = ((char *) info) + info->total_size;
|
const char *mboot_end = ((char *)info) + info->total_size;
|
||||||
|
|
||||||
char *tag_ptr = info->tags;
|
char *tag_ptr = info->tags;
|
||||||
|
|
||||||
while (tag_ptr < mboot_end) {
|
while (tag_ptr < mboot_end) {
|
||||||
struct mboot_tag *tag = (struct mboot_tag *) tag_ptr;
|
struct mboot_tag *tag = (struct mboot_tag *)tag_ptr;
|
||||||
|
|
||||||
if (tag->type == type)
|
if (tag->type == type)
|
||||||
return tag;
|
return tag;
|
||||||
|
|
|
@ -11,14 +11,14 @@
|
||||||
|
|
||||||
#include <lib.h>
|
#include <lib.h>
|
||||||
|
|
||||||
#define MBOOT_HEADER_MAGIC 0x36D76289
|
#define MBOOT_HEADER_MAGIC 0x36D76289
|
||||||
|
|
||||||
#define MBOOT_CMDLINE 1
|
#define MBOOT_CMDLINE 1
|
||||||
#define MBOOT_MEMORY_MAP 6
|
#define MBOOT_MEMORY_MAP 6
|
||||||
#define MBOOT_FRAMEBUFFER 8
|
#define MBOOT_FRAMEBUFFER 8
|
||||||
#define MBOOT_ELF_SYMBOLS 9
|
#define MBOOT_ELF_SYMBOLS 9
|
||||||
#define MBOOT_OLD_RSDP 14
|
#define MBOOT_OLD_RSDP 14
|
||||||
#define MBOOT_NEW_RSDP 15
|
#define MBOOT_NEW_RSDP 15
|
||||||
|
|
||||||
struct mboot_info {
|
struct mboot_info {
|
||||||
uint32_t total_size;
|
uint32_t total_size;
|
||||||
|
@ -70,7 +70,6 @@ struct mboot_tag_mmap {
|
||||||
struct mboot_mmap_entry entries[];
|
struct mboot_mmap_entry entries[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct mboot_tag_old_rsdp {
|
struct mboot_tag_old_rsdp {
|
||||||
uint32_t type;
|
uint32_t type;
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
|
|
|
@ -5,41 +5,30 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
static const char *segment_type[] = {
|
static const char *segment_type[] = { "Reserved", "Free",
|
||||||
"Reserved",
|
"Reserved", "ACPI Reserved",
|
||||||
"Free",
|
"Hibernation", "Defective",
|
||||||
"Reserved",
|
"Unknown" };
|
||||||
"ACPI Reserved",
|
|
||||||
"Hibernation",
|
|
||||||
"Defective",
|
|
||||||
"Unknown"
|
|
||||||
};
|
|
||||||
|
|
||||||
void mboot_load_mmap(volatile void *mboot, struct memory_map *res)
|
void mboot_load_mmap(volatile void *mboot, struct memory_map *res)
|
||||||
{
|
{
|
||||||
void *tag = locate_mboot_table(mboot, MBOOT_MEMORY_MAP);
|
void *tag = locate_mboot_table(mboot, MBOOT_MEMORY_MAP);
|
||||||
struct mboot_tag_mmap *mmap = (struct mboot_tag_mmap *) tag;
|
struct mboot_tag_mmap *mmap = (struct mboot_tag_mmap *)tag;
|
||||||
|
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
uintptr_t i = (uintptr_t)mmap->entries;
|
uintptr_t i = (uintptr_t)mmap->entries;
|
||||||
printf("MEMORY MAP\n");
|
printf("MEMORY MAP\n");
|
||||||
char buf[20];
|
char buf[20];
|
||||||
for (;
|
for (; i < (uintptr_t)mmap->entries + mmap->size;
|
||||||
i < (uintptr_t)mmap->entries + mmap->size;
|
i += mmap->entry_size, idx++) {
|
||||||
i += mmap->entry_size, idx++
|
struct mboot_mmap_entry *seg = (struct mboot_mmap_entry *)i;
|
||||||
) {
|
|
||||||
struct mboot_mmap_entry *seg = (struct mboot_mmap_entry *) i;
|
|
||||||
const char *type = NULL;
|
const char *type = NULL;
|
||||||
if (seg->type > 6)
|
if (seg->type > 6)
|
||||||
type = segment_type[6];
|
type = segment_type[6];
|
||||||
else
|
else
|
||||||
type = segment_type[seg->type];
|
type = segment_type[seg->type];
|
||||||
printf("ADDR: %16p LEN: %4s TYPE: %s (%d)\n",
|
printf("ADDR: %16p LEN: %4s TYPE: %s (%d)\n", (void *)seg->addr,
|
||||||
(void *)seg->addr,
|
btoa(seg->len, buf), type, seg->type);
|
||||||
btoa(seg->len, buf),
|
|
||||||
type,
|
|
||||||
seg->type
|
|
||||||
);
|
|
||||||
if (seg->type != 1 || seg->len < 1)
|
if (seg->type != 1 || seg->len < 1)
|
||||||
continue;
|
continue;
|
||||||
res->entries[idx].addr = seg->addr;
|
res->entries[idx].addr = seg->addr;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
volatile void *memcpyv(volatile void *restrict dest, const volatile void *restrict src,
|
volatile void *memcpyv(volatile void *restrict dest,
|
||||||
size_t n)
|
const volatile void *restrict src, size_t n)
|
||||||
{
|
{
|
||||||
volatile char *d = dest;
|
volatile char *d = dest;
|
||||||
volatile const char *s = src;
|
volatile const char *s = src;
|
||||||
|
|
17
lib/printf.c
17
lib/printf.c
|
@ -286,10 +286,9 @@ static int printf_lltoa(char *buf, options_t *opts, bool is_neg,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// print zeros if needed
|
// print zeros if needed
|
||||||
if (opts->width_set && len < opts->width && opts->zero) {
|
if (opts->width_set && len < opts->width && opts->zero) {
|
||||||
while(len++ < opts->width)
|
while (len++ < opts->width)
|
||||||
*(buf++) = '0';
|
*(buf++) = '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,7 +350,8 @@ static void handle_char_specifier(context_t *ctx, data_t c)
|
||||||
printf_putc(ctx, c.c);
|
printf_putc(ctx, c.c);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_string_specifier(context_t *ctx, options_t *opts, data_t data)
|
static void handle_string_specifier(context_t *ctx, options_t *opts,
|
||||||
|
data_t data)
|
||||||
{
|
{
|
||||||
char *str = data.str;
|
char *str = data.str;
|
||||||
int str_len = 0;
|
int str_len = 0;
|
||||||
|
@ -460,7 +460,7 @@ static void do_printf(context_t *ctx, va_list args)
|
||||||
// end int
|
// end int
|
||||||
case 's':
|
case 's':
|
||||||
// read string
|
// read string
|
||||||
data.str = va_arg(args, void*);
|
data.str = va_arg(args, void *);
|
||||||
break;
|
break;
|
||||||
// end string
|
// end string
|
||||||
case 'c':
|
case 'c':
|
||||||
|
@ -585,15 +585,18 @@ void vfprintf(FILE *stream, const char *format, va_list args)
|
||||||
do_printf(&ctx, args);
|
do_printf(&ctx, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void putc(char c) {
|
void putc(char c)
|
||||||
|
{
|
||||||
fputc(stdout, c);
|
fputc(stdout, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
void puts(const char *str) {
|
void puts(const char *str)
|
||||||
|
{
|
||||||
fputs(stdout, str);
|
fputs(stdout, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fputs(FILE *stream, const char *s) {
|
void fputs(FILE *stream, const char *s)
|
||||||
|
{
|
||||||
while (*s)
|
while (*s)
|
||||||
fputc(stream, *s++);
|
fputc(stream, *s++);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue