summaryrefslogtreecommitdiffhomepage
path: root/src/loader/inc
diff options
context:
space:
mode:
Diffstat (limited to 'src/loader/inc')
-rw-r--r--src/loader/inc/assert.h17
-rw-r--r--src/loader/inc/ide.h73
-rw-r--r--src/loader/inc/lib.h3
-rw-r--r--src/loader/inc/log.h2
4 files changed, 95 insertions, 0 deletions
diff --git a/src/loader/inc/assert.h b/src/loader/inc/assert.h
new file mode 100644
index 0000000..65db119
--- /dev/null
+++ b/src/loader/inc/assert.h
@@ -0,0 +1,17 @@
+// MIT License, Copyright (c) 2021 Marvin Borner
+
+#ifndef ASSERT_H
+#define ASSERT_H
+
+#include <log.h>
+#define assert(exp) \
+ { \
+ if (!(exp)) { \
+ log("%s:%d: %s: Kernel assertion '%s' failed\n", __FILE__, __LINE__, \
+ __func__, #exp); \
+ while (1) \
+ __asm__ volatile("cli\nhlt"); \
+ } \
+ }
+
+#endif
diff --git a/src/loader/inc/ide.h b/src/loader/inc/ide.h
new file mode 100644
index 0000000..24b4eb1
--- /dev/null
+++ b/src/loader/inc/ide.h
@@ -0,0 +1,73 @@
+// MIT License, Copyright (c) 2021 Marvin Borner
+
+#ifndef IDE_H
+#define IDE_H
+
+#define BLOCK_SIZE 1024
+#define BLOCK_COUNT 256 // BLOCK_SIZE / sizeof(u32)
+#define SECTOR_SIZE 512
+#define SECTOR_COUNT (BLOCK_SIZE / SECTOR_SIZE)
+
+#define ATA_PRIMARY_IO 0x1f0
+#define ATA_SECONDARY_IO 0x170
+
+// From spec
+#define ATA_PRIMARY 0x00
+#define ATA_SECONDARY 0x01
+#define ATA_READ 0x00
+#define ATA_WRITE 0x013
+#define ATA_MASTER 0x00
+#define ATA_SLAVE 0x01
+#define ATA_SR_BSY 0x80
+#define ATA_SR_DRDY 0x40
+#define ATA_SR_DF 0x20
+#define ATA_SR_DSC 0x10
+#define ATA_SR_DRQ 0x08
+#define ATA_SR_CORR 0x04
+#define ATA_SR_IDX 0x02
+#define ATA_SR_ERR 0x01
+#define ATA_REG_DATA 0x00
+#define ATA_REG_ERROR 0x01
+#define ATA_REG_FEATURES 0x01
+#define ATA_REG_SECCOUNT0 0x02
+#define ATA_REG_LBA0 0x03
+#define ATA_REG_LBA1 0x04
+#define ATA_REG_LBA2 0x05
+#define ATA_REG_HDDEVSEL 0x06
+#define ATA_REG_COMMAND 0x07
+#define ATA_REG_STATUS 0x07
+#define ATA_REG_SECCOUNT1 0x08
+#define ATA_REG_LBA3 0x09
+#define ATA_REG_LBA4 0x0a
+#define ATA_REG_LBA5 0x0b
+#define ATA_REG_CONTROL 0x0c
+#define ATA_REG_ALTSTATUS 0x0c
+#define ATA_REG_DEVADDRESS 0x0d
+#define ATA_CMD_READ_PIO 0x20
+#define ATA_CMD_READ_PIO_EXT 0x24
+#define ATA_CMD_READ_DMA 0xc8
+#define ATA_CMD_READ_DMA_EXT 0x25
+#define ATA_CMD_WRITE_PIO 0x30
+#define ATA_CMD_WRITE_PIO_EXT 0x34
+#define ATA_CMD_WRITE_DMA 0xca
+#define ATA_CMD_WRITE_DMA_EXT 0x35
+#define ATA_CMD_CACHE_FLUSH 0xe7
+#define ATA_CMD_CACHE_FLUSH_EXT 0xea
+#define ATA_CMD_PACKET 0xa0
+#define ATA_CMD_IDENTIFY_PACKET 0xa1
+#define ATA_CMD_IDENTIFY 0xec
+#define ATA_IDENT_DEVICETYPE 0
+#define ATA_IDENT_CYLINDERS 2
+#define ATA_IDENT_HEADS 6
+#define ATA_IDENT_SECTORS 12
+#define ATA_IDENT_SERIAL 20
+#define ATA_IDENT_MODEL 54
+#define ATA_IDENT_CAPABILITIES 98
+#define ATA_IDENT_FIELDVALID 106
+#define ATA_IDENT_MAX_LBA 120
+#define ATA_IDENT_COMMANDSETS 164
+#define ATA_IDENT_MAX_LBA_EXT 200
+
+void ata_install(void);
+
+#endif
diff --git a/src/loader/inc/lib.h b/src/loader/inc/lib.h
index 997db67..d5984dd 100644
--- a/src/loader/inc/lib.h
+++ b/src/loader/inc/lib.h
@@ -9,6 +9,9 @@ u32 strlen(const char *str);
u32 strnlen(const char *s, u32 max);
u32 strlcpy(char *dst, const char *src, u32 size);
+void *memcpy(void *dest, const void *src, u32 n);
+void *memset(void *dest, u32 val, u32 n);
+
int itoa(s32 value, char *buffer, u32 base);
#endif
diff --git a/src/loader/inc/log.h b/src/loader/inc/log.h
index 2d65a76..6fad366 100644
--- a/src/loader/inc/log.h
+++ b/src/loader/inc/log.h
@@ -6,6 +6,8 @@
void serial_install(void);
void serial_print(const char *data);
+void vga_clear(void);
+
void log(const char *format, ...);
#endif