2026-02-18 00:57:22 +01:00
|
|
|
//#include <stdint.h>
|
|
|
|
|
|
|
|
|
|
typedef unsigned char uint8_t;
|
|
|
|
|
typedef unsigned short uint16_t;
|
|
|
|
|
typedef unsigned int uint32_t;
|
2026-02-17 19:44:29 +01:00
|
|
|
|
|
|
|
|
#define COM1_BASE_PORT 0x3F8
|
|
|
|
|
|
|
|
|
|
static inline uint8_t
|
|
|
|
|
inb(uint16_t port)
|
|
|
|
|
{
|
|
|
|
|
uint8_t data;
|
|
|
|
|
__asm__ ("inb %%dx, %%al" : "=a"(data) : "d"(port));
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
outb(uint16_t port, uint8_t data)
|
|
|
|
|
{
|
|
|
|
|
__asm__ ("outb %%al, %%dx" :: "a"(data), "d"(port));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void serial_write_char(char c)
|
|
|
|
|
{
|
|
|
|
|
while (1) {
|
|
|
|
|
int line_status = inb(COM1_BASE_PORT + 5);
|
|
|
|
|
if (line_status & 0x20) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
outb(COM1_BASE_PORT, c);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-18 00:39:02 +01:00
|
|
|
void serial_write(const char *msg)
|
|
|
|
|
{
|
|
|
|
|
for (const char *c = msg; *c; c++) {
|
|
|
|
|
outb(0xE9, *c);
|
|
|
|
|
//serial_write_char(*c);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-18 00:57:22 +01:00
|
|
|
extern void bios_write(const char *msg, unsigned length);
|
2026-02-18 01:27:49 +01:00
|
|
|
extern void *bios_getmap(void *buffer);
|
|
|
|
|
|
|
|
|
|
unsigned char memmap[24 * 128];
|
2026-02-18 00:39:02 +01:00
|
|
|
|
2026-02-17 19:44:29 +01:00
|
|
|
void
|
|
|
|
|
main()
|
|
|
|
|
{
|
2026-02-18 00:57:22 +01:00
|
|
|
bios_write("init\r\n", 6);
|
2026-02-18 01:27:49 +01:00
|
|
|
void *end = bios_getmap(memmap);
|
2026-02-18 00:57:22 +01:00
|
|
|
bios_write("karlos\r\n", 8);
|
2026-02-18 01:27:49 +01:00
|
|
|
for (int i = 0; ; i++) {
|
|
|
|
|
unsigned char *entry = memmap + 24 * i;
|
|
|
|
|
if (entry >= end) break;
|
|
|
|
|
unsigned char type = *(entry + 16);
|
|
|
|
|
char c = type < 10 ? type + '0' : '?';
|
|
|
|
|
bios_write(&c, 1);
|
|
|
|
|
}
|
2026-02-17 19:44:29 +01:00
|
|
|
for (;;) {
|
2026-02-18 00:57:22 +01:00
|
|
|
__asm__ ("hlt" :);
|
2026-02-17 19:44:29 +01:00
|
|
|
}
|
|
|
|
|
}
|