At the moment I have a very simple boot loader that follows the example of x86 bare metal (https://github.com/cirosantilli/x86-bare-metal-examples) and OSDev's Bare Bones to load the rest of the code, enter protected mode, and calls the C function that is the kernel entry point. I also have a few functions that can write using VGA text mode.
This is the "OS" code:
Code: Select all
#include "icos.h"
#include "vga_text.h"
unsigned d1 = 0x57575757; // initialized and put in .data section
unsigned not_initialized; // uninitialized and put in .bss section
void bss_test() {
not_initialized = 0x11223344;
// Set up the VGA output
vga_text_section_t head, body;
vgat_initialize_head_body(&head, &body, 5);
//print the addresses and values of the global data.
vgat_write_unsigned_hex(&body, (unsigned)&d1, " <= &d1\n");
vgat_write_unsigned_hex(&body, (unsigned)¬_initialized, " <= &ni\n");
vgat_write_unsigned_hex(&body, not_initialized, " <= Original ni value\n");
// Take the address of not_initialized, discard all but the low 16 bits,
// then use that new value as a pointer.
unsigned* pni = ¬_initialized;
unsigned* pni2 = (unsigned*) ((unsigned) pni &0xffff);
vgat_write_unsigned_hex(&body, (unsigned) pni2, " <='fake' pointer\n");
*pni2 = 0x55667788;
// Modifying the "fake"/"truncated" pointer modifies not_initialized
vgat_write_unsigned_hex(&body, not_initialized, " <= updated ni value\n");
}
Code: Select all
0x9814 <= &d1
0x10a204 <= &ni
0x11223344 <= Original ni value
0xa204 <= 'fake' pointer
0x55667788 <= updated ni value