This is the code (64-bit kernel code started from my own bootloader in asm):
Code: Select all
unsigned long long dx = 0xdeadcafebabebeaf;
void printhex(unsigned long long v);
void main(void)
{
printhex((unsigned long long)&dx);
__asm__("hlt");
}
void printhex(unsigned long long v)
{
char buf[16];
for (int i = 0; i < 16; ++i)
{
int r = v & 0xf;
if (r < 10)
buf[15 - i] = '0' + r;
else
buf[15 - i] = 'A' + r - 10;
v >>= 4;
}
char *video = (char*)0xB8000;
bool showzeroes = false;
for (int i = 0; i < 16; ++i)
{
if (showzeroes || buf[i] != '0')
{
*video++ = buf[i];
*video++ = 0x07;
showzeroes = true;
}
}
}
Code: Select all
ENTRY(_start);
SECTIONS {
_start = 0x1a00 ;
.text : ALIGN(0x1a00) {
_TEXT_START_ = .;
*(.text)
_TEXT_END_ = .;
}
.data : ALIGN(0x1a00) {
_DATA_START_ = .;
*(.data)
_DATA_END_ = .;
}
.bss : ALIGN(0x1a00) {
_BSS_START_ = .;
*(.bss)
_BSS_END_ = .;
}
}
In my opinion, the output of this on screen should be something like: 3400
But the output is: DEADCAFEBABEBEAF !!! which is the value in the variable...
I would expect that to be the result when the code would be:
Code: Select all
printhex(dx);
This is so weird... Am I doing something so completely wrong here?
Must be something stupid of course, but I can't see it...
I'm so confused!