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
GCC kernal
Re: GCC kernal
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.Bipman wrote: I'm not even sure this is possible so maybe I should stick to assembler?
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
Re: GCC kernal
Hi
The C I understand, it's the the other stuff in my description above I don't know how to do.
Bipman
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
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.Bipman wrote: Load RSP with the stack address
Code: Select all
mov rsp, stack_address // x64 code
If you are talking about the kernel itself, yes you can move it. Higher_Half_KernelBipman wrote: Compile C code for a particular memory address
You can use Paging and map your addresses however you like. You have around 256TiB of virtual addresses available when using x64.Bipman wrote: Use a specific data address for all data i.e. the 64 bit data range of the x64 pae tables
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
Re: GCC kernal
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
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
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.
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
Re: GCC kernal
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.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
Learn to read.
Re: GCC kernal
Thanks, I'll take a look.