Page 1 of 1
GCC kernal
Posted: Sun Apr 23, 2017 10:08 am
by Bipman
Hi all
I've now written the bootloader and start kernel in X86 assembler,switched to 64 bit long mode and now want to switch to C for convenience. The tutorials for this all seem to be rather complex for what I want to do. I need to :-
Compile C code for a particular memory address
Load RSP with the stack address
Use a specific data address for all data i.e. the 64 bit data range of the x64 pae tables
I'm not even sure this is possible so maybe I should stick to assembler?
Bipman
Re: GCC kernal
Posted: Sun Apr 23, 2017 10:15 am
by Octacone
Bipman wrote:
I'm not even sure this is possible so maybe I should stick to assembler?
It is quite possible, most of the kernels out there are written in C/C++. C is really easy to learn, shouldn't take you too much to learn it.
Re: GCC kernal
Posted: Sun Apr 23, 2017 10:16 am
by Bipman
Hi
The C I understand, it's the the other stuff in my description above I don't know how to do.
Bipman
Re: GCC kernal
Posted: Sun Apr 23, 2017 10:28 am
by Octacone
Bipman wrote:
Load RSP with the stack address
You can mix C and Assembly. All doe some things are better left "pure" (e.g interrupt handler). You can do this in Assembly before jumping to your C code.
Code: Select all
mov rsp, stack_address // x64 code
Bipman wrote:
Compile C code for a particular memory address
If you are talking about the kernel itself, yes you can move it.
Higher_Half_Kernel
Bipman wrote:
Use a specific data address for all data i.e. the 64 bit data range of the x64 pae tables
You can use
Paging and map your addresses however you like. You have around 256TiB of virtual addresses available when using x64.
Re: GCC kernal
Posted: Sun Apr 23, 2017 11:37 am
by Bipman
Ah yes. Thing is, what i want to do is an org in C as in :-
Org 0x1000000
Would assemble the code to fit this address and all I would have to do is read it from HD into that address and jump to it and I don't know how to do this in C. The data 'page' is set from 1GB-4GB so not sure how to limit the C code to this range for data. There won't be any libraries either so I will have to write these anyway so not sure if C is going to help that much.
Bipman
Re: GCC kernal
Posted: Sun Apr 23, 2017 12:34 pm
by Korona
Use the wiki to look up how linkers work. Also research how the GCC, LD, AS toolchain works. There is plenty information on these topics on the web.
Re: GCC kernal
Posted: Sun Apr 23, 2017 12:35 pm
by Bipman
Will do ta.
Re: GCC kernal
Posted: Mon Apr 24, 2017 3:56 am
by dozniak
Bipman wrote:Ah yes. Thing is, what i want to do is an org in C as in :-
Org 0x1000000
Would assemble the code to fit this address and all I would have to do is read it from HD into that address and jump to it and I don't know how to do this in C. The data 'page' is set from 1GB-4GB so not sure how to limit the C code to this range for data. There won't be any libraries either so I will have to write these anyway so not sure if C is going to help that much.
Bipman
For C code this is done via a linker script. See "LD linker script" in any of the hobby OSes on github and on osdev wiki - there are plenty examples.
Re: GCC kernal
Posted: Mon Apr 24, 2017 7:54 am
by Bipman
Thanks, I'll take a look.