#include #include static void puts(const char *c); static void sio_putc(char c); extern char _start[]; extern char _end[]; extern uint64_t pdpt[]; extern uint64_t ptd[]; extern uint64_t ptp[]; int main(void) { uint32_t start, end, n; uint32_t i, r; puts("hello from protected mode...\r\n"); start = (uint32_t)_start & ~(4096 - 1); end = ((uint32_t)_end + 4096) & ~(4096 - 1); n = (end - start) / 4096; for (i = 0; i < 4; i++) pdpt[i] = ((uint32_t)ptd + (i * 4096)) | 1; ptd[0] = (uint32_t)ptp | 3; for (i = 0; i < n; i++) { ptp[((start >> 12) & ((1 << 9) - 1)) + i] = (start + (i * 4096)) | 3; } asm volatile( " movl %1, %%cr3 ; " " movl %%cr4, %0 ; " " orl %2, %0 ; " " movl %0, %%cr4 ; " " movl %%cr0, %0 ; " " orl %3, %0 ; " " movl %0, %%cr0 ; " " jmp 1f ; " " 1: " : "=r" (r) : "r" (pdpt), "i" (1U << 5), "i" (1U << 31)); puts("hello from pae...\r\n"); } static void puts(const char *s) { while (*s != '\0') sio_putc(*s++); } static void sio_putc(char c) { while ((inb(0x3f8 + 5) & 0x20) == 0) ; outb(0x3f8, c); }