So much for OO Programming
So much for OO Programming
Okay, it probably isn't really OO Programming. But my pretty basic (print to screen, get input, work the keyboard, basic memory management) kernel was getting kinda large so I split the file up a bit into a main kernel.c file and then a smaller io.c file with all the input and output routines.
Both of these compiled to .o files in DJGPP absolutely fine.
Then I linked em with ld
The command was
ld -T link.ld -o kernel.bin ks.o io.o kernel.o
ks.o is a "boilerplate" dealie
Anyway, when I came to execute the formerly working kernel, all i got was a simulation of a continually restarting computer.
I dont want to put all my source code up here - slow down peoples' connections too much BUT I will if you need to know. I just want to know if it's a simple mistake.
Thanks in advance,
-Steve
Both of these compiled to .o files in DJGPP absolutely fine.
Then I linked em with ld
The command was
ld -T link.ld -o kernel.bin ks.o io.o kernel.o
ks.o is a "boilerplate" dealie
Anyway, when I came to execute the formerly working kernel, all i got was a simulation of a continually restarting computer.
I dont want to put all my source code up here - slow down peoples' connections too much BUT I will if you need to know. I just want to know if it's a simple mistake.
Thanks in advance,
-Steve
Re:So much for OO Programming
Well, that's certainly strange. There should be no problem splitting up a kernel like that -- my kernel is spread across 21 source files and 22 header files, for example.
I would hazard a guess that this is a linking problem. Take a look at objdump's output (use -x), and make sure things look fine there. Look for undefined symbols and such. Are there any cross-module dependencies on static variables?
Step through the code, either in a debugger or by putting carefully placed writes to video memory all over the place to see how far it gets.
I would hazard a guess that this is a linking problem. Take a look at objdump's output (use -x), and make sure things look fine there. Look for undefined symbols and such. Are there any cross-module dependencies on static variables?
Step through the code, either in a debugger or by putting carefully placed writes to video memory all over the place to see how far it gets.
Re:So much for OO Programming
I'd bet a thousand it's a problem with the linker script. Could you post it? Moreover, try to put a cli hlt combo as early in the code as possible and see if it will hang. That way you'll see if it ever gets to initialisation.
Are you loading it with GRUB, or a custom bootloader?
Good luck in Debugerland
Adrian.
Are you loading it with GRUB, or a custom bootloader?
Good luck in Debugerland
Adrian.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:So much for OO Programming
You may want to check the type of the generated file. if you wish the linked file to look like if it was just a single file, could try iterative linking (-r or -i) ...Steve Fendyke wrote: I dont want to put all my source code up here - slow down peoples' connections too much BUT I will if you need to know. I just want to know if it's a simple mistake.
If you register, you'll have the option to attach a zip of your files so that people that have broadband and wish to consult it can do so ...
Re:So much for OO Programming
It is very strange! I think i'll just clear up a few points. My kernel is all C++ except the "boilerplate" ASM.
I won't post the linker script. My kernel is based on the "Writing a basic C++ Kernel" tutorial that you can find all over the place - specifically www.osdever.net if it's up when you look. So yes, i've kept using the linker script from there. I dont have a clue how linker scripts work so maybe i need to change it. C++ is what I can do, not ld
Sorry if that sounds naive - i'm learning all the time writing this kernel. It's actually fun - what does that say about me?
I'm using John Fine's bootloader. The one that looks for a kernel.bin file and then runs that.
The code doesn't seem to get ANYwhere. It - Bochs - starts with "Booting from Floppy..." and restarts when my intro would normally appear.
Just to check, i put all my code back in one file and it compiled fine and worked properly - so the code seems to be ok.
Finally, Bochs says it's interrupt 13, exception 3 (?) I think that's right anyway. I'm writing that from memory. Whatever the problem was, i checked around and apparantly it's the computers way of saying it's a "general" problem. Helpful, huh?
Thanks in advance,
-Steve
PS I will register and post it wheni get a chance and can sort all my files out - Great idea.
I won't post the linker script. My kernel is based on the "Writing a basic C++ Kernel" tutorial that you can find all over the place - specifically www.osdever.net if it's up when you look. So yes, i've kept using the linker script from there. I dont have a clue how linker scripts work so maybe i need to change it. C++ is what I can do, not ld
Sorry if that sounds naive - i'm learning all the time writing this kernel. It's actually fun - what does that say about me?
I'm using John Fine's bootloader. The one that looks for a kernel.bin file and then runs that.
The code doesn't seem to get ANYwhere. It - Bochs - starts with "Booting from Floppy..." and restarts when my intro would normally appear.
Just to check, i put all my code back in one file and it compiled fine and worked properly - so the code seems to be ok.
Finally, Bochs says it's interrupt 13, exception 3 (?) I think that's right anyway. I'm writing that from memory. Whatever the problem was, i checked around and apparantly it's the computers way of saying it's a "general" problem. Helpful, huh?
Thanks in advance,
-Steve
PS I will register and post it wheni get a chance and can sort all my files out - Great idea.
Re:So much for OO Programming
Hey, me again. I just registered and i'm posting all the files i think are relevant. The code isn't very well commented or prepared - I never expected anyone else to be seeing it so soon. If there are any questions (along the lines of "What the hell were you thinking when you did this?") i'll be happy to try and answer em.
-Steve
-Steve
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:So much for OO Programming
given that
i'd rather have used '.text 0xFF800000' than '.text 0x100000' ...; The CPU is in protected mode with paging enabled.
; The image file is loaded at linear address FF800000
Re:So much for OO Programming
I don't think that's the problem. I got away with having my kernel linked to 0x100000 using that bootloader for months before it started being a bug. I've attached a modified version of Bootf02 that I did earlier this year which you might want to use. It is generally "tidier" code (IMHO) and has some different features as detailed in the header block:-
Because of the driver loading bit, you need to stick a file with the same filename as the "driver" string (at the bottom of the file) and it MUST NOT BE empty.
Any one can use this code. Its in the public domain. The original said:-
Pete
PS. If anyone knows a contact for John Fine could they please PM me with it. I've tried to find a working email for him but all the ones around on news groups, and his code don't work. I'd like to let him know what I've done with his code.
EDIT: Forgot to attach. Compiling is as follows and requires JLOC which is available from here:-
Where bootf.lnk is :-
Pete
Code: Select all
; FAT12 Floppy Bootsector
;
; Original code by John S Fine (1999)
; Modified by Therx (2004)
;
; Origial contained:-
; - Enables A20 and pmode
; - Loads Kernel at 0x100000
; - Paging setup
;
; Modified version contains:-
; - Modified original code to save space
; - Paging code removed
; - Places an E820 memory map at 0x500
; - Loads one module to 0x80000
; - Turns off floppy drive motor
;
; WARNING : These are the limitations / problems
; - Doesn't check for correct CPU etc.
; - If there is an error it just hangs (no output).
; - The FAT structure must be the first thing on the drive (no partitions). It just uses "reserved" sectors before the FAT, not "hidden" etc.
; - The sector size must be 512 bytes
; - There are less than 256 sectors per fat (safe, since FAT12 has less than 4096*1.5 bytes per FAT).
; - LBN of root directory less than 65536 (safe in unpartitioned FAT12)
Any one can use this code. Its in the public domain. The original said:-
And I'm saying the same. ;D; I do not place any restrictions on your use of this source code
; I do not provide any warranty of the correctness of this source code
Pete
PS. If anyone knows a contact for John Fine could they please PM me with it. I've tried to find a working email for him but all the ones around on news groups, and his code don't work. I'd like to let him know what I've done with his code.
EDIT: Forgot to attach. Compiling is as follows and requires JLOC which is available from here:-
Code: Select all
NASM -f obj -l bootf.lst bootf.asm
JLOC bootf.lnk bootf.bin
Code: Select all
; bootf.lnk JLOC control file for bootp.asm
; Version 1.0, Apr 14, 1999
; Sample code
; by John S. Fine [email protected]
; I do not place any restrictions on your use of this source code
; I do not provide any warranty of the correctness of this source code
;_____________________________________________________________________________
ALL:
bootf.obj
BOOT: 0 7C00 0
*
Re:So much for OO Programming
There she goes - my boot sector for atlantisos 0.0.2.1 and below. It loads from a FAT12 boot disk (same) three modules, one to 0x10000 (setup), one to 0x20000 (kernel) and one to 0x60000 (module something, in my case module set) and jumps to the setup code (which then doesn't have to load any more code but can just be a short stub to load the kernel/module support code).Pete wrote: ; Origial contained:-
; - Enables A20 and pmode
; - Loads Kernel at 0x100000
; - Paging setup
;
; Modified version contains:-
; - Modified original code to save space
; - Paging code removed
; - Places an E820 memory map at 0x500
; - Loads one module to 0x80000
; - Turns off floppy drive motor
Dito, but...; WARNING : These are the limitations / problems
; - Doesn't check for correct CPU etc.
; - If there is an error it just hangs (no output).
; - The FAT structure must be the first thing on the drive (no partitions). It just uses "reserved" sectors before the FAT, not "hidden" etc.
; - The sector size must be 512 bytes
; - There are less than 256 sectors per fat (safe, since FAT12 has less than 4096*1.5 bytes per FAT).
; - LBN of root directory less than 65536 (safe in unpartitioned FAT12)
1.44M disk format exactly hardcoded, the disk parameter table also provided for that layout. Not for harddisks obviously, unless you can find an 18-sector/track 2-head 80-track harddisk...
Dito here.Any one can use this code. Its in the public domain. The original said:-
And I'm saying the same. ;D; I do not place any restrictions on your use of this source code
; I do not provide any warranty of the correctness of this source code
Compiling is plain on linux, don't know on windows (but probably the nasm/jloc stuff). For linux, nasm -f binary -o boot.o bs.asm.
The file can be found at www.sf.net/projects/atlantisos in the source archive, file src/boot/bs.asm. Going to put it on my pd page asap.
Re:So much for OO Programming
Does yours go into pmode? Doesn't look like it from the code. Also If you want it then my modified bootf02 gives a memory map of the system from the BIOS.
Competition!
Pete
Competition!
Pete
Re:So much for OO Programming
Got me a nice setup loader that does... Still being rewritten but atm it loads the A20 gate, loads PM, sets up paging (and YES, it can do PAE paging), identity maps the first 2M/4M (pae/non-pae) and clears out the first 1-9M of memory to zeroes (to prevent warnings in early code). It then loads the object loaded at 0x20000 to memory (using paging), as an ELF file with page alignment, at the places indicated in the ELF. Then, it jumps to the entry point. The kernel is and remains responsible for unmapping the 0-2/4M.Pete wrote: Does yours go into pmode? Doesn't look like it from the code. Also If you want it then my modified bootf02 gives a memory map of the system from the BIOS.
Newer version should also work with nonpagealigned ELFs, and not have the compile kludge that the current one has. You need to hexedit setup.o to remove the 16-bit relocations... fix underway! BTW, the setup is atm BSD new style'd, might be PD sometime soon.
Re:So much for OO Programming
Hey,
I tried changing the address in the linker script. No help there i'm afraid. I guess i'll have to read up on debugging.
Unless one of those new bootblocks stands a chance of solving my problem?
-Steve
I tried changing the address in the linker script. No help there i'm afraid. I guess i'll have to read up on debugging.
Unless one of those new bootblocks stands a chance of solving my problem?
-Steve