Confused Noob - why is the value not being set?
Posted: Thu Dec 20, 2012 3:39 pm
I haven't really programmed much in C for some time, so I've been using the JamesM's tutorial to try and play with a new kernel. I have changed it to be a 64 bit binary and most things seem to work, except global variables don't seem to be able to retain their value. The simplest test code I came up with is.
The problem I have is that cursor_x1 always comes out as 0. However if I make it a local variable, it works OK. I'm really confused as to what I'm doing and would appreciate it if anyone can point to what I'm doing wrong.
I'm compiling with Eclipse and it uses...
gcc -I/usr/src/linux-headers-3.2.0-33 -O0 -g3 -Wall -c -fmessage-length=0 -ffreestanding -m64 -nostdlib -mno-red-zone -Map=out.map -MMD -MP -MF"srcOriginal/main.d" -MT"srcOriginal/main.d" -o "srcOriginal/main.o" "../srcOriginal/
The link script is
If there is anything else that would be useful, I can easily add it.
Thanks!
Code: Select all
// main.c -- Defines the C-code kernel entry point, calls initialisation routines.
// Made for JamesM's tutorials <www.jamesmolloy.co.uk>
#include "monitor.h"
#include "multiboot.h"
u8int cursor_x1 = 1;
void temp_write(u16int *videoOut, u32int n) {
s32int tmp;
char noZeroes = 1;
int i;
for (i = 28; i > 0; i -= 4)
{
tmp = (n >> i) & 0xF;
if (!tmp && noZeroes)
{
continue;
}
if (tmp >= 0xA)
{
noZeroes = 0;
*videoOut++ = (tmp-0xA+'a') + (0x1e<<8);
}
else
{
noZeroes = 0;
*videoOut++ = (tmp+'0') + (0x1e<<8);
}
}
tmp = n & 0xF;
if (tmp >= 0xA)
{
*videoOut++ = (tmp-0xA+'a') + (0x1e<<8);
}
else
{
*videoOut++ = (tmp+'0') + (0x1e<<8);
}
}
int main(struct multiboot_info *mboot_ptr)
{
temp_write((u16int *)0xB8000+400, cursor_x1++);
temp_write((u16int *)0xB8000+420, cursor_x1++);
return 0;
}
I'm compiling with Eclipse and it uses...
gcc -I/usr/src/linux-headers-3.2.0-33 -O0 -g3 -Wall -c -fmessage-length=0 -ffreestanding -m64 -nostdlib -mno-red-zone -Map=out.map -MMD -MP -MF"srcOriginal/main.d" -MT"srcOriginal/main.d" -o "srcOriginal/main.o" "../srcOriginal/
The link script is
Code: Select all
ENTRY(start)
SECTIONS
{
.text 0x100000 :
{
code = .; _code = .; __code = .;
*(.text)
. = ALIGN(4096);
}
.data :
{
data = .; _data = .; __data = .;
*(.data)
*(.rodata)
. = ALIGN(4096);
}
.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .; _end = .; __end = .;
}
Thanks!