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

Make standalone kernel actually standalone #58

Merged
merged 51 commits into from
Nov 27, 2019
Merged

Make standalone kernel actually standalone #58

merged 51 commits into from
Nov 27, 2019

Conversation

tomaka
Copy link
Owner

@tomaka tomaka commented Nov 24, 2019

cc #57

It is not possible to finish this PR.
It is mostly here for notes taking (i.e. looking at the changes later).

@tomaka
Copy link
Owner Author

tomaka commented Nov 25, 2019

Unfortunately it seems that the spin library doesn't compile for thumbv6m-none-eabi despite being no_std.

@tomaka tomaka marked this pull request as ready for review November 25, 2019 19:38
@tomaka tomaka changed the title Work-in-progress for no_std core Make core compile for no_std Nov 25, 2019
@tomaka
Copy link
Owner Author

tomaka commented Nov 25, 2019

For a reason I don't understand, trying to compile the freestanding kernel yields:

error: cannot produce bin for nametbd-standalone-kernel v0.1.0 (/home/pierre/Projets/os/kernel/standalone) as the target x86_64-unknown-none does not support these crate types

Even when I run rustc +nightly -Z unstable-options --print target-spec-json and copy-paste the result in the .json file, I get the same error.

EDIT: there was apparently some caching issue; cleaning my target directory fixed it

@tomaka
Copy link
Owner Author

tomaka commented Nov 25, 2019

Now running into:

LLVM ERROR: Do not know how to split the result of this operator!

rust-lang/rust#61721

This seems to be caused by +soft-float. Disabling this feature leads to linking errors instead.

@tomaka
Copy link
Owner Author

tomaka commented Nov 25, 2019

Notes for anyone who might find this page on Google:

I got rid of the __libc_csu_init, __libc_csu_fini and __libc_start_main symbols by passing -nostdlib to the linker.
aa1a0f7

@tomaka tomaka changed the title Make core compile for no_std Make standalone kernel actually standalone Nov 25, 2019
@tomaka
Copy link
Owner Author

tomaka commented Nov 25, 2019

If the #[start] function isn't named _start with #[no_mangle] then everything gets stripped 🤔

Also, the following is generated for the main function, which is clearly wrong:

