Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v86 compatibility. #13

Open
zap8600 opened this issue Aug 7, 2023 · 18 comments
Open

v86 compatibility. #13

zap8600 opened this issue Aug 7, 2023 · 18 comments

Comments

@zap8600
Copy link

zap8600 commented Aug 7, 2023

I would like to boot sectorc in the web with v86, but it can't read the image when loading as a hard drive. Is there any way to put sectorc.bin into a .img file?

@zap8600
Copy link
Author

zap8600 commented Aug 7, 2023

Update: I fixed the issue by loading it as a floppy image instead. However, I want to know how I can send the files over serial manually instead of through cat $@ | qemu-system-i386 -hda build/sectorc.bin -serial stdio. I believe it is sent through serial, so how can I send it the C code manually?

@xorvoid
Copy link
Owner

xorvoid commented Aug 7, 2023

This is a pretty cool idea! I'd be more than happy to add a little interactive app to my website and give you attribution.

Honestly, I'm not sure the best way. I selected serial port because that was just a simple way to work with QEMU.

Other "sector languages" (sectorforth and sectorlisp) drop you into a REPL, IIRC.

C traditionally never had a REPL so that felt inappropriate.

I'm happy to advise on other approaches to do I/O if the serial interface can't be made to work.

FWIW I'm not very familiar with v86 and what capabilities it provides.

@xorvoid
Copy link
Owner

xorvoid commented Aug 7, 2023

"x86 virtualization in your browser, recompiling x86 to wasm on the fly"

