OS Kernel on Dreamcast
- Masen
- DCEmu Freak
- Posts: 68
- https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
- Joined: Mon Mar 28, 2005 1:35 pm
- Has thanked: 0
- Been thanked: 0
OS Kernel on Dreamcast
Hi
im working on an OS kernel (written in C) and thought about if it would be possible to port it on DC and Booting from a existing Bootloader from LinuxSH ...
so would this be possible and how ?
im working on an OS kernel (written in C) and thought about if it would be possible to port it on DC and Booting from a existing Bootloader from LinuxSH ...
so would this be possible and how ?
-
- DC Developer
- Posts: 9951
- Joined: Sun Dec 30, 2001 9:02 am
- Has thanked: 0
- Been thanked: 1 time
In theory, it's possible. It depends on the design of your OS.
You don't really need a bootloader. The Dreamcast's built-in loader is capable of loading very large binaries. It dumps them in memory at a certain address, and you can execute from there.
You basically need to provide a Dreamcast port of your kernel, and appropriate drivers to make it do something interesting (like a serial port driver). You can probably get the required information (maybe even code) from KallistiOS. Any PC-specific code you have (especially anything in x86 assembly) must be re-written.
You don't really need a bootloader. The Dreamcast's built-in loader is capable of loading very large binaries. It dumps them in memory at a certain address, and you can execute from there.
You basically need to provide a Dreamcast port of your kernel, and appropriate drivers to make it do something interesting (like a serial port driver). You can probably get the required information (maybe even code) from KallistiOS. Any PC-specific code you have (especially anything in x86 assembly) must be re-written.
but how i can compile the kernel to run it on DC ? would it work when i scramble the kernel Bin file ???
it is not realy necassary that the OS will run perfectly with 100% of it functions ... it would be nice if it would boot and display it boot messages and then maybe crashes ... so how i can compile it ? it has a c-kernel with a asm kernel entry so it would need the sh assembler and c cross compiler or ?
but ive tried to get the SH Linux kernel too boot ... but ive failed for several reasons ...
it is not realy necassary that the OS will run perfectly with 100% of it functions ... it would be nice if it would boot and display it boot messages and then maybe crashes ... so how i can compile it ? it has a c-kernel with a asm kernel entry so it would need the sh assembler and c cross compiler or ?
but ive tried to get the SH Linux kernel too boot ... but ive failed for several reasons ...
- Morphv2
- Insane DCEmu
- Posts: 230
- Joined: Sun Sep 12, 2004 1:36 pm
- Location: Someplace
- Has thanked: 0
- Been thanked: 0
- Contact:
dcdev @ yahoo groups has a lot of info about SH4 assembly and such. Thats where most of the KalistiOS was put together (not counting Dan's desk XD). Anything that you would be looking for would be found there. Just dont try and ask anything TRULY hardware related, like modding a console. They dont,know jack squat about that :p
-
- DC Developer
- Posts: 9951
- Joined: Sun Dec 30, 2001 9:02 am
- Has thanked: 0
- Been thanked: 1 time
You're using a DOS compiler under Windows? Seems strange, but...
You should be able to use the same tools that we use to build KallistiOS and homebrew games. Probably the best way would be to download a Dreamcast cross compiler that uses KallistiOS (I think there are some around here that use Cygwin as a base), then use KallistiOS as a guide (complete source code is available) to getting your own OS working with those tools.
There's a fair bit of hardware documentation available though. A good site to read through is this one.
You should be able to use the same tools that we use to build KallistiOS and homebrew games. Probably the best way would be to download a Dreamcast cross compiler that uses KallistiOS (I think there are some around here that use Cygwin as a base), then use KallistiOS as a guide (complete source code is available) to getting your own OS working with those tools.
No, only example code, in the form of KallistiOS, libdream (older version of KallistiOS), NetBSD, Linux, and a few older assembly examples. The SH-4 isn't really used in anything aside from the Dreamcast (which is supposed to be a closed system), and a few older WinCE handhelds (which you could never do system-level programming for anyway).are they any tuts for this matter ??
There's a fair bit of hardware documentation available though. A good site to read through is this one.
- Quzar
- Dream Coder
- Posts: 7497
- Joined: Wed Jul 31, 2002 12:14 am
- Location: Miami, FL
- Has thanked: 4 times
- Been thanked: 9 times
- Contact:
Don't forget the SH4 is also used in little weird embedded devices that are driven pretty much entirely by the sh versions of linux, QNX and NetBSD such as the following:
http://www.emtrion.com/products/hicosh4.html
http://sh2000.sh-linux.org/sh2004.html
http://www.si-linux.com/product/cat68701/
http://www.emtrion.com/products/hicosh4.html
http://sh2000.sh-linux.org/sh2004.html
http://www.si-linux.com/product/cat68701/
"When you post fewer lines of text than your signature, consider not posting at all." - A Wise Man
searching in my cygwin dirs ive found this compilers and etc. :
sh4-linux-as / the assembler i think ?
sh4-linux-gcc
sh4-linux-ld
sh4-linux-objcopy and other binutils
;
sh-elf-as
sh-elf-gcc
sh-elf-ld
sh-elf-objcopy and other binutils
;and:
as
gcc
ld
opjcopy and other binutils
so when the as is the assembler (other name for gas or ?) i should have all the tools i need or ???
so to the kernel problem , ive read in the SegaDocs in the Docs for Embedded Systems that you need a entry assembler data crt0 witch calls the main . but how i can merge the kernel entry and the kernel in the linker script ?
and can i compile it to an elf file witch the sh-elf compile can than convert it to an .bin and scramble it to an 1st_read.bin ???
sh4-linux-as / the assembler i think ?
sh4-linux-gcc
sh4-linux-ld
sh4-linux-objcopy and other binutils
;
sh-elf-as
sh-elf-gcc
sh-elf-ld
sh-elf-objcopy and other binutils
;and:
as
gcc
ld
opjcopy and other binutils
so when the as is the assembler (other name for gas or ?) i should have all the tools i need or ???
so to the kernel problem , ive read in the SegaDocs in the Docs for Embedded Systems that you need a entry assembler data crt0 witch calls the main . but how i can merge the kernel entry and the kernel in the linker script ?
and can i compile it to an elf file witch the sh-elf compile can than convert it to an .bin and scramble it to an 1st_read.bin ???
-
- DC Developer
- Posts: 9951
- Joined: Sun Dec 30, 2001 9:02 am
- Has thanked: 0
- Been thanked: 1 time
They're both suitable. The first are targeted at SH-4 Linux, but should work fine. The second are targeted at generic SH and produce ELF format binaries, which will also be suitable. However, you need all the additional compiler and linker flags (the same as you'd be using on the PC side, pretty much) to remove the standard libraries, header files, and so on.sh4-linux-as / the assembler i think ?
sh4-linux-gcc
sh4-linux-ld
sh4-linux-objcopy and other binutils
;
sh-elf-as
sh-elf-gcc
sh-elf-ld
sh-elf-objcopy and other binutils
as is indeed the assembler.
Native compilers, which generate x86 code.as
gcc
ld
opjcopy and other binutils
Exactly the same way you're doing it on the PC side.so to the kernel problem , ive read in the SegaDocs in the Docs for Embedded Systems that you need a entry assembler data crt0 witch calls the main . but how i can merge the kernel entry and the kernel in the linker script ?
The general process is to make damned sure that your crt0 is being linked in before anything else. Have a look at KallistiOS for a Dreamcast-specific example on how to do that. Doesn't use a linker script (it uses command-line parameters instead), but it's basically the same thing. The kernel entry code should be right at the beginning of the file, because it's the very first piece of code that will be executed by the Dreamcast's bootloader.
Yes, that's the general procedure. You can also upload the ELF file over a serial cable or broadband adaptor.and can i compile it to an elf file witch the sh-elf compile can than convert it to an .bin and scramble it to an 1st_read.bin ???
-
- DC Developer
- Posts: 968
- Joined: Tue Feb 11, 2003 4:12 pm
- Location: In a Dream
- Has thanked: 5 times
- Been thanked: 5 times
Since you're not doing anything too complex in asm, you don't really know how to program in sh4. Most of it should be familiar if you've already coded for the x86.
Unfortunately, there is no "official" asm entry file. Most of the code you need should be in startup.s. This is the file that needs to be at the head of your binary. If you look in the gcc sources in the config/sh directory, you'll see the links gcc needs (init, fini, bss...) which I think are present in the startup.s. (another place to look is in the ronin sources. Ronin is another dreamcast coding library you can look at). Once these links are provided, gcc will be happy, so you'll just tell it that everything you need is available by passing the flags "-nostdlib -nostartfiles" and link with your entry file as the first file.
You will see exception handling code in there too, which you'll have to interface with or rewrite as you see fit.
You can then call your io libs from C or C+asm as usual since, with the exception of the gdrom, dreamcast devices can be accessed from C without changing the abi.
Unfortunately, there is no "official" asm entry file. Most of the code you need should be in startup.s. This is the file that needs to be at the head of your binary. If you look in the gcc sources in the config/sh directory, you'll see the links gcc needs (init, fini, bss...) which I think are present in the startup.s. (another place to look is in the ronin sources. Ronin is another dreamcast coding library you can look at). Once these links are provided, gcc will be happy, so you'll just tell it that everything you need is available by passing the flags "-nostdlib -nostartfiles" and link with your entry file as the first file.
You will see exception handling code in there too, which you'll have to interface with or rewrite as you see fit.
You can then call your io libs from C or C+asm as usual since, with the exception of the gdrom, dreamcast devices can be accessed from C without changing the abi.
behold the mind
inspired by Dreamcast
inspired by Dreamcast
-
- DC Developer
- Posts: 968
- Joined: Tue Feb 11, 2003 4:12 pm
- Location: In a Dream
- Has thanked: 5 times
- Been thanked: 5 times
If I may offer a better response than the one I gave before...
To get your kernel booting on Dreamcast, you do not really need a
bootloader; just a little knowledge of the cpu and the bios.
First, the sh4 has different address spaces for user and privileged
modes. In privileged mode, the address space is divided into 4 smaller
address spaces P0-P4. These address spaces affect which cpu resources
and external ram can be accessed. If you are not using the mmu (an
assumption I will make), then established convention is to divide your
work among P1, P2 and P4.
P1 is cacheable and is where your normal programs will run. P2 is
non-cacheable and is where your kernel will run and set critical cpu
devices (cache, mmu). P4 cannot run programs but is where cpu devices
have been mmapped. The bios loads binaries into the P1 area so the
first thing you'll see being done is to enter P2 area by masking the
address of a setup function where the cache is configured (mmu might
also be configured if you need it).
Since it's just your kernel you want to test, you don't have to worry
about what entries gcc needs (because you're coding in C) so you can
just interface to the main entry point of your program directly. I
usually just give my "main" a different name, like "void start()" and
call it directly afer setting up the cpu. You'll just need to learn a
little sh4 asm to save/restore cpu context etc.
To handle exceptions on the sh4 you have to set VBR manually as the
base and offset the entry points manually as well
You can get other io code eg printing text, serial, maple from
existing libs (libdream, kos, ronin, dcos, netbsd)
eg in startup.s
In your C program main.c
You can compile such a program by passing the following command line
to sh-elf-gcc
This should work for the kernel. If you want your kernel to start user
programs properly, you'll have to mess with calling gcc constructors
etc
You don't have to worry too much about exceptions at first, especially
if you're using dcload which has exception handling code that restarts
it.
To get your kernel booting on Dreamcast, you do not really need a
bootloader; just a little knowledge of the cpu and the bios.
First, the sh4 has different address spaces for user and privileged
modes. In privileged mode, the address space is divided into 4 smaller
address spaces P0-P4. These address spaces affect which cpu resources
and external ram can be accessed. If you are not using the mmu (an
assumption I will make), then established convention is to divide your
work among P1, P2 and P4.
P1 is cacheable and is where your normal programs will run. P2 is
non-cacheable and is where your kernel will run and set critical cpu
devices (cache, mmu). P4 cannot run programs but is where cpu devices
have been mmapped. The bios loads binaries into the P1 area so the
first thing you'll see being done is to enter P2 area by masking the
address of a setup function where the cache is configured (mmu might
also be configured if you need it).
Since it's just your kernel you want to test, you don't have to worry
about what entries gcc needs (because you're coding in C) so you can
just interface to the main entry point of your program directly. I
usually just give my "main" a different name, like "void start()" and
call it directly afer setting up the cpu. You'll just need to learn a
little sh4 asm to save/restore cpu context etc.
To handle exceptions on the sh4 you have to set VBR manually as the
base and offset the entry points manually as well
You can get other io code eg printing text, serial, maple from
existing libs (libdream, kos, ronin, dcos, netbsd)
eg in startup.s
Code: Select all
.global start
start:
! First, make sure to run in the P2 area
mova setup_cache, r0
mov.l p2_mask, r1
or r1, r0
jmp @r0
nop
setup_cache:
! Now that we are in P2, it's safe
! to enable the cache
mov.l ccr_addr, r0
mov.w ccr_data, r1
mov.l r1, @r0
! After changing CCR, eight instructions
! must be executed before it's safe to enter
! a cached area such as P1
mov.l main_addr, r0 ! 1
mov #0, r1 ! 2
nop ! 3
nop ! 4
nop ! 5
nop ! 6
nop ! 7
nop ! 8
jmp @r0 ! go
mov r1, r0
.balign 4
p2_mask: .long 0xa0000000
main_addr: .long main
ccr_addr: .long 0xff00001c
ccr_data: .word 0x090d
main:
!! do basic config eg set up fpu, stack...
!! set vbr
mova expt_entry, r0
ldc r0, vbr
!! you have set up everything, so call your C start
mov.l start_addr, r0
jmp @r0
nop
exit:
!! restore previous stack etc and return
!! in this case return to dcload
mov.l dcload_syscall, r0
mov.l @r0, r0
jmp @r0
mov #15, r4
.balign 4
start_addr: .long _start
dcload_syscall: .long 0x8c004008
expt_entry: .space 0x100
expt:
!! write code to get expevt/tra and call your
!! exception-handling code accordingly
expt_end: .space 0x400 - (. - expt_entry)
mmu_expt:
!! handle mmu expt
mmu_expt_end: .space 0x600 - (. - expt_entry)
intr_exp:
!! handle interrupts
.balign 4
tra_addr: . long 0xff000020
expevt_addr: . long 0xff000024
intevt_addr: . long 0xff000028
Code: Select all
#include <sys_header.h>
#include "my_header.h"
/* this will be assembled to _start accessed by startup.s above */
void start() {
// do whatever
}
to sh-elf-gcc
Code: Select all
sh-elf-gcc -m4 -ml -O2 -fomit-frame-pointer -Wl,-EL,-Ttext,0x8c010000,-e,start
-nostdlib -nostartfiles startup.s main.c $(MY_MODULES) -o kernel.elf -lgcc
programs properly, you'll have to mess with calling gcc constructors
etc
You don't have to worry too much about exceptions at first, especially
if you're using dcload which has exception handling code that restarts
it.
behold the mind
inspired by Dreamcast
inspired by Dreamcast
-
- DC Developer
- Posts: 968
- Joined: Tue Feb 11, 2003 4:12 pm
- Location: In a Dream
- Has thanked: 5 times
- Been thanked: 5 times
You need -lgcc because it provides internal functions used by gcc. It is automatically installed and ld should know where to find it... I'm not sure, but I think your compiler set may have a problem. Have you used it to compile working kos programs? Check that libgcc.a exists in "sh-elf/lib/gcc-lib/[version]/m4/ml" (not too sure about last dirs
behold the mind
inspired by Dreamcast
inspired by Dreamcast