0000000000401010 <_ZN25nametbd_standalone_kernel4main17ha1b358a6a4062b4eE>:
  401010:       48 c7 04 25 c0 0f 00    movq   $0x0,0xfc0
  401017:       00 00 00 00 00 
  40101c:       48 c7 04 25 80 0f 00    movq   $0xfc0,0xf80
  401023:       00 c0 0f 00 00 
  401028:       48 c7 04 25 40 0f 00    movq   $0xf80,0xf40
  40102f:       00 80 0f 00 00 
  401034:       48 c7 04 25 00 0f 00    movq   $0xf40,0xf00
  40103b:       00 40 0f 00 00 
  401040:       48 c7 04 25 c0 0e 00    movq   $0xf00,0xec0
  401047:       00 00 0f 00 00 
  40104c:       48 c7 04 25 80 0e 00    movq   $0xec0,0xe80
  401053:       00 c0 0e 00 00 
  401058:       48 c7 04 25 40 0e 00    movq   $0xe80,0xe40
  40105f:       00 80 0e 00 00 
  401064:       48 c7 04 25 00 0e 00    movq   $0xe40,0xe00
  40106b:       00 40 0e 00 00 
  401070:       48 c7 04 25 c0 0d 00    movq   $0xe00,0xdc0
  401077:       00 00 0e 00 00 
  40107c:       48 c7 04 25 80 0d 00    movq   $0xdc0,0xd80
  401083:       00 c0 0d 00 00 
  401088:       48 c7 04 25 40 0d 00    movq   $0xd80,0xd40
  40108f:       00 80 0d 00 00 
  401094:       48 c7 04 25 00 0d 00    movq   $0xd40,0xd00
  40109b:       00 40 0d 00 00 
  4010a0:       48 c7 04 25 c0 0c 00    movq   $0xd00,0xcc0
  4010a7:       00 00 0d 00 00 
  4010ac:       48 c7 04 25 80 0c 00    movq   $0xcc0,0xc80
  4010b3:       00 c0 0c 00 00 
  4010b8:       48 c7 04 25 40 0c 00    movq   $0xc80,0xc40
  4010bf:       00 80 0c 00 00 
  4010c4:       48 c7 04 25 00 0c 00    movq   $0xc40,0xc00
  4010cb:       00 40 0c 00 00 
  4010d0:       48 c7 04 25 c0 0b 00    movq   $0xc00,0xbc0
  4010d7:       00 00 0c 00 00 
  4010dc:       48 c7 04 25 80 0b 00    movq   $0xbc0,0xb80
  4010e3:       00 c0 0b 00 00 
  4010e8:       48 c7 04 25 40 0b 00    movq   $0xb80,0xb40
  4010ef:       00 80 0b 00 00 
  4010f4:       48 c7 04 25 00 0b 00    movq   $0xb40,0xb00
  4010fb:       00 40 0b 00 00 
  401100:       48 c7 04 25 c0 0a 00    movq   $0xb00,0xac0
  401107:       00 00 0b 00 00 
  40110c:       48 c7 04 25 80 0a 00    movq   $0xac0,0xa80
  401113:       00 c0 0a 00 00 
  401118:       48 c7 04 25 40 0a 00    movq   $0xa80,0xa40
  40111f:       00 80 0a 00 00 
  401124:       48 c7 04 25 00 0a 00    movq   $0xa40,0xa00
  40112b:       00 40 0a 00 00 
  401130:       48 c7 04 25 c0 09 00    movq   $0xa00,0x9c0
  401137:       00 00 0a 00 00 
  40113c:       48 c7 04 25 80 09 00    movq   $0x9c0,0x980
  401143:       00 c0 09 00 00 
  401148:       48 c7 04 25 40 09 00    movq   $0x980,0x940
  40114f:       00 80 09 00 00 
  401154:       48 c7 04 25 00 09 00    movq   $0x940,0x900
  40115b:       00 40 09 00 00 
  401160:       48 c7 04 25 c0 08 00    movq   $0x900,0x8c0
  401167:       00 00 09 00 00 
  40116c:       48 c7 04 25 80 08 00    movq   $0x8c0,0x880
  401173:       00 c0 08 00 00 
  401178:       48 c7 04 25 40 08 00    movq   $0x880,0x840
  40117f:       00 80 08 00 00 
  401184:       48 c7 04 25 00 08 00    movq   $0x840,0x800
  40118b:       00 40 08 00 00 
  401190:       48 c7 04 25 c0 07 00    movq   $0x800,0x7c0
  401197:       00 00 08 00 00 
  40119c:       48 c7 04 25 80 07 00    movq   $0x7c0,0x780
  4011a3:       00 c0 07 00 00 
  4011a8:       48 c7 04 25 40 07 00    movq   $0x780,0x740
  4011af:       00 80 07 00 00 
  4011b4:       48 c7 04 25 00 07 00    movq   $0x740,0x700
  4011bb:       00 40 07 00 00 
  4011c0:       48 c7 04 25 c0 06 00    movq   $0x700,0x6c0
  4011c7:       00 00 07 00 00 
  4011cc:       48 c7 04 25 80 06 00    movq   $0x6c0,0x680
  4011d3:       00 c0 06 00 00 
  4011d8:       48 c7 04 25 40 06 00    movq   $0x680,0x640
  4011df:       00 80 06 00 00 
  4011e4:       48 c7 04 25 00 06 00    movq   $0x640,0x600
  4011eb:       00 40 06 00 00 
  4011f0:       48 c7 04 25 c0 05 00    movq   $0x600,0x5c0
  4011f7:       00 00 06 00 00 
  4011fc:       48 c7 04 25 80 05 00    movq   $0x5c0,0x580
  401203:       00 c0 05 00 00 
  401208:       48 c7 04 25 40 05 00    movq   $0x580,0x540
  40120f:       00 80 05 00 00 
  401214:       48 c7 04 25 00 05 00    movq   $0x540,0x500
  40121b:       00 40 05 00 00 
  401220:       48 c7 04 25 c0 04 00    movq   $0x500,0x4c0
  401227:       00 00 05 00 00 
  40122c:       48 c7 04 25 80 04 00    movq   $0x4c0,0x480
  401233:       00 c0 04 00 00 
  401238:       48 c7 04 25 40 04 00    movq   $0x480,0x440
  40123f:       00 80 04 00 00 
  401244:       48 c7 04 25 00 04 00    movq   $0x440,0x400
  40124b:       00 40 04 00 00 
  401250:       48 c7 04 25 c0 03 00    movq   $0x400,0x3c0
  401257:       00 00 04 00 00 
  40125c:       48 c7 04 25 80 03 00    movq   $0x3c0,0x380
  401263:       00 c0 03 00 00 
  401268:       48 c7 04 25 40 03 00    movq   $0x380,0x340
  40126f:       00 80 03 00 00 
  401274:       48 c7 04 25 00 03 00    movq   $0x340,0x300
  40127b:       00 40 03 00 00 
  401280:       48 c7 04 25 c0 02 00    movq   $0x300,0x2c0
  401287:       00 00 03 00 00 
  40128c:       48 c7 04 25 80 02 00    movq   $0x2c0,0x280
  401293:       00 c0 02 00 00 
  401298:       48 c7 04 25 40 02 00    movq   $0x280,0x240
  40129f:       00 80 02 00 00 
  4012a4:       48 c7 04 25 00 02 00    movq   $0x240,0x200
  4012ab:       00 40 02 00 00 
  4012b0:       48 c7 04 25 c0 01 00    movq   $0x200,0x1c0
  4012b7:       00 00 02 00 00 
  4012bc:       48 c7 04 25 80 01 00    movq   $0x1c0,0x180
  4012c3:       00 c0 01 00 00 
  4012c8:       48 c7 04 25 40 01 00    movq   $0x180,0x140
  4012cf:       00 80 01 00 00 
  4012d4:       48 c7 04 25 00 01 00    movq   $0x140,0x100
  4012db:       00 40 01 00 00 
  4012e0:       48 c7 04 25 c0 00 00    movq   $0x100,0xc0
  4012e7:       00 00 01 00 00 
  4012ec:       48 c7 04 25 80 00 00    movq   $0xc0,0x80
  4012f3:       00 c0 00 00 00 
  4012f8:       48 c7 04 25 40 00 00    movq   $0x80,0x40
  4012ff:       00 80 00 00 00 
  401304:       0f 0b                   ud2    
  401306:       0f 0b                   ud2    

