I'm fifth grade elementary school student.(from korea) I'm making OS,but I found bug.I can't know why.Please help me!

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
SunuHwang
Posts: 6
Joined: Sat Apr 18, 2026 1:40 am

I'm fifth grade elementary school student.(from korea) I'm making OS,but I found bug.I can't know why.Please help me!

Post by SunuHwang »

Hello Everyone!
I made OS,but There's bug!
The bug is, editor(this OS have editor and brainfuck interprinter) print only S.
If there's no bug, editor'll print what user input.
I use this script for build, linking,run.:

Code: Select all

# 1. 기존 파일 청소
rm -f *.o *.bin *.img && \
\
# 2. 어셈블리 컴파일 (io.asm은 반드시 elf32 포맷)
nasm -f bin boot.asm -o boot.bin && \
nasm -f elf32 io.asm -o io.o && \
\
# 3. C 파일 컴파일 (핵심 옵션: -mregparm=0 추가)
# 이 옵션이 있어야 C에서 넘긴 인자가 스택 [bp+4] 위치에 정확히 들어갑니다.
gcc -m16 -ffreestanding -fno-stack-protector -fno-PIC -mregparm=0 -c main.c edit.c bf.c && \
\
# 4. 커널 링크 (main.o가 반드시 맨 앞!!)
ld -m elf_i386 -Ttext 0x8000 -e main --oformat binary main.o edit.o bf.o io.o -o kernel.bin && \
\
# 5. OS 이미지 생성 및 플로피 규격(1.44MB) 맞추기
cat boot.bin kernel.bin > os.img && \
truncate -s 1440k os.img && \
\
# 6. QEMU 실행 (즉시 결과 확인)
qemu-system-i386 -drive format=raw,file=os.img
I try to find why editor only print S in some hour,but I can't know.
I try to print constant like A,but only print S.
Please help me!
My github link is:https://github.com/sunuhwang/MyOS/tree/main
Please tell me in github issue!
Thanks to read this post,.
Goodbye! have a nice Day!
Last edited by SunuHwang on Sat Apr 18, 2026 7:53 am, edited 1 time in total.
SunuHwang
Posts: 6
Joined: Sat Apr 18, 2026 1:40 am

Re: I'm fifth grade elementary school student.(from korea) I'm making OS,but I found bug.I can't know why.Please help me

Post by SunuHwang »

Oh, I found Clue!
In boot.asm, [bits 16] is in front of [org 0x7c00]!
I don't know well about it,
but I Guess the reason related it.
So, I'll update code and test it.
SunuHwang
Posts: 6
Joined: Sat Apr 18, 2026 1:40 am

Re: I'm fifth grade elementary school student.(from korea) I'm making OS,but I found bug.I can't know why.Please help me

Post by SunuHwang »

I change [org 0x7c00] and [bits 16], but....
bug is still exist.
but once this bug will be fixed!
nullplan
Member
Member
Posts: 2034
Joined: Wed Aug 30, 2017 8:24 am

Re: I'm fifth grade elementary school student.(from korea) I'm making OS,but I found bug.I can't know why.Please help me

Post by nullplan »

Those declarations can appear in any order. They have no effect on each other. The org directive merely sets the initial position counter, and the bits declaration sets the operating mode for the following code.
Carpe diem!
SunuHwang
Posts: 6
Joined: Sat Apr 18, 2026 1:40 am

Re: I'm fifth grade elementary school student.(from korea) I'm making OS,but I found bug.I can't know why.Please help me

Post by SunuHwang »

Thanks to read my post!
Thanks to teach me.
Have a nice day!
SunuHwang
Posts: 6
Joined: Sat Apr 18, 2026 1:40 am

Re: I'm fifth grade elementary school student.(from korea) I'm making OS,but I found bug.I can't know why.Please help me

Post by SunuHwang »

Hmm...
I hardcoded the constant value, but it still prints 'S', so I suspect a calling convention issue.
Can you tell me about it?
SunuHwang
Posts: 6
Joined: Sat Apr 18, 2026 1:40 am

Re: I'm fifth grade elementary school student.(from korea) I'm making OS,but I found bug.I can't know why.Please help me

Post by SunuHwang »

Oh, I found clue!(I think exaully)
in my code, kernel.bin is in 0x8000,but stack is 0x9000!
I think kernel override stack.
how about you?
nullplan
Member
Member
Posts: 2034
Joined: Wed Aug 30, 2017 8:24 am

Re: I'm fifth grade elementary school student.(from korea) I'm making OS,but I found bug.I can't know why.Please help me

Post by nullplan »

How big is your code? I mean, yes, you can move the stack to 0x7C00 (then it will grow into an area you are not currently using), and you can do that quickly, since you only need to change a single line, but unless you either actually are using 4kB of stack space, or 4kB of code space, that is also not your issue. But may as well move the stack and see if the issue changes.

I would suggest using a debugger to find out what the argument of the print function evaluates to.
Carpe diem!
Tomrs123
Member
Member
Posts: 48
Joined: Mon Aug 19, 2024 11:12 am
GitHub: https://github.com/ilikecoding-197

Re: I'm fifth grade elementary school student.(from korea) I'm making OS,but I found bug.I can't know why.Please help me

Post by Tomrs123 »

You heavily assume the compiler will work correctly. First, `-m16` support is very dodgy (might include 32-bit features). You also assume the compiler will put main.c's main at the start, which I'm pretty sure it is (using some disassembly).

Overall, to be honest, your code is.. flawed. Not to be mean or anything, just honest; you're better off following a Bare-Bones tutorial and follow multiboot. It will be better in the long run (especially using full 32-bit instead of weird gcc 16-bit)
Octocontrabass
Member
Member
Posts: 6248
Joined: Mon Mar 25, 2013 7:01 pm

Re: I'm fifth grade elementary school student.(from korea) I'm making OS,but I found bug.I can't know why.Please help me

Post by Octocontrabass »

Tomrs123 wrote: Wed May 06, 2026 7:14 pmFirst, `-m16` support is very dodgy (might include 32-bit features).
There's nothing dodgy about -m16, but it may not do what you expect. It tells the compiler to generate the same code as -m32, except the code will run with 16-bit segments instead of 32-bit segments. (This means a 32-bit CPU is required.)
Post Reply