Browse Source

got rid of kernel/lib/common.h

master
Mathieu Serandour 9 months ago
parent
commit
fd5f6947b4
  1. 1
      kernel/acpi/acpi.c
  2. 33
      kernel/acpi/acpitables.h
  3. 6
      kernel/acpi/power.c
  4. 3
      kernel/drivers/terminal/video.c
  5. 7
      kernel/int/idt.c
  6. 3
      kernel/int/idt.h
  7. 39
      kernel/lib/common.h
  8. 15
      kernel/lib/registers.h
  9. 49
      kernel/memory/gdt.c

1
kernel/acpi/acpi.c

@ -6,7 +6,6 @@
#include "acpi.h"
#include "acpitables.h"
#include "../lib/common.h"
#include "../lib/assert.h"
#include "../lib/dump.h"
#include "../lib/sprintf.h"

33
kernel/acpi/acpitables.h

@ -3,7 +3,6 @@
#include <stddef.h>
#include <stdint.h>
#include "../lib/common.h"
#include "../drivers/pcie/scan.h"
struct RSDPDescriptor {
@ -12,7 +11,7 @@ struct RSDPDescriptor {
uint8_t OEMID[6];
uint8_t revision;
uint32_t rsdtAddress;
} __packed;
} __attribute__((packed));
struct RSDPDescriptor20 {
struct RSDPDescriptor firstPart;
@ -21,13 +20,13 @@ struct RSDPDescriptor20 {
uint64_t xsdtAddress;
uint8_t extendedChecksum;
uint8_t reserved[3];
} __packed;
} __attribute__((packed));
union acpi_signature {
char arg[4];
uint32_t raw;
} __packed;
} __attribute__((packed));
#define MADT_SIGNATURE 0x43495041
@ -51,7 +50,7 @@ struct ACPISDTHeader {
uint32_t OEMrevision;
uint32_t creatorID;
uint32_t creator_revision;
} __packed;
} __attribute__((packed));
// end
@ -59,19 +58,19 @@ struct ACPISDTHeader {
struct XSDT {
struct ACPISDTHeader header;
struct ACPISDTHeader* entries[];
} __packed;
} __attribute__((packed));
struct RSDT {
struct ACPISDTHeader header;
uint32_t entries[];
} __packed;
} __attribute__((packed));
struct MADTEntryHeader {
uint8_t type;
uint8_t length;
} __packed;
} __attribute__((packed));
struct MADT_lapic_entry {
@ -79,7 +78,7 @@ struct MADT_lapic_entry {
uint8_t proc_apic_ID;
uint8_t procID;
uint32_t flags; // bit0: enabled
} __packed;
} __attribute__((packed));
struct MADT_ioapic_entry {
@ -88,7 +87,7 @@ struct MADT_ioapic_entry {
uint8_t reserved;
uint32_t address;
uint32_t global_system_interrupt_base;
} __packed;
} __attribute__((packed));
struct MADT_ioapic_interrupt_source_override_entry {
@ -97,7 +96,7 @@ struct MADT_ioapic_interrupt_source_override_entry {
uint8_t irq_source;
uint32_t global_system_interrupt;
uint16_t flags;
} __packed;
} __attribute__((packed));
struct MADT_IO_NMI_entry {
@ -105,7 +104,7 @@ struct MADT_IO_NMI_entry {
uint8_t source;
uint8_t reserved;
uint32_t global_system_interrupt;
} __packed;
} __attribute__((packed));
struct MADT_LOCAL_NMI_entry {
@ -113,7 +112,7 @@ struct MADT_LOCAL_NMI_entry {
uint8_t procID;
uint16_t flags;
uint8_t lint; // 0 or 1
} __packed;
} __attribute__((packed));
struct MADT_LAPIC_address_override_entry {
@ -121,7 +120,7 @@ struct MADT_LAPIC_address_override_entry {
uint8_t procID;
uint8_t flags;
uint32_t lint; // 0 or 1
} __packed;
} __attribute__((packed));
struct MADT_lapicx2_entry {
@ -129,7 +128,7 @@ struct MADT_lapicx2_entry {
uint8_t proc_lapic_ID;
uint64_t flags; // bit0: enabled
uint32_t acpi_id;
} __packed;
} __attribute__((packed));
struct MADT {
@ -137,7 +136,7 @@ struct MADT {
uint32_t lAPIC_address;
uint32_t flags;
struct MADTEntryHeader* entries[];
} __packed;
} __attribute__((packed));
static_assert(
@ -148,7 +147,7 @@ struct PCIETable {
uint64_t reserved0;
struct PCIE_busgroup segments[];
} __packed;
} __attribute__((packed));
// MADT entry types

6
kernel/acpi/power.c

@ -34,8 +34,12 @@ void reboot(void) {
unsigned still_allocated = heap_get_n_allocation();
if(still_allocated) {
log_warn("%d FREE BLOCKS AT SHUTDOWN", still_allocated);
log_warn("%d FREE BLOCKS AT SHUTDOWN:", still_allocated);
#ifndef NDEBUG
heap_defragment();
heap_print();
panic("oui");
#endif
}
//panic("non");
//_cli();

3
kernel/drivers/terminal/video.c

@ -7,7 +7,6 @@
#include "../../lib/string.h"
#include "../../lib/logging.h"
#include "../../lib/common.h"
#include "../../lib/assert.h"
#include "../../lib/panic.h"
@ -280,7 +279,7 @@ struct BMPFileHeader {
int32_t h; // BMP height in pixels
uint16_t one; // should be eq to 1
uint16_t bpp; // bits per pixel
} __packed;
} __attribute__((packed));
static bool check_BMP_header(const struct BMPFileHeader* header) {

7
kernel/int/idt.c

@ -1,7 +1,6 @@
#include <stddef.h>
#include <stdint.h>
#include "../lib/common.h"
#include "idt.h"
@ -9,7 +8,7 @@
typedef struct {
uint16_t size;
const void* offset;
} __packed IDTD;
} __attribute__((packed)) IDTD;
typedef struct {
@ -17,7 +16,7 @@ typedef struct {
uint8_t z : 1;
uint8_t dpl : 2;
uint8_t p : 1;
} __packed type_attr_t;
} __attribute__((packed)) type_attr_t;
static_assert(sizeof(type_attr_t) == 1);
@ -33,7 +32,7 @@ typedef struct {
uint16_t offset_2; // offset bits 16..31
uint32_t offset_3; // offset bits 32..63
uint32_t zero; // reserved
} __packed IDTE;
} __attribute__((packed)) IDTE;
static_assert_equals(sizeof(IDTE), 16);

