blob: 917c07e1d0b96112cef76152b3dcce6c77a460d6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef unsigned long long u64;
#ifndef asm
#define asm __asm__ volatile
#endif
struct __attribute__((packed)) multiboot_info
{
/* Multiboot info version number */
u32 flags;
/* Available memory from BIOS */
u32 mem_lower;
u32 mem_upper;
/* "root" partition */
u32 boot_device;
/* Kernel command line */
u32 cmdline;
/* Boot-Module list */
u32 mods_count;
u32 mods_addr;
// union
// {
// multiboot_aout_symbol_table_t aout_sym;
// multiboot_elf_section_header_table_t elf_sec;
// } u;
u32 unused_1;
u32 unused_2;
u32 unused_3;
u32 unused_4;
/* Memory Mapping buffer */
u32 mmap_length;
u32 mmap_addr;
/* Drive Info buffer */
u32 drives_length;
u32 drives_addr;
/* ROM configuration table */
u32 config_table;
/* Boot Loader Name */
u32 boot_loader_name;
/* APM table */
u32 apm_table;
/* Video */
u32 vbe_control_info;
u32 vbe_mode_info;
u16 vbe_mode;
u16 vbe_interface_seg;
u16 vbe_interface_off;
u16 vbe_interface_len;
u64 framebuffer_addr;
u32 framebuffer_pitch;
u32 framebuffer_width;
u32 framebuffer_height;
u8 framebuffer_bpp;
#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0
#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1
#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2
u8 framebuffer_type;
union
{
struct
{
u32 framebuffer_palette_addr;
u16 framebuffer_palette_num_colors;
};
struct
{
u8 framebuffer_red_field_position;
u8 framebuffer_red_mask_size;
u8 framebuffer_green_field_position;
u8 framebuffer_green_mask_size;
u8 framebuffer_blue_field_position;
u8 framebuffer_blue_mask_size;
};
};
};
typedef struct multiboot_info multiboot_info_t;
u8 inportb(u16 port) {
u8 r;
asm("inb %1, %0" : "=a" (r) : "dN" (port));
return r;
}
void outportb(u16 port, u8 data) {
asm("outb %1, %0" : : "dN" (port), "a" (data));
}
// TODO: Why won't this work? void macaroni_panic(char* msg) {
void macaroni_panic() {
// we'll do something with msg later.
while(true){ asm("nop\n\t"); }
}
void macaroni_assert(bool condition) {
if (condition) {
return;
}
macaroni_panic();
}
void cmain(void) {
u32 magic_response = 0x1;
multiboot_info_t* p_multiboot_info;
asm("\t movl %%eax,%0" : "=r"(magic_response));
asm("\t movl %%ebx,%0" : "=r"(p_multiboot_info));
void *fb = (void *) (unsigned long) p_multiboot_info->framebuffer_addr;
u8* pixel = fb;
for (int i = 0; i < 10000; i++) {
*(pixel + i) = i * 2;
}
macaroni_assert(magic_response == 0x2BADB002);
//asm("int $0x13");
}
|