@tomaka
Copy link
Owner Author

tomaka commented Nov 25, 2019

Interestingly but not surprisingly, calling ALLOCATOR.init(0, ...) triggers a pretty big undefined behaviour, which is the reason why this was wrong.

However I'm now getting linking errors again after fixing this.

@tomaka
Copy link
Owner Author

tomaka commented Nov 25, 2019

Not sure how to get rid of memcpy, memmove, memcmp, memset, fmod and fmodf.

@tomaka
Copy link
Owner Author

tomaka commented Nov 27, 2019

The state of that is that it boots just fine. However once we start interpreting WASM code, in debug mode we get a panic (which I haven't identified yet), while in release mode we get undefined behaviours.

@tomaka
Copy link
Owner Author

tomaka commented Nov 27, 2019

Update: increased the stack size (it was only 8kiB), and now getting allocation errors from slab_allocator, in both debug and release.

Increasing the stack size seems to have fixed all the undefined behaviours.

@tomaka
Copy link
Owner Author

tomaka commented Nov 27, 2019

Using linked_list_allocator fixed the panics in the allocator.

@tomaka
Copy link
Owner Author

tomaka commented Nov 27, 2019

I reverted the two dependabot commits, as things don't compile anymore on no_std after the version bumps.

@tomaka
Copy link
Owner Author

tomaka commented Nov 27, 2019

This is now ready for merging after clean up.

@tomaka
Copy link
Owner Author

tomaka commented Nov 27, 2019

Some issues to open after merging:

  • We just assume that 1G pages are supported by the CPU, but this isn't necessarily the case. Most notably QEMU doesn't set the appropriate flag in the CPUID (but still supports them), while BOCHS has them disabled by default.
  • We only identity-map the first 4GiB rather than 512GiB as expected, because the paging code is wrong.
  • There's no stack protection. In case of a stack overflow, bad things happen.
  • The heap is initialized to a local array. This works, but it should be dynamic. Also, increasing the heap size seems to make rustc crash, which isn't great.
  • The cleanness of the standalone kernel code is debatable and needs improvements.
  • qemu -cdrom ... works but qemu -kernel ... produces garbage. I'm not even sure that the entry point is being called at all.

@tomaka tomaka merged commit 944f88f into master Nov 27, 2019
@tomaka tomaka deleted the no-std-core branch November 27, 2019 19:55
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

Successfully merging this pull request may close these issues.

1 participant