OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Apr 18, 2024 7:59 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: GCC kernal
PostPosted: Sun Apr 23, 2017 10:08 am 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: GCC kernal
PostPosted: Sun Apr 23, 2017 10:15 am 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
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


Top
 Profile  
 
 Post subject: Re: GCC kernal
PostPosted: Sun Apr 23, 2017 10:16 am 
Offline
Member
Member

Joined: Wed Mar 15, 2017 9:22 am
Posts: 40
Hi

The C I understand, it's the the other stuff in my description above I don't know how to do.

Bipman


Top
 Profile  
 
 Post subject: Re: GCC kernal
PostPosted: Sun Apr 23, 2017 10:28 am 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
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:
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


Top
 Profile  
 
 Post subject: Re: GCC kernal
PostPosted: Sun Apr 23, 2017 11:37 am 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: GCC kernal
PostPosted: Sun Apr 23, 2017 12:34 pm 
Offline
Member
Member

Joined: Thu May 17, 2007 1:27 pm
Posts: 999
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].


Top
 Profile  
 
 Post subject: Re: GCC kernal
PostPosted: Sun Apr 23, 2017 12:35 pm 
Offline
Member
Member

Joined: Wed Mar 15, 2017 9:22 am
Posts: 40
Will do ta.


Top
 Profile  
 
 Post subject: Re: GCC kernal
PostPosted: Mon Apr 24, 2017 3:56 am 
Offline
Member
Member
User avatar

Joined: Thu Jul 12, 2012 7:29 am
Posts: 723
Location: Tallinn, Estonia
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.


Top
 Profile  
 
 Post subject: Re: GCC kernal
PostPosted: Mon Apr 24, 2017 7:54 am 
Offline
Member
Member

Joined: Wed Mar 15, 2017 9:22 am
Posts: 40
Thanks, I'll take a look.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 85 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group