pascal os development
pascal os development
I just want to inform you that I have started a Google Group on operating system development in pascal. I plan to write a small series of tutorials on making a basic Hello world operating system in pascal, and maybe even more. Who knows ?
If you're interested, please visit us @ http://groups-beta.google.com/group/pascalosdev
If you're interested, please visit us @ http://groups-beta.google.com/group/pascalosdev
Re:pascal os development
I made a turbo pascal OS, when i first started OS Dev, for the basic its quite easy, here's a funny example.
This code will restart your pc.
But this code works fine
If you boot it using a program like "bootprog" available here: http://alexfru.chat.ru/epm.html#bootprog.
This code will restart your pc.
Code: Select all
begin
writeln('Hello. from my OS ')
end.
Code: Select all
uses
Crt;
begin
writeln('Hello. from my OS')
end.
Re:pascal os development
Not the freepascal, but Turbo Pascal version 7, as I plan to make a simple real mode OS just to demonstrate to people that it is possible and as easy as in any other language to make an operating system in Pascal.
Re:pascal os development
I'm writing in FreePascal 2.0 series and can contribute an RTL.
Re:pascal os development
If you've done anything, a basic Hello World in Free Pascal, and could spare some time writing a tutorial, and making a sample Hello World OS, it would be great, as I plan to start a small web site on Pascal OS dev, and I would appreciate any kind of help.
Best regards
P.S. well not really, most of your code did not end up in PowerDOS, as I wrote all the code by my self, but I did learn a lot from your code. Thanks again
Best regards
P.S. well not really, most of your code did not end up in PowerDOS, as I wrote all the code by my self, but I did learn a lot from your code. Thanks again
Re:pascal os development
A simple Hello world OS is done, and I hope that I'll find some time these days to write a tutorial on how you can do it your self.
Anyone interested ?
Anyone interested ?
Re:pascal os development
Why not create a 32BIT hello world os in pascal using freepascal...
a 16BIT OS is absolute... and turbo pascal's compiler is sooo old...
You will be pointing people to the rong direction.
Get a GRUB boot disk with elf kernel support.
Get new freepascal compiler.
Get NASM or not if you use AS.
Crosscompile gnu bin utils (i could upload them) in cygwin.
And your set for developing an 32BIT OS using freepascal.
First write a stub in asm to jump to the kernel.
[stub.asm]
[Small system unit (needed by compiler)]
[..\support\system.pas]
[Multiboot header]
[..\include\multiboot.pas]
a 16BIT OS is absolute... and turbo pascal's compiler is sooo old...
You will be pointing people to the rong direction.
Get a GRUB boot disk with elf kernel support.
Get new freepascal compiler.
Get NASM or not if you use AS.
Crosscompile gnu bin utils (i could upload them) in cygwin.
And your set for developing an 32BIT OS using freepascal.
First write a stub in asm to jump to the kernel.
[stub.asm]
Code: Select all
;
; Kernel stub
;
;
; We are in 32bits protected mode
;
[bits 32]
;
; Export entrypoint
;
[global kstart]
;
; Import kernel entrypoint
;
[extern kmain]
;
; Posible multiboot header flags
;
MULTIBOOT_MODULE_ALIGN equ 1<<0
MULTIBOOT_MEMORY_MAP equ 1<<1
MULTIBOOT_GRAPHICS_FIELDS equ 1<<2
MULTIBOOT_ADDRESS_FIELDS equ 1<<16
;
; Multiboot header defines
;
MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_MODULE_ALIGN | MULTIBOOT_MEMORY_MAP
MULTIBOOT_HEADER_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
;
; Kernel stack size
;
KERNEL_STACKSIZE equ 0x4000
section .text
;
; Multiboot header
;
align 4
dd MULTIBOOT_HEADER_MAGIC
dd MULTIBOOT_HEADER_FLAGS
dd MULTIBOOT_HEADER_CHECKSUM
;
; Entrypoint
;
kstart:
mov esp, KERNEL_STACK+KERNEL_STACKSIZE ;Create kernel stack
push eax ;Multiboot magic number
push ebx ;Multiboot info
call kmain ;Call kernel entrypoint
cli ;Clear interrupts
hlt ;Halt machine
section .bss
;
; Kernel stack location
;
align 32
KERNEL_STACK:
resb KERNEL_STACKSIZE
[..\support\system.pas]
Code: Select all
unit system;
interface
{$define FPC_IS_SYSTEM}
type
DWORD = LongWord;
Cardinal = LongWord;
Integer = Longint;
SizeInt = Longint;
SizeUInt = DWord;
PtrInt = Longint;
PtrUInt = DWord;
ValSIn = Longint;
ValUInt = Cardinal;
PChar = ^Char;
PPChar = ^PChar;
TAnsiChar = Char;
AnsiChar = Char;
PAnsiChar = PChar;
PPAnsiChar = PPChar;
UCS4Char = type LongWord;
PUCS4Char = ^UCS4Char;
TUCS4CharArray = array[0..$effffff] of UCS4Char;
PUCS4CharArray = ^TUCS4CharArray;
UCS4String = array of UCS4Char;
UTF8String = type ansistring;
PUTF8String = ^UTF8String;
HRESULT = type Longint;
TDateTime = type Double;
Error = type Longint;
PSingle = ^Single;
PDouble = ^Double;
PCurrency = ^Currency;
PComp = ^Comp;
PExtended = ^Extended;
PSmallInt = ^Smallint;
PShortInt = ^Shortint;
PInteger = ^Longint;
PByte = ^Byte;
PWord = ^word;
PDWord = ^DWord;
PLongWord = ^LongWord;
PLongint = ^Longint;
PCardinal = ^Cardinal;
PQWord = ^QWord;
PInt64 = ^Int64;
PPtrInt = ^PtrInt;
PSizeInt = ^SizeInt;
PPointer = ^Pointer;
PPPointer = ^PPointer;
PBoolean = ^Boolean;
PWordBool = ^WordBool;
PLongBool = ^LongBool;
PShortString = ^ShortString;
PAnsiString = ^AnsiString;
PDate = ^TDateTime;
PError = ^Error;
PWideChar = ^WideChar;
PPWideChar = ^PWideChar;
WChar = Widechar;
UCS2Char = WideChar;
PUCS2Char = PWideChar;
PWideString = ^WideString;
implementation
begin
end.
[..\include\multiboot.pas]
Code: Select all
unit multiboot;
interface
const
KERNEL_STACKSIZE = $4000;
MULTIBOOT_BOOTLOADER_MAGIC = $2BADB002;
type
Pelf_section_header_table_t = ^elf_section_header_table_t;
elf_section_header_table_t = packed record
num: DWORD;
size: DWORD;
addr: DWORD;
shndx: DWORD;
end;
Pmultiboot_info_t = ^multiboot_info_t;
multiboot_info_t = packed record
flags: DWORD;
mem_lower: DWORD;
mem_upper: DWORD;
boot_device: DWORD;
cmdline: DWORD;
mods_count: DWORD;
mods_addr: DWORD;
elf_sec: elf_section_header_table_t;
mmap_length: DWORD;
mmap_addr: DWORD;
end;
Pmodule_t = ^module_t;
module_t = packed record
mod_start: DWORD;
mod_end: DWORD;
name: DWORD;
reserved: DWORD;
end;
Pmemory_map_t = ^memory_map_t;
memory_map_t = packed record
size: DWORD;
base_addr_low: DWORD;
base_addr_high: DWORD;
length_low: DWORD;
length_high: DWORD;
mtype: DWORD;
end;
implementation
end.
Re:pascal os development
Now write a 32bit unit in pascal, with hello world code.
[kernel.pas]
Now to build it:
[linker script]
[build kernel.bat]
[kernel.pas]
Code: Select all
unit kernel;
interface
uses
multiboot;
implementation
var
vidmem: PChar = PChar($b8000);
xpos: Integer = 0;
ypos: Integer = 0;
procedure kclearscreen(); [public, alias: 'kclearscreen'];
var
i: Integer;
begin
for i := 0 to 3999 do
vidmem[i] := #0;
end;
procedure kwritestr(s: PChar); [public, alias: 'kwritestr'];
var
offset, i: Integer;
begin
if (ypos > 24) then
ypos := 0;
if (xpos > 79) then
xpos := 0;
offset := (xpos shl 1) + (ypos * 160);
i := 0;
while (s[i] <> Char($0)) do
begin
vidmem[offset] := s[i];
offset += 1;
vidmem[offset] := #7;
offset += 1;
i += 1;
end;
xpos := (offset mod 160);
ypos := (offset - xpos) div 160;
xpos := xpos shr 1;
end;
procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: DWORD); stdcall; [public, alias: 'kmain'];
begin
kclearscreen();
kwritestr('HELLO WORLD FROM FREEPASCAL');
xpos := 0;
ypos += 1;
if (mbmagic <> MULTIBOOT_BOOTLOADER_MAGIC) then
kwritestr('Not booted by a multiboot-compliant bootloader!');
else
kwritestr('Booted by a multiboot-compliant bootloader!');
end;
end.
Now to build it:
[linker script]
Code: Select all
OUTPUT_FORMAT("elf32-i386")
ENTRY(kstart)
SECTIONS
{
.text 0x100000 :
{
text = .; _text = .; __text = .;
*(.text)
. = ALIGN(4096);
}
.data :
{
data = .; _data = .; __data = .;
*(.data)
kimage_text = .;
LONG(text);
kimage_data = .;
LONG(data);
kimage_bss = .;
LONG(bss);
kimage_end = .;
LONG(end);
. = ALIGN(4096);
}
.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .; _end = .; __end = .;
}
Code: Select all
@echo off
if %1'==build' goto build
if %1'==' goto force
if not %1'==' goto end
:force
echo Enabeling extentions...
cmd /V:ON /C "build kernel.bat" build
goto end
:build
cd .\kernel
echo Executing nasm...
..\bin\nasm -f elf stub.asm -o ..\output\obj\stub.o
echo Executing freepascal...
..\bin\ppc386 -Aelf -FE..\output\obj -Fi.\include -Fu.\support -n -OG3p3 -Si -Sc -Sg -Xd -Rintel -Tlinux kernel.pas
echo Executing linker...
for %%c in (..\output\obj\*.o) do set objects=!objects! %%c
..\bin\ld -T kernel.ld -o ..\output\kernel\kernel.elf%objects%
cd ..
echo Executing strip...
.\bin\strip .\output\kernel\kernel.elf
pause
goto end
:end
@echo on
Re:pascal os development
I wrote this a bit fast so i hope its correct... got exams.
Meaby after my exams are done, ill upload a beginner package with compiler, build tools, and basic hello world kernel.
Greets Kim.
Meaby after my exams are done, ill upload a beginner package with compiler, build tools, and basic hello world kernel.
Greets Kim.
Re:pascal os development
Well, this is just a tutorial for absolute beginners in OS development, and its goal is to show people that it is possible to develope an os in pascal just as it is in C or some other language.
Hopefully, I'll set up a web site for Pascal OS Dev these days, so if you're willing to contribute with your tutorials etc. you're WELCOME.
Thanks anyway.
Best regards
Hopefully, I'll set up a web site for Pascal OS Dev these days, so if you're willing to contribute with your tutorials etc. you're WELCOME.
Thanks anyway.
Best regards
Re:pascal os development
If that was the smallest possible Hello World kernel in Pascal then I don't want anything to do with that language.
Re:pascal os development
I'm currently working on seting up a web site for Pascal OS Dev, and there you'll be able to download all the tutorials, and some code snipets.
Anyway, if someone is interested in Hello world kernel in pascal, feel free to email me, and I'll send it to you.
Anyway, if someone is interested in Hello world kernel in pascal, feel free to email me, and I'll send it to you.