I haven't dug that deep but reading between the lines, it looks like the goal is targeted at modern x86 software? SectorC is 16-bit real mode code that leans on the Bios a bit. However, it's not a lot. The compiler itself uses hardly any of it. The examples use a lot it and the original IBM hardware emulation (this is mostly because it makes the examples more fun: who doesn't love graphics and audio! 😁)

So there's a couple avenues to explore: (1) add a few small bits of bios support, (2) get a full bios from some other project (e.g. dosbox), (3) rip out the bios parts from SectorC (which means that you probably loose the cool example code)

Personally I think having SectorC able to use these bios functions to be a big part of what makes it fun. You could do a lot with a little code on these early machines. Modern machines instead require big long complicated boiler-plate setup routines before you can do anything interesting with the hardware. Having to do that is SectorC's dialect of C would be not fun.

@zap8600
Copy link
Author

zap8600 commented Aug 7, 2023

This is a pretty cool idea! I'd be more than happy to add a little interactive app to my website and give you attribution.

Honestly, I'm not sure the best way. I selected serial port because that was just a simple way to work with QEMU.

Other "sector languages" (sectorforth and sectorlisp) drop you into a REPL, IIRC.

C traditionally never had a REPL so that felt inappropriate.

I'm happy to advise on other approaches to do I/O if the serial interface can't be made to work.

FWIW I'm not very familiar with v86 and what capabilities it provides.

I understand the use of serial instead of something like a REPL. I have an idea, but im not sure if it would be possible, so I'll wait. I have a question about how it receives input. Does it fail if it doesn't receive input immediately? And when does it know when there is no more code? Is there a character that gets sent that indicates the end of the code?

@xorvoid
Copy link
Owner

xorvoid commented Aug 7, 2023

It keeps retrying serial read until it gets a character.

It stops compiling when it finishes compiling the _start() function.

And then it jumps into the compiled code.

You could.. in theory then build a stage2 compiler for x86-64 and read that source in next (but I haven't done that)

Currently it just ignores whatever follows the _start() function.

@zap8600
Copy link
Author

zap8600 commented Aug 7, 2023

Thanks. This should help me get it working in v86. Also, v86 does support 16-bit real mode. All modern computers (including 64-bit) require it, so v86 requires it as well, meaning sectorc should be able to run in v86.

@xorvoid
Copy link
Owner

xorvoid commented Aug 7, 2023

Oh, excellent! Keep me in the loop. I'm excited to see this working!!

@zap8600
Copy link
Author

zap8600 commented Aug 7, 2023

While I'm working on this, I'm going to present my idea. My idea was to let the user type in (through PS/2) all the C code to compile. Then when they input something like CTRL+S, it'll compile and run.

@xorvoid
Copy link
Owner

xorvoid commented Aug 7, 2023

You can do that. But be aware that the compiler does basically no error checking. One small typo leads to issues.

You might consider running the "lint" app on the web front end to improve the user experience.

@zap8600
Copy link
Author

zap8600 commented Aug 7, 2023

You can do that. But be aware that the compiler does basically no error checking. One small typo leads to issues.

You might consider running the "lint" app on the web front end to improve the user experience.

Are you saying that the website would have an editor that creates the files and sends them over serial to the compiler?

@xorvoid
Copy link
Owner

xorvoid commented Aug 8, 2023

What I'm saying is that it'll be incredibly hard (as a user) to use it directly from the keyboard. That's why I didn't do it that way originally.

I have a hard enough time in ordinary C avoiding syntax errors. Compilers are very good at diagnostics. SectorC is Very Bad at diagnostics.

@zap8600
Copy link
Author

zap8600 commented Aug 8, 2023

What I'm saying is that it'll be incredibly hard (as a user) to use it directly from the keyboard. That's why I didn't do it that way originally.

I have a hard enough time in ordinary C avoiding syntax errors. Compilers are very good at diagnostics. SectorC is Very Bad at diagnostics.

I see where you are going with this now. I don't know why I didn't originally see this. Sorry, sometimes I'm just really dumb. I'll get to working on this.

@zap8600
Copy link
Author

zap8600 commented Aug 8, 2023

In theory, this should be working. However, nothing seems to be happening. I'm not sure why. I'll upload all the files required for running this in case you would like to experiment.
sectorc.zip

@xorvoid
Copy link
Owner

xorvoid commented Aug 9, 2023 via email

@zap8600
Copy link
Author

zap8600 commented Aug 9, 2023

Could you put it in a git repo somewhere? I’m careful to avoid random files from email. You can just create a branch in the SectorC repo if you like.

On Tue, Aug 8, 2023 at 2:06 PM zap8600 @.> wrote: In theory, this should be working. However, nothing seems to be happening. I'm not sure why. I'll upload all the files required for running this in case you would like to experiment. sectorc.zip https://github.com/xorvoid/sectorc/files/12295017/sectorc.zip — Reply to this email directly, view it on GitHub <#13 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOKLWCUXR7PRT5ZYAEPBBNLXUKE47ANCNFSM6AAAAAA3HDKKIY . You are receiving this because you commented.Message ID: @.>

I understand. I forked the repo and made a web branch. However, I'm not exactly sure how to add the branch via pull request.

@xorvoid
Copy link
Owner

xorvoid commented Aug 16, 2023

The serial send function isn't working with it:

A simple test with a simple x86-16 program:

001   bits 16
002   cpu 386
003 
004   mov ax,0xb800
005   mov es,ax
006 
007   mov word es:0, 0xf41
008 
009   call getch_tryagain
010 
011   or ax,0xf00
012   mov word es:2, ax
013 
014   mov word es:4, 0xf42
015 
016   ;; mov ax,'A'                                                                                                                                                                                                                                                                         
017   ;; mov ah,1                                                                                                                                                                                                                                                                           
018   ;; mov dx,0                                                                                                                                                                                                                                                                           
019   ;; int 0x14                                                                                                                                                                                                                                                                           
020 
021 halt:
022   jmp halt
023 
024 getch_tryagain:
025   push dx                       ; need to save dx because tok_next uses it for flags                                                                                                                                                                                                    
026   mov ax,0x0200
027   xor dx,dx
028   int 0x14                      ; get a char from serial (bios function)                                                                                                                                                                                                                
029 
030   and ah,0x80                   ; check for failure and clear ah as a side-effect                                                                                                                                                                                                       
031   jne getch_tryagain            ; failed, try again later                                                                                                                                                                                                                               
032 
033 getch_done:
034   pop dx
035   ret
036 
037 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;                                                                                                                                                                                                                  
038 ;;; boot signature                                                                                                                                                                                                                                                                      
039 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;                                                                                                                                                                                                                  
040   times 510-($-$$) db 0
041   db 0x55, 0xaa
emulator.serial0_send('G');

The program hangs after writing an A to the screen.

@zap8600
Copy link
Author

zap8600 commented Aug 17, 2023

I'll make an issue about this.

@zap8600
Copy link
Author

zap8600 commented Aug 17, 2023

I think we might need to add a listener like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants