diff --git a/COPYING b/COPYING index 25d6fb7..f288702 100644 --- a/COPYING +++ b/COPYING @@ -672,6 +672,3 @@ may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . - -======= - diff --git a/Makefile b/Makefile index 71e74a6..a9242fb 100644 --- a/Makefile +++ b/Makefile @@ -25,3 +25,23 @@ tests: make tests -f Makefile.out.2 rm Makefile.out Makefile.out.2 +ASM=nasm +ASMFLAGS= +BOOTFLAGS=-f bin + +BOOTDIR=boot +OBJDIR=build/obj +BINDIR=build/bin + +boot.mbr.asm: $(BOOTDIR)/mbr.asm $(BOOTDIR)/mbr.inc + $(ASM) $(BOOTFLAGS) $(BOOTDIR)/mbr.asm -o $(OBJDIR)/boot/mbr.bin + +boot.loader.asm: $(BOOTDIR)/loader.asm + $(ASM) $(BOOTFLAGS) $(BOOTDIR)/loader.asm -o $(OBJDIR)/boot/loader.bin + +bootloader: boot.mbr.asm boot.loader.asm + cp $(OBJDIR)/boot/mbr.bin $(BINDIR)/mbr.bin + cp $(OBJDIR)/boot/loader.bin $(BINDIR)/loader.bin + +all: bootloader kernel + diff --git a/Makefile.in b/Makefile.in index 5c26235..3b7a9c6 100644 --- a/Makefile.in +++ b/Makefile.in @@ -22,10 +22,6 @@ CFLAGS=$(CFLAGS1) $(CFLAGS2) $(SFLAG) CC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CINCLUDES) -ASM=nasm -ASMFLAGS= -BOOTFLAGS=-f bin - BINDIR=./build/bin OBJDIR=./build/obj @@ -35,18 +31,6 @@ KERNDIR=kaleid/kernel SYSTDIR=kaleid/system LINXDIR=kaleid/common/test -all: bootloader kernel - -boot.mbr.s: $(BOOTDIR)/mbr.s $(BOOTDIR)/mbr.inc - $(ASM) $(BOOTFLAGS) $(BOOTDIR)/mbr.asm -o $(OBJDIR)/boot/mbr.bin - -boot.loader.s: $(BOOTDIR)/loader.s - $(ASM) $(BOOTFLAGS) $(BOOTDIR)/loader.asm -o $(OBJDIR)/boot/loader.bin - -bootloader: boot.mbr.s boot.loader.s - cp $(OBJDIR)/boot/mbr.bin $(BINDIR)/mbr.bin - cp $(OBJDIR)/boot/loader.bin $(BINDIR)/loader.bin - //----------------------------------------------------------------------------# // TESTING MAKEFILE diff --git a/Makefile.out.2 b/Makefile.out.2 new file mode 100644 index 0000000..1b457e2 --- /dev/null +++ b/Makefile.out.2 @@ -0,0 +1,103 @@ +# 1 "./Makefile.in" +# 1 "" +# 1 "" +# 31 "" +# 1 "/usr/include/stdc-predef.h" 1 3 4 +# 32 "" 2 +# 1 "./Makefile.in" +# 11 "./Makefile.in" +# 1 "./build/preproc.h" 1 +# 12 "./Makefile.in" 2 + +CCNAME="/opt/cross-cc/bin/x86_64-elf-gcc" +CC2NAME=gcc +COPTIM=-O2 +CWARNS=-Wall -Wextra -Wshadow -Wpedantic +CINCLUDES=-isystem./kaleid/include + +CFLAGS1=-std=gnu11 -nostdlib -ffreestanding -mcmodel=large +CFLAGS2=-m64 -masm=intel -mno-red-zone -mno-mmx -mno-sse -mno-sse2 +CFLAGS=$(CFLAGS1) $(CFLAGS2) $(SFLAG) + +CC=$(CCNAME) $(COPTIM) $(CWARNS) $(CFLAGS) $(CINCLUDES) + +ASM=nasm +ASMFLAGS= +BOOTFLAGS=-f bin + +BINDIR=./build/bin +OBJDIR=./build/obj + +BOOTDIR=boot +COMMDIR=kaleid/common +KERNDIR=kaleid/kernel +SYSTDIR=kaleid/system +LINXDIR=kaleid/common/test + +all: bootloader kernel + +boot.mbr.s: $(BOOTDIR)/mbr.s $(BOOTDIR)/mbr.inc + $(ASM) $(BOOTFLAGS) $(BOOTDIR)/mbr.asm -o $(OBJDIR)/boot/mbr.bin + +boot.loader.s: $(BOOTDIR)/loader.s + $(ASM) $(BOOTFLAGS) $(BOOTDIR)/loader.asm -o $(OBJDIR)/boot/loader.bin + +bootloader: boot.mbr.s boot.loader.s + cp $(OBJDIR)/boot/mbr.bin $(BINDIR)/mbr.bin + cp $(OBJDIR)/boot/loader.bin $(BINDIR)/loader.bin + + + + +pseudo_kern: + $(ASM) $(BOOTFLAGS) $(BOOTDIR)/pseudo_kernel.s -o $(OBJDIR)/boot/pkernel.bin + +testing: bootloader pseudo_kern + cat $(BINDIR)/bootloader.bin $(OBJDIR)/boot/pkernel.bin > $(BINDIR)/boot.bin + + + + +COBJDIR=$(OBJDIR)/$(COMMDIR) +LOBJDIR=$(OBJDIR)/$(LINXDIR) + +COMMOBJS=$(COBJDIR)/string.o $(COBJDIR)/status.o $(COBJDIR)/rand.o $(COBJDIR)/memory.o $(COBJDIR)/arith.o $(COBJDIR)/strtol.o $(COBJDIR)/itoa.o $(COBJDIR)/ltoa.o $(COBJDIR)/utoa.o $(COBJDIR)/ultoa.o $(COBJDIR)/atoi.o $(COBJDIR)/atol.o $(COBJDIR)/atou.o $(COBJDIR)/atoul.o + +TCC=$(CC2NAME) $(COPTIM) $(CWARNS) $(CINCLUDES) +KCC=$(CC) -T ./build/kernel.ld -D_OSK_SOURCE -D_KALEID_KERNEL + +comm-convert: + $(KCC) -c $(COMMDIR)/itoa.c -o $(COBJDIR)/itoa.o -D_NEED_ITOA + $(KCC) -c $(COMMDIR)/itoa.c -o $(COBJDIR)/ltoa.o -D_NEED_LTOA + $(KCC) -c $(COMMDIR)/itoa.c -o $(COBJDIR)/utoa.o -D_NEED_UTOA + $(KCC) -c $(COMMDIR)/itoa.c -o $(COBJDIR)/ultoa.o -D_NEED_ULTOA + $(KCC) -c $(COMMDIR)/atoi.c -o $(COBJDIR)/atoi.o -D_NEED_ATOI + $(KCC) -c $(COMMDIR)/atoi.c -o $(COBJDIR)/atol.o -D_NEED_ATOL + $(KCC) -c $(COMMDIR)/atoi.c -o $(COBJDIR)/atou.o -D_NEED_ATOU + $(KCC) -c $(COMMDIR)/atoi.c -o $(COBJDIR)/atoul.o -D_NEED_ATOUL + +common: comm-convert + $(KCC) -c $(COMMDIR)/rand.c -o $(COBJDIR)/rand.o + $(KCC) -c $(COMMDIR)/arith.c -o $(COBJDIR)/arith.o + $(KCC) -c $(COMMDIR)/string.c -o $(COBJDIR)/string.o + $(KCC) -c $(COMMDIR)/status.c -o $(COBJDIR)/status.o + $(KCC) -c $(COMMDIR)/memory.c -o $(COBJDIR)/memory.o + $(KCC) -c $(COMMDIR)/strtol.c -o $(COBJDIR)/strtol.o + +tests: common + $(TCC) -c $(LINXDIR)/test-common.c -o $(LOBJDIR)/test-common.o + $(TCC) $(COMMOBJS) $(LOBJDIR)/test-common.o -o $(BINDIR)/kaleid-common.elf + + + + +KOBJDIR=$(OBJDIR)/$(KERNDIR) + +KERNOBJS=$(KOBJDIR)/init/init.o $(KOBJDIR)/init/table.o $(KOBJDIR)/ke/panic.o $(KOBJDIR)/ke/terminal.o + +kernel: common + $(KCC) -c $(KERNDIR)/init/init.c -o $(KOBJDIR)/init/init.o + $(KCC) -c $(KERNDIR)/init/table.c -o $(KOBJDIR)/init/table.o + $(KCC) -c $(KERNDIR)/ke/panic.c -o $(KOBJDIR)/ke/panic.o + $(KCC) -c $(KERNDIR)/ke/terminal.c -o $(KOBJDIR)/ke/terminal.o + $(KCC) $(CLDSCR) $(COMMOBJS) $(KERNOBJS) -o $(BINDIR)/kaleid-kernel.elf diff --git a/ProjectTree b/ProjectTree index 90c5627..965face 100644 --- a/ProjectTree +++ b/ProjectTree @@ -60,8 +60,6 @@ src/ | | | + kernel/ | | | - | | - kernel.ld - | | | | | + init/ | | | | | | | - init.c @@ -99,6 +97,8 @@ src/ | | | - preproc.h | - iddtool.h + | | + | - kernel.ld | | | + bin/ | + obj/ diff --git a/Readme.md b/Readme.md index 59ac8e9..8e765d1 100644 --- a/Readme.md +++ b/Readme.md @@ -1,6 +1,7 @@ # GNU-GPL OS/K (OS on Kaleid) ### Fully open-source operating system from scratch (WIP), released under the GNU GPL version 3.0 + #### Master Branch For the project plan, see [OS/K Project](https://github.com/orgs/os-k-team/projects/1) diff --git a/boot/elf/elf.c b/boot/elf/elf.c new file mode 100644 index 0000000..1781d7b --- /dev/null +++ b/boot/elf/elf.c @@ -0,0 +1,10 @@ +//----------------------------------------------------------------------------// +// GNU GPL OS/K // +// // +// Authors: spectral` // +// NeoX // +// // +// Desc: ELF64 Parser and Loader // +//----------------------------------------------------------------------------// + +//STUB diff --git a/boot/loader.asm b/boot/loader.asm index ef5bf44..43f5fe8 100644 --- a/boot/loader.asm +++ b/boot/loader.asm @@ -33,6 +33,8 @@ %define volumeLabel bp+0x2b ; Volume Label %define fatTypeLabel bp+0x36 ; File system type + + [BITS 16] [ORG 0x1000] @@ -41,24 +43,19 @@ mov ds, ax ; hm... And ds too mov es, ax ; And es because it is jealous mov [Bootdrv], dl +xor dl, dl jmp 0x0000:main -;; DATA - -Bootdrv db 0 -VGA_HEIGHT dq 0 -VIDEO_MODE dw 0 - ;; GDT WITH DOC GDT64: NULL_SELECTOR: ;; null selector within 64 bits - dw GDT_LENGTH ; limit of GDT - dw GDT64 ; linear address of GDT - dd 0x0 ; + dw GDT_LENGTH ; limit of GDT + dw GDT64 ; linear address of GDT + dd 0x0 ; CODE_SELECTOR: ;; 32-bit code selector (ring 0) - dw 0x0FFFF ; Segment Limit - db 0x0, 0x0, 0x0 ; Base Address + dw 0x0000FFFF ; Segment Limit + db 0x0, 0x0, 0x0 ; Base Address db 10011010b ; |7|6|5|4|3|2|1|0| ; | | | | | | | `----- 1 when segment used. ; | | | | | | `------ 1 when writable. @@ -68,7 +65,7 @@ GDT64: ; | | `---------- DPL !!! 0 for ring 0 ; | `----------- DPL (2/2) ; `------------ 1 if in physical memory, 0 if page fault - db 11001111b ; |7|6|5|4|3|2|1|0| + db 11001111b ; |7|6|5|4|3|2|1|0| ; | | | | | | | `----- Limit 16 ; | | | | | | `------ Limit 17 ; | | | | | `------- Limit 18 @@ -77,11 +74,11 @@ GDT64: ; | | `---------- 0 always ; | `----------- size of data. 1 for 32bits ; `------------ 0 if limit is in Bytes, 1 if it's in pages (4ko) - db 0x0 ; Base Address + db 0x0 ; Base Address DATA_SELECTOR: ;; flat data selector (ring 0) - dw 0x0FFFF ; Segment Limit - db 0x0, 0x0, 0x0 ; Base Address + dw 0x0000FFFF ; Segment Limit + db 0x0, 0x0, 0x0 ; Base Address db 10010010b ; |7|6|5|4|3|2|1|0| ; | | | | | | | `----- 1 when segment used. ; | | | | | | `------ 1 when writable. @@ -91,7 +88,7 @@ GDT64: ; | | `---------- DPL !!! 0 for ring 0 ; | `----------- DPL (2/2) ; `------------ 1 if in physical memory, 0 if page fault - db 10001111b ; |7|6|5|4|3|2|1|0| + db 10001111b ; |7|6|5|4|3|2|1|0| ; | | | | | | | `----- Limit 16 ; | | | | | | `------ Limit 17 ; | | | | | `------- Limit 18 @@ -100,11 +97,11 @@ GDT64: ; | | `---------- 0 always ; | `----------- size of data. 1 for 32bits ; `------------ 0 if limit is in Bytes, 1 if it's in pages (4ko) - db 0x0 ; Base Address + db 0x0 ; Base Address LONG_SELECTOR: ;; 64-bit code selector (ring 0) - dw 0x0FFFF ; Segment Limit - db 0x0, 0x0, 0x0 ; Base Address + dw 0x0000FFFF ; Segment Limit + db 0x0, 0x0, 0x0 ; Base Address db 10011010b ; |7|6|5|4|3|2|1|0| ; | | | | | | | `----- 1 when segment used. ; | | | | | | `------ 1 when writable. @@ -114,7 +111,7 @@ GDT64: ; | | `---------- DPL !!! 0 for ring 0 ; | `----------- DPL (2/2) ; `------------ 1 if in physical memory, 0 if page fault - db 10101111b ; |7|6|5|4|3|2|1|0| + db 10101111b ; |7|6|5|4|3|2|1|0| ; | | | | | | | `----- Limit 16 ; | | | | | | `------ Limit 17 ; | | | | | `------- Limit 18 @@ -123,13 +120,15 @@ GDT64: ; | | `---------- 0 always ; | `----------- size of data. 1 for 32bits ; `------------ 0 if limit is in Bytes, 1 if it's in pages (4ko) - db 0x0 ; Base Address + db 0x0 ; Base Address GDT_LENGTH: %include "boot/loader16.inc" main: + ;; compatibility check + push si mov si, Init call PrintB pop si @@ -138,8 +137,10 @@ main: push si mov si, Pass call PrintB + pop si ;; Enabling A20 + push si mov si, EnA20 call PrintB pop si @@ -149,11 +150,12 @@ main: push si mov si, Pass call PrintB + pop si ;; DISABLING CURSOR BLINKING AND GETTING INFOS call get_dimensions call disable_cursor - + ;;GO GDT64 cli ; disable interrupts lgdt [GDT64] @@ -172,15 +174,35 @@ main: push dword [VIDEO_MODE] push dword [VGA_HEIGHT] jmp (CODE_SELECTOR-GDT64):main32 + +ErrorNo64: + mov si, NoLongMode + call PrintB +Die: + cli + hlt ; die nooooow + jmp 0xF000:0xFFF0 [BITS 32] -VIDEO_MODE32 dw 0 -VGA_HEIGHT32 dw 0 - main32: pop dword [VGA_HEIGHT32] pop dword [VIDEO_MODE32] + ;; VERIFY A20 + pushad + mov edi,0x112345 ;odd megabyte address. + mov esi,0x012345 ;even megabyte address. + mov [esi],esi ;making sure that both addresses contain diffrent values. + mov [edi],edi ;(if A20 line is cleared the two pointers would point to the address 0x012345 that would contain 0x112345 (edi)) + cmpsd ;compare addresses to see if the're equivalent. + popad + jne .A20_on ;if not equivalent , A20 line is set. + mov WORD [A20_OK], 0 + jmp .A20_end +.A20_on: + mov BYTE [A20_OK], 1 +.A20_end: + ;; INITIALIZE PROTECTED MODE SEGMENT REGISTERS mov ax, DATA_SELECTOR-GDT64 mov ds, ax @@ -239,18 +261,33 @@ main32: %include "boot/loader64.inc" ;; DATA -txt db 0x09, " Switching to Long Mode... ", 0 Init db "Booting OS/K !", 0x0D, 0x0A, 0x0D, 0x0A, 0x09, " Checking CPUID...",0 -Reinit db "Booting OS/K !", 0x0D, 0x0A, 0x0D, 0x0A, 0 CPUIDD db 0x09, " Checking CPUID...", 0 EnA20 db 0x09, " Enabling A20 line...", 0 -NoLongMode db 0x0A, 0x0D, "ERROR : Your computer is not designed for x64 OS", 0 +ReadAttempt db 0x09, " Attempt to read a sector with ATA commands...", 0x0A, 0x0D, 0x0A, 0x0D,0 +txt db 0x09, " Switching to Long Mode... ", 0 +Reinit db "Booting OS/K !", 0x0D, 0x0A, 0x0D, 0x0A, 0 Pass db " OK", 0x0A, 0x0D, 0 +Fail db " FAIL!", 0x0A, 0x0D, 0 +msg db "The system is now in x64 mode. Is this not beautiful ?", 0x0A, 0x0D, 0 + +NoLongMode db 0x0A, 0x0D, "ERROR : Your computer is not designed for x64 OS", 0 +FileNotFound db "Second Stage Error : The Kernel was not found.", 0x0A, 0x0D, 0 +DiskError db "Second Stage Error : The Disk has crashed.", 0x0A, 0x0D, 0 + +filename db "KERNEL BIN" + +Bootdrv db 0 +UserData dw 0 +VGA_HEIGHT dq 0 +VIDEO_MODE dw 0 +VIDEO_MODE32 dw 0 +VGA_HEIGHT32 dw 0 NextTRAM dq 0x0B8000 ; Last position of cursor VIDEO_MODE64 dq 0 VGA_HEIGHT64 dq 0 -VGA_X dq 0x0 -msg db "The system is now in x64 mode. Is this not beautiful ?", 0x0A, 0x0D, 0 +VGA_X dq 0 +A20_OK db 0 main64: pop qword [VGA_HEIGHT64] @@ -277,10 +314,17 @@ main64: mov esi, EnA20 call write + cmp BYTE [A20_OK], 1 + je .A20Success + mov bl, 0x0C + mov esi, Fail + call write + jmp Die +.A20Success: mov bl, 0x0A mov esi, Pass call write - + mov bl, 0x0F mov esi, txt call write @@ -292,14 +336,22 @@ main64: mov bl, 0x0D mov esi, msg call write - + + mov bl, 0x0F + mov esi, ReadAttempt + call write + + mov rcx, 2 +.looping: + nop + nop + nop + loop .looping ; Temporized because the ATA drive must be ready + + call ata_read + jmp Die - -[BITS 16] -ErrorNo64: - mov si, NoLongMode - call PrintB -Die: - cli - hlt ; die nooooow - jmp 0xF000:0xFFF0 + + ; times 1024 nop + ; XXX ; + ; It seems impossible to have an executable > 2.0 kB... diff --git a/boot/loader64.inc b/boot/loader64.inc index f6611fb..28d8145 100644 --- a/boot/loader64.inc +++ b/boot/loader64.inc @@ -71,6 +71,129 @@ write: pop rax jmp .pLoop .scroll: - ; XXX ; + ; XXX I don't think I'll implement this, but never know...; jmp .pLoop + +dump: +;-----------------------------------------------------------------------; +; x64/LM Dump Printing Functions ; +; bl : color code ; +; esi : string address ; +;-----------------------------------------------------------------------; + mov edi, [NextTRAM] ; TRAM ADDRESS + push rsi + push rdi + push rcx + mov rcx, 512 +.pLoop: + lodsb + stosb ; text subpixel + mov al, bl + stosb ; color subpixel + add qword [NextTRAM], 0x2 ; Cursor moving + add qword [VGA_X], 0x2 ; coord + 2 because 2 subpixels + loop .pLoop + pop rcx + pop rdi + pop rsi + ret +ata_read: +;-----------------------------------------------------------------------; +; x64/LM ATA Reading function ; +; ; +; ; +;-----------------------------------------------------------------------; + +; Technical infos about the ports (Intel Doc): +; +; Port Access Mode Misc +; +; 1f0 r/w Data register, the bytes of the disk itself +; 1f1 r Error register that can be handled +; 1f2 r/w Sector count, how many sectors to read +; 1f3 r/w Sector number, the actual sector wanted +; 1f4 r/w Cylinder low, cylinders is 0-1024 +; 1f5 r/w Cylinder high, this makes up the rest of the 1024 +; 1f6 r/w Drive/head +; bit 7 = 1 +; bit 6 = 0 +; bit 5 = 1 +; bit 4 = 0 drive 0 select +; = 1 drive 1 select +; bit 3-0 head select bits +; 1f7 r Status register +; bit 7 = 1 controller is executing a command +; bit 6 = 1 drive is ready +; bit 5 = 1 write fault +; bit 4 = 1 seek complete +; bit 3 = 1 sector buffer requires servicing +; bit 2 = 1 disk data read corrected +; bit 1 = 1 index - set to 1 each revolution +; bit 0 = 1 previous command ended in an error +; 1f7 w Command register +; commands: +; 50h format track +; 20h read sectors with retry +; 21h read sectors without retry +; 22h read long with retry +; 23h read long without retry +; 30h write sectors with retry +; 31h write sectors without retry +; 32h write long with retry +; 33h write long without retry +; + + push rax + push rbx + push rdx + push rcx + push rdi + mov dx,1f6h ;Drive and head port + mov al,0a0h ;Drive 0, head 0 + out dx,al + + mov dx,1f2h ;Sector count port + mov al,1 ;Read one sector + out dx,al + + mov dx,1f3h ;Sector number port + mov al,1 ;Read sector one + out dx,al + + mov dx,1f4h ;Cylinder low port + mov al,0 ;Cylinder 0 + out dx,al + + mov dx,1f5h ;Cylinder high port + mov al,0 ;The rest of the cylinder 0 + out dx,al + + mov dx,1f7h ;Command port + mov al,20h ;Read with retry. + out dx,al +still_going: + in al,dx + test al,8 ;This means the sector buffer requires + ;servicing. + jz still_going ;Don't continue until the sector buffer + ;is ready. + + mov cx,512/2 ;One sector /2 + mov rdi,buffer + mov dx,1f0h ;Data port - data comes in and out of here. + rep insw + pop rdi + pop rcx + pop rdx + pop rbx + pop rax + mov bl, 0x0F + mov esi, buffer + call dump + mov bl, 0x0A + mov esi, end + call write + ret + buffer: times 512 db "_" + end: db "[End of Sector]", 0x0 diff --git a/boot/mbr.inc b/boot/mbr.inc index 0efe8d4..dc11db1 100644 --- a/boot/mbr.inc +++ b/boot/mbr.inc @@ -7,6 +7,7 @@ ; Desc: Bootsector for OS/K INCLUDED FUNCTIONS ; ; (x86_64 architecture only) ; ;=----------------------------------------------------------------------------=; +[BITS 16] read_clusters: ;---------------------------------------------------; @@ -100,7 +101,7 @@ read_sectors: shl ah, 1 or cl, ah ; Now cx is set with respective track and sector numbers mov dl, byte [Bootdrv] ; Set correct Bootdrv for int 13h - mov di, 5 ; Try five times to read the sector because i love 5 + mov di, 21 ; Try five times to read the sector because i love 21 .attempt_read: mov ax, 0x0201 ; Read Sectors func of int 13h, read one sector int 0x13 ; Call int 13h (BIOS disk I/O) diff --git a/build/bin/disk.img b/build/bin/disk.img index beefdec..087b3f3 100644 Binary files a/build/bin/disk.img and b/build/bin/disk.img differ diff --git a/build/bin/loader.bin b/build/bin/loader.bin index 0887d7c..096e80a 100644 Binary files a/build/bin/loader.bin and b/build/bin/loader.bin differ diff --git a/build/bin/mbr.bin b/build/bin/mbr.bin index bb5a870..37ff74f 100644 Binary files a/build/bin/mbr.bin and b/build/bin/mbr.bin differ diff --git a/build/obj/boot/loader.bin b/build/obj/boot/loader.bin index 0887d7c..096e80a 100644 Binary files a/build/obj/boot/loader.bin and b/build/obj/boot/loader.bin differ diff --git a/build/obj/boot/mbr.bin b/build/obj/boot/mbr.bin index bb5a870..37ff74f 100644 Binary files a/build/obj/boot/mbr.bin and b/build/obj/boot/mbr.bin differ diff --git a/kaleid/common/atoi.c b/kaleid/common/atoi.c index f5a22a6..0ea016c 100644 --- a/kaleid/common/atoi.c +++ b/kaleid/common/atoi.c @@ -15,9 +15,9 @@ // #define _ATOI_IMPL(_Name, _Type, _Func) \ _Type _Name(const char *str) { \ - error_t old = errno; \ + __get_errno(old); \ _Type ret = (_Type)_Func(str, NULL, 0); \ - errno = old; \ + __set_errno(old); \ return ret; \ } diff --git a/kaleid/common/status.c b/kaleid/common/status.c index 457e741..2866833 100644 --- a/kaleid/common/status.c +++ b/kaleid/common/status.c @@ -9,7 +9,7 @@ #include -error_t errno = 0; +error_t __errno = 0; /* static const char *descriptions[] = { @@ -17,7 +17,7 @@ static const char *descriptions[] = { [-FAILED] = "Failed (no precision)", [-NOT_PERMITTED] = "Operation not permitted", [-ACCESS_DENIED] = "Access denied", - + [-BAD_ARGUMENT] = "Bad argument", [-BAD_ARG_RANGE] = "Bad argument (not in range)", [-BAD_ARG_NULL] = "Bad argument (null pointer)", diff --git a/kaleid/common/strtol.c b/kaleid/common/strtol.c index 2e1aad6..7636822 100644 --- a/kaleid/common/strtol.c +++ b/kaleid/common/strtol.c @@ -13,7 +13,7 @@ long strtol(const char *str, char **endp, int base) { (void)str; (void)endp; (void)base; - errno = ENOSYS; + __set_errno(ENOSYS); return 0; } @@ -21,7 +21,7 @@ ulong strtoul(const char *str, char **endp, int base) { (void)str; (void)endp; (void)base; - errno = ENOSYS; + __set_errno(ENOSYS); return 0; } diff --git a/kaleid/include/common/kalcrt.h b/kaleid/include/common/kalcrt.h index 75e34e1..167ab52 100644 --- a/kaleid/include/common/kalcrt.h +++ b/kaleid/include/common/kalcrt.h @@ -43,7 +43,24 @@ typedef struct { long quot, rem; } ldiv_t; // Global variables // //------------------------------------------// -extern error_t errno; +#ifndef _KALEID_KERNEL + +extern error_t __errno; + +#ifndef errno +#define errno __errno +#endif + +#define __get_errno(x) error_t x = errno; +#define __set_errno(x) (errno = (x)) + +#else + +#define errno +#define __get_errno(x) +#define __set_errno(x) + +#endif //------------------------------------------// // Macros // diff --git a/kaleid/include/kernel/kernbase.h b/kaleid/include/kernel/kernbase.h index 171c048..baf8e95 100644 --- a/kaleid/include/kernel/kernbase.h +++ b/kaleid/include/kernel/kernbase.h @@ -184,7 +184,8 @@ void WriteByteOnPort(port_t port, port_t val) static inline uchar ReadByteFromPort(port_t port) { - errno = ENOSYS; + + KalAssert(FALSE && ENOSYS); (void)port; return 0; } @@ -192,7 +193,7 @@ uchar ReadByteFromPort(port_t port) static inline ushort ReadWordFromPort(port_t port) { - errno = ENOSYS; + KalAssert(FALSE && ENOSYS); (void)port; return 0; }