GCC kernal

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.
Post Reply
Bipman
Member
Member
Posts: 40
Joined: Wed Mar 15, 2017 9:22 am

GCC kernal

Post 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
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: GCC kernal

Post 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.
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
Bipman
Member
Member
Posts: 40
Joined: Wed Mar 15, 2017 9:22 am

Re: GCC kernal

Post 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
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: GCC kernal

Post 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.
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
Bipman
Member
Member
Posts: 40
Joined: Wed Mar 15, 2017 9:22 am

Re: GCC kernal

Post 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
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Re: GCC kernal

Post 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.
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].
Bipman
Member
Member
Posts: 40
Joined: Wed Mar 15, 2017 9:22 am

Re: GCC kernal

Post by Bipman »

Will do ta.
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: GCC kernal

Post 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.
Learn to read.
Bipman
Member
Member
Posts: 40
Joined: Wed Mar 15, 2017 9:22 am

Re: GCC kernal

Post by Bipman »

Thanks, I'll take a look.
Post Reply