From f7c494456621122e446d3cb9518d44d8895b6f06 Mon Sep 17 00:00:00 2001 From: Morten Delenk Date: Sat, 30 Jul 2016 12:11:04 +0200 Subject: [PATCH] Before rewrite --- boot/x86/Makefile | 8 +++++--- boot/x86/core.img | Bin 0 -> 1535 bytes boot/x86/d.img | Bin 0 -> 1474560 bytes boot/x86/disk.img | Bin 0 -> 2047 bytes boot/x86/mbrcode.bin | Bin 0 -> 512 bytes boot/x86/stage2/Makefile | 12 ++++++++++++ boot/x86/stage2/init.c | 13 +++++++++++++ boot/x86/stage2/init.o | Bin 0 -> 1236 bytes boot/x86/stage2/stage2.ld | 18 +++++++++++++++++ boot/x86/stage2/start.S | 40 ++++++++++++++++++-------------------- boot/x86/stage2/start.o | Bin 0 -> 2624 bytes 11 files changed, 67 insertions(+), 24 deletions(-) create mode 100755 boot/x86/core.img create mode 100644 boot/x86/d.img create mode 100644 boot/x86/disk.img create mode 100644 boot/x86/mbrcode.bin create mode 100644 boot/x86/stage2/Makefile create mode 100644 boot/x86/stage2/init.c create mode 100644 boot/x86/stage2/init.o create mode 100644 boot/x86/stage2/stage2.ld create mode 100644 boot/x86/stage2/start.o diff --git a/boot/x86/Makefile b/boot/x86/Makefile index 5b1f0b5..b924710 100644 --- a/boot/x86/Makefile +++ b/boot/x86/Makefile @@ -1,7 +1,9 @@ all: mbrcode.bin core.img - + cat mbrcode.bin core.img > disk.img mbrcode.bin: stage1.S nasm -f bin -o $@ $^ -core.img: stage2/start.S - nasm -f bin -o $@ $^ \ No newline at end of file +core.img: + $(MAKE) -C stage2 + mv stage2/core.img . +.PHONY: core.img \ No newline at end of file diff --git a/boot/x86/core.img b/boot/x86/core.img new file mode 100755 index 0000000000000000000000000000000000000000..b1d75ec6b812ecdd259257e3eb876ebeb15a784b GIT binary patch literal 1535 zcmeHE-%Aux6ux(MS5vfI`Y9!Oi^Vc*DT|Oa#UEitk)^2-S<}wd9h{xJ&fL*9j09iQ z&<9_7spopA@S%qVVRmE9H_6@v-@@dIJyb-3iPOE)WWDtV)P+0ed~?2YzH`n^fzZUl zL}qNy7igCQ_8GD&$sUG`LHj9W@8P;V1KA>E?Y`B`i$qqif-bc+5mOVs5kUL<;jkGesuGaTC#)Ox>VrB3U!AtR#^frD{LtDx8Zt zuxcng<2tbnWF}3D<47Uc)DQC#Rw6+R>M97uEfLhO%Ba5ia_e6byJhpIx@heeSLC6n zEChZD_3C5*4a6{wVS~4fx0DcX+ntZksuLMBK+&UdGwI8nqL zjl`AVD@HOhX+=}134Y->nAc3nYHgo05!9Ir*!D7(^)g(?<^e& zqyV746a-zja!a0MS=!0VSY;_+cy6~58QK8cmxNy|{JqtX7N(%U34wdFHU=yA9eV?? z0mps>Sf8^r`Ao8M3#9Po@?_SY2dv9kXD7kbi)DqCgQKw7@d zLSX78hk4*TtKvP-V0KC2mDYuU+}JA;+v%)s2Em#HwvOX)ck(Sbk2Q^yqXx0-CPI`u zN$epW-{sNay{iBYZiD*^{QeOLKqdcQ%x^Wn4+N*N0D`7aK(fHOpwFT?p&ZE?4EZGM zt`vLCV|CfO*}69kJYBHeGk!7bA71+8^liA$a>dT|0WiIje}d_6!Sv$r$D($2VbgI& yi^Hs5*i&J4#={jJKI-8^9^U8S9Ujj2u*B`~OlTZ`z0O~LT;9lj{eS-H4g3IYO=mR# literal 0 HcmV?d00001 diff --git a/boot/x86/d.img b/boot/x86/d.img new file mode 100644 index 0000000000000000000000000000000000000000..d70c88ff68e8b307b40c858d2cafab37cf3b3098 GIT binary patch literal 1474560 zcmeIyPi$OA9RT3jwH-Gh#TJ3Kf`~ql6(~xr5>OSjB~_YMA<#b|Y134Qkj494ud?2C zcHbs7GNMv0X&@HLg$tZP2#^m|O!OLapjAXAH_9?^?X=JfCvM+L z`(}PSzj-tB&CK2ynhRlVG5l=)>K{V*U@?UGrTJ@T?|E=8|7lnZqeXNsMmItTqoLlc zRBMfwlV_ga-)uh}gS3^rvisrj@$tL2gni9Uy_z(dS<*_|X_i!5wNvSO(^H2IJ$LAl zTFQ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ce%5~gKP z>nO6}+?C%)hCi7K@*uoB_FnmsclX8fP3K2yua@$qyQ}%NB?!6EP{&+ouxBnf*s&af zp5>s|arq5zv}ZOr+A$l#7s&!e3C7+J@BOmOm%QeZv#%J4tvqAJFK+?rve4UwzWa#8 zb`~XpGXhVPT?)58^4u-p)1Lb|@JX+-@U`rOTjkjH`a;=V1wQ80_-j!3Ze8V_P+0Xv zWqgqDg~Bfg_P}VXygtsOQ1~8UGu-2cF$NYXS5&;ICWM5-y(RND{2z(HUHRcF@I2HP zeug)xuA7~tPt>~KG}RBXw1M#a=>}i=a0sN_4(YkpU~pCf=*HjM@jHUw$AWXbRf7I# zNOs^vB;c^7Xp`*Zq5;{tB&UAFv)*#=a_>)lXfD|Pnm-u}&Q$*NCb#^yyyJ!g0E=z7 zMV9`GEZv;>W6ubGYuod#w8!`{AzzR2Lk-;3z^^p$iw*p213%TkEe$NAoVgL5r<)hB P^YhA9dGqo5UsvF7nPkLP literal 0 HcmV?d00001 diff --git a/boot/x86/mbrcode.bin b/boot/x86/mbrcode.bin new file mode 100644 index 0000000000000000000000000000000000000000..3f76c0690751900add80481637d4f17d23292d1a GIT binary patch literal 512 zcmaFGTEoEbYX`%Gz6*O87=G_yVCXy0ccVj0x8_9;!wv=k5U&f!d&R)OAi$85pO})F zm#*L&;+|jZ1LUL@DO6aP>FMe5axpmPm*%7>N@I!&!mXpAPTyu6gnL|7-DmX*Dk%|9|~&CpUv< z$t$4yK&~nJ0wQ-ZF>HglaW@0Q2Cf(E4EywIUTph+IAI?X!xpBq!o{3^MQjF7fQ*lc Ohk+g#1!y4X? literal 0 HcmV?d00001 diff --git a/boot/x86/stage2/Makefile b/boot/x86/stage2/Makefile new file mode 100644 index 0000000..be7f338 --- /dev/null +++ b/boot/x86/stage2/Makefile @@ -0,0 +1,12 @@ +CC=/opt/bin/i686-mtgos-gcc +LD=/opt/bin/i686-mtgos-ld +CFLAGS16=-m16 +ASFLAGS=-f elf +core.img: start.o init.o + $(LD) -T stage2.ld -o core.img start.o init.o + +%.o: %.c + $(CC) $(CFLAGS16) -o $@ $^ + +%.o: %.S + nasm $(ASFLAGS) -o $@ $^ \ No newline at end of file diff --git a/boot/x86/stage2/init.c b/boot/x86/stage2/init.c new file mode 100644 index 0000000..aae8bf7 --- /dev/null +++ b/boot/x86/stage2/init.c @@ -0,0 +1,13 @@ +void putstring(short); +void main() { + putstring((short)"Hello, C!\r\n"); + putstring((short)"Goodbye, C!\r\n"); + putstring((short)"Hello, C!\r\n"); + putstring((short)"Goodbye, C!\r\n"); + putstring((short)"Hello, C!\r\n"); + putstring((short)"Goodbye, C!\r\n"); + putstring((short)"Hello, C!\r\n"); + putstring((short)"Goodbye, C!\r\n"); + putstring((short)"Hello, C!\r\n"); + putstring((short)"Goodbye, C!\r\n"); +} \ No newline at end of file diff --git a/boot/x86/stage2/init.o b/boot/x86/stage2/init.o new file mode 100644 index 0000000000000000000000000000000000000000..727e45604b91a397ecca3bdc36e6a3c9f143440f GIT binary patch literal 1236 zcmbVM&ubGw6n?v##2OQ_7E!T1q)@R!9gI{difD*29;)~&0hMYu&1wSKY)y8dl|m1> z*hBso?}A0Do&^5@uN8Xmpdg+C>-TnNnzbN`58iz5$2afI&b(x!yl`F9G*Y6GK_ido zqaJ1ELYSc}rRj#Y^I>)KOYPpBH@xq421{=1 zXKw3r|LgJE?l1^~&B^Hq=Oq58-+yNg>>m#vJzgAG!)>aRN*D7pm0Q)*`3s^T&T{)B zyg;-UcS&0x(KFT1KOanbdtM=M3LVnJL|0Hx1oi)thgTD{dD* z6yKMyUG5q|{LT{eJs4$Z-;J^_FIAEZMB-x5@AVBz#?xSr?eh=pMff|$!OzARCflt} z%M;7wSgj7N_+HQJwmQ#<4kM+Z{85P~fqI(gjKuR2FH0;-yeY9NaZ#cz(UF*EOkokd zHOI5+K(8BNQ(2z9>XB$zo<*YG>yhZX>@c$+3UKYVU=9LS*Yj6MEW3_lcd&_5cJs;8 zuH|s&f0GH&_`Ud8EYWO7Hm~X}r=+c3=TE#-;PH$6jW;XnoddFPy%V7oE!>y&ibQq3 z+wjBr1hRzh3A_Y72)zmo1!J`Y;}A3n}DX?!)!?o7s-n+Xe3! IVoFrKUq|htYybcN literal 0 HcmV?d00001 diff --git a/boot/x86/stage2/stage2.ld b/boot/x86/stage2/stage2.ld new file mode 100644 index 0000000..fa14f34 --- /dev/null +++ b/boot/x86/stage2/stage2.ld @@ -0,0 +1,18 @@ +OUTPUT_FORMAT(binary); +SECTIONS { + . = 0x0; + .init_text :{ + *(.init_text); + } + .text : { + *(.text); + } + .data : { + *(.data); + *(.rodata); + } + .bss : { + *(.bss); + *(.end); + } +} \ No newline at end of file diff --git a/boot/x86/stage2/start.S b/boot/x86/stage2/start.S index 1793ad7..c69b13f 100644 --- a/boot/x86/stage2/start.S +++ b/boot/x86/stage2/start.S @@ -1,5 +1,5 @@ -org 0x0000 bits 16 +section .init_text start: mov ax, 0x1000 ; update segment registers mov ds, ax @@ -13,27 +13,10 @@ start: mov si, unrealstart call putstr cli - push ds - lgdt [gdtinfo] - mov eax, cr0 - or al, 1 - mov cr0, eax ;Activate pmode -bits 32 - jmp $+2 ;Pls don't crash 386/486 - mov bx, 0x08 - mov ds, bx - and al, 0xFE - mov cr0, eax ; Turn off pmode -bits 16 - pop ds - sti - mov ax, 0 - mov fs, ax - mov bx, 0x0f01 - mov eax, 0x0B8000 - mov word [fs:eax], bx mov si, smiley call putstr +extern main + call main jmp $ bootmsg db "Loaded MTGosloader. Checking for any open A20 gates...",13,10,0 a20open db "It seems that A20 is already activated... Weird",13,10,0 @@ -45,6 +28,19 @@ a20success db "Successfully opened the A20 gate!",13,10,0 unrealstart db "Trying to init unreal mode",13,10,0 smiley db "Do you see a smiley in the top-left corner?",13,10,0 bootdrv db 0 +global putstring + +putstring: + push bp + mov bp, sp + push si + push bx + mov si, [bp+4] + call putstr + pop bx + pop si + pop bp + ret putstr: lodsb or al, al @@ -193,6 +189,8 @@ gdtinfo: dd gdt ;start of table gdt dd 0,0 ; entry 0 is always unused +flatcode db 0xff, 0xff, 0, 0, 0, 10011010b, 10001111b, 0 flatdesc db 0xff, 0xff, 0, 0, 0, 10010010b, 11001111b, 0 gdt_end: -times 5120-($-$$) hlt \ No newline at end of file +section .end +times 512 hlt \ No newline at end of file diff --git a/boot/x86/stage2/start.o b/boot/x86/stage2/start.o new file mode 100644 index 0000000000000000000000000000000000000000..d17172b8ed8a95f432dd46a6e7c1c333704cb38c GIT binary patch literal 2624 zcmeH}U1(fI6oAiccbi7ic8iG$7Bgyysm3KuM8s-ZZB+u51X9~bF`Jvcv&l90XM68# z(nX|!pwv|Jke9w#eX~AP$%8^b*e-18TQR;B@**{c8|zC_ArM2Z=iI%!JMl&ERR?Cz z`R1HC^Rsv6%%wL@zsVSbYGJSk>I85iGQ1GV4roC8zbO=xYAotJg3zFZs*c(8H@{q5 z=@i*0#38IocgXDpc$o}Qsm6O8xjH797SJz=4GGj+u~PUX)~B(m@k;vunyW$3R#l%v zy%B4*{ERSyKyk>2BzCQpMM%!woh!{gvcZa-;IA|PSgbh1e4iDsGyfjjD&AuLGV^zW z`#Yx{O&2;?&4#b6kaNo+W!#rN$v?@ zd0dWbGBg?<*GyMvdVy;hX-uN8j=ubyFkBsbyzAs$?iD;KEUr7kv!B5b`CQI%WjF$j zSQ~^-8XAASuYd3#I%YMmGCEDI>P!82Mxz0$15Mb@6rUOwa$LALWl;t>onm=Akr^QKwZ zKHOt9(v#?O#x2m2rNa%|kUVeW-kIETbXvzLCmaU1m}}g#3{w=)EsP0vMXSa@)=1QAOb9Zk- zqL@sy&n5U_Dl z1paWa<@dnCH>J0wm7WQ=T-b!3=X3%6mCQPs>08rzNBy$ z>e~ua4mwer6oXU9GYa=3Usw1%@-2l&kv9~U$g$diV(K6pQHgK(hVsApO zzYEx|TuXWSeXI|n{Yg^B^`z#?)F4=zVOIb~9Y$56nRk0beMB)^R0Z;^a}l41P|hb*ks literal 0 HcmV?d00001