3
kernel/int/idt.h

@ -4,7 +4,6 @@
#include <stdint.h>
#include <stddef.h>
#include "../lib/assert.h"
#include "../lib/common.h"
#define ATTR_64_GATE 0b1110
#define ATTR_64_TRAP 0b1110
@ -17,7 +16,7 @@ struct IFrame {
uint64_t RFLAGS;
uint64_t RSP;
uint64_t SS;
} __packed;
} __attribute__((packed));
static_assert(sizeof(struct IFrame) == 40);

39
kernel/lib/common.h

@ -1,39 +0,0 @@
#ifndef COMMON_H
#define COMMON_H
#include <stdint.h>
typedef uint16_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;
#define __packed __attribute__((packed))
#define __align(N) __attribute__ ((aligned(N)))
#define __noreturn __attribute__((noreturn))
#ifndef NDEBUG
#define PDEBUG printf("'%s':%d - %s()\n", __FILE__, __LINE__,__func__);
#endif
inline uint64_t allign16(uint64_t p) {
uint64_t offset = p & 0x0f;
if(offset)
p = (p+16) & (~0xf);
return p;
}
inline void* mallign16(void* ptr) {
return (void*)allign16((uint64_t)ptr);
}
// 8 = ring 0 && id 1
#endif //COMMON_H

15
kernel/lib/registers.h

@ -1,14 +1,13 @@
#ifndef REGISTERS_H
#define REGISTERS_H
#include "common.h"
u16 _cs(void);
u16 _ds(void);
u16 _ss(void);
u16 _es(void);
u16 _fs(void);
u16 _gs(void);
uint16_t _cs(void);
uint16_t _ds(void);
uint16_t _ss(void);
uint16_t _es(void);
uint16_t _fs(void);
uint16_t _gs(void);
uint64_t get_rflags(void);
uint64_t get_cr0(void);

49
kernel/memory/gdt.c

@ -1,5 +1,4 @@
#include "gdt.h"
#include "../lib/common.h"
#include "../lib/sprintf.h"
#include "../lib/assert.h"
@ -24,44 +23,44 @@ static_assert_equals(sizeof(struct TSS), 104);
const struct TSS tss = {0, {(uint64_t)kernel_stack,0,0}, 0, {0}, 0,0,sizeof(struct TSS)};
struct GDTentry {
u16 limit1; // x86_64: ignrored
u16 base1; // x86_64: ignrored
u8 base2; // x86_64: ignrored
uint16_t limit1; // x86_64: ignrored
uint16_t base1; // x86_64: ignrored
uint8_t base2; // x86_64: ignrored
// access byte
//union {
// struct {
u8 accessed: 1; // should be 0 (the CPU sets it to 1 when accessed)
u8 read_write: 1; // for code selectors: readable bit
uint8_t accessed: 1; // should be 0 (the CPU sets it to 1 when accessed)
uint8_t read_write: 1; // for code selectors: readable bit
// for data selectors: writable bit
u8 dir_conforming: 1; // for code selectors: should be 0 in longmode
uint8_t dir_conforming: 1; // for code selectors: should be 0 in longmode
// (code can be executed by lower privilege level)
// for data selectors: 0: segment grows upward, downward otherwise
u8 executable: 1; // for code selectors
u8 descriptor: 1; // should be 1 for data/code segments, 0 for system (tss)
u8 ring: 2; // privilege ring
u8 present: 1; // should always be 1
//} __packed;
// u8 access_byte;
//} __packed;
uint8_t executable: 1; // for code selectors
uint8_t descriptor: 1; // should be 1 for data/code segments, 0 for system (tss)
uint8_t ring: 2; // privilege ring
uint8_t present: 1; // should always be 1
//} __attribute__((packed));
// uint8_t access_byte;
//} __attribute__((packed));
u8 limit2: 4; // x86_64: ignrored
uint8_t limit2: 4; // x86_64: ignrored
//union {
//struct {
u8 nullbits: 1; // must be 0
u8 longcode: 1; // x86_64: 1
u8 size: 1; // x86_64: must be 0
u8 granularity: 1; // x86_64: ignrored
//} __packed;
// u8 flags: 4;
//} __packed;
u8 base3; // x86_64: ignrored
} __packed;
uint8_t nullbits: 1; // must be 0
uint8_t longcode: 1; // x86_64: 1
uint8_t size: 1; // x86_64: must be 0
uint8_t granularity: 1; // x86_64: ignrored
//} __attribute__((packed));
// uint8_t flags: 4;
//} __attribute__((packed));
uint8_t base3; // x86_64: ignrored
} __attribute__((packed));
struct GDTDescriptor {
uint16_t size; // size of the GDT - 1
uint64_t offset; // address of the table
} __packed;
} __attribute__((packed));

Loading…
Cancel
Save