Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
I've just went from pm to lm, and now i'm fixing my print char function, and i found out that the get cursor function returns the cursor position but 3 less, the get cursor pos was working perfectly in pm.
*((volatile char *) 0xB80A0) = 'O'; // If the get_cursor_offset() works right, 'H' should cover the 'O'
*((volatile char *) 0xB80A0 + get_cursor_offset()) = 'H';
Output:
I think i'm just doing something stupid but idk what, can someone help me look?
thx
Seems like you have linker issues. Fix those. You may wish to consult linker options such as "-z max-page-size=0x1000". Otherwise we will need to see your linker script to know where the problem is. BTW, my linker script looks like this:
ENTRY(_kstart)
OUTPUT_FORMAT("elf64-x86-64")
PHDRS {
headers PT_PHDR PHDRS;
text PT_LOAD FILEHDR PHDRS;
data PT_LOAD;
}
SECTIONS {
. = 0xffffffff80000000 + SIZEOF_HEADERS;
.text : {
*(.text)
*(.text.*)
} :text
.rodata : {
*(.rodata)
*(.rodata.*)
}
/* Normally, the overlap between text and data section is handled by having
* two different pages for the last bits of text and the first bits of data.
* That way, if the last bits of text are overwritten, it won't affect the
* text that is actually used. Unfortunately, for the kernel this is not
* possible. The whole file is loaded into memory en bloc, so the same page
* would be mapped twice. Therefore, a write access to the writable page
* would end up being visible in the non-writable side of things. Therefore,
* we must actually page-align here.
*/
. = ALIGN(2M);
.data : {
*(.data)
*(.data.*)
} :data
.bss : {
*(.bss)
*(COMMON)
*(.bss.*)
}
}
cyao1234 wrote:I think i'm just doing something stupid but idk what
You never switch to a 64-bit code segment, so the CPU is still in 32-bit compatibility mode. The two modes are similar enough that your code still runs, but it gives you incorrect results.
Octocontrabass wrote:You never switch to a 64-bit code segment, so the CPU is still in 32-bit compatibility mode. The two modes are similar enough that your code still runs, but it gives you incorrect results.
So I would need to do a `jmp CODE_SEG:a_lable_at_almost_the_same_place` after the lgdt right?
And do I need to clear the 32 bit mode bit in cr0?
cyao1234 wrote:So I would need to do a `jmp CODE_SEG:a_lable_at_almost_the_same_place` after the lgdt right?
You need to perform the JMP after you've enabled long mode by setting CR4.PAE, EFER.LME, and CR0.PG. You don't have a 64-bit code segment in your GDT, so you will need to add one.
cyao1234 wrote:And do I need to clear the 32 bit mode bit in cr0?